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 #include "ash/system/web_notification/web_notification_tray.h" | 5 #include "ash/system/web_notification/web_notification_tray.h" |
6 | 6 |
7 #include "ash/root_window_controller.h" | |
7 #include "ash/shell.h" | 8 #include "ash/shell.h" |
8 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
9 #include "ash/system/status_area_widget.h" | 10 #include "ash/system/status_area_widget.h" |
10 #include "ash/system/tray/tray_bubble_wrapper.h" | |
11 #include "ash/system/tray/tray_constants.h" | |
12 #include "ash/system/tray/tray_views.h" | |
13 #include "ash/wm/shelf_layout_manager.h" | 11 #include "ash/wm/shelf_layout_manager.h" |
14 #include "base/message_loop.h" | |
15 #include "base/stringprintf.h" | |
16 #include "grit/ash_resources.h" | 12 #include "grit/ash_resources.h" |
17 #include "grit/ash_strings.h" | 13 #include "grit/ash_strings.h" |
18 #include "ui/aura/window.h" | |
19 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
21 #include "ui/gfx/screen.h" | 16 #include "ui/message_center/message_center_tray.h" |
22 #include "ui/message_center/message_center_bubble.h" | 17 #include "ui/message_center/message_center_tray_host.h" |
23 #include "ui/message_center/message_popup_bubble.h" | |
24 #include "ui/message_center/quiet_mode_bubble.h" | 18 #include "ui/message_center/quiet_mode_bubble.h" |
25 #include "ui/views/bubble/tray_bubble_view.h" | |
26 #include "ui/views/widget/widget_observer.h" | |
27 | 19 |
28 namespace { | 20 #if defined(ENABLE_MESSAGE_CENTER) && !defined(OS_WIN) |
Pete Williamson
2013/01/16 19:43:20
Should we check for not windows or that we do have
dewittj
2013/01/16 22:30:40
There is a windows version of this function, in ch
| |
21 namespace chrome { | |
29 | 22 |
30 // Tray constants | 23 ui::MessageCenterTrayHost* GetMessageCenterTray() { |
31 const int kTrayContainerVerticalPaddingBottomAlignment = 3; | 24 return ash::Shell::GetPrimaryRootWindowController()->status_area_widget()-> |
32 const int kTrayContainerHorizontalPaddingBottomAlignment = 1; | 25 web_notification_tray(); |
33 const int kTrayContainerVerticalPaddingVerticalAlignment = 1; | 26 } |
34 const int kTrayContainerHorizontalPaddingVerticalAlignment = 0; | |
35 const int kPaddingFromLeftEdgeOfSystemTrayBottomAlignment = 8; | |
36 const int kPaddingFromTopEdgeOfSystemTrayVerticalAlignment = 10; | |
37 | 27 |
38 } // namespace | 28 } // namespace chrome |
29 #endif | |
30 | |
39 | 31 |
40 namespace ash { | 32 namespace ash { |
41 | 33 |
Pete Williamson
2013/01/16 19:43:20
Where did the WebNotificationBubbleWrapper functio
dewittj
2013/01/16 22:30:40
It was squashed partly into the MessageCenterTray
| |
42 namespace internal { | |
43 | |
44 // Class to initialize and manage the WebNotificationBubble and | |
45 // TrayBubbleWrapper instances for a bubble. | |
46 | |
47 class WebNotificationBubbleWrapper { | |
48 public: | |
49 // Takes ownership of |bubble| and creates |bubble_wrapper_|. | |
50 WebNotificationBubbleWrapper(WebNotificationTray* tray, | |
51 message_center::MessageBubbleBase* bubble) { | |
52 bubble_.reset(bubble); | |
53 views::TrayBubbleView::AnchorAlignment anchor_alignment = | |
54 tray->GetAnchorAlignment(); | |
55 views::TrayBubbleView::InitParams init_params = | |
56 bubble->GetInitParams(anchor_alignment); | |
57 views::View* anchor = tray->tray_container(); | |
58 if (anchor_alignment == views::TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { | |
59 gfx::Point bounds(anchor->width() / 2, 0); | |
60 views::View::ConvertPointToWidget(anchor, &bounds); | |
61 init_params.arrow_offset = bounds.x(); | |
62 } | |
63 views::TrayBubbleView* bubble_view = views::TrayBubbleView::Create( | |
64 tray->GetBubbleWindowContainer(), anchor, tray, &init_params); | |
65 bubble_wrapper_.reset(new TrayBubbleWrapper(tray, bubble_view)); | |
66 bubble->InitializeContents(bubble_view); | |
67 } | |
68 | |
69 message_center::MessageBubbleBase* bubble() const { return bubble_.get(); } | |
70 | |
71 // Convenience accessors. | |
72 views::TrayBubbleView* bubble_view() const { return bubble_->bubble_view(); } | |
73 | |
74 private: | |
75 scoped_ptr<message_center::MessageBubbleBase> bubble_; | |
76 scoped_ptr<internal::TrayBubbleWrapper> bubble_wrapper_; | |
77 }; | |
78 | |
79 } // namespace internal | |
80 | |
81 WebNotificationTray::WebNotificationTray( | 34 WebNotificationTray::WebNotificationTray( |
82 internal::StatusAreaWidget* status_area_widget) | 35 internal::StatusAreaWidget* status_area_widget) |
83 : internal::TrayBackgroundView(status_area_widget), | 36 : TrayBackgroundView(status_area_widget), |
84 button_(NULL), | 37 button_(NULL), |
85 show_message_center_on_unlock_(false) { | 38 show_message_center_on_unlock_(false), |
86 message_center_ = message_center::MessageCenter::GetInstance(); | 39 message_center_visible_(false) { |
87 message_center_->AddObserver(this); | |
88 button_ = new views::ImageButton(this); | 40 button_ = new views::ImageButton(this); |
89 button_->set_triggerable_event_flags( | 41 button_->set_triggerable_event_flags( |
90 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON); | 42 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON); |
91 tray_container()->AddChildView(button_); | 43 tray_container()->AddChildView(button_); |
92 SetVisible(false); | 44 SetVisible(false); |
93 UpdateTray(); | 45 message_center_tray_ = make_scoped_ptr(new ui::MessageCenterTray(this)); |
46 OnMessageCenterTrayChanged(); | |
94 } | 47 } |
95 | 48 |
96 WebNotificationTray::~WebNotificationTray() { | 49 WebNotificationTray::~WebNotificationTray() { } |
97 // Ensure the message center doesn't notify a destroyed object. | 50 |
98 message_center_->RemoveObserver(this); | 51 bool WebNotificationTray::CanShowMessageCenter() { |
99 // Release any child views that might have back pointers before ~View(). | 52 return status_area_widget()->login_status() != user::LOGGED_IN_LOCKED && |
100 message_center_bubble_.reset(); | 53 status_area_widget()->ShouldShowWebNotifications(); |
101 popup_bubble_.reset(); | |
102 if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget()) | |
103 quiet_mode_bubble_->GetBubbleWidget()->RemoveObserver(this); | |
104 quiet_mode_bubble_.reset(); | |
105 } | 54 } |
106 | 55 |
107 void WebNotificationTray::ShowMessageCenterBubble() { | 56 message_center::MessageCenter* WebNotificationTray::message_center() { |
108 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) | 57 return message_center_tray_->message_center(); |
109 return; | 58 } |
110 if (quiet_mode_bubble()) | |
111 quiet_mode_bubble_.reset(); | |
112 if (message_center_bubble()) { | |
113 UpdateTray(); | |
114 return; | |
115 } | |
116 // Indicate that the message center is visible. Clears the unread count. | |
117 message_center_->SetMessageCenterVisible(true); | |
118 UpdateTray(); | |
119 HidePopupBubble(); | |
120 message_center::MessageCenterBubble* bubble = | |
121 new message_center::MessageCenterBubble(message_center_); | |
122 message_center_bubble_.reset( | |
123 new internal::WebNotificationBubbleWrapper(this, bubble)); | |
124 | 59 |
60 | |
61 void WebNotificationTray::OnShowMessageCenterBubble() { | |
62 message_center_visible_ = true; | |
125 status_area_widget()->SetHideSystemNotifications(true); | 63 status_area_widget()->SetHideSystemNotifications(true); |
126 GetShelfLayoutManager()->UpdateAutoHideState(); | 64 GetShelfLayoutManager()->UpdateAutoHideState(); |
127 } | 65 } |
128 | 66 |
129 void WebNotificationTray::HideMessageCenterBubble() { | 67 void WebNotificationTray::OnHideMessageCenterBubble() { |
130 if (!message_center_bubble()) | 68 message_center_visible_ = false; |
131 return; | |
132 message_center_bubble_.reset(); | |
133 show_message_center_on_unlock_ = false; | 69 show_message_center_on_unlock_ = false; |
134 message_center_->SetMessageCenterVisible(false); | |
135 UpdateTray(); | |
136 status_area_widget()->SetHideSystemNotifications(false); | 70 status_area_widget()->SetHideSystemNotifications(false); |
137 GetShelfLayoutManager()->UpdateAutoHideState(); | 71 GetShelfLayoutManager()->UpdateAutoHideState(); |
138 } | 72 } |
139 | 73 |
140 void WebNotificationTray::SetHidePopupBubble(bool hide) { | 74 void WebNotificationTray::SetHidePopupBubble(bool hide) { |
141 if (hide) | 75 if (hide) |
142 HidePopupBubble(); | 76 message_center_tray_->HidePopupBubble(); |
143 else | 77 else |
144 ShowPopupBubble(); | 78 message_center_tray_->ShowPopupBubble(); |
145 } | 79 } |
146 | 80 |
147 void WebNotificationTray::ShowPopupBubble() { | 81 bool WebNotificationTray::CanShowPopups() { |
148 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) | 82 return status_area_widget()->login_status() != user::LOGGED_IN_LOCKED && |
149 return; | 83 status_area_widget()->ShouldShowWebNotifications(); |
150 if (message_center_bubble()) | |
151 return; | |
152 if (!status_area_widget()->ShouldShowWebNotifications()) | |
153 return; | |
154 UpdateTray(); | |
155 if (popup_bubble()) { | |
156 popup_bubble()->bubble()->ScheduleUpdate(); | |
157 } else if (message_center_->HasPopupNotifications()) { | |
158 popup_bubble_.reset( | |
159 new internal::WebNotificationBubbleWrapper( | |
160 this, new message_center::MessagePopupBubble( | |
161 message_center_))); | |
162 } | |
163 } | 84 } |
164 | 85 |
165 void WebNotificationTray::HidePopupBubble() { | |
166 popup_bubble_.reset(); | |
167 } | |
168 | 86 |
169 bool WebNotificationTray::ShouldShowQuietModeBubble(const ui::Event& event) { | 87 namespace { // XXX move this to top after merge |
88 | |
89 bool ShouldShowQuietModeBubble(const ui::Event& event) { | |
170 // TODO(mukai): Add keyboard event handler. | 90 // TODO(mukai): Add keyboard event handler. |
171 if (!event.IsMouseEvent()) | 91 if (!event.IsMouseEvent()) |
172 return false; | 92 return false; |
173 | 93 |
174 const ui::MouseEvent* mouse_event = | 94 const ui::MouseEvent* mouse_event = |
175 static_cast<const ui::MouseEvent*>(&event); | 95 static_cast<const ui::MouseEvent*>(&event); |
176 | 96 |
177 return mouse_event->IsRightMouseButton(); | 97 return mouse_event->IsRightMouseButton(); |
178 } | 98 } |
179 | 99 |
100 } // namespace | |
101 | |
180 void WebNotificationTray::ShowQuietModeBubble() { | 102 void WebNotificationTray::ShowQuietModeBubble() { |
181 aura::Window* parent = Shell::GetContainer( | 103 aura::Window* parent = Shell::GetContainer( |
182 Shell::GetPrimaryRootWindow(), | 104 Shell::GetPrimaryRootWindow(), |
183 internal::kShellWindowId_SettingBubbleContainer); | 105 internal::kShellWindowId_SettingBubbleContainer); |
184 quiet_mode_bubble_.reset(new message_center::QuietModeBubble( | 106 quiet_mode_bubble_.reset(new message_center::QuietModeBubble( |
185 button_, parent, message_center_->notification_list())); | 107 button_, |
108 parent, | |
109 message_center_tray_->message_center()->notification_list())); | |
186 quiet_mode_bubble_->GetBubbleWidget()->StackAtTop(); | 110 quiet_mode_bubble_->GetBubbleWidget()->StackAtTop(); |
187 quiet_mode_bubble_->GetBubbleWidget()->AddObserver(this); | 111 quiet_mode_bubble_->GetBubbleWidget()->AddObserver(this); |
188 } | 112 } |
189 | 113 |
190 void WebNotificationTray::UpdateAfterLoginStatusChange( | 114 void WebNotificationTray::UpdateAfterLoginStatusChange( |
191 user::LoginStatus login_status) { | 115 user::LoginStatus login_status) { |
192 if (login_status == user::LOGGED_IN_LOCKED) { | 116 if (login_status == user::LOGGED_IN_LOCKED) { |
193 if (message_center_bubble()) { | 117 bool hidden = message_center_tray_->HideMessageCenterBubble(); |
194 message_center_bubble_.reset(); | 118 if (hidden) |
195 show_message_center_on_unlock_ = true; | 119 show_message_center_on_unlock_ = true; |
196 } | 120 message_center_tray_->HidePopupBubble(); |
197 HidePopupBubble(); | |
198 } else { | 121 } else { |
199 if (show_message_center_on_unlock_) | 122 if (show_message_center_on_unlock_) |
200 ShowMessageCenterBubble(); | 123 message_center_tray_->ShowMessageCenterBubble(); |
201 show_message_center_on_unlock_ = false; | 124 show_message_center_on_unlock_ = false; |
202 } | 125 } |
203 // The status icon should be always visible except for lock screen / login | 126 // The status icon should be always visible except for lock screen / login |
204 // screen, to allow quiet mode and settings. | 127 // screen, to allow quiet mode and settings. |
205 SetVisible((login_status != user::LOGGED_IN_NONE) && | 128 SetVisible((login_status != user::LOGGED_IN_NONE) && |
206 (login_status != user::LOGGED_IN_LOCKED)); | 129 (login_status != user::LOGGED_IN_LOCKED)); |
207 UpdateTray(); | 130 OnMessageCenterTrayChanged(); |
208 } | 131 } |
209 | 132 |
210 bool WebNotificationTray::ShouldBlockLauncherAutoHide() const { | 133 bool WebNotificationTray::ShouldBlockLauncherAutoHide() const { |
211 return IsMessageCenterBubbleVisible() || quiet_mode_bubble() != NULL; | 134 return message_center_visible_ || quiet_mode_bubble_.get() != NULL; |
212 } | 135 } |
213 | 136 |
214 bool WebNotificationTray::IsMessageCenterBubbleVisible() const { | 137 bool WebNotificationTray::IsMessageCenterBubbleVisible() const { |
215 return (message_center_bubble() && | 138 return message_center_visible_; |
216 message_center_bubble_->bubble()->IsVisible()); | |
217 } | 139 } |
218 | 140 |
219 bool WebNotificationTray::IsMouseInNotificationBubble() const { | 141 bool WebNotificationTray::IsMouseInNotificationBubble() const { |
220 if (!popup_bubble()) | 142 // We only care about the mouse being in the popup view. |
143 views::View* popup_bubble_view = message_center_tray_->GetPopupBubbleView(); | |
144 if (!popup_bubble_view) | |
221 return false; | 145 return false; |
222 return popup_bubble_->bubble_view()->GetBoundsInScreen().Contains( | 146 return popup_bubble_view->GetBoundsInScreen().Contains( |
223 Shell::GetScreen()->GetCursorScreenPoint()); | 147 Shell::GetScreen()->GetCursorScreenPoint()); |
224 } | 148 } |
225 | 149 |
226 void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) { | 150 void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) { |
227 if (alignment == shelf_alignment()) | 151 if (alignment == shelf_alignment()) |
228 return; | 152 return; |
229 internal::TrayBackgroundView::SetShelfAlignment(alignment); | 153 internal::TrayBackgroundView::SetShelfAlignment(alignment); |
230 // Destroy any existing bubble so that it will be rebuilt correctly. | 154 // Destroy any existing bubble so that it will be rebuilt correctly. |
231 HideMessageCenterBubble(); | 155 message_center_tray_->HideMessageCenterBubble(); |
232 HidePopupBubble(); | 156 message_center_tray_->HidePopupBubble(); |
233 } | 157 } |
234 | 158 |
235 void WebNotificationTray::AnchorUpdated() { | 159 void WebNotificationTray::AnchorUpdated() { |
236 if (popup_bubble_.get()) { | 160 views::TrayBubbleView* popup_bubble_view = |
237 popup_bubble_->bubble_view()->UpdateBubble(); | 161 message_center_tray_->GetPopupBubbleView(); |
162 if (popup_bubble_view) { | |
163 popup_bubble_view->UpdateBubble(); | |
238 // Ensure that the notification buble is above the launcher/status area. | 164 // Ensure that the notification buble is above the launcher/status area. |
239 popup_bubble_->bubble_view()->GetWidget()->StackAtTop(); | 165 popup_bubble_view->GetWidget()->StackAtTop(); |
240 UpdateBubbleViewArrow(popup_bubble_->bubble_view()); | 166 UpdateBubbleViewArrow(popup_bubble_view); |
241 } | 167 } |
242 if (message_center_bubble_.get()) { | 168 views::TrayBubbleView* message_center_bubble_view = |
243 message_center_bubble_->bubble_view()->UpdateBubble(); | 169 message_center_tray_->GetMessageCenterBubbleView(); |
244 UpdateBubbleViewArrow(message_center_bubble_->bubble_view()); | 170 if (message_center_bubble_view) { |
171 message_center_bubble_view->UpdateBubble(); | |
172 UpdateBubbleViewArrow(message_center_bubble_view); | |
245 } | 173 } |
246 // Quiet mode settings bubble has to be on top. | 174 // Quiet mode settings bubble has to be on top. |
247 if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget()) | 175 if (quiet_mode_bubble_.get() && quiet_mode_bubble_->GetBubbleWidget()) |
248 quiet_mode_bubble_->GetBubbleWidget()->StackAtTop(); | 176 quiet_mode_bubble_->GetBubbleWidget()->StackAtTop(); |
249 } | 177 } |
250 | 178 |
251 string16 WebNotificationTray::GetAccessibleNameForTray() { | 179 string16 WebNotificationTray::GetAccessibleNameForTray() { |
252 return l10n_util::GetStringUTF16( | 180 return l10n_util::GetStringUTF16( |
253 IDS_ASH_WEB_NOTIFICATION_TRAY_ACCESSIBLE_NAME); | 181 IDS_ASH_WEB_NOTIFICATION_TRAY_ACCESSIBLE_NAME); |
254 } | 182 } |
255 | 183 |
256 void WebNotificationTray::HideBubbleWithView( | 184 void WebNotificationTray::HideBubbleWithView( |
257 const views::TrayBubbleView* bubble_view) { | 185 const views::TrayBubbleView* bubble_view) { |
258 if (message_center_bubble() && | 186 message_center_tray_->HideBubble(bubble_view); |
259 bubble_view == message_center_bubble()->bubble_view()) { | |
260 HideMessageCenterBubble(); | |
261 } else if (popup_bubble() && bubble_view == popup_bubble()->bubble_view()) { | |
262 HidePopupBubble(); | |
263 } | |
264 } | 187 } |
265 | 188 |
266 bool WebNotificationTray::PerformAction(const ui::Event& event) { | 189 bool WebNotificationTray::PerformAction(const ui::Event& event) { |
267 if (!quiet_mode_bubble() && ShouldShowQuietModeBubble(event)) { | 190 if (!quiet_mode_bubble_.get() && ShouldShowQuietModeBubble(event)) { |
191 //XXX Put these back in? | |
Pete Williamson
2013/01/16 19:43:20
This should be resolved before checkin. Also, the
dewittj
2013/01/16 22:30:40
The XXX means I'm definitely not checking it in.
| |
192 message_center_tray_->HideMessageCenterBubble(); | |
193 message_center_tray_->HidePopupBubble(); | |
268 ShowQuietModeBubble(); | 194 ShowQuietModeBubble(); |
269 return true; | 195 return true; |
270 } | 196 } |
271 quiet_mode_bubble_.reset(); | 197 quiet_mode_bubble_.reset(); |
272 ToggleMessageCenterBubble(); | 198 message_center_tray_->ToggleMessageCenterBubble(); |
273 return true; | 199 return true; |
274 } | 200 } |
275 | 201 |
Pete Williamson
2013/01/16 19:43:20
Where did BubbleViewDestroyed go?
dewittj
2013/01/16 22:30:40
It's back.
| |
276 void WebNotificationTray::BubbleViewDestroyed() { | |
277 if (message_center_bubble()) | |
278 message_center_bubble()->bubble()->BubbleViewDestroyed(); | |
279 if (popup_bubble()) | |
280 popup_bubble()->bubble()->BubbleViewDestroyed(); | |
281 } | |
282 | |
283 void WebNotificationTray::OnMouseEnteredView() { | |
284 if (popup_bubble()) | |
285 popup_bubble()->bubble()->OnMouseEnteredView(); | |
286 } | |
287 | |
288 void WebNotificationTray::OnMouseExitedView() { | |
289 if (popup_bubble()) | |
290 popup_bubble()->bubble()->OnMouseExitedView(); | |
291 } | |
292 | |
293 string16 WebNotificationTray::GetAccessibleNameForBubble() { | 202 string16 WebNotificationTray::GetAccessibleNameForBubble() { |
294 return GetAccessibleNameForTray(); | 203 return GetAccessibleNameForTray(); |
295 } | 204 } |
296 | 205 |
297 gfx::Rect WebNotificationTray::GetAnchorRect(views::Widget* anchor_widget, | 206 gfx::Rect WebNotificationTray::GetAnchorRect( |
298 AnchorType anchor_type, | 207 views::Widget* anchor_widget, |
299 AnchorAlignment anchor_alignment) { | 208 views::TrayBubbleView::AnchorType anchor_type, |
209 views::TrayBubbleView::AnchorAlignment anchor_alignment) { | |
300 return GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment); | 210 return GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment); |
301 } | 211 } |
302 | 212 |
303 void WebNotificationTray::HideBubble(const views::TrayBubbleView* bubble_view) { | |
304 HideBubbleWithView(bubble_view); | |
305 } | |
306 | |
307 void WebNotificationTray::OnMessageCenterChanged(bool new_notification) { | |
308 if (message_center_bubble()) { | |
309 if (message_center_->NotificationCount() == 0) | |
310 HideMessageCenterBubble(); | |
311 else | |
312 message_center_bubble()->bubble()->ScheduleUpdate(); | |
313 } | |
314 if (popup_bubble()) { | |
315 if (message_center_->NotificationCount() == 0) | |
316 HidePopupBubble(); | |
317 else | |
318 popup_bubble()->bubble()->ScheduleUpdate(); | |
319 } | |
320 UpdateTray(); | |
321 if (new_notification) | |
322 ShowPopupBubble(); | |
323 } | |
324 | 213 |
325 void WebNotificationTray::ButtonPressed(views::Button* sender, | 214 void WebNotificationTray::ButtonPressed(views::Button* sender, |
326 const ui::Event& event) { | 215 const ui::Event& event) { |
327 DCHECK_EQ(button_, sender); | 216 DCHECK_EQ(button_, sender); |
328 PerformAction(event); | 217 PerformAction(event); |
329 } | 218 } |
330 | 219 |
331 void WebNotificationTray::OnWidgetClosing(views::Widget* widget) { | 220 void WebNotificationTray::OnWidgetClosing(views::Widget* widget) { |
332 if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget() == widget) { | 221 if (quiet_mode_bubble_.get() && |
222 quiet_mode_bubble_->GetBubbleWidget() == widget) { | |
333 widget->RemoveObserver(this); | 223 widget->RemoveObserver(this); |
334 } | 224 } |
335 quiet_mode_bubble_.reset(); | 225 quiet_mode_bubble_.reset(); |
336 } | 226 } |
337 | 227 |
338 // Private methods | 228 gfx::NativeView WebNotificationTray::GetBubbleWindowContainer() { |
339 | 229 return TrayBackgroundView::GetBubbleWindowContainer(); |
340 void WebNotificationTray::ToggleMessageCenterBubble() { | |
341 if (message_center_bubble()) | |
342 HideMessageCenterBubble(); | |
343 else | |
344 ShowMessageCenterBubble(); | |
345 UpdateTray(); | |
346 } | 230 } |
347 | 231 |
348 void WebNotificationTray::UpdateTray() { | 232 views::View* WebNotificationTray::GetAnchorView() { |
233 return tray_container(); | |
234 } | |
235 | |
236 views::TrayBubbleView::AnchorAlignment | |
237 WebNotificationTray::GetAnchorAlignment() { | |
238 return TrayBackgroundView::GetAnchorAlignment(); | |
239 } | |
240 | |
241 void WebNotificationTray::UpdateInitParams( | |
242 views::TrayBubbleView::InitParams* init_params) { | |
243 if (GetAnchorAlignment() == views::TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { | |
244 gfx::Point bounds(tray_container()->width() / 2, 0); | |
245 views::View::ConvertPointToWidget(tray_container(), &bounds); | |
246 init_params->arrow_offset = bounds.x(); | |
247 } | |
248 } | |
249 | |
250 void WebNotificationTray::OnMessageCenterTrayChanged() { | |
349 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 251 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
350 if (message_center_->UnreadNotificationCount() > 0) { | 252 message_center::MessageCenter* message_center = |
253 message_center_tray_->message_center(); | |
254 if (message_center->UnreadNotificationCount() > 0) { | |
351 button_->SetImage(views::CustomButton::STATE_NORMAL, rb.GetImageSkiaNamed( | 255 button_->SetImage(views::CustomButton::STATE_NORMAL, rb.GetImageSkiaNamed( |
352 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_NORMAL)); | 256 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_NORMAL)); |
353 button_->SetImage(views::CustomButton::STATE_HOVERED, rb.GetImageSkiaNamed( | 257 button_->SetImage(views::CustomButton::STATE_HOVERED, rb.GetImageSkiaNamed( |
354 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_HOVER)); | 258 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_HOVER)); |
355 button_->SetImage(views::CustomButton::STATE_PRESSED, rb.GetImageSkiaNamed( | 259 button_->SetImage(views::CustomButton::STATE_PRESSED, rb.GetImageSkiaNamed( |
356 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_PRESSED)); | 260 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_PRESSED)); |
357 } else { | 261 } else { |
358 button_->SetImage(views::CustomButton::STATE_NORMAL, rb.GetImageSkiaNamed( | 262 button_->SetImage(views::CustomButton::STATE_NORMAL, rb.GetImageSkiaNamed( |
359 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_NORMAL)); | 263 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_NORMAL)); |
360 button_->SetImage(views::CustomButton::STATE_HOVERED, rb.GetImageSkiaNamed( | 264 button_->SetImage(views::CustomButton::STATE_HOVERED, rb.GetImageSkiaNamed( |
361 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_HOVER)); | 265 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_HOVER)); |
362 button_->SetImage(views::CustomButton::STATE_PRESSED, rb.GetImageSkiaNamed( | 266 button_->SetImage(views::CustomButton::STATE_PRESSED, rb.GetImageSkiaNamed( |
363 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_PRESSED)); | 267 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_PRESSED)); |
364 } | 268 } |
365 if (message_center_bubble()) | 269 if (message_center_visible_) |
366 button_->SetState(views::CustomButton::STATE_PRESSED); | 270 button_->SetState(views::CustomButton::STATE_PRESSED); |
367 else | 271 else |
368 button_->SetState(views::CustomButton::STATE_NORMAL); | 272 button_->SetState(views::CustomButton::STATE_NORMAL); |
369 Layout(); | 273 Layout(); |
370 SchedulePaint(); | 274 SchedulePaint(); |
371 } | 275 } |
372 | 276 |
373 bool WebNotificationTray::ClickedOutsideBubble() { | 277 bool WebNotificationTray::ClickedOutsideBubble() { |
374 // Only hide the message center and quiet mode bubble. | 278 // Only hide the message center and quiet mode bubble. |
375 if (!message_center_bubble() && !quiet_mode_bubble()) | 279 if (!message_center_visible_ && !quiet_mode_bubble_.get()) |
376 return false; | 280 return false; |
377 quiet_mode_bubble_.reset(); | 281 quiet_mode_bubble_.reset(); |
378 HideMessageCenterBubble(); | 282 message_center_tray_->HideMessageCenterBubble(); |
379 return true; | 283 return true; |
380 } | 284 } |
381 | 285 |
382 // Methods for testing | 286 void WebNotificationTray::ShowMessageCenter() { |
383 | 287 message_center_tray_->ShowMessageCenterBubble(); |
Pete Williamson
2013/01/16 19:43:20
We removed some testing methods, does that mean we
dewittj
2013/01/16 22:30:40
They were a work in progress. The patch you read
| |
384 message_center::MessageCenterBubble* | |
385 WebNotificationTray::GetMessageCenterBubbleForTest() { | |
386 if (!message_center_bubble_.get()) | |
387 return NULL; | |
388 return static_cast<message_center::MessageCenterBubble*>( | |
389 message_center_bubble_->bubble()); | |
390 } | 288 } |
391 | 289 |
392 message_center::MessagePopupBubble* | 290 bool WebNotificationTray::IsPopupVisible() const { |
393 WebNotificationTray::GetPopupBubbleForTest() { | 291 return message_center_tray_->IsPopupVisible(); |
394 if (!popup_bubble_.get()) | |
395 return NULL; | |
396 return static_cast<message_center::MessagePopupBubble*>( | |
397 popup_bubble_->bubble()); | |
398 } | 292 } |
399 | 293 |
400 } // namespace ash | 294 } // namespace ash |
OLD | NEW |