OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef ASH_SYSTEM_TRAY_TRAY_BUBBLE_VIEW_H_ | |
6 #define ASH_SYSTEM_TRAY_TRAY_BUBBLE_VIEW_H_ | |
7 | |
8 #include "ash/ash_export.h" | |
9 #include "ui/views/bubble/bubble_delegate.h" | |
10 | |
11 // Specialized bubble view for bubbles associated with a tray icon (e.g. the | |
12 // Ash status area). Mostly this handles custom anchor location and arrow and | |
13 // border rendering. This also has its own delegate for handling mouse events | |
14 // and other implementation specific details. | |
15 | |
16 namespace ui { | |
17 class LocatedEvent; | |
18 } | |
19 | |
20 namespace views { | |
21 class View; | |
22 class Widget; | |
23 } | |
24 | |
25 // TODO(stevenjb): Move this out of message_center namespace once in views. | |
26 namespace message_center { | |
27 | |
28 namespace internal { | |
29 class TrayBubbleBorder; | |
30 class TrayBubbleBackground; | |
31 } | |
32 | |
33 class ASH_EXPORT TrayBubbleView : public views::BubbleDelegateView { | |
34 public: | |
35 enum AnchorType { | |
36 ANCHOR_TYPE_TRAY, | |
37 ANCHOR_TYPE_BUBBLE | |
38 }; | |
39 | |
40 enum AnchorAlignment { | |
41 ANCHOR_ALIGNMENT_BOTTOM, | |
42 ANCHOR_ALIGNMENT_LEFT, | |
43 ANCHOR_ALIGNMENT_RIGHT | |
44 }; | |
45 | |
46 class ASH_EXPORT Delegate { | |
47 public: | |
48 typedef TrayBubbleView::AnchorType AnchorType; | |
49 typedef TrayBubbleView::AnchorAlignment AnchorAlignment; | |
50 | |
51 Delegate() {} | |
52 virtual ~Delegate() {} | |
53 | |
54 // Called when the view is destroyed. Any pointers to the view should be | |
55 // cleared when this gets called. | |
56 virtual void BubbleViewDestroyed() = 0; | |
57 | |
58 // Called when the mouse enters/exits the view. | |
59 virtual void OnMouseEnteredView() = 0; | |
60 virtual void OnMouseExitedView() = 0; | |
61 | |
62 // Called from GetAccessibleState(); should return the appropriate | |
63 // accessible name for the bubble. | |
64 virtual string16 GetAccessibleNameForBubble() = 0; | |
65 | |
66 // Passes responsibility for BubbleDelegateView::GetAnchorRect to the | |
67 // delegate. | |
68 virtual gfx::Rect GetAnchorRect(views::Widget* anchor_widget, | |
69 AnchorType anchor_type, | |
70 AnchorAlignment anchor_alignment) = 0; | |
71 | |
72 // Called when a bubble wants to hide/destroy itself (e.g. last visible | |
73 // child view was closed). | |
74 virtual void HideBubble(const TrayBubbleView* bubble_view) = 0; | |
75 | |
76 private: | |
77 DISALLOW_COPY_AND_ASSIGN(Delegate); | |
78 }; | |
79 | |
80 struct InitParams { | |
81 static const int kArrowDefaultOffset; | |
82 | |
83 InitParams(AnchorType anchor_type, | |
84 AnchorAlignment anchor_alignment, | |
85 int bubble_width); | |
86 AnchorType anchor_type; | |
87 AnchorAlignment anchor_alignment; | |
88 int bubble_width; | |
89 int max_height; | |
90 bool can_activate; | |
91 bool close_on_deactivate; | |
92 SkColor top_color; | |
93 SkColor arrow_color; | |
94 views::BubbleBorder::ArrowLocation arrow_location; | |
95 int arrow_offset; | |
96 views::BubbleBorder::Shadow shadow; | |
97 }; | |
98 | |
99 // Constructs and returns a TrayBubbleView. init_params may be modified. | |
100 static TrayBubbleView* Create(aura::Window* parent_window, | |
101 views::View* anchor, | |
102 Delegate* delegate, | |
103 InitParams* init_params); | |
104 | |
105 virtual ~TrayBubbleView(); | |
106 | |
107 // Sets up animations, and show the bubble. Must occur after CreateBubble() | |
108 // is called. | |
109 void InitializeAndShowBubble(); | |
110 | |
111 // Called whenever the bubble size or location may have changed. | |
112 void UpdateBubble(); | |
113 | |
114 // Sets the maximum bubble height and resizes the bubble. | |
115 void SetMaxHeight(int height); | |
116 | |
117 // Returns the border insets. Called by TrayEventFilter. | |
118 void GetBorderInsets(gfx::Insets* insets) const; | |
119 | |
120 // Called when the delegate is destroyed. | |
121 void reset_delegate() { delegate_ = NULL; } | |
122 | |
123 Delegate* delegate() { return delegate_; } | |
124 | |
125 void set_gesture_dragging(bool dragging) { is_gesture_dragging_ = dragging; } | |
126 bool is_gesture_dragging() const { return is_gesture_dragging_; } | |
127 | |
128 // Overridden from views::WidgetDelegate. | |
129 virtual bool CanActivate() const OVERRIDE; | |
130 virtual views::NonClientFrameView* CreateNonClientFrameView( | |
131 views::Widget* widget) OVERRIDE; | |
132 virtual bool WidgetHasHitTestMask() const OVERRIDE; | |
133 virtual void GetWidgetHitTestMask(gfx::Path* mask) const OVERRIDE; | |
134 | |
135 // Overridden from views::BubbleDelegateView. | |
136 virtual gfx::Rect GetAnchorRect() OVERRIDE; | |
137 | |
138 // Overridden from views::View. | |
139 virtual gfx::Size GetPreferredSize() OVERRIDE; | |
140 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; | |
141 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; | |
142 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | |
143 | |
144 protected: | |
145 TrayBubbleView(aura::Window* parent_window, | |
146 views::View* anchor, | |
147 Delegate* delegate, | |
148 const InitParams& init_params); | |
149 | |
150 // Overridden from views::BubbleDelegateView. | |
151 virtual void Init() OVERRIDE; | |
152 | |
153 // Overridden from views::View. | |
154 virtual void ChildPreferredSizeChanged(View* child) OVERRIDE; | |
155 virtual void ViewHierarchyChanged(bool is_add, | |
156 views::View* parent, | |
157 views::View* child) OVERRIDE; | |
158 | |
159 private: | |
160 InitParams params_; | |
161 Delegate* delegate_; | |
162 internal::TrayBubbleBorder* bubble_border_; | |
163 internal::TrayBubbleBackground* bubble_background_; | |
164 bool is_gesture_dragging_; | |
165 | |
166 DISALLOW_COPY_AND_ASSIGN(TrayBubbleView); | |
167 }; | |
168 | |
169 } // namespace message_center | |
170 | |
171 #endif // ASH_SYSTEM_TRAY_TRAY_BUBBLE_VIEW_H_ | |
OLD | NEW |