Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/display/display_util.h" | 5 #include "ash/display/display_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/common/display/display_info.h" | 9 #include "ash/common/display/display_info.h" |
| 10 #include "ash/common/system/system_notifier.h" | 10 #include "ash/common/system/system_notifier.h" |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 41 // is clicked. | 41 // is clicked. |
| 42 class DisplayErrorNotificationDelegate | 42 class DisplayErrorNotificationDelegate |
| 43 : public message_center::NotificationDelegate { | 43 : public message_center::NotificationDelegate { |
| 44 public: | 44 public: |
| 45 DisplayErrorNotificationDelegate() = default; | 45 DisplayErrorNotificationDelegate() = default; |
| 46 | 46 |
| 47 // message_center::NotificationDelegate: | 47 // message_center::NotificationDelegate: |
| 48 bool HasClickedListener() override { return true; } | 48 bool HasClickedListener() override { return true; } |
| 49 | 49 |
| 50 void Click() override { | 50 void Click() override { |
| 51 ash::Shell::GetInstance()->new_window_delegate()->OpenFeedbackPage(); | 51 Shell::GetInstance()->new_window_delegate()->OpenFeedbackPage(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 private: | 54 private: |
| 55 // Private destructor since NotificationDelegate is ref-counted. | 55 // Private destructor since NotificationDelegate is ref-counted. |
| 56 ~DisplayErrorNotificationDelegate() override = default; | 56 ~DisplayErrorNotificationDelegate() override = default; |
| 57 | 57 |
| 58 DISALLOW_COPY_AND_ASSIGN(DisplayErrorNotificationDelegate); | 58 DISALLOW_COPY_AND_ASSIGN(DisplayErrorNotificationDelegate); |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 // List of value UI Scale values. Scales for 2x are equivalent to 640, | 61 // List of value UI Scale values. Scales for 2x are equivalent to 640, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 119 auto iter = std::find_if(modes.begin(), modes.end(), | 119 auto iter = std::find_if(modes.begin(), modes.end(), |
| 120 [ui_scale](const DisplayMode& mode) { | 120 [ui_scale](const DisplayMode& mode) { |
| 121 return mode.ui_scale == ui_scale; | 121 return mode.ui_scale == ui_scale; |
| 122 }); | 122 }); |
| 123 if (iter == modes.end()) | 123 if (iter == modes.end()) |
| 124 return false; | 124 return false; |
| 125 *out = *iter; | 125 *out = *iter; |
| 126 return true; | 126 return true; |
| 127 } | 127 } |
| 128 | 128 |
| 129 void FindNextMode(std::vector<DisplayMode>::const_iterator& iter, | 129 DisplayMode FindNextMode(const std::vector<DisplayMode>& modes, |
|
Daniel Erat
2016/07/11 17:50:20
i don't understand why these changes are here; the
Lei Zhang
2016/07/11 17:53:10
Just fixing lint errors. |iter| was being passed b
| |
| 130 const std::vector<DisplayMode>& modes, | 130 size_t index, |
| 131 bool up, | 131 bool up) { |
| 132 DisplayMode* out) { | 132 DCHECK_LT(index, modes.size()); |
| 133 DCHECK(iter != modes.end()); | 133 size_t new_index = index; |
| 134 if (up && (iter + 1) != modes.end()) | 134 if (up && (index + 1 < modes.size())) |
| 135 *out = *(iter + 1); | 135 ++new_index; |
| 136 else if (!up && iter != modes.begin()) | 136 else if (!up && index != 0) |
| 137 *out = *(iter - 1); | 137 --new_index; |
| 138 else | 138 return modes[new_index]; |
| 139 *out = *iter; | |
| 140 } | 139 } |
| 141 | 140 |
| 142 } // namespace | 141 } // namespace |
| 143 | 142 |
| 144 std::vector<DisplayMode> CreateInternalDisplayModeList( | 143 std::vector<DisplayMode> CreateInternalDisplayModeList( |
| 145 const DisplayMode& native_mode) { | 144 const DisplayMode& native_mode) { |
| 146 std::vector<DisplayMode> display_mode_list; | 145 std::vector<DisplayMode> display_mode_list; |
| 147 | 146 |
| 148 float native_ui_scale = (native_mode.device_scale_factor == 1.25f) | 147 float native_ui_scale = (native_mode.device_scale_factor == 1.25f) |
| 149 ? 1.0f | 148 ? 1.0f |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 bool up, | 206 bool up, |
| 208 DisplayMode* out) { | 207 DisplayMode* out) { |
| 209 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 208 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 210 if (!display_manager->IsActiveDisplayId(info.id()) || | 209 if (!display_manager->IsActiveDisplayId(info.id()) || |
| 211 !display::Display::IsInternalDisplayId(info.id())) { | 210 !display::Display::IsInternalDisplayId(info.id())) { |
| 212 return false; | 211 return false; |
| 213 } | 212 } |
| 214 const std::vector<DisplayMode>& modes = info.display_modes(); | 213 const std::vector<DisplayMode>& modes = info.display_modes(); |
| 215 ScaleComparator comparator(info.configured_ui_scale()); | 214 ScaleComparator comparator(info.configured_ui_scale()); |
| 216 auto iter = std::find_if(modes.begin(), modes.end(), comparator); | 215 auto iter = std::find_if(modes.begin(), modes.end(), comparator); |
| 217 FindNextMode(iter, modes, up, out); | 216 *out = FindNextMode(modes, iter - modes.begin(), up); |
| 218 return true; | 217 return true; |
| 219 } | 218 } |
| 220 | 219 |
| 221 bool GetDisplayModeForNextResolution(const DisplayInfo& info, | 220 bool GetDisplayModeForNextResolution(const DisplayInfo& info, |
| 222 bool up, | 221 bool up, |
| 223 DisplayMode* out) { | 222 DisplayMode* out) { |
| 224 if (display::Display::IsInternalDisplayId(info.id())) | 223 if (display::Display::IsInternalDisplayId(info.id())) |
| 225 return false; | 224 return false; |
| 226 const std::vector<DisplayMode>& modes = info.display_modes(); | 225 const std::vector<DisplayMode>& modes = info.display_modes(); |
| 227 DisplayMode tmp(info.size_in_pixel(), 0.0f, false, false); | 226 DisplayMode tmp(info.size_in_pixel(), 0.0f, false, false); |
| 228 tmp.device_scale_factor = info.device_scale_factor(); | 227 tmp.device_scale_factor = info.device_scale_factor(); |
| 229 gfx::Size resolution = tmp.GetSizeInDIP(false); | 228 gfx::Size resolution = tmp.GetSizeInDIP(false); |
| 230 auto iter = std::find_if(modes.begin(), modes.end(), | 229 auto iter = std::find_if(modes.begin(), modes.end(), |
| 231 [resolution](const DisplayMode& mode) { | 230 [resolution](const DisplayMode& mode) { |
| 232 return mode.GetSizeInDIP(false) == resolution; | 231 return mode.GetSizeInDIP(false) == resolution; |
| 233 }); | 232 }); |
| 234 FindNextMode(iter, modes, up, out); | 233 *out = FindNextMode(modes, iter - modes.begin(), up); |
| 235 return true; | 234 return true; |
| 236 } | 235 } |
| 237 | 236 |
| 238 bool SetDisplayUIScale(int64_t id, float ui_scale) { | 237 bool SetDisplayUIScale(int64_t id, float ui_scale) { |
| 239 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 238 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 240 if (!display_manager->IsActiveDisplayId(id) || | 239 if (!display_manager->IsActiveDisplayId(id) || |
| 241 !display::Display::IsInternalDisplayId(id)) { | 240 !display::Display::IsInternalDisplayId(id)) { |
| 242 return false; | 241 return false; |
| 243 } | 242 } |
| 244 const DisplayInfo& info = display_manager->GetDisplayInfo(id); | 243 const DisplayInfo& info = display_manager->GetDisplayInfo(id); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 432 DCHECK_NE(id1, id2); | 431 DCHECK_NE(id1, id2); |
| 433 // Output index is stored in the first 8 bits. See GetDisplayIdFromEDID | 432 // Output index is stored in the first 8 bits. See GetDisplayIdFromEDID |
| 434 // in edid_parser.cc. | 433 // in edid_parser.cc. |
| 435 int index_1 = id1 & 0xFF; | 434 int index_1 = id1 & 0xFF; |
| 436 int index_2 = id2 & 0xFF; | 435 int index_2 = id2 & 0xFF; |
| 437 DCHECK_NE(index_1, index_2) << id1 << " and " << id2; | 436 DCHECK_NE(index_1, index_2) << id1 << " and " << id2; |
| 438 return display::Display::IsInternalDisplayId(id1) || | 437 return display::Display::IsInternalDisplayId(id1) || |
| 439 (index_1 < index_2 && !display::Display::IsInternalDisplayId(id2)); | 438 (index_1 < index_2 && !display::Display::IsInternalDisplayId(id2)); |
| 440 } | 439 } |
| 441 | 440 |
| 441 #if defined(OS_CHROMEOS) | |
| 442 void ShowDisplayErrorNotification(int message_id) { | 442 void ShowDisplayErrorNotification(int message_id) { |
| 443 // Always remove the notification to make sure the notification appears | 443 // Always remove the notification to make sure the notification appears |
| 444 // as a popup in any situation. | 444 // as a popup in any situation. |
| 445 message_center::MessageCenter::Get()->RemoveNotification( | 445 message_center::MessageCenter::Get()->RemoveNotification( |
| 446 kDisplayErrorNotificationId, false /* by_user */); | 446 kDisplayErrorNotificationId, false /* by_user */); |
| 447 | 447 |
| 448 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 448 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 449 std::unique_ptr<message_center::Notification> notification( | 449 std::unique_ptr<message_center::Notification> notification( |
| 450 new message_center::Notification( | 450 new message_center::Notification( |
| 451 message_center::NOTIFICATION_TYPE_SIMPLE, kDisplayErrorNotificationId, | 451 message_center::NOTIFICATION_TYPE_SIMPLE, kDisplayErrorNotificationId, |
| 452 base::string16(), // title | 452 base::string16(), // title |
| 453 l10n_util::GetStringUTF16(message_id), | 453 l10n_util::GetStringUTF16(message_id), |
| 454 bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY), | 454 bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY), |
| 455 base::string16(), // display_source | 455 base::string16(), // display_source |
| 456 GURL(), message_center::NotifierId( | 456 GURL(), message_center::NotifierId( |
| 457 message_center::NotifierId::SYSTEM_COMPONENT, | 457 message_center::NotifierId::SYSTEM_COMPONENT, |
| 458 system_notifier::kNotifierDisplayError), | 458 system_notifier::kNotifierDisplayError), |
| 459 message_center::RichNotificationData(), | 459 message_center::RichNotificationData(), |
| 460 new DisplayErrorNotificationDelegate)); | 460 new DisplayErrorNotificationDelegate)); |
| 461 message_center::MessageCenter::Get()->AddNotification( | 461 message_center::MessageCenter::Get()->AddNotification( |
| 462 std::move(notification)); | 462 std::move(notification)); |
| 463 } | 463 } |
| 464 #endif | |
| 464 | 465 |
| 465 base::string16 GetDisplayErrorNotificationMessageForTest() { | 466 base::string16 GetDisplayErrorNotificationMessageForTest() { |
| 466 message_center::NotificationList::Notifications notifications = | 467 message_center::NotificationList::Notifications notifications = |
| 467 message_center::MessageCenter::Get()->GetVisibleNotifications(); | 468 message_center::MessageCenter::Get()->GetVisibleNotifications(); |
| 468 for (auto* const notification : notifications) { | 469 for (auto* const notification : notifications) { |
| 469 if (notification->id() == kDisplayErrorNotificationId) | 470 if (notification->id() == kDisplayErrorNotificationId) |
| 470 return notification->message(); | 471 return notification->message(); |
| 471 } | 472 } |
| 472 return base::string16(); | 473 return base::string16(); |
| 473 } | 474 } |
| 474 | 475 |
| 475 } // namespace ash | 476 } // namespace ash |
| OLD | NEW |