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" |
8 #include "ui/aura/event_filter.h" | 9 #include "ui/aura/event_filter.h" |
9 #include "ui/views/bubble/bubble_delegate.h" | 10 #include "ui/views/bubble/bubble_delegate.h" |
10 | 11 |
11 namespace aura { | 12 namespace aura { |
12 class LocatedEvent; | 13 class LocatedEvent; |
13 } | 14 } |
14 | 15 |
15 namespace views { | 16 namespace views { |
16 class View; | 17 class View; |
17 class Widget; | 18 class Widget; |
18 } | 19 } |
19 | 20 |
20 namespace ash { | 21 namespace ash { |
21 namespace internal { | 22 namespace internal { |
22 | 23 |
23 // Specialized bubble view for status area tray bubbles. | 24 // Specialized bubble view for status area tray bubbles. |
24 // Mostly this handles custom anchor location and arrow and border rendering. | 25 // Mostly this handles custom anchor location and arrow and border rendering. |
25 class TrayBubbleView : public views::BubbleDelegateView { | 26 class TrayBubbleView : public views::BubbleDelegateView { |
26 public: | 27 public: |
| 28 enum AnchorType { |
| 29 ANCHOR_TYPE_TRAY, |
| 30 ANCHOR_TYPE_BUBBLE |
| 31 }; |
| 32 |
27 class Host : public aura::EventFilter { | 33 class Host : public aura::EventFilter { |
28 public: | 34 public: |
29 Host(); | 35 Host(); |
30 virtual ~Host(); | 36 virtual ~Host(); |
31 | 37 |
32 void InitializeHost(views::Widget* widget, views::View* tray_view); | 38 // Set widget_ and tray_view_, set up animations, and show the bubble. |
| 39 // Must occur after bubble_view->CreateBubble() is called. |
| 40 void InitializeAndShowBubble(views::Widget* widget, |
| 41 TrayBubbleView* bubble_view, |
| 42 views::View* tray_view); |
33 | 43 |
34 virtual void BubbleViewDestroyed() = 0; | 44 virtual void BubbleViewDestroyed() = 0; |
35 virtual gfx::Rect GetAnchorRect() const = 0; | |
36 virtual void OnMouseEnteredView() = 0; | 45 virtual void OnMouseEnteredView() = 0; |
37 virtual void OnMouseExitedView() = 0; | 46 virtual void OnMouseExitedView() = 0; |
38 virtual void OnClickedOutsideView() = 0; | 47 virtual void OnClickedOutsideView() = 0; |
39 | 48 |
40 // Overridden from aura::EventFilter. | 49 // Overridden from aura::EventFilter. |
41 virtual bool PreHandleKeyEvent(aura::Window* target, | 50 virtual bool PreHandleKeyEvent(aura::Window* target, |
42 aura::KeyEvent* event) OVERRIDE; | 51 aura::KeyEvent* event) OVERRIDE; |
43 virtual bool PreHandleMouseEvent(aura::Window* target, | 52 virtual bool PreHandleMouseEvent(aura::Window* target, |
44 aura::MouseEvent* event) OVERRIDE; | 53 aura::MouseEvent* event) OVERRIDE; |
45 virtual ui::TouchStatus PreHandleTouchEvent( | 54 virtual ui::TouchStatus PreHandleTouchEvent( |
46 aura::Window* target, | 55 aura::Window* target, |
47 aura::TouchEvent* event) OVERRIDE; | 56 aura::TouchEvent* event) OVERRIDE; |
48 virtual ui::GestureStatus PreHandleGestureEvent( | 57 virtual ui::GestureStatus PreHandleGestureEvent( |
49 aura::Window* target, | 58 aura::Window* target, |
50 aura::GestureEvent* event) OVERRIDE; | 59 aura::GestureEvent* event) OVERRIDE; |
51 | 60 |
52 private: | 61 private: |
53 void ProcessLocatedEvent(const aura::LocatedEvent& event); | 62 void ProcessLocatedEvent(const aura::LocatedEvent& event); |
54 | 63 |
55 views::Widget* widget_; | 64 views::Widget* widget_; |
56 views::View* tray_view_; | 65 views::View* tray_view_; |
57 | 66 |
58 DISALLOW_COPY_AND_ASSIGN(Host); | 67 DISALLOW_COPY_AND_ASSIGN(Host); |
59 }; | 68 }; |
60 | 69 |
61 TrayBubbleView(views::View* anchor, | 70 struct InitParams { |
62 views::BubbleBorder::ArrowLocation arrow_location, | 71 static const int kArrowDefaultOffset; |
63 Host* host, | 72 |
64 bool can_activate, | 73 InitParams(AnchorType anchor_type, |
65 int bubble_width); | 74 ShelfAlignment shelf_alignment); |
| 75 AnchorType anchor_type; |
| 76 ShelfAlignment shelf_alignment; |
| 77 int bubble_width; |
| 78 int max_height; |
| 79 bool can_activate; |
| 80 int arrow_offset; |
| 81 SkColor arrow_color; |
| 82 }; |
| 83 |
| 84 static TrayBubbleView* Create(views::View* anchor, |
| 85 Host* host, |
| 86 const InitParams& init_params); |
| 87 |
66 virtual ~TrayBubbleView(); | 88 virtual ~TrayBubbleView(); |
67 | 89 |
68 // Creates a bubble border with the specified arrow offset. | 90 // Called whenever the bubble size or location may have changed. |
69 void SetBubbleBorder(int arrow_offset); | |
70 | |
71 // Called whenever the bubble size or location may have moved. | |
72 void UpdateBubble(); | 91 void UpdateBubble(); |
73 | 92 |
74 // Sets the maximum bubble height and resizes the bubble. | 93 // Sets the maximum bubble height and resizes the bubble. |
75 void SetMaxHeight(int height); | 94 void SetMaxHeight(int height); |
76 | 95 |
77 // Called when the host is destroyed. | 96 // Called when the host is destroyed. |
78 void reset_host() { host_ = NULL; } | 97 void reset_host() { host_ = NULL; } |
79 | 98 |
80 // Overridden from views::WidgetDelegate. | 99 // Overridden from views::WidgetDelegate. |
81 virtual bool CanActivate() const OVERRIDE; | 100 virtual bool CanActivate() const OVERRIDE; |
| 101 virtual views::NonClientFrameView* CreateNonClientFrameView( |
| 102 views::Widget* widget) OVERRIDE; |
82 | 103 |
83 // Overridden from views::BubbleDelegateView. | 104 // Overridden from views::BubbleDelegateView. |
84 virtual gfx::Rect GetAnchorRect() OVERRIDE; | 105 virtual gfx::Rect GetAnchorRect() OVERRIDE; |
85 | 106 |
86 // Overridden from views::View. | 107 // Overridden from views::View. |
87 virtual gfx::Size GetPreferredSize() OVERRIDE; | 108 virtual gfx::Size GetPreferredSize() OVERRIDE; |
88 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE; | 109 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE; |
89 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; | 110 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; |
90 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | 111 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
91 | 112 |
92 protected: | 113 protected: |
| 114 TrayBubbleView(const InitParams& init_params, |
| 115 views::BubbleBorder::ArrowLocation arrow_location, |
| 116 views::View* anchor, |
| 117 Host* host); |
| 118 |
93 // Overridden from views::BubbleDelegateView. | 119 // Overridden from views::BubbleDelegateView. |
94 virtual void Init() OVERRIDE; | 120 virtual void Init() OVERRIDE; |
95 virtual gfx::Rect GetBubbleBounds() OVERRIDE; | 121 virtual gfx::Rect GetBubbleBounds() OVERRIDE; |
96 | 122 |
97 // Overridden from views::View. | 123 // Overridden from views::View. |
98 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; | 124 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; |
99 virtual void ViewHierarchyChanged(bool is_add, | 125 virtual void ViewHierarchyChanged(bool is_add, |
100 views::View* parent, | 126 views::View* parent, |
101 views::View* child) OVERRIDE; | 127 views::View* child) OVERRIDE; |
102 | 128 |
103 private: | 129 private: |
| 130 InitParams params_; |
104 Host* host_; | 131 Host* host_; |
105 bool can_activate_; | |
106 int max_height_; | |
107 int bubble_width_; | |
108 | 132 |
109 DISALLOW_COPY_AND_ASSIGN(TrayBubbleView); | 133 DISALLOW_COPY_AND_ASSIGN(TrayBubbleView); |
110 }; | 134 }; |
111 | 135 |
112 } // namespace internal | 136 } // namespace internal |
113 } // namespace ash | 137 } // namespace ash |
114 | 138 |
115 #endif // ASH_SYSTEM_TRAY_TRAY_BUBBLE_VIEW_H_ | 139 #endif // ASH_SYSTEM_TRAY_TRAY_BUBBLE_VIEW_H_ |
OLD | NEW |