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