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

Unified Diff: ui/display/manager/display_manager_utilities.cc

Issue 2426103004: Specify a default display UI scale to reset the zoom to (Closed)
Patch Set: Clean up, simplify Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: ui/display/manager/display_manager_utilities.cc
diff --git a/ui/display/manager/display_manager_utilities.cc b/ui/display/manager/display_manager_utilities.cc
index 7a6b77ddd38fe56dc9814811f075b6202007b6cb..bc5be3a69eba8012422a9dc812e6e79a642082b0 100644
--- a/ui/display/manager/display_manager_utilities.cc
+++ b/ui/display/manager/display_manager_utilities.cc
@@ -20,33 +20,51 @@ namespace {
// 800, 1024, 1280, 1440, 1600 and 1920 pixel width respectively on
// 2560 pixel width 2x density display. Please see crbug.com/233375
// for the full list of resolutions.
-const float kUIScalesFor2x[] = {0.5f, 0.625f, 0.8f, 1.0f,
+constexpr float kUIScalesFor2x[] = {0.5f, 0.625f, 0.8f, 1.0f,
1.125f, 1.25f, 1.5f, 2.0f};
-const float kUIScalesFor1_25x[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.25f};
-const float kUIScalesFor1280[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.125f};
-const float kUIScalesFor1366[] = {0.5f, 0.6f, 0.75f, 1.0f, 1.125f};
+constexpr float kUIScalesFor1_25x[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.25f};
+constexpr float kUIScalesFor1280[] = {0.5f, 0.625f, 0.8f, 1.0f, 1.125f};
+constexpr float kUIScalesFor1366[] = {0.5f, 0.6f, 0.75f, 1.0f, 1.125f};
+
+// The default UI scales for the above display densities.
+constexpr float kDefaultUIScaleFor2x = 1.0f;
+constexpr float kDefaultUIScaleFor1_25x = 0.8f;
+constexpr float kDefaultUIScaleFor1280 = 1.0f;
+constexpr float kDefaultUIScaleFor1366 = 1.0f;
+
+// Encapsulates the list of UI scales and the default one.
+struct DisplayUIScales {
+ std::vector<float> scales;
+ float default_scale;
+};
+
-std::vector<float> GetScalesForDisplay(
+DisplayUIScales GetScalesForDisplay(
const scoped_refptr<display::ManagedDisplayMode>& native_mode) {
#define ASSIGN_ARRAY(v, a) v.assign(a, a + arraysize(a))
- std::vector<float> ret;
+ DisplayUIScales ret;
if (native_mode->device_scale_factor() == 2.0f) {
- ASSIGN_ARRAY(ret, kUIScalesFor2x);
+ ASSIGN_ARRAY(ret.scales, kUIScalesFor2x);
+ ret.default_scale = kDefaultUIScaleFor2x;
return ret;
} else if (native_mode->device_scale_factor() == 1.25f) {
- ASSIGN_ARRAY(ret, kUIScalesFor1_25x);
+ ASSIGN_ARRAY(ret.scales, kUIScalesFor1_25x);
+ ret.default_scale = kDefaultUIScaleFor1_25x;
return ret;
}
switch (native_mode->size().width()) {
case 1280:
- ASSIGN_ARRAY(ret, kUIScalesFor1280);
+ ASSIGN_ARRAY(ret.scales, kUIScalesFor1280);
+ ret.default_scale = kDefaultUIScaleFor1280;
break;
case 1366:
- ASSIGN_ARRAY(ret, kUIScalesFor1366);
+ ASSIGN_ARRAY(ret.scales, kUIScalesFor1366);
+ ret.default_scale = kDefaultUIScaleFor1366;
break;
default:
- ASSIGN_ARRAY(ret, kUIScalesFor1280);
+ ASSIGN_ARRAY(ret.scales, kUIScalesFor1280);
+ ret.default_scale = kDefaultUIScaleFor1280;
#if defined(OS_CHROMEOS)
if (base::SysInfo::IsRunningOnChromeOS())
NOTREACHED() << "Unknown resolution:" << native_mode->size().ToString();
@@ -89,11 +107,13 @@ CreateInternalManagedDisplayModeList(
float native_ui_scale = (native_mode->device_scale_factor() == 1.25f)
? 1.0f
: native_mode->device_scale_factor();
- for (float ui_scale : GetScalesForDisplay(native_mode)) {
+ const DisplayUIScales display_ui_scales = GetScalesForDisplay(native_mode);
+ for (float ui_scale : display_ui_scales.scales) {
scoped_refptr<ManagedDisplayMode> mode(new ManagedDisplayMode(
native_mode->size(), native_mode->refresh_rate(),
native_mode->is_interlaced(), ui_scale == native_ui_scale, ui_scale,
native_mode->device_scale_factor()));
+ mode->set_is_default(ui_scale == display_ui_scales.default_scale);
display_mode_list.push_back(mode);
}
return display_mode_list;

Powered by Google App Engine
This is Rietveld 408576698