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