| OLD | NEW |
| 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 Loading... |
| 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 size_t closest_match = 0; | 113 ScaleFactor closest_match = SCALE_FACTOR_100P; |
| 114 float smallest_diff = std::numeric_limits<float>::max(); | 114 float smallest_diff = std::numeric_limits<float>::max(); |
| 115 for (size_t i = 0; i < kScaleFactorScalesLength; ++i) { | 115 const std::vector<ScaleFactor>& supported = |
| 116 float diff = std::abs(kScaleFactorScales[i] - scale); | 116 GetSupportedScaleFactorsInternal(); |
| 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); |
| 117 if (diff < smallest_diff) { | 120 if (diff < smallest_diff) { |
| 118 closest_match = i; | 121 closest_match = scale_factor; |
| 119 smallest_diff = diff; | 122 smallest_diff = diff; |
| 120 } | 123 } |
| 121 } | 124 } |
| 122 return static_cast<ui::ScaleFactor>(closest_match); | 125 return closest_match; |
| 123 } | 126 } |
| 124 | 127 |
| 125 float GetScaleFactorScale(ScaleFactor scale_factor) { | 128 float GetScaleFactorScale(ScaleFactor scale_factor) { |
| 126 return kScaleFactorScales[scale_factor]; | 129 return kScaleFactorScales[scale_factor]; |
| 127 } | 130 } |
| 128 | 131 |
| 129 std::vector<ScaleFactor> GetSupportedScaleFactors() { | 132 std::vector<ScaleFactor> GetSupportedScaleFactors() { |
| 130 return GetSupportedScaleFactorsInternal(); | 133 return GetSupportedScaleFactorsInternal(); |
| 131 } | 134 } |
| 132 | 135 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 157 return GetScaleFactorFromScale( | 160 return GetScaleFactorFromScale( |
| 158 root_window->compositor()->device_scale_factor()); | 161 root_window->compositor()->device_scale_factor()); |
| 159 #else | 162 #else |
| 160 NOTIMPLEMENTED(); | 163 NOTIMPLEMENTED(); |
| 161 return SCALE_FACTOR_NONE; | 164 return SCALE_FACTOR_NONE; |
| 162 #endif | 165 #endif |
| 163 } | 166 } |
| 164 #endif // !defined(OS_MACOSX) | 167 #endif // !defined(OS_MACOSX) |
| 165 | 168 |
| 166 } // namespace ui | 169 } // namespace ui |
| OLD | NEW |