Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: ash/display/display_manager.cc

Issue 2426103004: Specify a default display UI scale to reset the zoom to (Closed)
Patch Set: Working test Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/display/display_manager.h ('k') | ash/display/display_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/display/display_manager.h" 5 #include "ash/display/display_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 #include <map> 10 #include <map>
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 107
108 gfx::Size GetMaxNativeSize(const display::ManagedDisplayInfo& info) { 108 gfx::Size GetMaxNativeSize(const display::ManagedDisplayInfo& info) {
109 gfx::Size size; 109 gfx::Size size;
110 for (auto& mode : info.display_modes()) { 110 for (auto& mode : info.display_modes()) {
111 if (mode->size().GetArea() > size.GetArea()) 111 if (mode->size().GetArea() > size.GetArea())
112 size = mode->size(); 112 size = mode->size();
113 } 113 }
114 return size; 114 return size;
115 } 115 }
116 116
117 scoped_refptr<display::ManagedDisplayMode> GetDisplayModeForUIScale( 117 scoped_refptr<display::ManagedDisplayMode> GetDefaultDisplayMode(
118 const display::ManagedDisplayInfo& info, 118 const display::ManagedDisplayInfo& info) {
119 float ui_scale) { 119 const auto& modes = info.display_modes();
120 const display::ManagedDisplayInfo::ManagedDisplayModeList& modes = 120 auto iter =
121 info.display_modes(); 121 std::find_if(modes.begin(), modes.end(),
122 auto iter = std::find_if( 122 [](const scoped_refptr<display::ManagedDisplayMode>& mode) {
123 modes.begin(), modes.end(), 123 return mode->is_default();
124 [ui_scale](const scoped_refptr<display::ManagedDisplayMode>& mode) { 124 });
125 return mode->ui_scale() == ui_scale; 125
126 });
127 if (iter == modes.end()) 126 if (iter == modes.end())
128 return scoped_refptr<display::ManagedDisplayMode>(); 127 return scoped_refptr<display::ManagedDisplayMode>();
129 return *iter; 128 return *iter;
130 } 129 }
131 130
132 } // namespace 131 } // namespace
133 132
134 using std::string; 133 using std::string;
135 using std::vector; 134 using std::vector;
136 135
(...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after
1090 if (!IsActiveDisplayId(display_info.id()) || 1089 if (!IsActiveDisplayId(display_info.id()) ||
1091 !display::Display::IsInternalDisplayId(display_info.id())) { 1090 !display::Display::IsInternalDisplayId(display_info.id())) {
1092 return false; 1091 return false;
1093 } 1092 }
1094 mode = GetDisplayModeForNextUIScale(display_info, up); 1093 mode = GetDisplayModeForNextUIScale(display_info, up);
1095 } 1094 }
1096 1095
1097 return mode ? SetDisplayMode(display_id, mode) : false; 1096 return mode ? SetDisplayMode(display_id, mode) : false;
1098 } 1097 }
1099 1098
1100 bool DisplayManager::SetDisplayUIScale(int64_t id, float ui_scale) { 1099 bool DisplayManager::ResetDisplayToDefaultMode(int64_t id) {
1101 if (!IsActiveDisplayId(id) || !display::Display::IsInternalDisplayId(id)) { 1100 if (!IsActiveDisplayId(id) || !display::Display::IsInternalDisplayId(id))
1102 return false; 1101 return false;
1103 } 1102
1104 const display::ManagedDisplayInfo& info = GetDisplayInfo(id); 1103 const display::ManagedDisplayInfo& info = GetDisplayInfo(id);
1104 scoped_refptr<display::ManagedDisplayMode> mode = GetDefaultDisplayMode(info);
1105 1105
1106 scoped_refptr<display::ManagedDisplayMode> mode = 1106 return mode ? SetDisplayMode(id, mode) : false;
1107 GetDisplayModeForUIScale(info, ui_scale);
1108 if (!mode)
1109 return false;
1110 return SetDisplayMode(id, mode);
1111 } 1107 }
1112 1108
1113 void DisplayManager::ResetInternalDisplayZoom() { 1109 void DisplayManager::ResetInternalDisplayZoom() {
1114 if (IsInUnifiedMode()) { 1110 if (IsInUnifiedMode()) {
1115 const display::ManagedDisplayInfo& display_info = 1111 const display::ManagedDisplayInfo& display_info =
1116 GetDisplayInfo(DisplayManager::kUnifiedDisplayId); 1112 GetDisplayInfo(DisplayManager::kUnifiedDisplayId);
1117 const display::ManagedDisplayInfo::ManagedDisplayModeList& modes = 1113 const display::ManagedDisplayInfo::ManagedDisplayModeList& modes =
1118 display_info.display_modes(); 1114 display_info.display_modes();
1119 auto iter = std::find_if( 1115 auto iter = std::find_if(
1120 modes.begin(), modes.end(), 1116 modes.begin(), modes.end(),
1121 [](const scoped_refptr<display::ManagedDisplayMode>& mode) { 1117 [](const scoped_refptr<display::ManagedDisplayMode>& mode) {
1122 return mode->native(); 1118 return mode->native();
1123 }); 1119 });
1124 SetDisplayMode(kUnifiedDisplayId, *iter); 1120 SetDisplayMode(kUnifiedDisplayId, *iter);
1125 } else { 1121 } else {
1126 SetDisplayUIScale(GetDisplayIdForUIScaling(), 1.0f); 1122 ResetDisplayToDefaultMode(GetDisplayIdForUIScaling());
1127 } 1123 }
1128 } 1124 }
1129 1125
1130 void DisplayManager::CreateSoftwareMirroringDisplayInfo( 1126 void DisplayManager::CreateSoftwareMirroringDisplayInfo(
1131 DisplayInfoList* display_info_list) { 1127 DisplayInfoList* display_info_list) {
1132 // Use the internal display or 1st as the mirror source, then scale 1128 // Use the internal display or 1st as the mirror source, then scale
1133 // the root window so that it matches the external display's 1129 // the root window so that it matches the external display's
1134 // resolution. This is necessary in order for scaling to work while 1130 // resolution. This is necessary in order for scaling to work while
1135 // mirrored. 1131 // mirrored.
1136 switch (multi_display_mode_) { 1132 switch (multi_display_mode_) {
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
1433 1429
1434 const display::Display& DisplayManager::GetSecondaryDisplay() const { 1430 const display::Display& DisplayManager::GetSecondaryDisplay() const {
1435 CHECK_LE(2U, GetNumDisplays()); 1431 CHECK_LE(2U, GetNumDisplays());
1436 return GetDisplayAt(0).id() == 1432 return GetDisplayAt(0).id() ==
1437 display::Screen::GetScreen()->GetPrimaryDisplay().id() 1433 display::Screen::GetScreen()->GetPrimaryDisplay().id()
1438 ? GetDisplayAt(1) 1434 ? GetDisplayAt(1)
1439 : GetDisplayAt(0); 1435 : GetDisplayAt(0);
1440 } 1436 }
1441 1437
1442 } // namespace ash 1438 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/display_manager.h ('k') | ash/display/display_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698