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, |
| 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(TrayBubbleView::AnchorType anchor_type, |
65 int bubble_width); | 72 ShelfAlignment shelf_alignment); |
| 73 TrayBubbleView::AnchorType anchor_type; |
| 74 ShelfAlignment shelf_alignment; |
| 75 int bubble_width; |
| 76 int max_height; |
| 77 bool can_activate; |
| 78 int arrow_offset; |
| 79 }; |
| 80 |
| 81 static TrayBubbleView* Create(views::View* anchor, |
| 82 Host* host, |
| 83 const InitParams& init_params); |
| 84 |
66 virtual ~TrayBubbleView(); | 85 virtual ~TrayBubbleView(); |
67 | 86 |
68 // Creates a bubble border with the specified arrow offset. | |
69 void SetBubbleBorder(int arrow_offset); | |
70 | |
71 // Called whenever the bubble anchor location may have moved. | 87 // Called whenever the bubble anchor location may have moved. |
72 void UpdateAnchor(); | 88 void UpdateAnchor(); |
73 | 89 |
74 // Sets the maximum bubble height and resizes the bubble. | 90 // Sets the maximum bubble height and resizes the bubble. |
75 void SetMaxHeight(int height); | 91 void SetMaxHeight(int height); |
76 | 92 |
77 // Called when the host is destroyed. | 93 // Called when the host is destroyed. |
78 void reset_host() { host_ = NULL; } | 94 void reset_host() { host_ = NULL; } |
79 | 95 |
80 // Overridden from views::WidgetDelegate. | 96 // Overridden from views::WidgetDelegate. |
81 virtual bool CanActivate() const OVERRIDE; | 97 virtual bool CanActivate() const OVERRIDE; |
| 98 virtual views::NonClientFrameView* CreateNonClientFrameView( |
| 99 views::Widget* widget) OVERRIDE; |
82 | 100 |
83 // Overridden from views::BubbleDelegateView. | 101 // Overridden from views::BubbleDelegateView. |
84 virtual gfx::Rect GetAnchorRect() OVERRIDE; | 102 virtual gfx::Rect GetAnchorRect() OVERRIDE; |
85 | 103 |
86 // Overridden from views::View. | 104 // Overridden from views::View. |
87 virtual gfx::Size GetPreferredSize() OVERRIDE; | 105 virtual gfx::Size GetPreferredSize() OVERRIDE; |
88 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE; | 106 virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE; |
89 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; | 107 virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE; |
90 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | 108 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; |
91 | 109 |
92 protected: | 110 protected: |
| 111 TrayBubbleView(const InitParams& init_params, |
| 112 views::BubbleBorder::ArrowLocation arrow_location, |
| 113 views::View* anchor, |
| 114 Host* host); |
| 115 |
93 // Overridden from views::BubbleDelegateView. | 116 // Overridden from views::BubbleDelegateView. |
94 virtual void Init() OVERRIDE; | 117 virtual void Init() OVERRIDE; |
95 virtual gfx::Rect GetBubbleBounds() OVERRIDE; | 118 virtual gfx::Rect GetBubbleBounds() OVERRIDE; |
96 | 119 |
97 // Overridden from views::View. | 120 // Overridden from views::View. |
98 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; | 121 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; |
99 virtual void ViewHierarchyChanged(bool is_add, | 122 virtual void ViewHierarchyChanged(bool is_add, |
100 views::View* parent, | 123 views::View* parent, |
101 views::View* child) OVERRIDE; | 124 views::View* child) OVERRIDE; |
102 | 125 |
103 private: | 126 private: |
| 127 InitParams params_; |
104 Host* host_; | 128 Host* host_; |
105 bool can_activate_; | |
106 int max_height_; | |
107 int bubble_width_; | |
108 | 129 |
109 DISALLOW_COPY_AND_ASSIGN(TrayBubbleView); | 130 DISALLOW_COPY_AND_ASSIGN(TrayBubbleView); |
110 }; | 131 }; |
111 | 132 |
112 } // namespace internal | 133 } // namespace internal |
113 } // namespace ash | 134 } // namespace ash |
114 | 135 |
115 #endif // ASH_SYSTEM_TRAY_TRAY_BUBBLE_VIEW_H_ | 136 #endif // ASH_SYSTEM_TRAY_TRAY_BUBBLE_VIEW_H_ |
OLD | NEW |