Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_VIEWS_BUBBLE_TRAY_BUBBLE_VIEW_H_ | 5 #ifndef UI_VIEWS_BUBBLE_TRAY_BUBBLE_VIEW_H_ |
| 6 #define UI_VIEWS_BUBBLE_TRAY_BUBBLE_VIEW_H_ | 6 #define UI_VIEWS_BUBBLE_TRAY_BUBBLE_VIEW_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "ui/views/bubble/bubble_dialog_delegate.h" | 11 #include "ui/views/bubble/bubble_dialog_delegate.h" |
| 12 #include "ui/views/mouse_watcher.h" | 12 #include "ui/views/mouse_watcher.h" |
| 13 #include "ui/views/views_export.h" | 13 #include "ui/views/views_export.h" |
| 14 | 14 |
| 15 namespace views { | 15 namespace views { |
| 16 class View; | 16 class View; |
| 17 class Widget; | 17 class Widget; |
| 18 } | 18 } |
| 19 | 19 |
| 20 namespace views { | 20 namespace views { |
| 21 | 21 |
| 22 namespace internal { | 22 namespace internal { |
| 23 class TrayBubbleBorder; | 23 class TrayBubbleBorder; |
|
msw
2016/11/15 02:59:38
remove
Evan Stade
2016/11/15 17:01:29
Done.
| |
| 24 class TrayBubbleContentMask; | 24 class TrayBubbleContentMask; |
| 25 } | 25 } |
| 26 | 26 |
| 27 // Specialized bubble view for bubbles associated with a tray icon (e.g. the | 27 // Specialized bubble view for bubbles associated with a tray icon (e.g. the |
| 28 // Ash status area). Mostly this handles custom anchor location and arrow and | 28 // Ash status area). Mostly this handles custom anchor location and arrow and |
| 29 // border rendering. This also has its own delegate for handling mouse events | 29 // border rendering. This also has its own delegate for handling mouse events |
| 30 // and other implementation specific details. | 30 // and other implementation specific details. |
| 31 class VIEWS_EXPORT TrayBubbleView : public views::BubbleDialogDelegateView, | 31 class VIEWS_EXPORT TrayBubbleView : public views::BubbleDialogDelegateView, |
| 32 public views::MouseWatcherListener { | 32 public views::MouseWatcherListener { |
| 33 public: | 33 public: |
| 34 // AnchorType differentiates between bubbles that are anchored on a tray | |
| 35 // element (ANCHOR_TYPE_TRAY) and display an arrow, or that are floating on | |
| 36 // the screen away from the tray (ANCHOR_TYPE_BUBBLE). | |
| 37 enum AnchorType { | |
| 38 ANCHOR_TYPE_TRAY, | |
| 39 ANCHOR_TYPE_BUBBLE, | |
| 40 }; | |
| 41 | |
| 42 // AnchorAlignment determines to which side of the anchor the bubble will | 34 // AnchorAlignment determines to which side of the anchor the bubble will |
| 43 // align itself. | 35 // align itself. |
| 44 enum AnchorAlignment { | 36 enum AnchorAlignment { |
| 45 ANCHOR_ALIGNMENT_BOTTOM, | 37 ANCHOR_ALIGNMENT_BOTTOM, |
| 46 ANCHOR_ALIGNMENT_LEFT, | 38 ANCHOR_ALIGNMENT_LEFT, |
| 47 ANCHOR_ALIGNMENT_RIGHT, | 39 ANCHOR_ALIGNMENT_RIGHT, |
| 48 ANCHOR_ALIGNMENT_TOP | |
| 49 }; | 40 }; |
| 50 | 41 |
| 51 class VIEWS_EXPORT Delegate { | 42 class VIEWS_EXPORT Delegate { |
| 52 public: | 43 public: |
| 53 typedef TrayBubbleView::AnchorType AnchorType; | |
| 54 typedef TrayBubbleView::AnchorAlignment AnchorAlignment; | 44 typedef TrayBubbleView::AnchorAlignment AnchorAlignment; |
| 55 | 45 |
| 56 Delegate() {} | 46 Delegate() {} |
| 57 virtual ~Delegate() {} | 47 virtual ~Delegate() {} |
| 58 | 48 |
| 59 // Called when the view is destroyed. Any pointers to the view should be | 49 // Called when the view is destroyed. Any pointers to the view should be |
| 60 // cleared when this gets called. | 50 // cleared when this gets called. |
| 61 virtual void BubbleViewDestroyed() = 0; | 51 virtual void BubbleViewDestroyed() = 0; |
| 62 | 52 |
| 63 // Called when the mouse enters/exits the view. | 53 // Called when the mouse enters/exits the view. |
| 64 // Note: This event will only be called if the mouse gets actively moved by | 54 // Note: This event will only be called if the mouse gets actively moved by |
| 65 // the user to enter the view. | 55 // the user to enter the view. |
| 66 virtual void OnMouseEnteredView() = 0; | 56 virtual void OnMouseEnteredView() = 0; |
| 67 virtual void OnMouseExitedView() = 0; | 57 virtual void OnMouseExitedView() = 0; |
| 68 | 58 |
| 69 // Called from GetAccessibleNodeData(); should return the appropriate | 59 // Called from GetAccessibleNodeData(); should return the appropriate |
| 70 // accessible name for the bubble. | 60 // accessible name for the bubble. |
| 71 virtual base::string16 GetAccessibleNameForBubble() = 0; | 61 virtual base::string16 GetAccessibleNameForBubble() = 0; |
| 72 | 62 |
| 73 // Passes responsibility for BubbleDialogDelegateView::GetAnchorRect to the | |
| 74 // delegate. | |
| 75 virtual gfx::Rect GetAnchorRect( | |
| 76 views::Widget* anchor_widget, | |
| 77 AnchorType anchor_type, | |
| 78 AnchorAlignment anchor_alignment) const = 0; | |
| 79 | |
| 80 // Called before Widget::Init() on |bubble_widget|. Allows |params| to be | 63 // Called before Widget::Init() on |bubble_widget|. Allows |params| to be |
| 81 // modified. | 64 // modified. |
| 82 virtual void OnBeforeBubbleWidgetInit(Widget* anchor_widget, | 65 virtual void OnBeforeBubbleWidgetInit(Widget* anchor_widget, |
| 83 Widget* bubble_widget, | 66 Widget* bubble_widget, |
| 84 Widget::InitParams* params) const = 0; | 67 Widget::InitParams* params) const = 0; |
| 85 | 68 |
| 86 // Called when a bubble wants to hide/destroy itself (e.g. last visible | 69 // Called when a bubble wants to hide/destroy itself (e.g. last visible |
| 87 // child view was closed). | 70 // child view was closed). |
| 88 virtual void HideBubble(const TrayBubbleView* bubble_view) = 0; | 71 virtual void HideBubble(const TrayBubbleView* bubble_view) = 0; |
| 89 | 72 |
| 90 private: | 73 private: |
| 91 DISALLOW_COPY_AND_ASSIGN(Delegate); | 74 DISALLOW_COPY_AND_ASSIGN(Delegate); |
| 92 }; | 75 }; |
| 93 | 76 |
| 94 struct VIEWS_EXPORT InitParams { | 77 struct VIEWS_EXPORT InitParams { |
| 95 static const int kArrowDefaultOffset; | 78 InitParams(AnchorAlignment anchor_alignment, int min_width, int max_width); |
| 96 | |
| 97 InitParams(AnchorType anchor_type, | |
| 98 AnchorAlignment anchor_alignment, | |
| 99 int min_width, | |
| 100 int max_width); | |
| 101 InitParams(const InitParams& other); | 79 InitParams(const InitParams& other); |
| 102 AnchorType anchor_type; | |
| 103 AnchorAlignment anchor_alignment; | 80 AnchorAlignment anchor_alignment; |
| 104 int min_width; | 81 int min_width; |
| 105 int max_width; | 82 int max_width; |
| 106 int max_height; | 83 int max_height; |
| 107 bool can_activate; | 84 bool can_activate; |
| 108 bool close_on_deactivate; | 85 bool close_on_deactivate; |
| 109 SkColor arrow_color; | 86 SkColor bg_color; |
| 110 bool first_item_has_no_margin; | |
| 111 views::BubbleBorder::Arrow arrow; | |
| 112 int arrow_offset; | |
| 113 views::BubbleBorder::ArrowPaintType arrow_paint_type; | |
| 114 views::BubbleBorder::Shadow shadow; | |
| 115 views::BubbleBorder::BubbleAlignment arrow_alignment; | |
| 116 }; | 87 }; |
| 117 | 88 |
| 118 // Constructs and returns a TrayBubbleView. |init_params| may be modified. | 89 // Constructs and returns a TrayBubbleView. |init_params| may be modified. |
| 119 static TrayBubbleView* Create(views::View* anchor, | 90 static TrayBubbleView* Create(views::View* anchor, |
| 120 Delegate* delegate, | 91 Delegate* delegate, |
| 121 InitParams* init_params); | 92 InitParams* init_params); |
| 122 | 93 |
| 123 ~TrayBubbleView() override; | 94 ~TrayBubbleView() override; |
| 124 | 95 |
| 125 // Sets up animations, and show the bubble. Must occur after CreateBubble() | 96 // Sets up animations, and show the bubble. Must occur after CreateBubble() |
| 126 // is called. | 97 // is called. |
| 127 void InitializeAndShowBubble(); | 98 void InitializeAndShowBubble(); |
| 128 | 99 |
| 129 // Called whenever the bubble size or location may have changed. | 100 // Called whenever the bubble size or location may have changed. |
| 130 void UpdateBubble(); | 101 void UpdateBubble(); |
| 131 | 102 |
| 132 // Sets the maximum bubble height and resizes the bubble. | 103 // Sets the maximum bubble height and resizes the bubble. |
| 133 void SetMaxHeight(int height); | 104 void SetMaxHeight(int height); |
| 134 | 105 |
| 135 // Sets the bubble width. | 106 // Sets the bubble width. |
| 136 void SetWidth(int width); | 107 void SetWidth(int width); |
| 137 | 108 |
| 138 // Sets whether or not to paint the bubble border arrow. | |
| 139 void SetArrowPaintType(views::BubbleBorder::ArrowPaintType arrow_paint_type); | |
| 140 | |
| 141 // Returns the border insets. Called by TrayEventFilter. | 109 // Returns the border insets. Called by TrayEventFilter. |
| 142 gfx::Insets GetBorderInsets() const; | 110 gfx::Insets GetBorderInsets() const; |
| 143 | 111 |
| 144 // Called when the delegate is destroyed. | 112 // Called when the delegate is destroyed. |
| 145 void reset_delegate() { delegate_ = NULL; } | 113 void reset_delegate() { delegate_ = NULL; } |
| 146 | 114 |
| 147 Delegate* delegate() { return delegate_; } | 115 Delegate* delegate() { return delegate_; } |
| 148 | 116 |
| 149 void set_gesture_dragging(bool dragging) { is_gesture_dragging_ = dragging; } | 117 void set_gesture_dragging(bool dragging) { is_gesture_dragging_ = dragging; } |
| 150 bool is_gesture_dragging() const { return is_gesture_dragging_; } | 118 bool is_gesture_dragging() const { return is_gesture_dragging_; } |
| 151 | 119 |
| 152 // Overridden from views::WidgetDelegate. | 120 // Overridden from views::WidgetDelegate. |
| 153 views::NonClientFrameView* CreateNonClientFrameView( | 121 views::NonClientFrameView* CreateNonClientFrameView( |
| 154 views::Widget* widget) override; | 122 views::Widget* widget) override; |
| 155 bool WidgetHasHitTestMask() const override; | 123 bool WidgetHasHitTestMask() const override; |
| 156 void GetWidgetHitTestMask(gfx::Path* mask) const override; | 124 void GetWidgetHitTestMask(gfx::Path* mask) const override; |
| 157 base::string16 GetAccessibleWindowTitle() const override; | 125 base::string16 GetAccessibleWindowTitle() const override; |
| 158 | 126 |
| 159 // Overridden from views::BubbleDialogDelegateView. | 127 // Overridden from views::BubbleDialogDelegateView. |
| 160 gfx::Rect GetAnchorRect() const override; | 128 // gfx::Rect GetAnchorRect() const override; |
|
msw
2016/11/15 02:59:38
Remove
Evan Stade
2016/11/15 17:01:29
Done.
| |
| 161 void OnBeforeBubbleWidgetInit(Widget::InitParams* params, | 129 void OnBeforeBubbleWidgetInit(Widget::InitParams* params, |
| 162 Widget* bubble_widget) const override; | 130 Widget* bubble_widget) const override; |
| 163 | 131 |
| 164 // Overridden from views::View. | 132 // Overridden from views::View. |
| 165 gfx::Size GetPreferredSize() const override; | 133 gfx::Size GetPreferredSize() const override; |
| 166 gfx::Size GetMaximumSize() const override; | 134 gfx::Size GetMaximumSize() const override; |
| 167 int GetHeightForWidth(int width) const override; | 135 int GetHeightForWidth(int width) const override; |
| 168 void OnMouseEntered(const ui::MouseEvent& event) override; | 136 void OnMouseEntered(const ui::MouseEvent& event) override; |
| 169 void OnMouseExited(const ui::MouseEvent& event) override; | 137 void OnMouseExited(const ui::MouseEvent& event) override; |
| 170 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; | 138 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 185 void ChildPreferredSizeChanged(View* child) override; | 153 void ChildPreferredSizeChanged(View* child) override; |
| 186 void ViewHierarchyChanged( | 154 void ViewHierarchyChanged( |
| 187 const ViewHierarchyChangedDetails& details) override; | 155 const ViewHierarchyChangedDetails& details) override; |
| 188 | 156 |
| 189 private: | 157 private: |
| 190 InitParams params_; | 158 InitParams params_; |
| 191 Delegate* delegate_; | 159 Delegate* delegate_; |
| 192 int preferred_width_; | 160 int preferred_width_; |
| 193 // |bubble_border_| and |owned_bubble_border_| point to the same thing, but | 161 // |bubble_border_| and |owned_bubble_border_| point to the same thing, but |
| 194 // the latter ensures we don't leak it before passing off ownership. | 162 // the latter ensures we don't leak it before passing off ownership. |
| 195 internal::TrayBubbleBorder* bubble_border_; | 163 BubbleBorder* bubble_border_; |
| 196 std::unique_ptr<views::BubbleBorder> owned_bubble_border_; | 164 std::unique_ptr<views::BubbleBorder> owned_bubble_border_; |
| 197 std::unique_ptr<internal::TrayBubbleContentMask> bubble_content_mask_; | 165 std::unique_ptr<internal::TrayBubbleContentMask> bubble_content_mask_; |
| 198 bool is_gesture_dragging_; | 166 bool is_gesture_dragging_; |
| 199 | 167 |
| 200 // True once the mouse cursor was actively moved by the user over the bubble. | 168 // True once the mouse cursor was actively moved by the user over the bubble. |
| 201 // Only then the OnMouseExitedView() event will get passed on to listeners. | 169 // Only then the OnMouseExitedView() event will get passed on to listeners. |
| 202 bool mouse_actively_entered_; | 170 bool mouse_actively_entered_; |
| 203 | 171 |
| 204 // Used to find any mouse movements. | 172 // Used to find any mouse movements. |
| 205 std::unique_ptr<MouseWatcher> mouse_watcher_; | 173 std::unique_ptr<MouseWatcher> mouse_watcher_; |
| 206 | 174 |
| 207 DISALLOW_COPY_AND_ASSIGN(TrayBubbleView); | 175 DISALLOW_COPY_AND_ASSIGN(TrayBubbleView); |
| 208 }; | 176 }; |
| 209 | 177 |
| 210 } // namespace views | 178 } // namespace views |
| 211 | 179 |
| 212 #endif // UI_VIEWS_BUBBLE_TRAY_BUBBLE_VIEW_H_ | 180 #endif // UI_VIEWS_BUBBLE_TRAY_BUBBLE_VIEW_H_ |
| OLD | NEW |