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 void PostCreateBubble(views::Widget* widget, |
msw
2012/07/27 20:32:04
Add a comment; consider renaming InitBubble (natur
stevenjb
2012/07/30 20:09:03
Good suggestion, added comment and renamed Initial
| |
39 TrayBubbleView* bubble_view, | |
40 views::View* tray_view); | |
33 | 41 |
34 virtual void BubbleViewDestroyed() = 0; | 42 virtual void BubbleViewDestroyed() = 0; |
35 virtual gfx::Rect GetAnchorRect() const = 0; | |
36 virtual void OnMouseEnteredView() = 0; | 43 virtual void OnMouseEnteredView() = 0; |
37 virtual void OnMouseExitedView() = 0; | 44 virtual void OnMouseExitedView() = 0; |
38 virtual void OnClickedOutsideView() = 0; | 45 virtual void OnClickedOutsideView() = 0; |
39 | 46 |
40 // Overridden from aura::EventFilter. | 47 // Overridden from aura::EventFilter. |
41 virtual bool PreHandleKeyEvent(aura::Window* target, | 48 virtual bool PreHandleKeyEvent(aura::Window* target, |
42 aura::KeyEvent* event) OVERRIDE; | 49 aura::KeyEvent* event) OVERRIDE; |
43 virtual bool PreHandleMouseEvent(aura::Window* target, | 50 virtual bool PreHandleMouseEvent(aura::Window* target, |
44 aura::MouseEvent* event) OVERRIDE; | 51 aura::MouseEvent* event) OVERRIDE; |
45 virtual ui::TouchStatus PreHandleTouchEvent( | 52 virtual ui::TouchStatus PreHandleTouchEvent( |
46 aura::Window* target, | 53 aura::Window* target, |
47 aura::TouchEvent* event) OVERRIDE; | 54 aura::TouchEvent* event) OVERRIDE; |
48 virtual ui::GestureStatus PreHandleGestureEvent( | 55 virtual ui::GestureStatus PreHandleGestureEvent( |
49 aura::Window* target, | 56 aura::Window* target, |
50 aura::GestureEvent* event) OVERRIDE; | 57 aura::GestureEvent* event) OVERRIDE; |
51 | 58 |
52 private: | 59 private: |
53 void ProcessLocatedEvent(const aura::LocatedEvent& event); | 60 void ProcessLocatedEvent(const aura::LocatedEvent& event); |
54 | 61 |
55 views::Widget* widget_; | 62 views::Widget* widget_; |
56 views::View* tray_view_; | 63 views::View* tray_view_; |
57 | 64 |
58 DISALLOW_COPY_AND_ASSIGN(Host); | 65 DISALLOW_COPY_AND_ASSIGN(Host); |
59 }; | 66 }; |
60 | 67 |
61 TrayBubbleView(views::View* anchor, | 68 struct InitParams { |
62 views::BubbleBorder::ArrowLocation arrow_location, | 69 static const int kArrowDefaultOffset; |
63 Host* host, | 70 |
64 bool can_activate, | 71 InitParams(AnchorType anchor_type, |
65 int bubble_width); | 72 ShelfAlignment shelf_alignment); |
73 AnchorType anchor_type; | |
74 ShelfAlignment shelf_alignment; | |
75 int bubble_width; | |
76 int max_height; | |
77 bool can_activate; | |
78 int arrow_offset; | |
79 SkColor arrow_color; | |
80 }; | |
81 | |
82 static TrayBubbleView* Create(views::View* anchor, | |
83 Host* host, | |
84 const InitParams& init_params); | |
85 | |
66 virtual ~TrayBubbleView(); | 86 virtual ~TrayBubbleView(); |
67 | 87 |
68 // Creates a bubble border with the specified arrow offset. | 88 // Called whenever the bubble size or location may have moved. |
msw
2012/07/27 20:32:04
nit: s/moved/changed/
stevenjb
2012/07/30 20:09:03
Done.
| |
69 void SetBubbleBorder(int arrow_offset); | 89 void UpdateBubble(); |
70 | |
71 // Called whenever the bubble anchor location may have moved. | |
72 void UpdateAnchor(); | |
73 | 90 |
74 // Sets the maximum bubble height and resizes the bubble. | 91 // Sets the maximum bubble height and resizes the bubble. |
75 void SetMaxHeight(int height); | 92 void SetMaxHeight(int height); |
76 | 93 |
77 // Called when the host is destroyed. | 94 // Called when the host is destroyed. |
78 void reset_host() { host_ = NULL; } | 95 void reset_host() { host_ = NULL; } |
79 | 96 |
80 // Overridden from views::WidgetDelegate. | 97 // Overridden from views::WidgetDelegate. |
81 virtual bool CanActivate() const OVERRIDE; | 98 virtual bool CanActivate() const OVERRIDE; |
99 virtual views::NonClientFrameView* CreateNonClientFrameView( | |
100 views::Widget* widget) OVERRIDE; | |
82 | 101 |
83 // Overridden from views::BubbleDelegateView. | 102 // Overridden from views::BubbleDelegateView. |
84 virtual gfx::Rect GetAnchorRect() OVERRIDE; | 103 virtual gfx::Rect GetAnchorRect() OVERRIDE; |
85 | 104 |
86 // Overridden from views::View. | 105 // Overridden from views::View. |
87 virtual gfx::Size GetPreferredSize() OVERRIDE; | 106 virtual gfx::Size GetPreferredSize() OVERRIDE; |
88 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE; | 107 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE; |
89 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; | 108 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; |
90 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | 109 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
91 | 110 |
92 protected: | 111 protected: |
112 TrayBubbleView(const InitParams& init_params, | |
113 views::BubbleBorder::ArrowLocation arrow_location, | |
114 views::View* anchor, | |
115 Host* host); | |
116 | |
93 // Overridden from views::BubbleDelegateView. | 117 // Overridden from views::BubbleDelegateView. |
94 virtual void Init() OVERRIDE; | 118 virtual void Init() OVERRIDE; |
95 virtual gfx::Rect GetBubbleBounds() OVERRIDE; | 119 virtual gfx::Rect GetBubbleBounds() OVERRIDE; |
96 | 120 |
97 // Overridden from views::View. | 121 // Overridden from views::View. |
98 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; | 122 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; |
99 virtual void ViewHierarchyChanged(bool is_add, | 123 virtual void ViewHierarchyChanged(bool is_add, |
100 views::View* parent, | 124 views::View* parent, |
101 views::View* child) OVERRIDE; | 125 views::View* child) OVERRIDE; |
102 | 126 |
103 private: | 127 private: |
128 InitParams params_; | |
104 Host* host_; | 129 Host* host_; |
105 bool can_activate_; | |
106 int max_height_; | |
107 int bubble_width_; | |
108 | 130 |
109 DISALLOW_COPY_AND_ASSIGN(TrayBubbleView); | 131 DISALLOW_COPY_AND_ASSIGN(TrayBubbleView); |
110 }; | 132 }; |
111 | 133 |
112 } // namespace internal | 134 } // namespace internal |
113 } // namespace ash | 135 } // namespace ash |
114 | 136 |
115 #endif // ASH_SYSTEM_TRAY_TRAY_BUBBLE_VIEW_H_ | 137 #endif // ASH_SYSTEM_TRAY_TRAY_BUBBLE_VIEW_H_ |
OLD | NEW |