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