Chromium Code Reviews| 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/screen_layout_observer.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/metrics/user_metrics_action.h" |
| 12 #include "ash/common/system/chromeos/devicetype_utils.h" | 12 #include "ash/common/system/chromeos/devicetype_utils.h" |
| 13 #include "ash/common/system/system_notifier.h" | 13 #include "ash/common/system/system_notifier.h" |
| 14 #include "ash/common/system/tray/actionable_view.h" | 14 #include "ash/common/system/tray/actionable_view.h" |
|
James Cook
2016/08/05 17:00:24
not needed?
yiyix
2016/08/13 05:28:51
Done.
| |
| 15 #include "ash/common/system/tray/fixed_sized_image_view.h" | 15 #include "ash/common/system/tray/fixed_sized_image_view.h" |
| 16 #include "ash/common/system/tray/system_tray.h" | 16 #include "ash/common/system/tray/system_tray.h" |
| 17 #include "ash/common/system/tray/system_tray_delegate.h" | 17 #include "ash/common/system/tray/system_tray_delegate.h" |
| 18 #include "ash/common/system/tray/tray_constants.h" | 18 #include "ash/common/system/tray/tray_constants.h" |
| 19 #include "ash/common/system/tray/tray_notification_view.h" | 19 #include "ash/common/system/tray/tray_notification_view.h" |
| 20 #include "ash/common/wm_shell.h" | 20 #include "ash/common/wm_shell.h" |
| 21 #include "ash/display/display_manager.h" | 21 #include "ash/display/display_manager.h" |
| 22 #include "ash/display/screen_orientation_controller_chromeos.h" | 22 #include "ash/display/screen_orientation_controller_chromeos.h" |
| 23 #include "ash/shell.h" | 23 #include "ash/shell.h" |
| 24 #include "base/bind.h" | 24 #include "base/bind.h" |
| 25 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
| 26 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
| 27 #include "grit/ash_resources.h" | 27 #include "grit/ash_resources.h" |
| 28 #include "grit/ash_strings.h" | 28 #include "grit/ash_strings.h" |
| 29 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
| 30 #include "ui/base/resource/resource_bundle.h" | 30 #include "ui/base/resource/resource_bundle.h" |
| 31 #include "ui/display/display.h" | 31 #include "ui/display/display.h" |
| 32 #include "ui/message_center/message_center.h" | 32 #include "ui/message_center/message_center.h" |
| 33 #include "ui/message_center/notification.h" | 33 #include "ui/message_center/notification.h" |
| 34 #include "ui/message_center/notification_delegate.h" | 34 #include "ui/message_center/notification_delegate.h" |
| 35 #include "ui/views/controls/image_view.h" | 35 #include "ui/views/controls/image_view.h" |
| 36 #include "ui/views/controls/label.h" | 36 #include "ui/views/controls/label.h" |
|
James Cook
2016/08/05 17:00:24
not needed?
yiyix
2016/08/13 05:28:51
I will go through the list to remove all unnecessa
| |
| 37 #include "ui/views/layout/box_layout.h" | 37 #include "ui/views/layout/box_layout.h" |
| 38 | 38 |
| 39 using message_center::Notification; | 39 using message_center::Notification; |
| 40 | 40 |
| 41 namespace ash { | 41 namespace ash { |
| 42 namespace { | 42 namespace { |
| 43 | 43 |
| 44 DisplayManager* GetDisplayManager() { | 44 DisplayManager* GetDisplayManager() { |
| 45 return Shell::GetInstance()->display_manager(); | 45 return Shell::GetInstance()->display_manager(); |
| 46 } | 46 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 60 // to empty string if this happens on release build. | 60 // to empty string if this happens on release build. |
| 61 bool mirroring = display_manager->mirroring_display_id() == display_id; | 61 bool mirroring = display_manager->mirroring_display_id() == display_id; |
| 62 DCHECK(!mirroring); | 62 DCHECK(!mirroring); |
| 63 if (mirroring) | 63 if (mirroring) |
| 64 return base::string16(); | 64 return base::string16(); |
| 65 | 65 |
| 66 DCHECK(display->is_valid()); | 66 DCHECK(display->is_valid()); |
| 67 return base::UTF8ToUTF16(display->size().ToString()); | 67 return base::UTF8ToUTF16(display->size().ToString()); |
| 68 } | 68 } |
| 69 | 69 |
| 70 // Returns 1-line information for the specified display, like | |
| 71 // "InternalDisplay: 1280x750" | |
| 72 base::string16 GetDisplayInfoLine(int64_t display_id) { | |
| 73 const DisplayInfo& display_info = | |
| 74 GetDisplayManager()->GetDisplayInfo(display_id); | |
| 75 if (GetDisplayManager()->mirroring_display_id() == display_id) | |
| 76 return GetDisplayName(display_id); | |
| 77 | |
| 78 base::string16 size_text = GetDisplaySize(display_id); | |
| 79 base::string16 display_data; | |
| 80 if (display_info.has_overscan()) { | |
| 81 display_data = l10n_util::GetStringFUTF16( | |
| 82 IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION, size_text, | |
|
James Cook
2016/08/05 17:00:24
Are these strings still used? If not, remove them
yiyix
2016/08/13 05:28:51
Done.
| |
| 83 l10n_util::GetStringUTF16( | |
| 84 IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION_OVERSCAN)); | |
|
James Cook
2016/08/05 17:00:24
ditto
yiyix
2016/08/13 05:28:50
This string is used for notification. When user tr
| |
| 85 } else { | |
| 86 display_data = size_text; | |
| 87 } | |
| 88 | |
| 89 return l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_SINGLE_DISPLAY, | |
|
James Cook
2016/08/05 17:00:24
ditto
yiyix
2016/08/13 05:28:50
Done.
| |
| 90 GetDisplayName(display_id), display_data); | |
| 91 } | |
| 92 | |
| 93 base::string16 GetAllDisplayInfo() { | |
| 94 DisplayManager* display_manager = GetDisplayManager(); | |
| 95 std::vector<base::string16> lines; | |
| 96 int64_t internal_id = display::Display::kInvalidDisplayID; | |
| 97 // Make sure to show the internal display first. | |
| 98 if (!display_manager->IsInUnifiedMode() && | |
| 99 display::Display::IsInternalDisplayId( | |
| 100 display_manager->first_display_id())) { | |
| 101 internal_id = display_manager->first_display_id(); | |
| 102 lines.push_back(GetDisplayInfoLine(internal_id)); | |
| 103 } | |
| 104 | |
| 105 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | |
| 106 int64_t id = display_manager->GetDisplayAt(i).id(); | |
| 107 if (id == internal_id) | |
| 108 continue; | |
| 109 lines.push_back(GetDisplayInfoLine(id)); | |
| 110 } | |
| 111 | |
| 112 return base::JoinString(lines, base::ASCIIToUTF16("\n")); | |
| 113 } | |
| 114 | |
| 115 // Attempts to open the display settings, returns true if successful. | 70 // Attempts to open the display settings, returns true if successful. |
| 116 bool OpenSettings() { | 71 bool OpenSettings() { |
| 117 // switch is intentionally introduced without default, to cause an error when | 72 // switch is intentionally introduced without default, to cause an error when |
| 118 // a new type of login status is introduced. | 73 // a new type of login status is introduced. |
| 119 switch (WmShell::Get()->system_tray_delegate()->GetUserLoginStatus()) { | 74 switch (WmShell::Get()->system_tray_delegate()->GetUserLoginStatus()) { |
| 120 case LoginStatus::NOT_LOGGED_IN: | 75 case LoginStatus::NOT_LOGGED_IN: |
| 121 case LoginStatus::LOCKED: | 76 case LoginStatus::LOCKED: |
| 122 return false; | 77 return false; |
| 123 | 78 |
| 124 case LoginStatus::USER: | 79 case LoginStatus::USER: |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 142 WmShell::Get()->RecordUserMetricsAction( | 97 WmShell::Get()->RecordUserMetricsAction( |
| 143 UMA_STATUS_AREA_DISPLAY_NOTIFICATION_SELECTED); | 98 UMA_STATUS_AREA_DISPLAY_NOTIFICATION_SELECTED); |
| 144 if (OpenSettings()) { | 99 if (OpenSettings()) { |
| 145 WmShell::Get()->RecordUserMetricsAction( | 100 WmShell::Get()->RecordUserMetricsAction( |
| 146 UMA_STATUS_AREA_DISPLAY_NOTIFICATION_SHOW_SETTINGS); | 101 UMA_STATUS_AREA_DISPLAY_NOTIFICATION_SHOW_SETTINGS); |
| 147 } | 102 } |
| 148 } | 103 } |
| 149 | 104 |
| 150 } // namespace | 105 } // namespace |
| 151 | 106 |
| 152 const char TrayDisplay::kNotificationId[] = "chrome://settings/display"; | 107 base::string16 GetExternalDisplayName() { |
|
James Cook
2016/08/05 17:00:24
Is the old function comment still relevant? If so,
yiyix
2016/08/13 05:28:50
Done.
| |
| 108 DisplayManager* display_manager = GetDisplayManager(); | |
| 109 DCHECK(!display_manager->IsInMirrorMode()); | |
| 153 | 110 |
| 154 class DisplayView : public ActionableView { | 111 int64_t external_id = display::Display::kInvalidDisplayID; |
| 155 public: | 112 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
| 156 explicit DisplayView() { | 113 int64_t id = display_manager->GetDisplayAt(i).id(); |
| 157 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, | 114 if (!display::Display::IsInternalDisplayId(id)) { |
| 158 kTrayPopupPaddingHorizontal, 0, | 115 external_id = id; |
| 159 kTrayPopupPaddingBetweenItems)); | 116 break; |
| 160 | 117 } |
| 161 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
| 162 image_ = | |
| 163 new FixedSizedImageView(0, GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); | |
| 164 image_->SetImage( | |
| 165 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY).ToImageSkia()); | |
| 166 AddChildView(image_); | |
| 167 | |
| 168 label_ = new views::Label(); | |
| 169 label_->SetMultiLine(true); | |
| 170 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 171 AddChildView(label_); | |
| 172 Update(); | |
| 173 } | 118 } |
| 174 | 119 |
| 175 ~DisplayView() override {} | 120 if (external_id == display::Display::kInvalidDisplayID) { |
| 176 | 121 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); |
| 177 void Update() { | |
| 178 base::string16 message = GetTrayDisplayMessage(NULL); | |
| 179 if (message.empty() && ShouldShowFirstDisplayInfo()) | |
| 180 message = GetDisplayInfoLine(GetDisplayManager()->first_display_id()); | |
| 181 SetVisible(!message.empty()); | |
| 182 label_->SetText(message); | |
| 183 SetAccessibleName(message); | |
| 184 Layout(); | |
| 185 } | 122 } |
| 186 | 123 |
| 187 const views::Label* label() const { return label_; } | 124 // The external display name may have an annotation of "(width x height)" in |
| 188 | 125 // case that the display is rotated or its resolution is changed. |
| 189 // Overridden from views::View. | 126 base::string16 name = GetDisplayName(external_id); |
| 190 bool GetTooltipText(const gfx::Point& p, | 127 const DisplayInfo& display_info = |
| 191 base::string16* tooltip) const override { | 128 display_manager->GetDisplayInfo(external_id); |
| 192 base::string16 tray_message = GetTrayDisplayMessage(NULL); | 129 if (display_info.GetActiveRotation() != display::Display::ROTATE_0 || |
| 193 base::string16 display_message = GetAllDisplayInfo(); | 130 display_info.configured_ui_scale() != 1.0f || |
| 194 if (tray_message.empty() && display_message.empty()) | 131 !display_info.overscan_insets_in_dip().IsEmpty()) { |
| 195 return false; | 132 name = |
| 196 | 133 l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME, |
| 197 *tooltip = tray_message + base::ASCIIToUTF16("\n") + display_message; | 134 name, GetDisplaySize(external_id)); |
| 198 return true; | 135 } else if (display_info.overscan_insets_in_dip().IsEmpty() && |
| 136 display_info.has_overscan()) { | |
| 137 name = l10n_util::GetStringFUTF16( | |
| 138 IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME, name, | |
| 139 l10n_util::GetStringUTF16( | |
| 140 IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION_OVERSCAN)); | |
| 199 } | 141 } |
| 200 | 142 |
| 201 // Returns the name of the currently connected external display. | 143 return name; |
| 202 // This should not be used when the external display is used for | 144 } |
| 203 // mirroring. | |
| 204 static base::string16 GetExternalDisplayName() { | |
| 205 DisplayManager* display_manager = GetDisplayManager(); | |
| 206 DCHECK(!display_manager->IsInMirrorMode()); | |
| 207 | 145 |
| 208 int64_t external_id = display::Display::kInvalidDisplayID; | 146 base::string16 GetDisplayMessage(base::string16* additional_message_out) { |
|
James Cook
2016/08/05 17:00:24
ditto re: anonymous namespace
yiyix
2016/08/13 05:28:51
Done.
| |
| 209 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | 147 DisplayManager* display_manager = GetDisplayManager(); |
| 210 int64_t id = display_manager->GetDisplayAt(i).id(); | 148 if (display_manager->GetNumDisplays() > 1) { |
| 211 if (!display::Display::IsInternalDisplayId(id)) { | 149 if (display::Display::HasInternalDisplay()) { |
| 212 external_id = id; | 150 return l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, |
| 213 break; | 151 GetExternalDisplayName()); |
| 214 } | |
| 215 } | 152 } |
| 216 | 153 return l10n_util::GetStringUTF16( |
| 217 if (external_id == display::Display::kInvalidDisplayID) { | 154 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL); |
| 218 return l10n_util::GetStringUTF16( | |
| 219 IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); | |
| 220 } | |
| 221 | |
| 222 // The external display name may have an annotation of "(width x height)" in | |
| 223 // case that the display is rotated or its resolution is changed. | |
| 224 base::string16 name = GetDisplayName(external_id); | |
| 225 const DisplayInfo& display_info = | |
| 226 display_manager->GetDisplayInfo(external_id); | |
| 227 if (display_info.GetActiveRotation() != display::Display::ROTATE_0 || | |
| 228 display_info.configured_ui_scale() != 1.0f || | |
| 229 !display_info.overscan_insets_in_dip().IsEmpty()) { | |
| 230 name = | |
| 231 l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME, | |
| 232 name, GetDisplaySize(external_id)); | |
| 233 } else if (display_info.overscan_insets_in_dip().IsEmpty() && | |
| 234 display_info.has_overscan()) { | |
| 235 name = l10n_util::GetStringFUTF16( | |
| 236 IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME, name, | |
| 237 l10n_util::GetStringUTF16( | |
| 238 IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION_OVERSCAN)); | |
| 239 } | |
| 240 | |
| 241 return name; | |
| 242 } | 155 } |
| 243 | 156 |
| 244 static base::string16 GetTrayDisplayMessage( | 157 if (display_manager->IsInMirrorMode()) { |
| 245 base::string16* additional_message_out) { | 158 if (display::Display::HasInternalDisplay()) { |
| 246 DisplayManager* display_manager = GetDisplayManager(); | 159 return l10n_util::GetStringFUTF16( |
| 247 if (display_manager->GetNumDisplays() > 1) { | 160 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, |
| 248 if (display::Display::HasInternalDisplay()) { | 161 GetDisplayName(display_manager->mirroring_display_id())); |
| 249 return l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, | |
| 250 GetExternalDisplayName()); | |
| 251 } | |
| 252 return l10n_util::GetStringUTF16( | |
| 253 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL); | |
| 254 } | 162 } |
| 255 | 163 return l10n_util::GetStringUTF16( |
| 256 if (display_manager->IsInMirrorMode()) { | 164 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING_NO_INTERNAL); |
| 257 if (display::Display::HasInternalDisplay()) { | |
| 258 return l10n_util::GetStringFUTF16( | |
| 259 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, | |
| 260 GetDisplayName(display_manager->mirroring_display_id())); | |
| 261 } | |
| 262 return l10n_util::GetStringUTF16( | |
| 263 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING_NO_INTERNAL); | |
| 264 } | |
| 265 | |
| 266 if (display_manager->IsInUnifiedMode()) | |
| 267 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_UNIFIED); | |
| 268 | |
| 269 int64_t primary_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); | |
| 270 if (display::Display::HasInternalDisplay() && | |
| 271 !(display::Display::IsInternalDisplayId(primary_id))) { | |
| 272 if (additional_message_out) { | |
| 273 *additional_message_out = ash::SubstituteChromeOSDeviceType( | |
| 274 IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED_DESCRIPTION); | |
| 275 } | |
| 276 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED); | |
| 277 } | |
| 278 | |
| 279 return base::string16(); | |
| 280 } | 165 } |
| 281 | 166 |
| 282 private: | 167 if (display_manager->IsInUnifiedMode()) |
| 283 bool ShouldShowFirstDisplayInfo() const { | 168 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_UNIFIED); |
| 284 const int64_t first_display_id = GetDisplayManager()->first_display_id(); | |
| 285 | 169 |
| 286 const DisplayInfo& display_info = | 170 int64_t primary_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| 287 GetDisplayManager()->GetDisplayInfo(first_display_id); | 171 if (display::Display::HasInternalDisplay() && |
| 288 return (display_info.GetActiveRotation() != display::Display::ROTATE_0 && | 172 !(display::Display::IsInternalDisplayId(primary_id))) { |
| 289 (display_info.active_rotation_source() != | 173 if (additional_message_out) { |
| 290 display::Display::ROTATION_SOURCE_ACCELEROMETER || | 174 *additional_message_out = ash::SubstituteChromeOSDeviceType( |
| 291 !display::Display::IsInternalDisplayId(first_display_id))) || | 175 IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED_DESCRIPTION); |
| 292 display_info.configured_ui_scale() != 1.0f || | 176 } |
| 293 !display_info.overscan_insets_in_dip().IsEmpty() || | 177 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED); |
| 294 display_info.has_overscan(); | |
| 295 } | 178 } |
| 296 | 179 |
| 297 // Overridden from ActionableView. | 180 return base::string16(); |
| 298 bool PerformAction(const ui::Event& event) override { | 181 } |
| 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 } | |
| 305 return true; | |
| 306 } | |
| 307 | 182 |
| 308 void OnBoundsChanged(const gfx::Rect& previous_bounds) override { | 183 const char ScreenLayoutObserver::kNotificationId[] = |
| 309 int label_max_width = bounds().width() - kTrayPopupPaddingHorizontal * 2 - | 184 "chrome://settings/display"; |
| 310 kTrayPopupPaddingBetweenItems - | |
| 311 image_->GetPreferredSize().width(); | |
| 312 label_->SizeToFit(label_max_width); | |
| 313 } | |
| 314 | 185 |
| 315 views::ImageView* image_; | 186 ScreenLayoutObserver::ScreenLayoutObserver() { |
| 316 views::Label* label_; | |
| 317 | |
| 318 DISALLOW_COPY_AND_ASSIGN(DisplayView); | |
| 319 }; | |
| 320 | |
| 321 TrayDisplay::TrayDisplay(SystemTray* system_tray) | |
| 322 : SystemTrayItem(system_tray, UMA_DISPLAY), default_(nullptr) { | |
| 323 WmShell::Get()->AddDisplayObserver(this); | 187 WmShell::Get()->AddDisplayObserver(this); |
| 324 UpdateDisplayInfo(NULL); | 188 UpdateDisplayInfo(NULL); |
| 325 } | 189 } |
| 326 | 190 |
| 327 TrayDisplay::~TrayDisplay() { | 191 ScreenLayoutObserver::~ScreenLayoutObserver() { |
| 328 WmShell::Get()->RemoveDisplayObserver(this); | 192 WmShell::Get()->RemoveDisplayObserver(this); |
| 329 } | 193 } |
| 330 | 194 |
| 331 void TrayDisplay::UpdateDisplayInfo(TrayDisplay::DisplayInfoMap* old_info) { | 195 void ScreenLayoutObserver::UpdateDisplayInfo( |
| 196 ScreenLayoutObserver::DisplayInfoMap* old_info) { | |
| 332 if (old_info) | 197 if (old_info) |
| 333 old_info->swap(display_info_); | 198 old_info->swap(display_info_); |
| 334 display_info_.clear(); | 199 display_info_.clear(); |
| 335 | 200 |
| 336 DisplayManager* display_manager = GetDisplayManager(); | 201 DisplayManager* display_manager = GetDisplayManager(); |
| 337 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | 202 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
| 338 int64_t id = display_manager->GetDisplayAt(i).id(); | 203 int64_t id = display_manager->GetDisplayAt(i).id(); |
| 339 display_info_[id] = display_manager->GetDisplayInfo(id); | 204 display_info_[id] = display_manager->GetDisplayInfo(id); |
| 340 } | 205 } |
| 341 } | 206 } |
| 342 | 207 |
| 343 bool TrayDisplay::GetDisplayMessageForNotification( | 208 bool ScreenLayoutObserver::GetDisplayMessageForNotification( |
| 344 const TrayDisplay::DisplayInfoMap& old_info, | 209 const ScreenLayoutObserver::DisplayInfoMap& old_info, |
| 345 base::string16* message_out, | 210 base::string16* message_out, |
| 346 base::string16* additional_message_out) { | 211 base::string16* additional_message_out) { |
| 347 // Display is added or removed. Use the same message as the one in | 212 // Display is added or removed. Use the same message as the one in |
| 348 // the system tray. | 213 // the system tray. |
| 349 if (display_info_.size() != old_info.size()) { | 214 if (display_info_.size() != old_info.size()) { |
| 350 *message_out = DisplayView::GetTrayDisplayMessage(additional_message_out); | 215 *message_out = GetDisplayMessage(additional_message_out); |
| 351 return true; | 216 return true; |
| 352 } | 217 } |
| 353 | 218 |
| 354 for (DisplayInfoMap::const_iterator iter = display_info_.begin(); | 219 for (DisplayInfoMap::const_iterator iter = display_info_.begin(); |
| 355 iter != display_info_.end(); ++iter) { | 220 iter != display_info_.end(); ++iter) { |
| 356 DisplayInfoMap::const_iterator old_iter = old_info.find(iter->first); | 221 DisplayInfoMap::const_iterator old_iter = old_info.find(iter->first); |
| 357 // The display's number is same but different displays. This happens | 222 // The display's number is same but different displays. This happens |
| 358 // for the transition between docked mode and mirrored display. Falls back | 223 // for the transition between docked mode and mirrored display. Falls back |
| 359 // to GetTrayDisplayMessage(). | 224 // to GetDisplayMessage(). |
| 360 if (old_iter == old_info.end()) { | 225 if (old_iter == old_info.end()) { |
| 361 *message_out = DisplayView::GetTrayDisplayMessage(additional_message_out); | 226 *message_out = GetDisplayMessage(additional_message_out); |
| 362 return true; | 227 return true; |
| 363 } | 228 } |
| 364 | 229 |
| 365 if (iter->second.configured_ui_scale() != | 230 if (iter->second.configured_ui_scale() != |
| 366 old_iter->second.configured_ui_scale()) { | 231 old_iter->second.configured_ui_scale()) { |
| 367 *additional_message_out = l10n_util::GetStringFUTF16( | 232 *additional_message_out = l10n_util::GetStringFUTF16( |
| 368 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, | 233 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, |
| 369 GetDisplayName(iter->first), GetDisplaySize(iter->first)); | 234 GetDisplayName(iter->first), GetDisplaySize(iter->first)); |
| 370 return true; | 235 return true; |
| 371 } | 236 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 390 IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetDisplayName(iter->first), | 255 IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetDisplayName(iter->first), |
| 391 l10n_util::GetStringUTF16(rotation_text_id)); | 256 l10n_util::GetStringUTF16(rotation_text_id)); |
| 392 return true; | 257 return true; |
| 393 } | 258 } |
| 394 } | 259 } |
| 395 | 260 |
| 396 // Found nothing special | 261 // Found nothing special |
| 397 return false; | 262 return false; |
| 398 } | 263 } |
| 399 | 264 |
| 400 void TrayDisplay::CreateOrUpdateNotification( | 265 void ScreenLayoutObserver::CreateOrUpdateNotification( |
| 401 const base::string16& message, | 266 const base::string16& message, |
| 402 const base::string16& additional_message) { | 267 const base::string16& additional_message) { |
| 403 // Always remove the notification to make sure the notification appears | 268 // Always remove the notification to make sure the notification appears |
| 404 // as a popup in any situation. | 269 // as a popup in any situation. |
| 405 message_center::MessageCenter::Get()->RemoveNotification(kNotificationId, | 270 message_center::MessageCenter::Get()->RemoveNotification(kNotificationId, |
| 406 false /* by_user */); | 271 false /* by_user */); |
| 407 | 272 |
| 408 if (message.empty() && additional_message.empty()) | 273 if (message.empty() && additional_message.empty()) |
| 409 return; | 274 return; |
| 410 | 275 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 427 message_center::RichNotificationData(), | 292 message_center::RichNotificationData(), |
| 428 new message_center::HandleNotificationClickedDelegate( | 293 new message_center::HandleNotificationClickedDelegate( |
| 429 base::Bind(&OpenSettingsFromNotification)))); | 294 base::Bind(&OpenSettingsFromNotification)))); |
| 430 | 295 |
| 431 WmShell::Get()->RecordUserMetricsAction( | 296 WmShell::Get()->RecordUserMetricsAction( |
| 432 UMA_STATUS_AREA_DISPLAY_NOTIFICATION_CREATED); | 297 UMA_STATUS_AREA_DISPLAY_NOTIFICATION_CREATED); |
| 433 message_center::MessageCenter::Get()->AddNotification( | 298 message_center::MessageCenter::Get()->AddNotification( |
| 434 std::move(notification)); | 299 std::move(notification)); |
| 435 } | 300 } |
| 436 | 301 |
| 437 views::View* TrayDisplay::CreateDefaultView(LoginStatus status) { | 302 void ScreenLayoutObserver::OnDisplayConfigurationChanged() { |
| 438 DCHECK(default_ == NULL); | |
| 439 default_ = new DisplayView(); | |
| 440 return default_; | |
| 441 } | |
| 442 | |
| 443 void TrayDisplay::DestroyDefaultView() { | |
| 444 default_ = NULL; | |
| 445 } | |
| 446 | |
| 447 void TrayDisplay::OnDisplayConfigurationChanged() { | |
| 448 DisplayInfoMap old_info; | 303 DisplayInfoMap old_info; |
| 449 UpdateDisplayInfo(&old_info); | 304 UpdateDisplayInfo(&old_info); |
| 450 | 305 |
| 451 if (default_) | |
| 452 default_->Update(); | |
| 453 | |
| 454 if (!WmShell::Get() | 306 if (!WmShell::Get() |
| 455 ->system_tray_delegate() | 307 ->system_tray_delegate() |
| 456 ->ShouldShowDisplayNotification()) { | 308 ->ShouldShowDisplayNotification()) { |
| 457 return; | 309 return; |
| 458 } | 310 } |
| 459 | 311 |
| 460 base::string16 message; | 312 base::string16 message; |
| 461 base::string16 additional_message; | 313 base::string16 additional_message; |
| 462 if (GetDisplayMessageForNotification(old_info, &message, &additional_message)) | 314 if (GetDisplayMessageForNotification(old_info, &message, &additional_message)) |
| 463 CreateOrUpdateNotification(message, additional_message); | 315 CreateOrUpdateNotification(message, additional_message); |
| 464 } | 316 } |
| 465 | 317 |
| 466 base::string16 TrayDisplay::GetDefaultViewMessage() const { | |
| 467 if (!default_ || !default_->visible()) | |
| 468 return base::string16(); | |
| 469 | |
| 470 return static_cast<DisplayView*>(default_)->label()->text(); | |
| 471 } | |
| 472 | |
| 473 bool TrayDisplay::GetAccessibleStateForTesting(ui::AXViewState* state) { | |
| 474 views::View* view = default_; | |
| 475 if (view) { | |
| 476 view->GetAccessibleState(state); | |
| 477 return true; | |
| 478 } | |
| 479 return false; | |
| 480 } | |
| 481 | |
| 482 } // namespace ash | 318 } // namespace ash |
| OLD | NEW |