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

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

Issue 10959035: Revert 157906 - Don't return unsupported scales frrom GetScaleFactorFromScale() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 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/layout_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 "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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 #elif defined(OS_WIN) 103 #elif defined(OS_WIN)
104 if (UseTouchOptimizedUI()) 104 if (UseTouchOptimizedUI())
105 return LAYOUT_TOUCH; 105 return LAYOUT_TOUCH;
106 return LAYOUT_DESKTOP; 106 return LAYOUT_DESKTOP;
107 #else 107 #else
108 return LAYOUT_DESKTOP; 108 return LAYOUT_DESKTOP;
109 #endif 109 #endif
110 } 110 }
111 111
112 ScaleFactor GetScaleFactorFromScale(float scale) { 112 ScaleFactor GetScaleFactorFromScale(float scale) {
113 ScaleFactor closest_match = SCALE_FACTOR_100P; 113 size_t closest_match = 0;
114 float smallest_diff = std::numeric_limits<float>::max(); 114 float smallest_diff = std::numeric_limits<float>::max();
115 const std::vector<ScaleFactor>& supported = 115 for (size_t i = 0; i < kScaleFactorScalesLength; ++i) {
116 GetSupportedScaleFactorsInternal(); 116 float diff = std::abs(kScaleFactorScales[i] - scale);
117 for (size_t i = 0; i < supported.size(); ++i) {
118 ScaleFactor scale_factor = supported[i];
119 float diff = std::abs(kScaleFactorScales[scale_factor] - scale);
120 if (diff < smallest_diff) { 117 if (diff < smallest_diff) {
121 closest_match = scale_factor; 118 closest_match = i;
122 smallest_diff = diff; 119 smallest_diff = diff;
123 } 120 }
124 } 121 }
125 return closest_match; 122 return static_cast<ui::ScaleFactor>(closest_match);
126 } 123 }
127 124
128 float GetScaleFactorScale(ScaleFactor scale_factor) { 125 float GetScaleFactorScale(ScaleFactor scale_factor) {
129 return kScaleFactorScales[scale_factor]; 126 return kScaleFactorScales[scale_factor];
130 } 127 }
131 128
132 std::vector<ScaleFactor> GetSupportedScaleFactors() { 129 std::vector<ScaleFactor> GetSupportedScaleFactors() {
133 return GetSupportedScaleFactorsInternal(); 130 return GetSupportedScaleFactorsInternal();
134 } 131 }
135 132
(...skipping 24 matching lines...) Expand all
160 return GetScaleFactorFromScale( 157 return GetScaleFactorFromScale(
161 root_window->compositor()->device_scale_factor()); 158 root_window->compositor()->device_scale_factor());
162 #else 159 #else
163 NOTIMPLEMENTED(); 160 NOTIMPLEMENTED();
164 return SCALE_FACTOR_NONE; 161 return SCALE_FACTOR_NONE;
165 #endif 162 #endif
166 } 163 }
167 #endif // !defined(OS_MACOSX) 164 #endif // !defined(OS_MACOSX)
168 165
169 } // namespace ui 166 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/layout.h ('k') | ui/base/layout_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698