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" |
(...skipping 12 matching lines...) Expand all Loading... |
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" | 24 #include "ash/system/tray/system_tray_bubble.h" |
25 #include "ash/system/tray/system_tray_delegate.h" | 25 #include "ash/system/tray/system_tray_delegate.h" |
26 #include "ash/system/tray/system_tray_item.h" | 26 #include "ash/system/tray/system_tray_item.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_update.h" | 30 #include "ash/system/tray_update.h" |
31 #include "ash/system/user/login_status.h" | 31 #include "ash/system/user/login_status.h" |
32 #include "ash/system/user/tray_user.h" | 32 #include "ash/system/user/tray_user.h" |
33 #include "ash/wm/shelf_layout_manager.h" | |
34 #include "base/logging.h" | 33 #include "base/logging.h" |
35 #include "base/timer.h" | 34 #include "base/timer.h" |
36 #include "base/utf_string_conversions.h" | 35 #include "base/utf_string_conversions.h" |
37 #include "grit/ash_strings.h" | 36 #include "grit/ash_strings.h" |
38 #include "ui/aura/root_window.h" | 37 #include "ui/aura/root_window.h" |
39 #include "ui/base/accessibility/accessible_view_state.h" | 38 #include "ui/base/accessibility/accessible_view_state.h" |
40 #include "ui/base/events.h" | 39 #include "ui/base/events.h" |
41 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
42 #include "ui/compositor/layer.h" | 41 #include "ui/compositor/layer.h" |
43 #include "ui/gfx/canvas.h" | 42 #include "ui/gfx/canvas.h" |
(...skipping 20 matching lines...) Expand all Loading... |
64 bluetooth_observer_(NULL), | 63 bluetooth_observer_(NULL), |
65 brightness_observer_(NULL), | 64 brightness_observer_(NULL), |
66 caps_lock_observer_(NULL), | 65 caps_lock_observer_(NULL), |
67 clock_observer_(NULL), | 66 clock_observer_(NULL), |
68 drive_observer_(NULL), | 67 drive_observer_(NULL), |
69 ime_observer_(NULL), | 68 ime_observer_(NULL), |
70 locale_observer_(NULL), | 69 locale_observer_(NULL), |
71 network_observer_(NULL), | 70 network_observer_(NULL), |
72 update_observer_(NULL), | 71 update_observer_(NULL), |
73 user_observer_(NULL), | 72 user_observer_(NULL), |
74 should_show_launcher_(false), | |
75 default_bubble_height_(0), | 73 default_bubble_height_(0), |
76 hide_notifications_(false) { | 74 hide_notifications_(false) { |
77 } | 75 } |
78 | 76 |
79 SystemTray::~SystemTray() { | 77 SystemTray::~SystemTray() { |
80 bubble_.reset(); | 78 bubble_.reset(); |
81 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); | 79 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); |
82 it != items_.end(); | 80 it != items_.end(); |
83 ++it) { | 81 ++it) { |
84 (*it)->DestroyTrayView(); | 82 (*it)->DestroyTrayView(); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 (*it)->UpdateAfterShelfAlignmentChange(alignment); | 221 (*it)->UpdateAfterShelfAlignmentChange(alignment); |
224 } | 222 } |
225 } | 223 } |
226 | 224 |
227 void SystemTray::SetHideNotifications(bool hide_notifications) { | 225 void SystemTray::SetHideNotifications(bool hide_notifications) { |
228 if (notification_bubble_.get()) | 226 if (notification_bubble_.get()) |
229 notification_bubble_->SetVisible(!hide_notifications); | 227 notification_bubble_->SetVisible(!hide_notifications); |
230 hide_notifications_ = hide_notifications; | 228 hide_notifications_ = hide_notifications; |
231 } | 229 } |
232 | 230 |
| 231 bool SystemTray::IsSystemBubbleVisible() const { |
| 232 return (bubble_.get() && bubble_->IsVisible()); |
| 233 } |
| 234 |
233 bool SystemTray::IsAnyBubbleVisible() const { | 235 bool SystemTray::IsAnyBubbleVisible() const { |
234 if (bubble_.get() && bubble_->IsVisible()) | 236 if (bubble_.get() && bubble_->IsVisible()) |
235 return true; | 237 return true; |
236 if (notification_bubble_.get() && notification_bubble_->IsVisible()) | 238 if (notification_bubble_.get() && notification_bubble_->IsVisible()) |
237 return true; | 239 return true; |
238 return false; | 240 return false; |
239 } | 241 } |
240 | 242 |
| 243 bool SystemTray::IsMouseInNotificationBubble() const { |
| 244 if (!notification_bubble_.get()) |
| 245 return false; |
| 246 return notification_bubble_->bubble_view()->GetBoundsInScreen().Contains( |
| 247 gfx::Screen::GetCursorScreenPoint()); |
| 248 } |
| 249 |
241 bool SystemTray::CloseBubbleForTest() const { | 250 bool SystemTray::CloseBubbleForTest() const { |
242 if (!bubble_.get()) | 251 if (!bubble_.get()) |
243 return false; | 252 return false; |
244 bubble_->Close(); | 253 bubble_->Close(); |
245 return true; | 254 return true; |
246 } | 255 } |
247 | 256 |
248 // Private methods. | 257 // Private methods. |
249 | 258 |
250 void SystemTray::DestroyBubble() { | 259 void SystemTray::DestroyBubble() { |
251 bubble_.reset(); | 260 bubble_.reset(); |
252 detailed_item_ = NULL; | 261 detailed_item_ = NULL; |
253 } | 262 } |
254 | 263 |
255 void SystemTray::RemoveBubble(SystemTrayBubble* bubble) { | 264 void SystemTray::RemoveBubble(SystemTrayBubble* bubble) { |
256 if (bubble == bubble_.get()) { | 265 if (bubble == bubble_.get()) { |
257 DestroyBubble(); | 266 DestroyBubble(); |
258 UpdateNotificationBubble(); // State changed, re-create notifications. | 267 UpdateNotificationBubble(); // State changed, re-create notifications. |
259 if (should_show_launcher_) { | 268 UpdateShouldShowLauncher(); |
260 // No need to show the launcher if the mouse isn't over the status area | |
261 // anymore. | |
262 should_show_launcher_ = GetWidget()->GetWindowBoundsInScreen().Contains( | |
263 gfx::Screen::GetCursorScreenPoint()); | |
264 if (!should_show_launcher_) | |
265 Shell::GetInstance()->shelf()->UpdateAutoHideState(); | |
266 } | |
267 } else if (bubble == notification_bubble_) { | 269 } else if (bubble == notification_bubble_) { |
268 notification_bubble_.reset(); | 270 notification_bubble_.reset(); |
269 } else { | 271 } else { |
270 NOTREACHED(); | 272 NOTREACHED(); |
271 } | 273 } |
272 } | 274 } |
273 | 275 |
274 int SystemTray::GetTrayXOffset(SystemTrayItem* item) const { | 276 int SystemTray::GetTrayXOffset(SystemTrayItem* item) const { |
275 // Don't attempt to align the arrow if the shelf is on the left or right. | 277 // Don't attempt to align the arrow if the shelf is on the left or right. |
276 if (shelf_alignment() != SHELF_ALIGNMENT_BOTTOM) | 278 if (shelf_alignment() != SHELF_ALIGNMENT_BOTTOM) |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 } | 335 } |
334 // Save height of default view for creating detailed views directly. | 336 // Save height of default view for creating detailed views directly. |
335 if (!detailed) | 337 if (!detailed) |
336 default_bubble_height_ = bubble_->bubble_view()->height(); | 338 default_bubble_height_ = bubble_->bubble_view()->height(); |
337 | 339 |
338 if (detailed && items.size() > 0) | 340 if (detailed && items.size() > 0) |
339 detailed_item_ = items[0]; | 341 detailed_item_ = items[0]; |
340 else | 342 else |
341 detailed_item_ = NULL; | 343 detailed_item_ = NULL; |
342 | 344 |
343 // If we have focus the shelf should be visible and we need to continue | |
344 // showing the shelf when the popup is shown. | |
345 if (GetWidget()->IsActive()) | |
346 should_show_launcher_ = true; | |
347 | |
348 UpdateNotificationBubble(); // State changed, re-create notifications. | 345 UpdateNotificationBubble(); // State changed, re-create notifications. |
349 status_area_widget()->HideNonSystemNotifications(); | 346 status_area_widget()->HideNonSystemNotifications(); |
| 347 UpdateShouldShowLauncher(); |
350 } | 348 } |
351 | 349 |
352 void SystemTray::UpdateNotificationBubble() { | 350 void SystemTray::UpdateNotificationBubble() { |
353 // Only show the notification buble if we have notifications and we are not | 351 // Only show the notification buble if we have notifications and we are not |
354 // showing the default bubble. | 352 // showing the default bubble. |
355 if (notification_items_.empty() || | 353 if (notification_items_.empty() || |
356 (bubble_.get() && | 354 (bubble_.get() && |
357 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_DEFAULT)) { | 355 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_DEFAULT)) { |
358 notification_bubble_.reset(); | 356 notification_bubble_.reset(); |
359 return; | 357 return; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 gfx::Point point(located_event.x(), 0); | 438 gfx::Point point(located_event.x(), 0); |
441 ConvertPointToWidget(this, &point); | 439 ConvertPointToWidget(this, &point); |
442 arrow_offset = point.x(); | 440 arrow_offset = point.x(); |
443 } | 441 } |
444 } | 442 } |
445 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset); | 443 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset); |
446 } | 444 } |
447 return true; | 445 return true; |
448 } | 446 } |
449 | 447 |
450 void SystemTray::OnMouseEntered(const ui::MouseEvent& event) { | |
451 TrayBackgroundView::OnMouseEntered(event); | |
452 should_show_launcher_ = true; | |
453 } | |
454 | |
455 void SystemTray::OnMouseExited(const ui::MouseEvent& event) { | |
456 TrayBackgroundView::OnMouseExited(event); | |
457 // When the popup closes we'll update |should_show_launcher_|. | |
458 if (!bubble_.get()) | |
459 should_show_launcher_ = false; | |
460 } | |
461 | |
462 void SystemTray::GetAccessibleState(ui::AccessibleViewState* state) { | 448 void SystemTray::GetAccessibleState(ui::AccessibleViewState* state) { |
463 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; | 449 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; |
464 state->name = l10n_util::GetStringUTF16( | 450 state->name = l10n_util::GetStringUTF16( |
465 IDS_ASH_STATUS_TRAY_ACCESSIBLE_NAME); | 451 IDS_ASH_STATUS_TRAY_ACCESSIBLE_NAME); |
466 } | 452 } |
467 | 453 |
468 } // namespace ash | 454 } // namespace ash |
OLD | NEW |