| 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/chromeos/tray_display.h" | 5 #include "ash/system/chromeos/tray_display.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "ash/common/metrics/user_metrics_action.h" |
| 11 #include "ash/common/system/chromeos/devicetype_utils.h" | 12 #include "ash/common/system/chromeos/devicetype_utils.h" |
| 12 #include "ash/common/system/system_notifier.h" | 13 #include "ash/common/system/system_notifier.h" |
| 13 #include "ash/common/system/tray/actionable_view.h" | 14 #include "ash/common/system/tray/actionable_view.h" |
| 14 #include "ash/common/system/tray/fixed_sized_image_view.h" | 15 #include "ash/common/system/tray/fixed_sized_image_view.h" |
| 15 #include "ash/common/system/tray/system_tray_delegate.h" | 16 #include "ash/common/system/tray/system_tray_delegate.h" |
| 16 #include "ash/common/system/tray/tray_constants.h" | 17 #include "ash/common/system/tray/tray_constants.h" |
| 17 #include "ash/common/system/tray/tray_notification_view.h" | 18 #include "ash/common/system/tray/tray_notification_view.h" |
| 18 #include "ash/common/wm_shell.h" | 19 #include "ash/common/wm_shell.h" |
| 19 #include "ash/display/display_manager.h" | 20 #include "ash/display/display_manager.h" |
| 20 #include "ash/display/screen_orientation_controller_chromeos.h" | 21 #include "ash/display/screen_orientation_controller_chromeos.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | 105 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
| 105 int64_t id = display_manager->GetDisplayAt(i).id(); | 106 int64_t id = display_manager->GetDisplayAt(i).id(); |
| 106 if (id == internal_id) | 107 if (id == internal_id) |
| 107 continue; | 108 continue; |
| 108 lines.push_back(GetDisplayInfoLine(id)); | 109 lines.push_back(GetDisplayInfoLine(id)); |
| 109 } | 110 } |
| 110 | 111 |
| 111 return base::JoinString(lines, base::ASCIIToUTF16("\n")); | 112 return base::JoinString(lines, base::ASCIIToUTF16("\n")); |
| 112 } | 113 } |
| 113 | 114 |
| 114 void OpenSettings() { | 115 // Attempts to open the display settings, returns true if successful. |
| 116 bool OpenSettings() { |
| 115 // switch is intentionally introduced without default, to cause an error when | 117 // switch is intentionally introduced without default, to cause an error when |
| 116 // a new type of login status is introduced. | 118 // a new type of login status is introduced. |
| 117 switch (WmShell::Get()->system_tray_delegate()->GetUserLoginStatus()) { | 119 switch (WmShell::Get()->system_tray_delegate()->GetUserLoginStatus()) { |
| 118 case LoginStatus::NOT_LOGGED_IN: | 120 case LoginStatus::NOT_LOGGED_IN: |
| 119 case LoginStatus::LOCKED: | 121 case LoginStatus::LOCKED: |
| 120 return; | 122 return false; |
| 121 | 123 |
| 122 case LoginStatus::USER: | 124 case LoginStatus::USER: |
| 123 case LoginStatus::OWNER: | 125 case LoginStatus::OWNER: |
| 124 case LoginStatus::GUEST: | 126 case LoginStatus::GUEST: |
| 125 case LoginStatus::PUBLIC: | 127 case LoginStatus::PUBLIC: |
| 126 case LoginStatus::SUPERVISED: | 128 case LoginStatus::SUPERVISED: |
| 127 case LoginStatus::KIOSK_APP: | 129 case LoginStatus::KIOSK_APP: |
| 128 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 130 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 129 if (delegate->ShouldShowSettings()) | 131 if (delegate->ShouldShowSettings()) { |
| 130 delegate->ShowDisplaySettings(); | 132 delegate->ShowDisplaySettings(); |
| 133 return true; |
| 134 } |
| 135 } |
| 136 |
| 137 return false; |
| 138 } |
| 139 |
| 140 // Callback to handle a user selecting the notification view. |
| 141 void OpenSettingsFromNotification() { |
| 142 WmShell::Get()->RecordUserMetricsAction( |
| 143 UMA_STATUS_AREA_DISPLAY_NOTIFICATION_SELECTED); |
| 144 if (OpenSettings()) { |
| 145 WmShell::Get()->RecordUserMetricsAction( |
| 146 UMA_STATUS_AREA_DISPLAY_NOTIFICATION_SHOW_SETTINGS); |
| 131 } | 147 } |
| 132 } | 148 } |
| 133 | 149 |
| 134 } // namespace | 150 } // namespace |
| 135 | 151 |
| 136 const char TrayDisplay::kNotificationId[] = "chrome://settings/display"; | 152 const char TrayDisplay::kNotificationId[] = "chrome://settings/display"; |
| 137 | 153 |
| 138 class DisplayView : public ActionableView { | 154 class DisplayView : public ActionableView { |
| 139 public: | 155 public: |
| 140 explicit DisplayView() { | 156 explicit DisplayView() { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 (display_info.active_rotation_source() != | 288 (display_info.active_rotation_source() != |
| 273 display::Display::ROTATION_SOURCE_ACCELEROMETER || | 289 display::Display::ROTATION_SOURCE_ACCELEROMETER || |
| 274 !display::Display::IsInternalDisplayId(first_display_id))) || | 290 !display::Display::IsInternalDisplayId(first_display_id))) || |
| 275 display_info.configured_ui_scale() != 1.0f || | 291 display_info.configured_ui_scale() != 1.0f || |
| 276 !display_info.overscan_insets_in_dip().IsEmpty() || | 292 !display_info.overscan_insets_in_dip().IsEmpty() || |
| 277 display_info.has_overscan(); | 293 display_info.has_overscan(); |
| 278 } | 294 } |
| 279 | 295 |
| 280 // Overridden from ActionableView. | 296 // Overridden from ActionableView. |
| 281 bool PerformAction(const ui::Event& event) override { | 297 bool PerformAction(const ui::Event& event) override { |
| 282 OpenSettings(); | 298 WmShell::Get()->RecordUserMetricsAction( |
| 299 UMA_STATUS_AREA_DISPLAY_DEFAULT_SELECTED); |
| 300 if (OpenSettings()) { |
| 301 WmShell::Get()->RecordUserMetricsAction( |
| 302 UMA_STATUS_AREA_DISPLAY_DEFAULT_SHOW_SETTINGS); |
| 303 } |
| 283 return true; | 304 return true; |
| 284 } | 305 } |
| 285 | 306 |
| 286 void OnBoundsChanged(const gfx::Rect& previous_bounds) override { | 307 void OnBoundsChanged(const gfx::Rect& previous_bounds) override { |
| 287 int label_max_width = bounds().width() - kTrayPopupPaddingHorizontal * 2 - | 308 int label_max_width = bounds().width() - kTrayPopupPaddingHorizontal * 2 - |
| 288 kTrayPopupPaddingBetweenItems - | 309 kTrayPopupPaddingBetweenItems - |
| 289 image_->GetPreferredSize().width(); | 310 image_->GetPreferredSize().width(); |
| 290 label_->SizeToFit(label_max_width); | 311 label_->SizeToFit(label_max_width); |
| 291 } | 312 } |
| 292 | 313 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 418 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 398 std::unique_ptr<Notification> notification(new Notification( | 419 std::unique_ptr<Notification> notification(new Notification( |
| 399 message_center::NOTIFICATION_TYPE_SIMPLE, kNotificationId, message, | 420 message_center::NOTIFICATION_TYPE_SIMPLE, kNotificationId, message, |
| 400 additional_message, bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY), | 421 additional_message, bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY), |
| 401 base::string16(), // display_source | 422 base::string16(), // display_source |
| 402 GURL(), | 423 GURL(), |
| 403 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, | 424 message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT, |
| 404 system_notifier::kNotifierDisplay), | 425 system_notifier::kNotifierDisplay), |
| 405 message_center::RichNotificationData(), | 426 message_center::RichNotificationData(), |
| 406 new message_center::HandleNotificationClickedDelegate( | 427 new message_center::HandleNotificationClickedDelegate( |
| 407 base::Bind(&OpenSettings)))); | 428 base::Bind(&OpenSettingsFromNotification)))); |
| 408 | 429 |
| 430 WmShell::Get()->RecordUserMetricsAction( |
| 431 UMA_STATUS_AREA_DISPLAY_NOTIFICATION_CREATED); |
| 409 message_center::MessageCenter::Get()->AddNotification( | 432 message_center::MessageCenter::Get()->AddNotification( |
| 410 std::move(notification)); | 433 std::move(notification)); |
| 411 } | 434 } |
| 412 | 435 |
| 413 views::View* TrayDisplay::CreateDefaultView(LoginStatus status) { | 436 views::View* TrayDisplay::CreateDefaultView(LoginStatus status) { |
| 414 DCHECK(default_ == NULL); | 437 DCHECK(default_ == NULL); |
| 415 default_ = new DisplayView(); | 438 default_ = new DisplayView(); |
| 416 return default_; | 439 return default_; |
| 417 } | 440 } |
| 418 | 441 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 449 bool TrayDisplay::GetAccessibleStateForTesting(ui::AXViewState* state) { | 472 bool TrayDisplay::GetAccessibleStateForTesting(ui::AXViewState* state) { |
| 450 views::View* view = default_; | 473 views::View* view = default_; |
| 451 if (view) { | 474 if (view) { |
| 452 view->GetAccessibleState(state); | 475 view->GetAccessibleState(state); |
| 453 return true; | 476 return true; |
| 454 } | 477 } |
| 455 return false; | 478 return false; |
| 456 } | 479 } |
| 457 | 480 |
| 458 } // namespace ash | 481 } // namespace ash |
| OLD | NEW |