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/tray/system_tray.h" | 5 #include "ash/system/tray/system_tray.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/shell/panel_window.h" | 8 #include "ash/shell/panel_window.h" |
9 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
10 #include "ash/system/audio/tray_volume.h" | 10 #include "ash/system/audio/tray_volume.h" |
11 #include "ash/system/bluetooth/tray_bluetooth.h" | 11 #include "ash/system/bluetooth/tray_bluetooth.h" |
12 #include "ash/system/brightness/tray_brightness.h" | 12 #include "ash/system/brightness/tray_brightness.h" |
13 #include "ash/system/date/tray_date.h" | 13 #include "ash/system/date/tray_date.h" |
14 #include "ash/system/drive/tray_drive.h" | 14 #include "ash/system/drive/tray_drive.h" |
15 #include "ash/system/ime/tray_ime.h" | 15 #include "ash/system/ime/tray_ime.h" |
16 #include "ash/system/locale/tray_locale.h" | 16 #include "ash/system/locale/tray_locale.h" |
17 #include "ash/system/network/tray_network.h" | 17 #include "ash/system/network/tray_network.h" |
18 #include "ash/system/network/tray_sms.h" | 18 #include "ash/system/network/tray_sms.h" |
19 #include "ash/system/power/power_status_observer.h" | 19 #include "ash/system/power/power_status_observer.h" |
20 #include "ash/system/power/power_supply_status.h" | 20 #include "ash/system/power/power_supply_status.h" |
21 #include "ash/system/power/tray_power.h" | 21 #include "ash/system/power/tray_power.h" |
22 #include "ash/system/settings/tray_settings.h" | 22 #include "ash/system/settings/tray_settings.h" |
23 #include "ash/system/status_area_widget.h" | 23 #include "ash/system/status_area_widget.h" |
24 #include "ash/system/tray/system_tray_bubble.h" | |
25 #include "ash/system/tray/system_tray_delegate.h" | 24 #include "ash/system/tray/system_tray_delegate.h" |
26 #include "ash/system/tray/system_tray_item.h" | 25 #include "ash/system/tray/system_tray_item.h" |
26 #include "ash/system/tray/tray_bubble_wrapper.h" | |
27 #include "ash/system/tray/tray_constants.h" | 27 #include "ash/system/tray/tray_constants.h" |
28 #include "ash/system/tray_accessibility.h" | 28 #include "ash/system/tray_accessibility.h" |
29 #include "ash/system/tray_caps_lock.h" | 29 #include "ash/system/tray_caps_lock.h" |
30 #include "ash/system/tray_display.h" | 30 #include "ash/system/tray_display.h" |
31 #include "ash/system/tray_update.h" | 31 #include "ash/system/tray_update.h" |
32 #include "ash/system/user/login_status.h" | 32 #include "ash/system/user/login_status.h" |
33 #include "ash/system/user/tray_user.h" | 33 #include "ash/system/user/tray_user.h" |
34 #include "ash/wm/shelf_layout_manager.h" | 34 #include "ash/wm/shelf_layout_manager.h" |
35 #include "base/logging.h" | 35 #include "base/logging.h" |
36 #include "base/timer.h" | 36 #include "base/timer.h" |
37 #include "base/utf_string_conversions.h" | 37 #include "base/utf_string_conversions.h" |
38 #include "grit/ash_strings.h" | 38 #include "grit/ash_strings.h" |
39 #include "ui/aura/root_window.h" | 39 #include "ui/aura/root_window.h" |
40 #include "ui/base/events/event_constants.h" | 40 #include "ui/base/events/event_constants.h" |
41 #include "ui/base/l10n/l10n_util.h" | 41 #include "ui/base/l10n/l10n_util.h" |
42 #include "ui/compositor/layer.h" | 42 #include "ui/compositor/layer.h" |
43 #include "ui/gfx/canvas.h" | 43 #include "ui/gfx/canvas.h" |
44 #include "ui/gfx/screen.h" | 44 #include "ui/gfx/screen.h" |
45 #include "ui/gfx/skia_util.h" | 45 #include "ui/gfx/skia_util.h" |
46 #include "ui/views/border.h" | 46 #include "ui/views/border.h" |
47 #include "ui/views/controls/label.h" | 47 #include "ui/views/controls/label.h" |
48 #include "ui/views/layout/box_layout.h" | 48 #include "ui/views/layout/box_layout.h" |
49 #include "ui/views/layout/fill_layout.h" | 49 #include "ui/views/layout/fill_layout.h" |
50 #include "ui/views/view.h" | 50 #include "ui/views/view.h" |
51 | 51 |
52 using message_center::TrayBubbleView; | |
53 | |
52 namespace ash { | 54 namespace ash { |
53 | 55 |
56 namespace internal { | |
57 | |
58 // Class to initialize and manage the SystemTrayBubble and TrayBubbleWrapper | |
59 // instances for a bubble. | |
60 | |
61 class SystemBubbleWrapper { | |
62 public: | |
63 // Takes ownership of |bubble| and creates |bubble_wrapper_|. | |
64 SystemBubbleWrapper(TrayBackgroundView* tray, | |
65 internal::SystemTrayBubble* bubble, | |
66 views::View* anchor, | |
67 TrayBubbleView::InitParams* init_params) { | |
68 bubble_.reset(bubble); | |
miket_OOO
2012/10/16 01:05:42
Could this be an initializer?
stevenjb
2012/10/16 19:16:06
Done.
| |
69 user::LoginStatus login_status = | |
70 Shell::GetInstance()->tray_delegate()->GetUserLoginStatus(); | |
71 bubble->InitView(anchor, login_status, init_params); | |
72 bubble_wrapper_.reset( | |
73 new internal::TrayBubbleWrapper(tray, bubble->bubble_view())); | |
74 } | |
75 | |
76 // Convenience accessors: | |
77 SystemTrayBubble* bubble() const { return bubble_.get(); } | |
78 SystemTrayBubble::BubbleType bubble_type() const { | |
79 return bubble_->bubble_type(); | |
80 } | |
81 TrayBubbleView* bubble_view() const { return bubble_->bubble_view(); } | |
82 | |
83 private: | |
84 scoped_ptr<internal::SystemTrayBubble> bubble_; | |
85 scoped_ptr<internal::TrayBubbleWrapper> bubble_wrapper_; | |
86 }; | |
87 | |
88 } // namespace internal | |
89 | |
54 // SystemTray | 90 // SystemTray |
55 | 91 |
56 using internal::SystemTrayBubble; | 92 using internal::SystemTrayBubble; |
57 | 93 |
58 SystemTray::SystemTray(internal::StatusAreaWidget* status_area_widget) | 94 SystemTray::SystemTray(internal::StatusAreaWidget* status_area_widget) |
59 : internal::TrayBackgroundView(status_area_widget), | 95 : internal::TrayBackgroundView(status_area_widget), |
60 items_(), | 96 items_(), |
61 accessibility_observer_(NULL), | 97 accessibility_observer_(NULL), |
62 audio_observer_(NULL), | 98 audio_observer_(NULL), |
63 bluetooth_observer_(NULL), | 99 bluetooth_observer_(NULL), |
64 brightness_observer_(NULL), | 100 brightness_observer_(NULL), |
65 caps_lock_observer_(NULL), | 101 caps_lock_observer_(NULL), |
66 clock_observer_(NULL), | 102 clock_observer_(NULL), |
67 drive_observer_(NULL), | 103 drive_observer_(NULL), |
68 ime_observer_(NULL), | 104 ime_observer_(NULL), |
69 locale_observer_(NULL), | 105 locale_observer_(NULL), |
70 network_observer_(NULL), | 106 network_observer_(NULL), |
71 update_observer_(NULL), | 107 update_observer_(NULL), |
72 user_observer_(NULL), | 108 user_observer_(NULL), |
73 default_bubble_height_(0), | 109 default_bubble_height_(0), |
74 hide_notifications_(false) { | 110 hide_notifications_(false) { |
75 SetContentsBackground(); | 111 SetContentsBackground(); |
76 } | 112 } |
77 | 113 |
78 SystemTray::~SystemTray() { | 114 SystemTray::~SystemTray() { |
79 bubble_.reset(); | 115 system_bubble_.reset(); |
116 notification_bubble_.reset(); | |
miket_OOO
2012/10/16 01:05:42
I don't see why these are necessary. Does the Dest
stevenjb
2012/10/16 19:16:06
The order here doesn't really matter, they just ne
| |
80 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); | 117 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); |
81 it != items_.end(); | 118 it != items_.end(); |
82 ++it) { | 119 ++it) { |
83 (*it)->DestroyTrayView(); | 120 (*it)->DestroyTrayView(); |
84 } | 121 } |
85 } | 122 } |
86 | 123 |
87 void SystemTray::CreateItems() { | 124 void SystemTray::CreateItems() { |
88 internal::TrayVolume* tray_volume = new internal::TrayVolume(); | 125 internal::TrayVolume* tray_volume = new internal::TrayVolume(); |
89 internal::TrayBluetooth* tray_bluetooth = new internal::TrayBluetooth(); | 126 internal::TrayBluetooth* tray_bluetooth = new internal::TrayBluetooth(); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 TrayBubbleView::InitParams::kArrowDefaultOffset); | 199 TrayBubbleView::InitParams::kArrowDefaultOffset); |
163 } | 200 } |
164 | 201 |
165 void SystemTray::ShowDetailedView(SystemTrayItem* item, | 202 void SystemTray::ShowDetailedView(SystemTrayItem* item, |
166 int close_delay, | 203 int close_delay, |
167 bool activate, | 204 bool activate, |
168 BubbleCreationType creation_type) { | 205 BubbleCreationType creation_type) { |
169 std::vector<SystemTrayItem*> items; | 206 std::vector<SystemTrayItem*> items; |
170 items.push_back(item); | 207 items.push_back(item); |
171 ShowItems(items, true, activate, creation_type, GetTrayXOffset(item)); | 208 ShowItems(items, true, activate, creation_type, GetTrayXOffset(item)); |
172 bubble_->StartAutoCloseTimer(close_delay); | 209 system_bubble_->bubble()->StartAutoCloseTimer(close_delay); |
173 } | 210 } |
174 | 211 |
175 void SystemTray::SetDetailedViewCloseDelay(int close_delay) { | 212 void SystemTray::SetDetailedViewCloseDelay(int close_delay) { |
176 if (bubble_.get() && | 213 if (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DETAILED)) |
177 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_DETAILED) | 214 system_bubble_->bubble()->StartAutoCloseTimer(close_delay); |
178 bubble_->StartAutoCloseTimer(close_delay); | |
179 } | 215 } |
180 | 216 |
181 void SystemTray::HideDetailedView(SystemTrayItem* item) { | 217 void SystemTray::HideDetailedView(SystemTrayItem* item) { |
182 if (item != detailed_item_) | 218 if (item != detailed_item_) |
183 return; | 219 return; |
184 DestroyBubble(); | 220 DestroySystemBubble(); |
185 UpdateNotificationBubble(); | 221 UpdateNotificationBubble(); |
186 } | 222 } |
187 | 223 |
188 void SystemTray::ShowNotificationView(SystemTrayItem* item) { | 224 void SystemTray::ShowNotificationView(SystemTrayItem* item) { |
189 if (std::find(notification_items_.begin(), notification_items_.end(), item) | 225 if (std::find(notification_items_.begin(), notification_items_.end(), item) |
190 != notification_items_.end()) | 226 != notification_items_.end()) |
191 return; | 227 return; |
192 notification_items_.push_back(item); | 228 notification_items_.push_back(item); |
193 UpdateNotificationBubble(); | 229 UpdateNotificationBubble(); |
194 } | 230 } |
195 | 231 |
196 void SystemTray::HideNotificationView(SystemTrayItem* item) { | 232 void SystemTray::HideNotificationView(SystemTrayItem* item) { |
197 std::vector<SystemTrayItem*>::iterator found_iter = | 233 std::vector<SystemTrayItem*>::iterator found_iter = |
198 std::find(notification_items_.begin(), notification_items_.end(), item); | 234 std::find(notification_items_.begin(), notification_items_.end(), item); |
199 if (found_iter == notification_items_.end()) | 235 if (found_iter == notification_items_.end()) |
200 return; | 236 return; |
201 notification_items_.erase(found_iter); | 237 notification_items_.erase(found_iter); |
202 // Only update the notification bubble if visible (i.e. don't create one). | 238 // Only update the notification bubble if visible (i.e. don't create one). |
203 if (notification_bubble_.get()) | 239 if (notification_bubble_.get()) |
204 UpdateNotificationBubble(); | 240 UpdateNotificationBubble(); |
205 } | 241 } |
206 | 242 |
207 void SystemTray::UpdateAfterLoginStatusChange(user::LoginStatus login_status) { | 243 void SystemTray::UpdateAfterLoginStatusChange(user::LoginStatus login_status) { |
208 DestroyBubble(); | 244 DestroySystemBubble(); |
209 | 245 |
210 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); | 246 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); |
211 it != items_.end(); | 247 it != items_.end(); |
212 ++it) { | 248 ++it) { |
213 (*it)->UpdateAfterLoginStatusChange(login_status); | 249 (*it)->UpdateAfterLoginStatusChange(login_status); |
214 } | 250 } |
215 | 251 |
216 SetVisible(true); | 252 SetVisible(true); |
217 PreferredSizeChanged(); | 253 PreferredSizeChanged(); |
218 } | 254 } |
219 | 255 |
220 void SystemTray::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 256 void SystemTray::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
221 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); | 257 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); |
222 it != items_.end(); | 258 it != items_.end(); |
223 ++it) { | 259 ++it) { |
224 (*it)->UpdateAfterShelfAlignmentChange(alignment); | 260 (*it)->UpdateAfterShelfAlignmentChange(alignment); |
225 } | 261 } |
226 } | 262 } |
227 | 263 |
228 void SystemTray::SetHideNotifications(bool hide_notifications) { | 264 void SystemTray::SetHideNotifications(bool hide_notifications) { |
229 if (notification_bubble_.get()) | 265 if (notification_bubble_.get()) |
230 notification_bubble_->SetVisible(!hide_notifications); | 266 notification_bubble_->bubble()->SetVisible(!hide_notifications); |
231 hide_notifications_ = hide_notifications; | 267 hide_notifications_ = hide_notifications; |
232 } | 268 } |
233 | 269 |
234 bool SystemTray::HasSystemBubble() const { | 270 bool SystemTray::HasSystemBubble() const { |
235 return bubble_.get() != NULL; | 271 return system_bubble_.get() != NULL; |
272 } | |
273 | |
274 internal::SystemTrayBubble* SystemTray::GetSystemBubble() { | |
275 if (!system_bubble_.get()) | |
276 return NULL; | |
277 return system_bubble_->bubble(); | |
236 } | 278 } |
237 | 279 |
238 bool SystemTray::IsAnyBubbleVisible() const { | 280 bool SystemTray::IsAnyBubbleVisible() const { |
239 if (bubble_.get() && bubble_->IsVisible()) | 281 return ((system_bubble_.get() && |
240 return true; | 282 system_bubble_->bubble()->IsVisible()) || |
241 if (notification_bubble_.get() && notification_bubble_->IsVisible()) | 283 (notification_bubble_.get() && |
242 return true; | 284 notification_bubble_->bubble()->IsVisible())); |
243 return false; | |
244 } | 285 } |
245 | 286 |
246 bool SystemTray::IsMouseInNotificationBubble() const { | 287 bool SystemTray::IsMouseInNotificationBubble() const { |
247 if (!notification_bubble_.get()) | 288 if (!notification_bubble_.get()) |
248 return false; | 289 return false; |
249 return notification_bubble_->bubble_view()->GetBoundsInScreen().Contains( | 290 return notification_bubble_->bubble_view()->GetBoundsInScreen().Contains( |
250 Shell::GetScreen()->GetCursorScreenPoint()); | 291 Shell::GetScreen()->GetCursorScreenPoint()); |
251 } | 292 } |
252 | 293 |
253 bool SystemTray::CloseBubbleForTest() const { | 294 bool SystemTray::CloseBubbleForTest() const { |
254 if (!bubble_.get()) | 295 if (!system_bubble_.get()) |
255 return false; | 296 return false; |
256 bubble_->Close(); | 297 system_bubble_->bubble()->Close(); |
257 return true; | 298 return true; |
258 } | 299 } |
259 | 300 |
260 // Private methods. | 301 // Private methods. |
261 | 302 |
262 void SystemTray::DestroyBubble() { | 303 bool SystemTray::HasSystemBubbleType(SystemTrayBubble::BubbleType type) { |
263 bubble_.reset(); | 304 DCHECK(type != SystemTrayBubble::BUBBLE_TYPE_NOTIFICATION); |
305 return system_bubble_.get() && system_bubble_->bubble_type() == type; | |
306 } | |
307 | |
308 void SystemTray::DestroySystemBubble() { | |
309 system_bubble_.reset(); | |
264 detailed_item_ = NULL; | 310 detailed_item_ = NULL; |
265 } | 311 } |
266 | 312 |
267 void SystemTray::DestroyNotificationBubble() { | 313 void SystemTray::DestroyNotificationBubble() { |
268 notification_bubble_.reset(); | 314 notification_bubble_.reset(); |
269 status_area_widget()->SetHideWebNotifications(false); | 315 status_area_widget()->SetHideWebNotifications(false); |
270 } | 316 } |
271 | 317 |
272 int SystemTray::GetTrayXOffset(SystemTrayItem* item) const { | 318 int SystemTray::GetTrayXOffset(SystemTrayItem* item) const { |
273 // Don't attempt to align the arrow if the shelf is on the left or right. | 319 // Don't attempt to align the arrow if the shelf is on the left or right. |
(...skipping 29 matching lines...) Expand all Loading... | |
303 int arrow_offset) { | 349 int arrow_offset) { |
304 // Destroy any existing bubble and create a new one. | 350 // Destroy any existing bubble and create a new one. |
305 SystemTrayBubble::BubbleType bubble_type = detailed ? | 351 SystemTrayBubble::BubbleType bubble_type = detailed ? |
306 SystemTrayBubble::BUBBLE_TYPE_DETAILED : | 352 SystemTrayBubble::BUBBLE_TYPE_DETAILED : |
307 SystemTrayBubble::BUBBLE_TYPE_DEFAULT; | 353 SystemTrayBubble::BUBBLE_TYPE_DEFAULT; |
308 | 354 |
309 // Destroy the notification bubble here so that it doesn't get rebuilt | 355 // Destroy the notification bubble here so that it doesn't get rebuilt |
310 // while we add items to the main bubble_ (e.g. in HideNotificationView). | 356 // while we add items to the main bubble_ (e.g. in HideNotificationView). |
311 notification_bubble_.reset(); | 357 notification_bubble_.reset(); |
312 | 358 |
313 if (bubble_.get() && creation_type == BUBBLE_USE_EXISTING) { | 359 if (system_bubble_.get() && creation_type == BUBBLE_USE_EXISTING) { |
314 bubble_->UpdateView(items, bubble_type); | 360 system_bubble_->bubble()->UpdateView(items, bubble_type); |
315 } else { | 361 } else { |
316 bubble_.reset(new SystemTrayBubble(this, items, bubble_type)); | |
317 ash::SystemTrayDelegate* delegate = | |
318 ash::Shell::GetInstance()->tray_delegate(); | |
319 views::View* anchor = tray_container(); | |
320 TrayBubbleView::InitParams init_params(TrayBubbleView::ANCHOR_TYPE_TRAY, | 362 TrayBubbleView::InitParams init_params(TrayBubbleView::ANCHOR_TYPE_TRAY, |
321 GetAnchorAlignment(), | 363 GetAnchorAlignment(), |
322 kTrayPopupWidth); | 364 kTrayPopupWidth); |
323 init_params.can_activate = can_activate; | 365 init_params.can_activate = can_activate; |
324 if (detailed) { | 366 if (detailed) { |
325 // This is the case where a volume control or brightness control bubble | 367 // This is the case where a volume control or brightness control bubble |
326 // is created. | 368 // is created. |
327 init_params.max_height = default_bubble_height_; | 369 init_params.max_height = default_bubble_height_; |
328 init_params.top_color = kBackgroundColor; | 370 init_params.top_color = kBackgroundColor; |
329 init_params.arrow_color = kBackgroundColor; | 371 init_params.arrow_color = kBackgroundColor; |
330 } else { | 372 } else { |
331 init_params.top_color = kBackgroundColor; | 373 init_params.top_color = kBackgroundColor; |
332 init_params.arrow_color = kHeaderBackgroundColorDark; | 374 init_params.arrow_color = kHeaderBackgroundColorDark; |
333 } | 375 } |
334 init_params.arrow_offset = arrow_offset; | 376 init_params.arrow_offset = arrow_offset; |
335 bubble_->InitView(anchor, delegate->GetUserLoginStatus(), &init_params); | 377 SystemTrayBubble* bubble = new SystemTrayBubble(this, items, bubble_type); |
378 system_bubble_.reset(new internal::SystemBubbleWrapper( | |
379 this, bubble, tray_container(), &init_params)); | |
336 } | 380 } |
337 // Save height of default view for creating detailed views directly. | 381 // Save height of default view for creating detailed views directly. |
338 if (!detailed) | 382 if (!detailed) |
339 default_bubble_height_ = bubble_->bubble_view()->height(); | 383 default_bubble_height_ = system_bubble_->bubble_view()->height(); |
340 | 384 |
341 if (detailed && items.size() > 0) | 385 if (detailed && items.size() > 0) |
342 detailed_item_ = items[0]; | 386 detailed_item_ = items[0]; |
343 else | 387 else |
344 detailed_item_ = NULL; | 388 detailed_item_ = NULL; |
345 | 389 |
346 UpdateNotificationBubble(); // State changed, re-create notifications. | 390 UpdateNotificationBubble(); // State changed, re-create notifications. |
347 status_area_widget()->SetHideWebNotifications(true); | 391 status_area_widget()->SetHideWebNotifications(true); |
348 Shell::GetInstance()->shelf()->UpdateAutoHideState(); | 392 Shell::GetInstance()->shelf()->UpdateAutoHideState(); |
349 } | 393 } |
350 | 394 |
351 void SystemTray::UpdateNotificationBubble() { | 395 void SystemTray::UpdateNotificationBubble() { |
352 // Only show the notification buble if we have notifications and we are not | 396 // Only show the notification buble if we have notifications and we are not |
353 // showing the default bubble. | 397 // showing the default bubble. |
354 if (notification_items_.empty() || | 398 if (notification_items_.empty() || |
355 (bubble_.get() && | 399 HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DEFAULT)) { |
356 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_DEFAULT)) { | |
357 DestroyNotificationBubble(); | 400 DestroyNotificationBubble(); |
358 return; | 401 return; |
359 } | 402 } |
360 if (bubble_.get() && | 403 // Destroy the existing bubble before constructing a new one. |
361 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_DETAILED) { | 404 notification_bubble_.reset(); |
405 SystemTrayBubble* notification_bubble; | |
406 if (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DETAILED)) { | |
362 // Skip notifications for any currently displayed detailed item. | 407 // Skip notifications for any currently displayed detailed item. |
363 std::vector<SystemTrayItem*> items; | 408 std::vector<SystemTrayItem*> items; |
364 for (std::vector<SystemTrayItem*>::iterator iter = | 409 for (std::vector<SystemTrayItem*>::iterator iter = |
365 notification_items_.begin(); | 410 notification_items_.begin(); |
366 iter != notification_items_.end(); ++ iter) { | 411 iter != notification_items_.end(); ++ iter) { |
367 if (*iter != detailed_item_) | 412 if (*iter != detailed_item_) |
368 items.push_back(*iter); | 413 items.push_back(*iter); |
369 } | 414 } |
370 if (items.empty()) { | 415 if (items.empty()) { |
371 DestroyNotificationBubble(); | 416 DestroyNotificationBubble(); |
372 return; | 417 return; |
373 } | 418 } |
374 notification_bubble_.reset(new SystemTrayBubble( | 419 notification_bubble = new SystemTrayBubble( |
375 this, items, SystemTrayBubble::BUBBLE_TYPE_NOTIFICATION)); | 420 this, items, SystemTrayBubble::BUBBLE_TYPE_NOTIFICATION); |
376 } else { | 421 } else { |
377 // Show all notifications. | 422 // Show all notifications. |
378 notification_bubble_.reset(new SystemTrayBubble( | 423 notification_bubble = new SystemTrayBubble( |
379 this, notification_items_, SystemTrayBubble::BUBBLE_TYPE_NOTIFICATION)); | 424 this, notification_items_, SystemTrayBubble::BUBBLE_TYPE_NOTIFICATION); |
380 } | 425 } |
381 views::View* anchor; | 426 views::View* anchor; |
382 TrayBubbleView::AnchorType anchor_type; | 427 TrayBubbleView::AnchorType anchor_type; |
383 if (bubble_.get()) { | 428 if (system_bubble_.get()) { |
384 anchor = bubble_->bubble_view(); | 429 anchor = system_bubble_->bubble_view(); |
385 anchor_type = TrayBubbleView::ANCHOR_TYPE_BUBBLE; | 430 anchor_type = TrayBubbleView::ANCHOR_TYPE_BUBBLE; |
386 } else { | 431 } else { |
387 anchor = tray_container(); | 432 anchor = tray_container(); |
388 anchor_type = TrayBubbleView::ANCHOR_TYPE_TRAY; | 433 anchor_type = TrayBubbleView::ANCHOR_TYPE_TRAY; |
389 } | 434 } |
390 TrayBubbleView::InitParams init_params(anchor_type, | 435 TrayBubbleView::InitParams init_params(anchor_type, |
391 GetAnchorAlignment(), | 436 GetAnchorAlignment(), |
392 kTrayPopupWidth); | 437 kTrayPopupWidth); |
393 init_params.top_color = kBackgroundColor; | 438 init_params.top_color = kBackgroundColor; |
394 init_params.arrow_color = kBackgroundColor; | 439 init_params.arrow_color = kBackgroundColor; |
395 init_params.arrow_offset = GetTrayXOffset(notification_items_[0]); | 440 init_params.arrow_offset = GetTrayXOffset(notification_items_[0]); |
396 user::LoginStatus login_status = | 441 notification_bubble_.reset(new internal::SystemBubbleWrapper( |
397 Shell::GetInstance()->tray_delegate()->GetUserLoginStatus(); | 442 this, notification_bubble, anchor, &init_params)); |
398 notification_bubble_->InitView(anchor, login_status, &init_params); | 443 |
399 if (notification_bubble_->bubble_view()->child_count() == 0) { | 444 if (notification_bubble->bubble_view()->child_count() == 0) { |
400 // It is possible that none of the items generated actual notifications. | 445 // It is possible that none of the items generated actual notifications. |
401 DestroyNotificationBubble(); | 446 DestroyNotificationBubble(); |
402 return; | 447 return; |
403 } | 448 } |
404 if (hide_notifications_) | 449 if (hide_notifications_) |
405 notification_bubble_->SetVisible(false); | 450 notification_bubble->SetVisible(false); |
406 else | 451 else |
407 status_area_widget()->SetHideWebNotifications(true); | 452 status_area_widget()->SetHideWebNotifications(true); |
408 } | 453 } |
409 | 454 |
410 void SystemTray::Initialize() { | 455 void SystemTray::Initialize() { |
411 internal::TrayBackgroundView::Initialize(); | 456 internal::TrayBackgroundView::Initialize(); |
412 CreateItems(); | 457 CreateItems(); |
413 } | 458 } |
414 | 459 |
415 void SystemTray::SetShelfAlignment(ShelfAlignment alignment) { | 460 void SystemTray::SetShelfAlignment(ShelfAlignment alignment) { |
416 if (alignment == shelf_alignment()) | 461 if (alignment == shelf_alignment()) |
417 return; | 462 return; |
418 internal::TrayBackgroundView::SetShelfAlignment(alignment); | 463 internal::TrayBackgroundView::SetShelfAlignment(alignment); |
419 UpdateAfterShelfAlignmentChange(alignment); | 464 UpdateAfterShelfAlignmentChange(alignment); |
420 // Destroy any existing bubble so that it is rebuilt correctly. | 465 // Destroy any existing bubble so that it is rebuilt correctly. |
421 bubble_.reset(); | 466 system_bubble_.reset(); |
422 // Rebuild any notification bubble. | 467 // Rebuild any notification bubble. |
423 if (notification_bubble_.get()) { | 468 if (notification_bubble_.get()) { |
424 notification_bubble_.reset(); | 469 notification_bubble_.reset(); |
425 UpdateNotificationBubble(); | 470 UpdateNotificationBubble(); |
426 } | 471 } |
427 } | 472 } |
428 | 473 |
429 void SystemTray::AnchorUpdated() { | 474 void SystemTray::AnchorUpdated() { |
430 if (notification_bubble_.get()) { | 475 if (notification_bubble_.get()) { |
431 notification_bubble_->bubble_view()->UpdateBubble(); | 476 notification_bubble_->bubble_view()->UpdateBubble(); |
432 // Ensure that the notification buble is above the launcher/status area. | 477 // Ensure that the notification buble is above the launcher/status area. |
433 notification_bubble_->bubble_view()->GetWidget()->StackAtTop(); | 478 notification_bubble_->bubble_view()->GetWidget()->StackAtTop(); |
434 } | 479 } |
435 if (bubble_.get()) | 480 if (system_bubble_.get()) |
436 bubble_->bubble_view()->UpdateBubble(); | 481 system_bubble_->bubble_view()->UpdateBubble(); |
437 } | 482 } |
438 | 483 |
439 string16 SystemTray::GetAccessibleName() { | 484 string16 SystemTray::GetAccessibleNameForTray() { |
440 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ACCESSIBLE_NAME); | 485 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ACCESSIBLE_NAME); |
441 } | 486 } |
442 | 487 |
443 void SystemTray::HideBubbleWithView(const TrayBubbleView* bubble_view) { | 488 void SystemTray::HideBubbleWithView(const TrayBubbleView* bubble_view) { |
444 if (bubble_.get() && bubble_view == bubble_->bubble_view()) { | 489 if (system_bubble_.get() && bubble_view == system_bubble_->bubble_view()) { |
445 DestroyBubble(); | 490 DestroySystemBubble(); |
446 UpdateNotificationBubble(); // State changed, re-create notifications. | 491 UpdateNotificationBubble(); // State changed, re-create notifications. |
447 Shell::GetInstance()->shelf()->UpdateAutoHideState(); | 492 Shell::GetInstance()->shelf()->UpdateAutoHideState(); |
448 } else if (notification_bubble_.get() && | 493 } else if (notification_bubble_.get() && |
449 bubble_view == notification_bubble_->bubble_view()) { | 494 bubble_view == notification_bubble_->bubble_view()) { |
450 DestroyNotificationBubble(); | 495 DestroyNotificationBubble(); |
451 } | 496 } |
452 } | 497 } |
453 | 498 |
454 bool SystemTray::ClickedOutsideBubble() { | 499 bool SystemTray::ClickedOutsideBubble() { |
455 if (!bubble_.get() || | 500 if (!system_bubble_.get()) |
456 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_NOTIFICATION) { | |
457 return false; | 501 return false; |
502 HideBubbleWithView(system_bubble_->bubble_view()); | |
503 return true; | |
504 } | |
505 | |
506 void SystemTray::BubbleViewDestroyed() { | |
507 if (system_bubble_.get()) { | |
508 system_bubble_->bubble()->DestroyItemViews(); | |
509 system_bubble_->bubble()->BubbleViewDestroyed(); | |
458 } | 510 } |
459 HideBubbleWithView(bubble_->bubble_view()); | 511 } |
460 return true; | 512 |
513 void SystemTray::OnMouseEnteredView() { | |
514 if (system_bubble_.get()) | |
515 system_bubble_->bubble()->StopAutoCloseTimer(); | |
516 } | |
517 | |
518 void SystemTray::OnMouseExitedView() { | |
519 if (system_bubble_.get()) | |
520 system_bubble_->bubble()->RestartAutoCloseTimer(); | |
521 } | |
522 | |
523 string16 SystemTray::GetAccessibleNameForBubble() { | |
524 return GetAccessibleNameForTray(); | |
525 } | |
526 | |
527 gfx::Rect SystemTray::GetAnchorRect( | |
528 views::Widget* anchor_widget, | |
529 TrayBubbleView::AnchorType anchor_type, | |
530 TrayBubbleView::AnchorAlignment anchor_alignment) { | |
531 return GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment); | |
532 } | |
533 | |
534 void SystemTray::HideBubble(const TrayBubbleView* bubble_view) { | |
535 HideBubbleWithView(bubble_view); | |
461 } | 536 } |
462 | 537 |
463 bool SystemTray::PerformAction(const ui::Event& event) { | 538 bool SystemTray::PerformAction(const ui::Event& event) { |
464 // If we're already showing the default view, hide it; otherwise, show it | 539 // If we're already showing the default view, hide it; otherwise, show it |
465 // (and hide any popup that's currently shown). | 540 // (and hide any popup that's currently shown). |
466 if (bubble_.get() && | 541 if (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DEFAULT)) { |
467 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_DEFAULT) { | 542 system_bubble_->bubble()->Close(); |
468 bubble_->Close(); | |
469 } else { | 543 } else { |
470 int arrow_offset = TrayBubbleView::InitParams::kArrowDefaultOffset; | 544 int arrow_offset = TrayBubbleView::InitParams::kArrowDefaultOffset; |
471 if (event.IsMouseEvent() || event.type() == ui::ET_GESTURE_TAP) { | 545 if (event.IsMouseEvent() || event.type() == ui::ET_GESTURE_TAP) { |
472 const ui::LocatedEvent& located_event = | 546 const ui::LocatedEvent& located_event = |
473 static_cast<const ui::LocatedEvent&>(event); | 547 static_cast<const ui::LocatedEvent&>(event); |
474 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { | 548 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { |
475 gfx::Point point(located_event.x(), 0); | 549 gfx::Point point(located_event.x(), 0); |
476 ConvertPointToWidget(this, &point); | 550 ConvertPointToWidget(this, &point); |
477 arrow_offset = point.x(); | 551 arrow_offset = point.x(); |
478 } | 552 } |
479 } | 553 } |
480 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset); | 554 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset); |
481 } | 555 } |
482 return true; | 556 return true; |
483 } | 557 } |
484 | 558 |
485 } // namespace ash | 559 } // namespace ash |
OLD | NEW |