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