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