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" |
11 #include "ash/system/tray/tray_background_view.h" | |
10 #include "ash/system/tray/tray_bubble_wrapper.h" | 12 #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" | 13 #include "ash/wm/shelf_layout_manager.h" |
14 #include "base/message_loop.h" | |
15 #include "base/stringprintf.h" | |
16 #include "grit/ash_resources.h" | 14 #include "grit/ash_resources.h" |
17 #include "grit/ash_strings.h" | 15 #include "grit/ash_strings.h" |
18 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
19 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
21 #include "ui/gfx/screen.h" | 19 #include "ui/gfx/screen.h" |
20 #include "ui/message_center/message_bubble_base.h" | |
22 #include "ui/message_center/message_center_bubble.h" | 21 #include "ui/message_center/message_center_bubble.h" |
22 #include "ui/message_center/message_center_tray.h" | |
23 #include "ui/message_center/message_popup_bubble.h" | 23 #include "ui/message_center/message_popup_bubble.h" |
24 #include "ui/message_center/quiet_mode_bubble.h" | 24 #include "ui/message_center/quiet_mode_bubble.h" |
25 #include "ui/views/bubble/tray_bubble_view.h" | 25 #include "ui/views/bubble/tray_bubble_view.h" |
26 #include "ui/views/widget/widget_observer.h" | 26 #include "ui/views/widget/widget_observer.h" |
27 | 27 |
28 namespace { | 28 namespace ui { |
stevenjb
2013/01/23 23:14:18
There shouldn't be any code in the ui:: namespace
dewittj
2013/01/25 00:49:04
Removed.
| |
29 | 29 |
30 // Tray constants | 30 // static |
31 const int kTrayContainerVerticalPaddingBottomAlignment = 3; | 31 MessageCenterTrayDelegate* MessageCenterTrayDelegate::CreateForPlatform() { |
32 const int kTrayContainerHorizontalPaddingBottomAlignment = 1; | 32 // On Ash, the status area widget creates the WebNotificationTray directly. |
33 const int kTrayContainerVerticalPaddingVerticalAlignment = 1; | 33 return NULL; |
34 const int kTrayContainerHorizontalPaddingVerticalAlignment = 0; | 34 } |
35 const int kPaddingFromLeftEdgeOfSystemTrayBottomAlignment = 8; | |
36 const int kPaddingFromTopEdgeOfSystemTrayVerticalAlignment = 10; | |
37 | 35 |
38 } // namespace | 36 } // namespace |
39 | 37 |
40 namespace ash { | 38 namespace ash { |
41 | 39 |
42 namespace internal { | 40 namespace internal { |
43 | 41 |
44 // Class to initialize and manage the WebNotificationBubble and | 42 // Class to initialize and manage the WebNotificationBubble and |
45 // TrayBubbleWrapper instances for a bubble. | 43 // TrayBubbleWrapper instances for a bubble. |
46 | 44 |
(...skipping 16 matching lines...) Expand all Loading... | |
63 views::TrayBubbleView* bubble_view = views::TrayBubbleView::Create( | 61 views::TrayBubbleView* bubble_view = views::TrayBubbleView::Create( |
64 tray->GetBubbleWindowContainer(), anchor, tray, &init_params); | 62 tray->GetBubbleWindowContainer(), anchor, tray, &init_params); |
65 bubble_wrapper_.reset(new TrayBubbleWrapper(tray, bubble_view)); | 63 bubble_wrapper_.reset(new TrayBubbleWrapper(tray, bubble_view)); |
66 bubble->InitializeContents(bubble_view); | 64 bubble->InitializeContents(bubble_view); |
67 } | 65 } |
68 | 66 |
69 message_center::MessageBubbleBase* bubble() const { return bubble_.get(); } | 67 message_center::MessageBubbleBase* bubble() const { return bubble_.get(); } |
70 | 68 |
71 // Convenience accessors. | 69 // Convenience accessors. |
72 views::TrayBubbleView* bubble_view() const { return bubble_->bubble_view(); } | 70 views::TrayBubbleView* bubble_view() const { return bubble_->bubble_view(); } |
71 views::Widget* bubble_widget() const { | |
72 return bubble_wrapper_->bubble_widget(); | |
73 } | |
73 | 74 |
74 private: | 75 private: |
75 scoped_ptr<message_center::MessageBubbleBase> bubble_; | 76 scoped_ptr<message_center::MessageBubbleBase> bubble_; |
76 scoped_ptr<internal::TrayBubbleWrapper> bubble_wrapper_; | 77 scoped_ptr<internal::TrayBubbleWrapper> bubble_wrapper_; |
77 }; | 78 }; |
78 | 79 |
79 } // namespace internal | 80 } // namespace internal |
80 | 81 |
81 WebNotificationTray::WebNotificationTray( | 82 WebNotificationTray::WebNotificationTray( |
82 internal::StatusAreaWidget* status_area_widget) | 83 internal::StatusAreaWidget* status_area_widget) |
83 : internal::TrayBackgroundView(status_area_widget), | 84 : TrayBackgroundView(status_area_widget), |
84 button_(NULL), | 85 button_(NULL), |
85 show_message_center_on_unlock_(false) { | 86 show_message_center_on_unlock_(false) { |
86 message_center_ = ash::Shell::GetInstance()->message_center(); | |
87 message_center_->AddObserver(this); | |
88 button_ = new views::ImageButton(this); | 87 button_ = new views::ImageButton(this); |
89 button_->set_triggerable_event_flags( | 88 button_->set_triggerable_event_flags( |
90 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON); | 89 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON); |
91 tray_container()->AddChildView(button_); | 90 tray_container()->AddChildView(button_); |
92 SetVisible(false); | 91 SetVisible(false); |
93 UpdateTray(); | 92 message_center_tray_.reset( |
93 new ui::MessageCenterTray(this, Shell::GetInstance()->message_center())); | |
94 OnMessageCenterTrayChanged(); | |
94 } | 95 } |
95 | 96 |
96 WebNotificationTray::~WebNotificationTray() { | 97 WebNotificationTray::~WebNotificationTray() { |
97 // Ensure the message center doesn't notify an object under destruction. | |
98 message_center_->RemoveObserver(this); | |
99 // Release any child views that might have back pointers before ~View(). | 98 // Release any child views that might have back pointers before ~View(). |
100 message_center_bubble_.reset(); | 99 message_center_bubble_.reset(); |
101 popup_bubble_.reset(); | 100 popup_bubble_.reset(); |
102 if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget()) | 101 if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget()) |
103 quiet_mode_bubble_->GetBubbleWidget()->RemoveObserver(this); | 102 quiet_mode_bubble_->GetBubbleWidget()->RemoveObserver(this); |
104 quiet_mode_bubble_.reset(); | 103 quiet_mode_bubble_.reset(); |
105 } | 104 } |
106 | 105 |
107 void WebNotificationTray::ShowMessageCenterBubble() { | 106 // Public methods. |
108 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) | 107 |
109 return; | 108 bool WebNotificationTray::ShowMessageCenter( |
110 if (quiet_mode_bubble()) | 109 message_center::MessageBubbleBase* message_center_bubble) { |
111 quiet_mode_bubble_.reset(); | 110 if (!ShouldShowMessageCenter()) |
112 if (message_center_bubble()) { | 111 return false; |
113 UpdateTray(); | 112 |
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 // Sets the maximum height of the bubble based on the screen. | |
123 // TODO(mukai): move this to WebNotificationBubbleWrapper if it's safe | 113 // TODO(mukai): move this to WebNotificationBubbleWrapper if it's safe |
124 // to set the height of the popup. | 114 // to set the height of the popup. |
125 int max_height = 0; | 115 int max_height = 0; |
126 if (GetShelfLayoutManager()->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { | 116 if (GetShelfLayoutManager()->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { |
127 gfx::Rect shelf_bounds = GetShelfLayoutManager()->GetIdealBounds(); | 117 gfx::Rect shelf_bounds = GetShelfLayoutManager()->GetIdealBounds(); |
128 max_height = shelf_bounds.y(); | 118 max_height = shelf_bounds.y(); |
129 } else { | 119 } else { |
130 // Assume that the bottom line of the status area widget and the bubble are | 120 // Assume that the bottom line of the status area widget and the bubble are |
131 // aligned. | 121 // aligned. |
132 aura::Window* status_area_window = status_area_widget()->GetNativeWindow(); | 122 aura::Window* status_area_window = status_area_widget()->GetNativeWindow(); |
133 max_height = status_area_window->GetBoundsInRootWindow().bottom(); | 123 max_height = status_area_window->GetBoundsInRootWindow().bottom(); |
134 } | 124 } |
135 bubble->SetMaxHeight(max_height); | 125 message_center_bubble->SetMaxHeight(max_height); |
136 message_center_bubble_.reset( | 126 message_center_bubble_.reset( |
137 new internal::WebNotificationBubbleWrapper(this, bubble)); | 127 new internal::WebNotificationBubbleWrapper(this, message_center_bubble)); |
138 | 128 |
139 status_area_widget()->SetHideSystemNotifications(true); | 129 status_area_widget()->SetHideSystemNotifications(true); |
140 GetShelfLayoutManager()->UpdateAutoHideState(); | 130 GetShelfLayoutManager()->UpdateAutoHideState(); |
131 return true; | |
141 } | 132 } |
142 | 133 |
143 void WebNotificationTray::HideMessageCenterBubble() { | 134 void WebNotificationTray::UpdateMessageCenter() { |
135 if (message_center_bubble()) | |
136 message_center_bubble_->bubble()->ScheduleUpdate(); | |
137 } | |
138 | |
139 void WebNotificationTray::HideMessageCenter() { | |
144 if (!message_center_bubble()) | 140 if (!message_center_bubble()) |
145 return; | 141 return; |
146 message_center_bubble_.reset(); | 142 message_center_bubble_.reset(); |
147 show_message_center_on_unlock_ = false; | 143 show_message_center_on_unlock_ = false; |
148 message_center_->SetMessageCenterVisible(false); | |
149 UpdateTray(); | |
150 status_area_widget()->SetHideSystemNotifications(false); | 144 status_area_widget()->SetHideSystemNotifications(false); |
151 GetShelfLayoutManager()->UpdateAutoHideState(); | 145 GetShelfLayoutManager()->UpdateAutoHideState(); |
152 } | 146 } |
153 | 147 |
154 void WebNotificationTray::SetHidePopupBubble(bool hide) { | 148 void WebNotificationTray::SetHidePopupBubble(bool hide) { |
155 if (hide) | 149 if (hide) |
156 HidePopupBubble(); | 150 message_center_tray_->HidePopupBubble(); |
157 else | 151 else |
158 ShowPopupBubble(); | 152 message_center_tray_->ShowPopupBubble(); |
159 } | 153 } |
160 | 154 |
161 void WebNotificationTray::ShowPopupBubble() { | 155 bool WebNotificationTray::ShowPopups( |
162 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) | 156 message_center::MessageBubbleBase* popup_bubble) { |
163 return; | 157 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED || |
164 if (message_center_bubble()) | 158 message_center_bubble() || |
165 return; | 159 !status_area_widget()->ShouldShowWebNotifications()) |
166 if (!status_area_widget()->ShouldShowWebNotifications()) | 160 return false; |
stevenjb
2013/01/23 23:14:18
{}
dewittj
2013/01/25 00:49:04
Done.
| |
167 return; | 161 popup_bubble_.reset(new internal::WebNotificationBubbleWrapper( |
168 UpdateTray(); | 162 this, popup_bubble)); |
169 if (popup_bubble()) { | 163 return true; |
170 popup_bubble()->bubble()->ScheduleUpdate(); | |
171 } else if (message_center_->HasPopupNotifications()) { | |
172 popup_bubble_.reset( | |
173 new internal::WebNotificationBubbleWrapper( | |
174 this, new message_center::MessagePopupBubble(message_center_))); | |
175 } | |
176 } | 164 } |
177 | 165 |
178 void WebNotificationTray::HidePopupBubble() { | 166 void WebNotificationTray::UpdatePopups() { |
167 if (popup_bubble()) | |
168 popup_bubble_->bubble()->ScheduleUpdate(); | |
169 }; | |
170 | |
171 void WebNotificationTray::HidePopups() { | |
179 popup_bubble_.reset(); | 172 popup_bubble_.reset(); |
180 } | 173 } |
181 | 174 |
175 // Private methods. | |
176 | |
177 bool WebNotificationTray::ShouldShowMessageCenter() { | |
178 return status_area_widget()->login_status() != user::LOGGED_IN_LOCKED && | |
179 status_area_widget()->ShouldShowWebNotifications(); | |
180 } | |
181 | |
182 bool WebNotificationTray::ShouldShowQuietModeBubble(const ui::Event& event) { | 182 bool WebNotificationTray::ShouldShowQuietModeBubble(const ui::Event& event) { |
183 // TODO(mukai): Add keyboard event handler. | 183 // TODO(mukai): Add keyboard event handler. |
184 if (!event.IsMouseEvent()) | 184 if (!event.IsMouseEvent()) |
185 return false; | 185 return false; |
186 | 186 |
187 const ui::MouseEvent* mouse_event = | 187 const ui::MouseEvent* mouse_event = |
188 static_cast<const ui::MouseEvent*>(&event); | 188 static_cast<const ui::MouseEvent*>(&event); |
189 | 189 |
190 return mouse_event->IsRightMouseButton(); | 190 return mouse_event->IsRightMouseButton(); |
191 } | 191 } |
192 | 192 |
193 void WebNotificationTray::ShowQuietModeBubble() { | 193 void WebNotificationTray::ShowQuietModeBubble() { |
194 aura::Window* parent = Shell::GetContainer( | 194 aura::Window* parent = Shell::GetContainer( |
195 Shell::GetPrimaryRootWindow(), | 195 Shell::GetPrimaryRootWindow(), |
196 internal::kShellWindowId_SettingBubbleContainer); | 196 internal::kShellWindowId_SettingBubbleContainer); |
197 quiet_mode_bubble_.reset(new message_center::QuietModeBubble( | 197 quiet_mode_bubble_.reset(new message_center::QuietModeBubble( |
198 button_, parent, message_center_->notification_list())); | 198 button_, |
199 parent, | |
200 message_center_tray_->message_center()->notification_list())); | |
199 quiet_mode_bubble_->GetBubbleWidget()->StackAtTop(); | 201 quiet_mode_bubble_->GetBubbleWidget()->StackAtTop(); |
200 quiet_mode_bubble_->GetBubbleWidget()->AddObserver(this); | 202 quiet_mode_bubble_->GetBubbleWidget()->AddObserver(this); |
201 } | 203 } |
202 | 204 |
203 void WebNotificationTray::UpdateAfterLoginStatusChange( | 205 void WebNotificationTray::UpdateAfterLoginStatusChange( |
204 user::LoginStatus login_status) { | 206 user::LoginStatus login_status) { |
205 if (login_status == user::LOGGED_IN_LOCKED) { | 207 if (login_status == user::LOGGED_IN_LOCKED) { |
206 if (message_center_bubble()) { | 208 bool hidden = message_center_tray_->HideMessageCenterBubble(); |
207 message_center_bubble_.reset(); | 209 if (hidden) |
208 show_message_center_on_unlock_ = true; | 210 show_message_center_on_unlock_ = true; |
209 } | 211 message_center_tray_->HidePopupBubble(); |
210 HidePopupBubble(); | |
211 } else { | 212 } else { |
212 if (show_message_center_on_unlock_) | 213 if (show_message_center_on_unlock_) |
213 ShowMessageCenterBubble(); | 214 message_center_tray_->ShowMessageCenterBubble(); |
214 show_message_center_on_unlock_ = false; | 215 show_message_center_on_unlock_ = false; |
215 } | 216 } |
216 // The status icon should be always visible except for lock screen / login | 217 // The status icon should be always visible except for lock screen / login |
217 // screen, to allow quiet mode and settings. | 218 // screen, to allow quiet mode and settings. |
218 SetVisible((login_status != user::LOGGED_IN_NONE) && | 219 SetVisible((login_status != user::LOGGED_IN_NONE) && |
219 (login_status != user::LOGGED_IN_LOCKED)); | 220 (login_status != user::LOGGED_IN_LOCKED)); |
220 UpdateTray(); | 221 OnMessageCenterTrayChanged(); |
221 } | 222 } |
222 | 223 |
223 bool WebNotificationTray::ShouldBlockLauncherAutoHide() const { | 224 bool WebNotificationTray::ShouldBlockLauncherAutoHide() const { |
224 return IsMessageCenterBubbleVisible() || quiet_mode_bubble() != NULL; | 225 return IsMessageCenterBubbleVisible() || quiet_mode_bubble() != NULL; |
225 } | 226 } |
226 | 227 |
227 bool WebNotificationTray::IsMessageCenterBubbleVisible() const { | 228 bool WebNotificationTray::IsMessageCenterBubbleVisible() const { |
228 return (message_center_bubble() && | 229 return (message_center_bubble() && |
229 message_center_bubble_->bubble()->IsVisible()); | 230 message_center_bubble_->bubble()->IsVisible()); |
230 } | 231 } |
231 | 232 |
232 bool WebNotificationTray::IsMouseInNotificationBubble() const { | 233 bool WebNotificationTray::IsMouseInNotificationBubble() const { |
233 if (!popup_bubble()) | 234 if (!popup_bubble()) |
234 return false; | 235 return false; |
235 return popup_bubble_->bubble_view()->GetBoundsInScreen().Contains( | 236 return popup_bubble_->bubble_view()->GetBoundsInScreen().Contains( |
236 Shell::GetScreen()->GetCursorScreenPoint()); | 237 Shell::GetScreen()->GetCursorScreenPoint()); |
237 } | 238 } |
238 | 239 |
239 void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) { | 240 void WebNotificationTray::SetShelfAlignment(ShelfAlignment alignment) { |
240 if (alignment == shelf_alignment()) | 241 if (alignment == shelf_alignment()) |
241 return; | 242 return; |
242 internal::TrayBackgroundView::SetShelfAlignment(alignment); | 243 internal::TrayBackgroundView::SetShelfAlignment(alignment); |
243 // Destroy any existing bubble so that it will be rebuilt correctly. | 244 // Destroy any existing bubble so that it will be rebuilt correctly. |
244 HideMessageCenterBubble(); | 245 message_center_tray_->HideMessageCenterBubble(); |
245 HidePopupBubble(); | 246 message_center_tray_->HidePopupBubble(); |
246 } | 247 } |
247 | 248 |
248 void WebNotificationTray::AnchorUpdated() { | 249 void WebNotificationTray::AnchorUpdated() { |
249 if (popup_bubble_.get()) { | 250 if (popup_bubble_.get()) { |
250 popup_bubble_->bubble_view()->UpdateBubble(); | 251 popup_bubble_->bubble_view()->UpdateBubble(); |
251 // Ensure that the notification buble is above the launcher/status area. | 252 // Ensure that the notification buble is above the launcher/status area. |
252 popup_bubble_->bubble_view()->GetWidget()->StackAtTop(); | 253 popup_bubble_->bubble_view()->GetWidget()->StackAtTop(); |
253 UpdateBubbleViewArrow(popup_bubble_->bubble_view()); | 254 UpdateBubbleViewArrow(popup_bubble_->bubble_view()); |
254 } | 255 } |
255 if (message_center_bubble_.get()) { | 256 if (message_center_bubble_.get()) { |
256 message_center_bubble_->bubble_view()->UpdateBubble(); | 257 message_center_bubble_->bubble_view()->UpdateBubble(); |
257 UpdateBubbleViewArrow(message_center_bubble_->bubble_view()); | 258 UpdateBubbleViewArrow(message_center_bubble_->bubble_view()); |
258 } | 259 } |
259 // Quiet mode settings bubble has to be on top. | 260 // Quiet mode settings bubble has to be on top. |
260 if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget()) | 261 if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget()) |
261 quiet_mode_bubble_->GetBubbleWidget()->StackAtTop(); | 262 quiet_mode_bubble_->GetBubbleWidget()->StackAtTop(); |
262 } | 263 } |
263 | 264 |
264 string16 WebNotificationTray::GetAccessibleNameForTray() { | 265 string16 WebNotificationTray::GetAccessibleNameForTray() { |
265 return l10n_util::GetStringUTF16( | 266 return l10n_util::GetStringUTF16( |
266 IDS_ASH_WEB_NOTIFICATION_TRAY_ACCESSIBLE_NAME); | 267 IDS_ASH_WEB_NOTIFICATION_TRAY_ACCESSIBLE_NAME); |
267 } | 268 } |
268 | 269 |
269 void WebNotificationTray::HideBubbleWithView( | 270 void WebNotificationTray::HideBubbleWithView( |
270 const views::TrayBubbleView* bubble_view) { | 271 const views::TrayBubbleView* bubble_view) { |
271 if (message_center_bubble() && | 272 if (message_center_bubble() && |
272 bubble_view == message_center_bubble()->bubble_view()) { | 273 bubble_view == message_center_bubble()->bubble_view()) { |
273 HideMessageCenterBubble(); | 274 message_center_tray_->HideMessageCenterBubble(); |
274 } else if (popup_bubble() && bubble_view == popup_bubble()->bubble_view()) { | 275 } else if (popup_bubble() && bubble_view == popup_bubble()->bubble_view()) { |
275 HidePopupBubble(); | 276 message_center_tray_->HidePopupBubble(); |
276 } | 277 } |
277 } | 278 } |
278 | 279 |
279 bool WebNotificationTray::PerformAction(const ui::Event& event) { | 280 bool WebNotificationTray::PerformAction(const ui::Event& event) { |
280 if (!quiet_mode_bubble() && ShouldShowQuietModeBubble(event)) { | 281 if (!quiet_mode_bubble() && ShouldShowQuietModeBubble(event)) { |
281 ShowQuietModeBubble(); | 282 ShowQuietModeBubble(); |
282 return true; | 283 return true; |
283 } | 284 } |
284 quiet_mode_bubble_.reset(); | 285 quiet_mode_bubble_.reset(); |
285 ToggleMessageCenterBubble(); | 286 if (message_center_bubble()) |
287 message_center_tray_->HideMessageCenterBubble(); | |
288 else | |
289 message_center_tray_->ShowMessageCenterBubble(); | |
286 return true; | 290 return true; |
287 } | 291 } |
288 | 292 |
293 void WebNotificationTray::ShowMessageCenter() { | |
294 message_center_tray_->ShowMessageCenterBubble(); | |
295 } | |
296 | |
289 void WebNotificationTray::BubbleViewDestroyed() { | 297 void WebNotificationTray::BubbleViewDestroyed() { |
290 if (message_center_bubble()) | 298 if (message_center_bubble()) |
291 message_center_bubble()->bubble()->BubbleViewDestroyed(); | 299 message_center_bubble()->bubble()->BubbleViewDestroyed(); |
292 if (popup_bubble()) | 300 if (popup_bubble()) |
293 popup_bubble()->bubble()->BubbleViewDestroyed(); | 301 popup_bubble()->bubble()->BubbleViewDestroyed(); |
294 } | 302 } |
295 | 303 |
296 void WebNotificationTray::OnMouseEnteredView() { | 304 void WebNotificationTray::OnMouseEnteredView() { |
297 if (popup_bubble()) | 305 if (popup_bubble()) |
298 popup_bubble()->bubble()->OnMouseEnteredView(); | 306 popup_bubble()->bubble()->OnMouseEnteredView(); |
299 } | 307 } |
300 | 308 |
301 void WebNotificationTray::OnMouseExitedView() { | 309 void WebNotificationTray::OnMouseExitedView() { |
302 if (popup_bubble()) | 310 if (popup_bubble()) |
303 popup_bubble()->bubble()->OnMouseExitedView(); | 311 popup_bubble()->bubble()->OnMouseExitedView(); |
304 } | 312 } |
305 | 313 |
306 string16 WebNotificationTray::GetAccessibleNameForBubble() { | 314 string16 WebNotificationTray::GetAccessibleNameForBubble() { |
307 return GetAccessibleNameForTray(); | 315 return GetAccessibleNameForTray(); |
308 } | 316 } |
309 | 317 |
310 gfx::Rect WebNotificationTray::GetAnchorRect(views::Widget* anchor_widget, | 318 gfx::Rect WebNotificationTray::GetAnchorRect( |
311 AnchorType anchor_type, | 319 views::Widget* anchor_widget, |
312 AnchorAlignment anchor_alignment) { | 320 views::TrayBubbleView::AnchorType anchor_type, |
321 views::TrayBubbleView::AnchorAlignment anchor_alignment) { | |
313 return GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment); | 322 return GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment); |
314 } | 323 } |
315 | 324 |
316 void WebNotificationTray::HideBubble(const views::TrayBubbleView* bubble_view) { | 325 void WebNotificationTray::HideBubble(const views::TrayBubbleView* bubble_view) { |
317 HideBubbleWithView(bubble_view); | 326 HideBubbleWithView(bubble_view); |
318 } | 327 } |
319 | 328 |
320 void WebNotificationTray::OnMessageCenterChanged(bool new_notification) { | |
321 if (message_center_bubble()) { | |
322 if (message_center_->NotificationCount() == 0) | |
323 HideMessageCenterBubble(); | |
324 else | |
325 message_center_bubble()->bubble()->ScheduleUpdate(); | |
326 } | |
327 if (popup_bubble()) { | |
328 if (message_center_->NotificationCount() == 0) | |
329 HidePopupBubble(); | |
330 else | |
331 popup_bubble()->bubble()->ScheduleUpdate(); | |
332 } | |
333 UpdateTray(); | |
334 if (new_notification) | |
335 ShowPopupBubble(); | |
336 } | |
337 | |
338 void WebNotificationTray::ButtonPressed(views::Button* sender, | 329 void WebNotificationTray::ButtonPressed(views::Button* sender, |
339 const ui::Event& event) { | 330 const ui::Event& event) { |
340 DCHECK_EQ(button_, sender); | 331 DCHECK_EQ(button_, sender); |
341 PerformAction(event); | 332 PerformAction(event); |
342 } | 333 } |
343 | 334 |
344 void WebNotificationTray::OnWidgetClosing(views::Widget* widget) { | 335 void WebNotificationTray::OnWidgetClosing(views::Widget* widget) { |
345 if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget() == widget) { | 336 if (quiet_mode_bubble() && quiet_mode_bubble_->GetBubbleWidget() == widget) { |
346 widget->RemoveObserver(this); | 337 widget->RemoveObserver(this); |
347 } | 338 } |
348 quiet_mode_bubble_.reset(); | 339 quiet_mode_bubble_.reset(); |
349 } | 340 } |
350 | 341 |
351 // Private methods | 342 void WebNotificationTray::OnMessageCenterTrayChanged() { |
352 | |
353 void WebNotificationTray::ToggleMessageCenterBubble() { | |
354 if (message_center_bubble()) | |
355 HideMessageCenterBubble(); | |
356 else | |
357 ShowMessageCenterBubble(); | |
358 UpdateTray(); | |
359 } | |
360 | |
361 void WebNotificationTray::UpdateTray() { | |
362 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 343 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
363 if (message_center_->UnreadNotificationCount() > 0) { | 344 message_center::MessageCenter* message_center = |
345 message_center_tray_->message_center(); | |
346 if (message_center->UnreadNotificationCount() > 0) { | |
364 button_->SetImage(views::CustomButton::STATE_NORMAL, rb.GetImageSkiaNamed( | 347 button_->SetImage(views::CustomButton::STATE_NORMAL, rb.GetImageSkiaNamed( |
365 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_NORMAL)); | 348 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_NORMAL)); |
366 button_->SetImage(views::CustomButton::STATE_HOVERED, rb.GetImageSkiaNamed( | 349 button_->SetImage(views::CustomButton::STATE_HOVERED, rb.GetImageSkiaNamed( |
367 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_HOVER)); | 350 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_HOVER)); |
368 button_->SetImage(views::CustomButton::STATE_PRESSED, rb.GetImageSkiaNamed( | 351 button_->SetImage(views::CustomButton::STATE_PRESSED, rb.GetImageSkiaNamed( |
369 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_PRESSED)); | 352 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_ACTIVE_PRESSED)); |
370 } else { | 353 } else { |
371 button_->SetImage(views::CustomButton::STATE_NORMAL, rb.GetImageSkiaNamed( | 354 button_->SetImage(views::CustomButton::STATE_NORMAL, rb.GetImageSkiaNamed( |
372 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_NORMAL)); | 355 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_NORMAL)); |
373 button_->SetImage(views::CustomButton::STATE_HOVERED, rb.GetImageSkiaNamed( | 356 button_->SetImage(views::CustomButton::STATE_HOVERED, rb.GetImageSkiaNamed( |
374 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_HOVER)); | 357 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_HOVER)); |
375 button_->SetImage(views::CustomButton::STATE_PRESSED, rb.GetImageSkiaNamed( | 358 button_->SetImage(views::CustomButton::STATE_PRESSED, rb.GetImageSkiaNamed( |
376 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_PRESSED)); | 359 IDR_AURA_UBER_TRAY_NOTIFY_BUTTON_INACTIVE_PRESSED)); |
377 } | 360 } |
378 if (message_center_bubble()) | 361 if (IsMessageCenterBubbleVisible()) |
379 button_->SetState(views::CustomButton::STATE_PRESSED); | 362 button_->SetState(views::CustomButton::STATE_PRESSED); |
380 else | 363 else |
381 button_->SetState(views::CustomButton::STATE_NORMAL); | 364 button_->SetState(views::CustomButton::STATE_NORMAL); |
382 Layout(); | 365 Layout(); |
383 SchedulePaint(); | 366 SchedulePaint(); |
384 } | 367 } |
385 | 368 |
386 bool WebNotificationTray::ClickedOutsideBubble() { | 369 bool WebNotificationTray::ClickedOutsideBubble() { |
387 // Only hide the message center and quiet mode bubble. | 370 // Only hide the message center and quiet mode bubble. |
388 if (!message_center_bubble() && !quiet_mode_bubble()) | 371 if (!message_center_bubble() && !quiet_mode_bubble()) |
389 return false; | 372 return false; |
390 quiet_mode_bubble_.reset(); | 373 quiet_mode_bubble_.reset(); |
391 HideMessageCenterBubble(); | 374 message_center_tray_->HideMessageCenterBubble(); |
392 return true; | 375 return true; |
393 } | 376 } |
394 | 377 |
378 message_center::MessageCenter* WebNotificationTray::message_center() { | |
379 return message_center_tray_->message_center(); | |
380 } | |
381 | |
395 // Methods for testing | 382 // Methods for testing |
396 | 383 |
384 bool WebNotificationTray::IsPopupVisible() const { | |
385 return message_center_tray_->popups_visible(); | |
386 } | |
387 | |
397 message_center::MessageCenterBubble* | 388 message_center::MessageCenterBubble* |
398 WebNotificationTray::GetMessageCenterBubbleForTest() { | 389 WebNotificationTray::GetMessageCenterBubbleForTest() { |
399 if (!message_center_bubble_.get()) | 390 if (!message_center_bubble_.get()) |
400 return NULL; | 391 return NULL; |
401 return static_cast<message_center::MessageCenterBubble*>( | 392 return static_cast<message_center::MessageCenterBubble*>( |
402 message_center_bubble_->bubble()); | 393 message_center_bubble_->bubble()); |
403 } | 394 } |
404 | 395 |
405 message_center::MessagePopupBubble* | 396 message_center::MessagePopupBubble* |
406 WebNotificationTray::GetPopupBubbleForTest() { | 397 WebNotificationTray::GetPopupBubbleForTest() { |
407 if (!popup_bubble_.get()) | 398 if (!popup_bubble_.get()) |
408 return NULL; | 399 return NULL; |
409 return static_cast<message_center::MessagePopupBubble*>( | 400 return static_cast<message_center::MessagePopupBubble*>( |
410 popup_bubble_->bubble()); | 401 popup_bubble_->bubble()); |
411 } | 402 } |
412 | 403 |
413 } // namespace ash | 404 } // namespace ash |
OLD | NEW |