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

Side by Side Diff: chrome/browser/ui/webui/options/chromeos/display_options_handler.cc

Issue 2196923002: Make ash::DisplayMode more like ui::DisplayMode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 4 years, 4 months 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
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 "chrome/browser/ui/webui/options/chromeos/display_options_handler.h" 5 #include "chrome/browser/ui/webui/options/chromeos/display_options_handler.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 const std::string& field, 114 const std::string& field,
115 float* result) { 115 float* result) {
116 double double_result = 0; 116 double double_result = 0;
117 if (dict->GetDouble(field, &double_result)) { 117 if (dict->GetDouble(field, &double_result)) {
118 *result = static_cast<float>(double_result); 118 *result = static_cast<float>(double_result);
119 return true; 119 return true;
120 } 120 }
121 return false; 121 return false;
122 } 122 }
123 123
124 bool ConvertValueToDisplayMode(const base::DictionaryValue* dict, 124 scoped_refptr<ash::DisplayMode> ConvertValueToDisplayMode(
125 ash::DisplayMode* mode) { 125 const base::DictionaryValue* dict) {
126 mode->size.set_width(GetIntOrDouble(dict, "originalWidth")); 126 scoped_refptr<ash::DisplayMode> mode;
127 mode->size.set_height(GetIntOrDouble(dict, "originalHeight")); 127
128 if (mode->size.IsEmpty()) { 128 gfx::Size size;
129 size.set_width(GetIntOrDouble(dict, "originalWidth"));
130 size.set_height(GetIntOrDouble(dict, "originalHeight"));
131
132 if (size.IsEmpty()) {
129 LOG(ERROR) << "missing width or height."; 133 LOG(ERROR) << "missing width or height.";
130 return false; 134 return mode;
131 } 135 }
132 if (!GetFloat(dict, "refreshRate", &mode->refresh_rate)) { 136
137 float refresh_rate, ui_scale, device_scale_factor;
138 if (!GetFloat(dict, "refreshRate", &refresh_rate)) {
133 LOG(ERROR) << "missing refreshRate."; 139 LOG(ERROR) << "missing refreshRate.";
134 return false; 140 return mode;
135 } 141 }
136 if (!GetFloat(dict, "scale", &mode->ui_scale)) { 142 if (!GetFloat(dict, "scale", &ui_scale)) {
137 LOG(ERROR) << "missing ui-scale."; 143 LOG(ERROR) << "missing ui-scale.";
138 return false; 144 return mode;
139 } 145 }
140 if (!GetFloat(dict, "deviceScaleFactor", &mode->device_scale_factor)) { 146 if (!GetFloat(dict, "deviceScaleFactor", &device_scale_factor)) {
141 LOG(ERROR) << "missing deviceScaleFactor."; 147 LOG(ERROR) << "missing deviceScaleFactor.";
142 return false; 148 return mode;
143 } 149 }
144 return true; 150
151 // Used to select the actual mode.
152 mode =
153 new ash::DisplayMode(size, refresh_rate, false /* interlaced */,
154 false /* native */, ui_scale, device_scale_factor);
155 return mode;
145 } 156 }
146 157
147 base::DictionaryValue* ConvertDisplayModeToValue(int64_t display_id, 158 base::DictionaryValue* ConvertDisplayModeToValue(
148 const ash::DisplayMode& mode) { 159 int64_t display_id,
160 const scoped_refptr<ash::DisplayMode>& mode) {
149 bool is_internal = display::Display::HasInternalDisplay() && 161 bool is_internal = display::Display::HasInternalDisplay() &&
150 display::Display::InternalDisplayId() == display_id; 162 display::Display::InternalDisplayId() == display_id;
151 base::DictionaryValue* result = new base::DictionaryValue(); 163 base::DictionaryValue* result = new base::DictionaryValue();
152 gfx::Size size_dip = mode.GetSizeInDIP(is_internal); 164 gfx::Size size_dip = mode->GetSizeInDIP(is_internal);
153 result->SetInteger("width", size_dip.width()); 165 result->SetInteger("width", size_dip.width());
154 result->SetInteger("height", size_dip.height()); 166 result->SetInteger("height", size_dip.height());
155 result->SetInteger("originalWidth", mode.size.width()); 167 result->SetInteger("originalWidth", mode->size().width());
156 result->SetInteger("originalHeight", mode.size.height()); 168 result->SetInteger("originalHeight", mode->size().height());
157 result->SetDouble("deviceScaleFactor", mode.device_scale_factor); 169 result->SetDouble("deviceScaleFactor", mode->device_scale_factor());
158 result->SetDouble("scale", mode.ui_scale); 170 result->SetDouble("scale", mode->ui_scale());
159 result->SetDouble("refreshRate", mode.refresh_rate); 171 result->SetDouble("refreshRate", mode->refresh_rate());
172 result->SetBoolean("isBest",
173 is_internal ? (mode->ui_scale() == 1.0f) : mode->native());
174 result->SetBoolean("isNative", mode->native());
160 result->SetBoolean( 175 result->SetBoolean(
161 "isBest", is_internal ? (mode.ui_scale == 1.0f) : mode.native); 176 "selected",
162 result->SetBoolean("isNative", mode.native); 177 mode->IsEquivalent(
163 result->SetBoolean(
164 "selected", mode.IsEquivalent(
165 GetDisplayManager()->GetActiveModeForDisplayId(display_id))); 178 GetDisplayManager()->GetActiveModeForDisplayId(display_id)));
166 return result; 179 return result;
167 } 180 }
168 181
169 base::DictionaryValue* ConvertBoundsToValue(const gfx::Rect& bounds) { 182 base::DictionaryValue* ConvertBoundsToValue(const gfx::Rect& bounds) {
170 base::DictionaryValue* result = new base::DictionaryValue(); 183 base::DictionaryValue* result = new base::DictionaryValue();
171 result->SetInteger("left", bounds.x()); 184 result->SetInteger("left", bounds.x());
172 result->SetInteger("top", bounds.y()); 185 result->SetInteger("top", bounds.y());
173 result->SetInteger("width", bounds.width()); 186 result->SetInteger("width", bounds.width());
174 result->SetInteger("height", bounds.height()); 187 result->SetInteger("height", bounds.height());
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 js_display->SetString("name", 326 js_display->SetString("name",
314 display_manager->GetDisplayNameForId(display.id())); 327 display_manager->GetDisplayNameForId(display.id()));
315 base::DictionaryValue* display_bounds = 328 base::DictionaryValue* display_bounds =
316 ConvertBoundsToValue(display.bounds()); 329 ConvertBoundsToValue(display.bounds());
317 js_display->Set("bounds", display_bounds); 330 js_display->Set("bounds", display_bounds);
318 js_display->SetBoolean("isPrimary", display.id() == primary_id); 331 js_display->SetBoolean("isPrimary", display.id() == primary_id);
319 js_display->SetBoolean("isInternal", display.IsInternal()); 332 js_display->SetBoolean("isInternal", display.IsInternal());
320 js_display->SetInteger("rotation", display.RotationAsDegree()); 333 js_display->SetInteger("rotation", display.RotationAsDegree());
321 334
322 base::ListValue* js_resolutions = new base::ListValue(); 335 base::ListValue* js_resolutions = new base::ListValue();
323 for (const ash::DisplayMode& display_mode : display_info.display_modes()) { 336 for (const scoped_refptr<ash::DisplayMode>& display_mode :
337 display_info.display_modes()) {
324 js_resolutions->Append( 338 js_resolutions->Append(
325 ConvertDisplayModeToValue(display.id(), display_mode)); 339 ConvertDisplayModeToValue(display.id(), display_mode));
326 } 340 }
327 js_display->Set("resolutions", js_resolutions); 341 js_display->Set("resolutions", js_resolutions);
328 342
329 js_display->SetInteger("colorProfileId", display_info.color_profile()); 343 js_display->SetInteger("colorProfileId", display_info.color_profile());
330 base::ListValue* available_color_profiles = new base::ListValue(); 344 base::ListValue* available_color_profiles = new base::ListValue();
331 for (const auto& color_profile : display_info.available_color_profiles()) { 345 for (const auto& color_profile : display_info.available_color_profiles()) {
332 const base::string16 profile_name = GetColorProfileName(color_profile); 346 const base::string16 profile_name = GetColorProfileName(color_profile);
333 if (profile_name.empty()) 347 if (profile_name.empty())
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 int64_t display_id = GetDisplayIdFromArgs(args); 471 int64_t display_id = GetDisplayIdFromArgs(args);
458 if (display_id == display::Display::kInvalidDisplayID) 472 if (display_id == display::Display::kInvalidDisplayID)
459 return; 473 return;
460 474
461 const base::DictionaryValue* mode_data = nullptr; 475 const base::DictionaryValue* mode_data = nullptr;
462 if (!args->GetDictionary(1, &mode_data)) { 476 if (!args->GetDictionary(1, &mode_data)) {
463 LOG(ERROR) << "Failed to get mode data"; 477 LOG(ERROR) << "Failed to get mode data";
464 return; 478 return;
465 } 479 }
466 480
467 ash::DisplayMode mode; 481 scoped_refptr<ash::DisplayMode> mode = ConvertValueToDisplayMode(mode_data);
468 if (!ConvertValueToDisplayMode(mode_data, &mode)) 482 if (!mode)
469 return; 483 return;
470 484
471 content::RecordAction( 485 content::RecordAction(
472 base::UserMetricsAction("Options_DisplaySetResolution")); 486 base::UserMetricsAction("Options_DisplaySetResolution"));
473 ash::DisplayManager* display_manager = GetDisplayManager(); 487 ash::DisplayManager* display_manager = GetDisplayManager();
474 ash::DisplayMode current_mode = 488 scoped_refptr<ash::DisplayMode> current_mode =
475 display_manager->GetActiveModeForDisplayId(display_id); 489 display_manager->GetActiveModeForDisplayId(display_id);
476 if (!display_manager->SetDisplayMode(display_id, mode)) { 490 if (!display_manager->SetDisplayMode(display_id, mode)) {
477 LOG(ERROR) << "Unable to set display mode for: " << display_id 491 LOG(ERROR) << "Unable to set display mode for: " << display_id
478 << " Mode: " << *mode_data; 492 << " Mode: " << *mode_data;
479 return; 493 return;
480 } 494 }
481 if (display::Display::IsInternalDisplayId(display_id)) 495 if (display::Display::IsInternalDisplayId(display_id))
482 return; 496 return;
483 // For external displays, show a notification confirming the resolution 497 // For external displays, show a notification confirming the resolution
484 // change. 498 // change.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 bool enable = false; 569 bool enable = false;
556 if (!args->GetBoolean(0, &enable)) 570 if (!args->GetBoolean(0, &enable))
557 NOTREACHED(); 571 NOTREACHED();
558 572
559 GetDisplayManager()->SetDefaultMultiDisplayModeForCurrentDisplays( 573 GetDisplayManager()->SetDefaultMultiDisplayModeForCurrentDisplays(
560 enable ? ash::DisplayManager::UNIFIED : ash::DisplayManager::EXTENDED); 574 enable ? ash::DisplayManager::UNIFIED : ash::DisplayManager::EXTENDED);
561 } 575 }
562 576
563 } // namespace options 577 } // namespace options
564 } // namespace chromeos 578 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698