Yulun Wu | 9310ee3 | 2020-02-26 01:49:00 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef ASH_SHELF_CONTEXTUAL_NUDGE_H_ |
| 6 | #define ASH_SHELF_CONTEXTUAL_NUDGE_H_ |
| 7 | |
| 8 | #include "ash/ash_export.h" |
Toni Barzic | 0f6eb8cc | 2020-03-11 16:39:02 | [diff] [blame] | 9 | #include "base/callback.h" |
Yulun Wu | 9310ee3 | 2020-02-26 01:49:00 | [diff] [blame] | 10 | #include "ui/views/bubble/bubble_dialog_delegate_view.h" |
| 11 | #include "ui/views/controls/label.h" |
| 12 | |
| 13 | namespace views { |
| 14 | class View; |
| 15 | } // namespace views |
| 16 | |
| 17 | namespace ash { |
| 18 | |
| 19 | // The implementation of contextual nudge tooltip bubbles. |
| 20 | class ASH_EXPORT ContextualNudge : public views::BubbleDialogDelegateView { |
| 21 | public: |
Toni Barzic | 1a51c14 | 2020-02-26 22:04:54 | [diff] [blame] | 22 | // Indicates whether the nudge should be shown below or above the anchor. |
| 23 | enum class Position { kBottom, kTop }; |
| 24 | |
| 25 | // |anchor| - The view to which the nudge bubble should be anchored. May be |
| 26 | // nullptr, in which case anchor bounds should be provided using |
| 27 | // UpdateAnchorRect(). |
| 28 | // |parent_window| - if set, the window that should parent the nudge native |
| 29 | // window. If not set, the shelf container in the anchor view's root |
| 30 | // window will be used. |
Toni Barzic | 1a51c14 | 2020-02-26 22:04:54 | [diff] [blame] | 31 | // |position| - The nudge position relative to the anchor rectangle. |
Toni Barzic | 4ebccb50 | 2020-02-28 16:00:40 | [diff] [blame] | 32 | // |margins| - The margins added to the nudge bubble. |
| 33 | // |text| - The nudge text. |
| 34 | // |text_color| - The nudge text label foreground color. |
Toni Barzic | 0f6eb8cc | 2020-03-11 16:39:02 | [diff] [blame] | 35 | // |tap_callback| - If set, the callback called when the user taps the nuge. |
Toni Barzic | 1a51c14 | 2020-02-26 22:04:54 | [diff] [blame] | 36 | ContextualNudge(views::View* anchor, |
| 37 | aura::Window* parent_window, |
Toni Barzic | 4ebccb50 | 2020-02-28 16:00:40 | [diff] [blame] | 38 | Position position, |
| 39 | const gfx::Insets& margins, |
Jan Wilken Dörrie | 85285b0 | 2021-03-11 23:38:47 | [diff] [blame^] | 40 | const std::u16string& text, |
Toni Barzic | 0f6eb8cc | 2020-03-11 16:39:02 | [diff] [blame] | 41 | SkColor text_color, |
| 42 | const base::RepeatingClosure& tap_callback); |
Yulun Wu | 9310ee3 | 2020-02-26 01:49:00 | [diff] [blame] | 43 | ~ContextualNudge() override; |
| 44 | |
| 45 | ContextualNudge(const ContextualNudge&) = delete; |
| 46 | ContextualNudge& operator=(const ContextualNudge&) = delete; |
| 47 | |
| 48 | views::Label* label() { return label_; } |
| 49 | |
Toni Barzic | 1a51c14 | 2020-02-26 22:04:54 | [diff] [blame] | 50 | // Sets the nudge bubble anchor rect - should be used to set the anchor rect |
| 51 | // if no valid anchor was passed to the nudge bubble. |
| 52 | void UpdateAnchorRect(const gfx::Rect& rect); |
| 53 | |
Yulun Wu | 9310ee3 | 2020-02-26 01:49:00 | [diff] [blame] | 54 | // BubbleDialogDelegateView: |
Yulun Wu | 9310ee3 | 2020-02-26 01:49:00 | [diff] [blame] | 55 | ui::LayerType GetLayerType() const override; |
Toni Barzic | 0f6eb8cc | 2020-03-11 16:39:02 | [diff] [blame] | 56 | void OnGestureEvent(ui::GestureEvent* event) override; |
Yulun Wu | 9310ee3 | 2020-02-26 01:49:00 | [diff] [blame] | 57 | |
| 58 | private: |
Toni Barzic | 0f6eb8cc | 2020-03-11 16:39:02 | [diff] [blame] | 59 | base::RepeatingClosure tap_callback_; |
| 60 | |
Yulun Wu | 9310ee3 | 2020-02-26 01:49:00 | [diff] [blame] | 61 | views::Label* label_; |
| 62 | }; |
| 63 | |
| 64 | } // namespace ash |
| 65 | |
| 66 | #endif // ASH_SHELF_CONTEXTUAL_NUDGE_H_ |