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 ASH_SYSTEM_TRAY_TRAY_BUBBLE_VIEW_H_ | 5 #ifndef ASH_SYSTEM_TRAY_TRAY_BUBBLE_VIEW_H_ |
| 6 #define ASH_SYSTEM_TRAY_TRAY_BUBBLE_VIEW_H_ | 6 #define ASH_SYSTEM_TRAY_TRAY_BUBBLE_VIEW_H_ |
| 7 | 7 |
| 8 #include "ash/wm/shelf_types.h" | |
| 9 #include "ui/aura/event_filter.h" | |
| 10 #include "ui/views/bubble/bubble_delegate.h" | 8 #include "ui/views/bubble/bubble_delegate.h" |
| 11 | 9 |
| 12 namespace ui { | 10 namespace ui { |
| 13 class LocatedEvent; | 11 class LocatedEvent; |
| 14 } | 12 } |
| 15 | 13 |
| 16 namespace views { | 14 namespace views { |
| 17 class View; | 15 class View; |
| 18 class Widget; | 16 class Widget; |
| 19 } | 17 } |
| 20 | 18 |
| 21 namespace ash { | 19 namespace ash { |
| 22 namespace internal { | |
| 23 | 20 |
| 24 class TrayBubbleBorder; | 21 class TrayBubbleBorder; |
| 25 class TrayBubbleBackground; | 22 class TrayBubbleBackground; |
| 26 | 23 |
| 27 // Specialized bubble view for status area tray bubbles. | 24 // Specialized bubble view for status area tray bubbles. |
| 28 // Mostly this handles custom anchor location and arrow and border rendering. | 25 // Mostly this handles custom anchor location and arrow and border rendering. |
| 29 class TrayBubbleView : public views::BubbleDelegateView { | 26 class TrayBubbleView : public views::BubbleDelegateView { |
| 30 public: | 27 public: |
| 31 enum AnchorType { | 28 enum AnchorType { |
| 32 ANCHOR_TYPE_TRAY, | 29 ANCHOR_TYPE_TRAY, |
| 33 ANCHOR_TYPE_BUBBLE | 30 ANCHOR_TYPE_BUBBLE |
| 34 }; | 31 }; |
| 35 | 32 |
| 36 class Host : public aura::EventFilter { | 33 enum AnchorAlignment { |
| 34 ANCHOR_ALIGNMENT_BOTTOM, | |
| 35 ANCHOR_ALIGNMENT_LEFT, | |
| 36 ANCHOR_ALIGNMENT_RIGHT | |
| 37 }; | |
| 38 | |
| 39 class Delegate { | |
| 37 public: | 40 public: |
| 38 Host(); | 41 typedef TrayBubbleView::AnchorType AnchorType; |
| 39 virtual ~Host(); | 42 typedef TrayBubbleView::AnchorAlignment AnchorAlignment; |
| 40 | 43 |
| 41 // Set widget_ and tray_view_, set up animations, and show the bubble. | 44 Delegate() {} |
| 42 // Must occur after bubble_view->CreateBubble() is called. | 45 virtual ~Delegate() {} |
| 43 void InitializeAndShowBubble(views::Widget* widget, | |
| 44 TrayBubbleView* bubble_view, | |
| 45 views::View* tray_view); | |
| 46 | 46 |
| 47 virtual void BubbleViewDestroyed() = 0; | 47 virtual void BubbleViewDestroyed() = 0; |
| 48 virtual void OnMouseEnteredView() = 0; | 48 virtual void OnMouseEnteredView() = 0; |
| 49 virtual void OnMouseExitedView() = 0; | 49 virtual void OnMouseExitedView() = 0; |
| 50 virtual void OnClickedOutsideView() = 0; | |
| 51 virtual string16 GetAccessibleName() = 0; | 50 virtual string16 GetAccessibleName() = 0; |
| 52 | 51 virtual gfx::Rect GetAnchorRect(views::Widget* anchor_widget, |
| 53 // Overridden from aura::EventFilter. | 52 AnchorType anchor_type, |
| 54 virtual bool PreHandleKeyEvent(aura::Window* target, | 53 AnchorAlignment anchor_alignment) = 0; |
| 55 ui::KeyEvent* event) OVERRIDE; | |
| 56 virtual bool PreHandleMouseEvent(aura::Window* target, | |
| 57 ui::MouseEvent* event) OVERRIDE; | |
| 58 virtual ui::TouchStatus PreHandleTouchEvent( | |
| 59 aura::Window* target, | |
| 60 ui::TouchEvent* event) OVERRIDE; | |
| 61 virtual ui::EventResult PreHandleGestureEvent( | |
| 62 aura::Window* target, | |
| 63 ui::GestureEvent* event) OVERRIDE; | |
| 64 | 54 |
| 65 private: | 55 private: |
| 66 void ProcessLocatedEvent(aura::Window* target, | 56 DISALLOW_COPY_AND_ASSIGN(Delegate); |
| 67 const ui::LocatedEvent& event); | |
| 68 | |
| 69 views::Widget* widget_; | |
| 70 TrayBubbleView* bubble_view_; | |
| 71 views::View* tray_view_; | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(Host); | |
| 74 }; | 57 }; |
| 75 | 58 |
| 76 struct InitParams { | 59 struct InitParams { |
| 77 static const int kArrowDefaultOffset; | 60 static const int kArrowDefaultOffset; |
| 78 | 61 |
| 79 InitParams(AnchorType anchor_type, | 62 InitParams(AnchorType anchor_type, |
| 80 ShelfAlignment shelf_alignment); | 63 AnchorAlignment anchor_alignment, |
| 64 int bubble_width); | |
| 81 AnchorType anchor_type; | 65 AnchorType anchor_type; |
| 82 ShelfAlignment shelf_alignment; | 66 AnchorAlignment anchor_alignment; |
| 83 int bubble_width; | 67 int bubble_width; |
| 84 int max_height; | 68 int max_height; |
| 85 bool can_activate; | 69 bool can_activate; |
| 86 bool close_on_deactivate; | 70 bool close_on_deactivate; |
| 87 SkColor top_color; | 71 SkColor top_color; |
| 88 SkColor arrow_color; | 72 SkColor arrow_color; |
| 73 views::BubbleBorder::ArrowLocation arrow_location; | |
| 89 int arrow_offset; | 74 int arrow_offset; |
| 90 views::BubbleBorder::Shadow shadow; | 75 views::BubbleBorder::Shadow shadow; |
| 91 }; | 76 }; |
| 92 | 77 |
| 93 static TrayBubbleView* Create(views::View* anchor, | 78 // Constructs and returns a TrayBubbleView. init_params may be modified. |
| 94 Host* host, | 79 static TrayBubbleView* Create(aura::Window* parent_window, |
| 95 const InitParams& init_params); | 80 views::View* anchor, |
| 81 Delegate* delegate, | |
| 82 InitParams* init_params); | |
| 96 | 83 |
| 97 virtual ~TrayBubbleView(); | 84 virtual ~TrayBubbleView(); |
| 98 | 85 |
| 86 // Set up animations, and show the bubble. Must occur after CreateBubble() | |
| 87 // is called. | |
|
jennyz
2012/10/12 23:05:34
Set->Sets
stevenjb
2012/10/12 23:41:50
Done.
| |
| 88 void InitializeAndShowBubble(views::Widget* widget); | |
| 89 | |
| 99 // Called whenever the bubble size or location may have changed. | 90 // Called whenever the bubble size or location may have changed. |
| 100 void UpdateBubble(); | 91 void UpdateBubble(); |
| 101 | 92 |
| 102 // Sets the maximum bubble height and resizes the bubble. | 93 // Sets the maximum bubble height and resizes the bubble. |
| 103 void SetMaxHeight(int height); | 94 void SetMaxHeight(int height); |
| 104 | 95 |
| 105 // Called when the host is destroyed. | 96 // Return the border insets. Called by TrayEventFilter. |
|
jennyz
2012/10/12 23:05:34
Return->Returns
stevenjb
2012/10/12 23:41:50
Done.
| |
| 106 void reset_host() { host_ = NULL; } | 97 void GetBorderInsets(gfx::Insets* insets) const; |
| 98 | |
| 99 // Called when the delegate is destroyed. | |
| 100 void reset_delegate() { delegate_ = NULL; } | |
| 107 | 101 |
| 108 void set_gesture_dragging(bool dragging) { is_gesture_dragging_ = dragging; } | 102 void set_gesture_dragging(bool dragging) { is_gesture_dragging_ = dragging; } |
| 109 bool is_gesture_dragging() const { return is_gesture_dragging_; } | 103 bool is_gesture_dragging() const { return is_gesture_dragging_; } |
| 110 | 104 |
| 111 TrayBubbleBorder* bubble_border() { return bubble_border_; } | |
| 112 | |
| 113 // Overridden from views::WidgetDelegate. | 105 // Overridden from views::WidgetDelegate. |
| 114 virtual bool CanActivate() const OVERRIDE; | 106 virtual bool CanActivate() const OVERRIDE; |
| 115 virtual views::NonClientFrameView* CreateNonClientFrameView( | 107 virtual views::NonClientFrameView* CreateNonClientFrameView( |
| 116 views::Widget* widget) OVERRIDE; | 108 views::Widget* widget) OVERRIDE; |
| 117 virtual bool WidgetHasHitTestMask() const OVERRIDE; | 109 virtual bool WidgetHasHitTestMask() const OVERRIDE; |
| 118 virtual void GetWidgetHitTestMask(gfx::Path* mask) const OVERRIDE; | 110 virtual void GetWidgetHitTestMask(gfx::Path* mask) const OVERRIDE; |
| 119 | 111 |
| 120 // Overridden from views::BubbleDelegateView. | 112 // Overridden from views::BubbleDelegateView. |
| 121 virtual gfx::Rect GetAnchorRect() OVERRIDE; | 113 virtual gfx::Rect GetAnchorRect() OVERRIDE; |
| 122 | 114 |
| 123 // Overridden from views::View. | 115 // Overridden from views::View. |
| 124 virtual gfx::Size GetPreferredSize() OVERRIDE; | 116 virtual gfx::Size GetPreferredSize() OVERRIDE; |
| 125 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; | 117 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; |
| 126 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; | 118 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; |
| 127 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | 119 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
| 128 | 120 |
| 129 protected: | 121 protected: |
| 130 TrayBubbleView(const InitParams& init_params, | 122 TrayBubbleView(aura::Window* parent_window, |
| 131 views::BubbleBorder::ArrowLocation arrow_location, | |
| 132 views::View* anchor, | 123 views::View* anchor, |
| 133 Host* host); | 124 Delegate* delegate, |
| 125 const InitParams& init_params); | |
| 134 | 126 |
| 135 // Overridden from views::BubbleDelegateView. | 127 // Overridden from views::BubbleDelegateView. |
| 136 virtual void Init() OVERRIDE; | 128 virtual void Init() OVERRIDE; |
| 137 | 129 |
| 138 // Overridden from views::View. | 130 // Overridden from views::View. |
| 139 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; | 131 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; |
| 140 virtual void ViewHierarchyChanged(bool is_add, | 132 virtual void ViewHierarchyChanged(bool is_add, |
| 141 views::View* parent, | 133 views::View* parent, |
| 142 views::View* child) OVERRIDE; | 134 views::View* child) OVERRIDE; |
| 143 | 135 |
| 144 private: | 136 private: |
| 145 InitParams params_; | 137 InitParams params_; |
| 146 Host* host_; | 138 Delegate* delegate_; |
| 147 TrayBubbleBorder* bubble_border_; | 139 TrayBubbleBorder* bubble_border_; |
| 148 TrayBubbleBackground* bubble_background_; | 140 TrayBubbleBackground* bubble_background_; |
| 149 bool is_gesture_dragging_; | 141 bool is_gesture_dragging_; |
| 150 | 142 |
| 151 DISALLOW_COPY_AND_ASSIGN(TrayBubbleView); | 143 DISALLOW_COPY_AND_ASSIGN(TrayBubbleView); |
| 152 }; | 144 }; |
| 153 | 145 |
| 154 } // namespace internal | |
| 155 } // namespace ash | 146 } // namespace ash |
| 156 | 147 |
| 157 #endif // ASH_SYSTEM_TRAY_TRAY_BUBBLE_VIEW_H_ | 148 #endif // ASH_SYSTEM_TRAY_TRAY_BUBBLE_VIEW_H_ |
| OLD | NEW |