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

Side by Side Diff: ui/base/layout.cc

Issue 291073002: Move IsScaleFactorSupported, FindClosestScaleFactorUnsafe to ui/base/resource_bundle.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « ui/base/layout.h ('k') | ui/base/resource/resource_bundle.h » ('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 "ui/base/layout.h" 5 #include "ui/base/layout.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 10
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } 83 }
84 84
85 float GetImageScale(ScaleFactor scale_factor) { 85 float GetImageScale(ScaleFactor scale_factor) {
86 #if defined(OS_WIN) 86 #if defined(OS_WIN)
87 if (gfx::IsHighDPIEnabled()) 87 if (gfx::IsHighDPIEnabled())
88 return gfx::win::GetDeviceScaleFactor(); 88 return gfx::win::GetDeviceScaleFactor();
89 #endif 89 #endif
90 return GetScaleForScaleFactor(scale_factor); 90 return GetScaleForScaleFactor(scale_factor);
91 } 91 }
92 92
93 bool IsScaleFactorSupported(ScaleFactor scale_factor) {
94 DCHECK(g_supported_scale_factors != NULL);
95 return std::find(g_supported_scale_factors->begin(),
96 g_supported_scale_factors->end(),
97 scale_factor) != g_supported_scale_factors->end();
98 }
99
100 // Returns the scale factor closest to |scale| from the full list of factors.
101 // Note that it does NOT rely on the list of supported scale factors.
102 // Finding the closest match is inefficient and shouldn't be done frequently.
103 ScaleFactor FindClosestScaleFactorUnsafe(float scale) {
104 float smallest_diff = std::numeric_limits<float>::max();
105 ScaleFactor closest_match = SCALE_FACTOR_100P;
106 for (int i = SCALE_FACTOR_100P; i < NUM_SCALE_FACTORS; ++i) {
107 const ScaleFactor scale_factor = static_cast<ScaleFactor>(i);
108 float diff = std::abs(kScaleFactorScales[scale_factor] - scale);
109 if (diff < smallest_diff) {
110 closest_match = scale_factor;
111 smallest_diff = diff;
112 }
113 }
114 return closest_match;
115 }
116
117 float GetScaleForScaleFactor(ScaleFactor scale_factor) { 93 float GetScaleForScaleFactor(ScaleFactor scale_factor) {
118 return kScaleFactorScales[scale_factor]; 94 return kScaleFactorScales[scale_factor];
119 } 95 }
120 96
121 namespace test { 97 namespace test {
122 98
123 ScopedSetSupportedScaleFactors::ScopedSetSupportedScaleFactors( 99 ScopedSetSupportedScaleFactors::ScopedSetSupportedScaleFactors(
124 const std::vector<ui::ScaleFactor>& new_scale_factors) { 100 const std::vector<ui::ScaleFactor>& new_scale_factors) {
125 if (g_supported_scale_factors) { 101 if (g_supported_scale_factors) {
126 original_scale_factors_ = 102 original_scale_factors_ =
(...skipping 21 matching lines...) Expand all
148 gfx::Screen* screen = gfx::Screen::GetScreenFor(view); 124 gfx::Screen* screen = gfx::Screen::GetScreenFor(view);
149 if (screen->IsDIPEnabled()) { 125 if (screen->IsDIPEnabled()) {
150 gfx::Display display = screen->GetDisplayNearestWindow(view); 126 gfx::Display display = screen->GetDisplayNearestWindow(view);
151 return display.device_scale_factor(); 127 return display.device_scale_factor();
152 } 128 }
153 return 1.0f; 129 return 1.0f;
154 } 130 }
155 #endif // !defined(OS_MACOSX) 131 #endif // !defined(OS_MACOSX)
156 132
157 } // namespace ui 133 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/layout.h ('k') | ui/base/resource/resource_bundle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698