| 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/common/ash_switches.h" | 7 #include "ash/common/ash_switches.h" |
| 8 #include "ash/common/session/session_state_delegate.h" | 8 #include "ash/common/session/session_state_delegate.h" |
| 9 #include "ash/common/shelf/wm_shelf.h" | 9 #include "ash/common/shelf/wm_shelf.h" |
| 10 #include "ash/common/shelf/wm_shelf_util.h" | 10 #include "ash/common/shelf/wm_shelf_util.h" |
| 11 #include "ash/common/shell_window_ids.h" | 11 #include "ash/common/shell_window_ids.h" |
| 12 #include "ash/common/system/date/tray_date.h" | 12 #include "ash/common/system/date/tray_date.h" |
| 13 #include "ash/common/system/tray/system_tray_delegate.h" | 13 #include "ash/common/system/tray/system_tray_delegate.h" |
| 14 #include "ash/common/system/tray/system_tray_item.h" | 14 #include "ash/common/system/tray/system_tray_item.h" |
| 15 #include "ash/common/system/tray/tray_bubble_wrapper.h" |
| 15 #include "ash/common/system/tray/tray_constants.h" | 16 #include "ash/common/system/tray/tray_constants.h" |
| 16 #include "ash/common/system/tray_accessibility.h" | 17 #include "ash/common/system/tray_accessibility.h" |
| 17 #include "ash/common/system/update/tray_update.h" | 18 #include "ash/common/system/update/tray_update.h" |
| 18 #include "ash/common/wm_lookup.h" | 19 #include "ash/common/wm_lookup.h" |
| 19 #include "ash/common/wm_root_window_controller.h" | 20 #include "ash/common/wm_root_window_controller.h" |
| 20 #include "ash/common/wm_shell.h" | 21 #include "ash/common/wm_shell.h" |
| 21 #include "ash/common/wm_window.h" | 22 #include "ash/common/wm_window.h" |
| 22 #include "ash/shell.h" | 23 #include "ash/shell.h" |
| 23 #include "ash/system/cast/tray_cast.h" | 24 #include "ash/system/cast/tray_cast.h" |
| 24 #include "ash/system/status_area_widget.h" | 25 #include "ash/system/status_area_widget.h" |
| 25 #include "ash/system/tray/tray_bubble_wrapper.h" | |
| 26 #include "ash/system/user/login_status.h" | 26 #include "ash/system/user/login_status.h" |
| 27 #include "ash/system/user/tray_user.h" | 27 #include "ash/system/user/tray_user.h" |
| 28 #include "ash/system/user/tray_user_separator.h" | 28 #include "ash/system/user/tray_user_separator.h" |
| 29 #include "ash/system/web_notification/web_notification_tray.h" | 29 #include "ash/system/web_notification/web_notification_tray.h" |
| 30 #include "base/logging.h" | 30 #include "base/logging.h" |
| 31 #include "base/metrics/histogram.h" | 31 #include "base/metrics/histogram.h" |
| 32 #include "base/strings/utf_string_conversions.h" | 32 #include "base/strings/utf_string_conversions.h" |
| 33 #include "base/timer/timer.h" | 33 #include "base/timer/timer.h" |
| 34 #include "grit/ash_strings.h" | 34 #include "grit/ash_strings.h" |
| 35 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 std::unique_ptr<TrayBubbleWrapper> bubble_wrapper_; | 123 std::unique_ptr<TrayBubbleWrapper> bubble_wrapper_; |
| 124 bool is_persistent_; | 124 bool is_persistent_; |
| 125 | 125 |
| 126 DISALLOW_COPY_AND_ASSIGN(SystemBubbleWrapper); | 126 DISALLOW_COPY_AND_ASSIGN(SystemBubbleWrapper); |
| 127 }; | 127 }; |
| 128 | 128 |
| 129 | 129 |
| 130 // SystemTray | 130 // SystemTray |
| 131 | 131 |
| 132 SystemTray::SystemTray(StatusAreaWidget* status_area_widget) | 132 SystemTray::SystemTray(StatusAreaWidget* status_area_widget) |
| 133 : TrayBackgroundView(status_area_widget), | 133 : TrayBackgroundView(status_area_widget->wm_shelf()), |
| 134 status_area_widget_(status_area_widget), |
| 134 items_(), | 135 items_(), |
| 135 detailed_item_(nullptr), | 136 detailed_item_(nullptr), |
| 136 default_bubble_height_(0), | 137 default_bubble_height_(0), |
| 137 hide_notifications_(false), | 138 hide_notifications_(false), |
| 138 full_system_tray_menu_(false), | 139 full_system_tray_menu_(false), |
| 139 tray_accessibility_(nullptr), | 140 tray_accessibility_(nullptr), |
| 140 tray_cast_(nullptr), | 141 tray_cast_(nullptr), |
| 141 tray_date_(nullptr), | 142 tray_date_(nullptr), |
| 142 tray_update_(nullptr), | 143 tray_update_(nullptr), |
| 143 screen_capture_tray_item_(nullptr), | 144 screen_capture_tray_item_(nullptr), |
| 144 screen_share_tray_item_(nullptr) { | 145 screen_share_tray_item_(nullptr) { |
| 146 DCHECK(status_area_widget_); |
| 145 SetContentsBackground(); | 147 SetContentsBackground(); |
| 146 } | 148 } |
| 147 | 149 |
| 148 SystemTray::~SystemTray() { | 150 SystemTray::~SystemTray() { |
| 149 // Destroy any child views that might have back pointers before ~View(). | 151 // Destroy any child views that might have back pointers before ~View(). |
| 150 system_bubble_.reset(); | 152 system_bubble_.reset(); |
| 151 notification_bubble_.reset(); | 153 notification_bubble_.reset(); |
| 152 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); | 154 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); |
| 153 it != items_.end(); | 155 it != items_.end(); |
| 154 ++it) { | 156 ++it) { |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 default_bubble_height_ = system_bubble_->bubble_view()->height(); | 522 default_bubble_height_ = system_bubble_->bubble_view()->height(); |
| 521 | 523 |
| 522 if (detailed && items.size() > 0) | 524 if (detailed && items.size() > 0) |
| 523 detailed_item_ = items[0]; | 525 detailed_item_ = items[0]; |
| 524 else | 526 else |
| 525 detailed_item_ = NULL; | 527 detailed_item_ = NULL; |
| 526 | 528 |
| 527 UpdateNotificationBubble(); // State changed, re-create notifications. | 529 UpdateNotificationBubble(); // State changed, re-create notifications. |
| 528 if (!notification_bubble_) | 530 if (!notification_bubble_) |
| 529 UpdateWebNotifications(); | 531 UpdateWebNotifications(); |
| 530 GetShelf()->UpdateAutoHideState(); | 532 shelf()->UpdateAutoHideState(); |
| 531 | 533 |
| 532 // When we show the system menu in our alternate shelf layout, we need to | 534 // When we show the system menu in our alternate shelf layout, we need to |
| 533 // tint the background. | 535 // tint the background. |
| 534 if (full_system_tray_menu_) | 536 if (full_system_tray_menu_) |
| 535 SetDrawBackgroundAsActive(true); | 537 SetDrawBackgroundAsActive(true); |
| 536 } | 538 } |
| 537 | 539 |
| 538 void SystemTray::UpdateNotificationBubble() { | 540 void SystemTray::UpdateNotificationBubble() { |
| 539 // Only show the notification bubble if we have notifications. | 541 // Only show the notification bubble if we have notifications. |
| 540 if (notification_items_.empty()) { | 542 if (notification_items_.empty()) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 591 | 593 |
| 592 int height = 0; | 594 int height = 0; |
| 593 if (bubble_view) { | 595 if (bubble_view) { |
| 594 gfx::Rect work_area = | 596 gfx::Rect work_area = |
| 595 display::Screen::GetScreen() | 597 display::Screen::GetScreen() |
| 596 ->GetDisplayNearestWindow(bubble_view->GetWidget()->GetNativeView()) | 598 ->GetDisplayNearestWindow(bubble_view->GetWidget()->GetNativeView()) |
| 597 .work_area(); | 599 .work_area(); |
| 598 height = | 600 height = |
| 599 std::max(0, work_area.height() - bubble_view->GetBoundsInScreen().y()); | 601 std::max(0, work_area.height() - bubble_view->GetBoundsInScreen().y()); |
| 600 } | 602 } |
| 601 status_area_widget()->web_notification_tray()->SetSystemTrayHeight(height); | 603 status_area_widget_->web_notification_tray()->SetSystemTrayHeight(height); |
| 602 } | 604 } |
| 603 | 605 |
| 604 base::string16 SystemTray::GetAccessibleTimeString( | 606 base::string16 SystemTray::GetAccessibleTimeString( |
| 605 const base::Time& now) const { | 607 const base::Time& now) const { |
| 606 base::HourClockType hour_type = | 608 base::HourClockType hour_type = |
| 607 WmShell::Get()->system_tray_delegate()->GetHourClockType(); | 609 WmShell::Get()->system_tray_delegate()->GetHourClockType(); |
| 608 return base::TimeFormatTimeOfDayWithHourClockType( | 610 return base::TimeFormatTimeOfDayWithHourClockType( |
| 609 now, hour_type, base::kKeepAmPm); | 611 now, hour_type, base::kKeepAmPm); |
| 610 } | 612 } |
| 611 | 613 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 640 } | 642 } |
| 641 | 643 |
| 642 void SystemTray::BubbleResized(const TrayBubbleView* bubble_view) { | 644 void SystemTray::BubbleResized(const TrayBubbleView* bubble_view) { |
| 643 UpdateWebNotifications(); | 645 UpdateWebNotifications(); |
| 644 } | 646 } |
| 645 | 647 |
| 646 void SystemTray::HideBubbleWithView(const TrayBubbleView* bubble_view) { | 648 void SystemTray::HideBubbleWithView(const TrayBubbleView* bubble_view) { |
| 647 if (system_bubble_.get() && bubble_view == system_bubble_->bubble_view()) { | 649 if (system_bubble_.get() && bubble_view == system_bubble_->bubble_view()) { |
| 648 DestroySystemBubble(); | 650 DestroySystemBubble(); |
| 649 UpdateNotificationBubble(); // State changed, re-create notifications. | 651 UpdateNotificationBubble(); // State changed, re-create notifications. |
| 650 GetShelf()->UpdateAutoHideState(); | 652 shelf()->UpdateAutoHideState(); |
| 651 } else if (notification_bubble_.get() && | 653 } else if (notification_bubble_.get() && |
| 652 bubble_view == notification_bubble_->bubble_view()) { | 654 bubble_view == notification_bubble_->bubble_view()) { |
| 653 DestroyNotificationBubble(); | 655 DestroyNotificationBubble(); |
| 654 } | 656 } |
| 655 } | 657 } |
| 656 | 658 |
| 657 void SystemTray::ClickedOutsideBubble() { | 659 void SystemTray::ClickedOutsideBubble() { |
| 658 if (!system_bubble_ || system_bubble_->is_persistent()) | 660 if (!system_bubble_ || system_bubble_->is_persistent()) |
| 659 return; | 661 return; |
| 660 HideBubbleWithView(system_bubble_->bubble_view()); | 662 HideBubbleWithView(system_bubble_->bubble_view()); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 .work_area() | 770 .work_area() |
| 769 .height(); | 771 .height(); |
| 770 if (work_area_height > 0) { | 772 if (work_area_height > 0) { |
| 771 UMA_HISTOGRAM_CUSTOM_COUNTS( | 773 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 772 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", | 774 "Ash.SystemMenu.PercentageOfWorkAreaHeightCoveredByMenu", |
| 773 100 * bubble_view->height() / work_area_height, 1, 300, 100); | 775 100 * bubble_view->height() / work_area_height, 1, 300, 100); |
| 774 } | 776 } |
| 775 } | 777 } |
| 776 | 778 |
| 777 } // namespace ash | 779 } // namespace ash |
| OLD | NEW |