Chromium Code Reviews| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 size_t closest_match = 0; |
| 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 for (size_t i = 0; i < kScaleFactorScalesLength; ++i) { |
| 116 if (!IsScaleFactorSupported(static_cast<ScaleFactor>(i))) | |
|
pkotwicz
2012/09/19 21:05:17
Nit: iterate through the scale factors you get fro
Xianzhu
2012/09/19 21:38:23
Oops I should have made that kind of change :)
| |
| 117 continue; | |
| 116 float diff = std::abs(kScaleFactorScales[i] - scale); | 118 float diff = std::abs(kScaleFactorScales[i] - scale); |
| 117 if (diff < smallest_diff) { | 119 if (diff < smallest_diff) { |
| 118 closest_match = i; | 120 closest_match = i; |
| 119 smallest_diff = diff; | 121 smallest_diff = diff; |
| 120 } | 122 } |
| 121 } | 123 } |
| 122 return static_cast<ui::ScaleFactor>(closest_match); | 124 return static_cast<ScaleFactor>(closest_match); |
| 123 } | 125 } |
| 124 | 126 |
| 125 float GetScaleFactorScale(ScaleFactor scale_factor) { | 127 float GetScaleFactorScale(ScaleFactor scale_factor) { |
| 126 return kScaleFactorScales[scale_factor]; | 128 return kScaleFactorScales[scale_factor]; |
| 127 } | 129 } |
| 128 | 130 |
| 129 std::vector<ScaleFactor> GetSupportedScaleFactors() { | 131 std::vector<ScaleFactor> GetSupportedScaleFactors() { |
| 130 return GetSupportedScaleFactorsInternal(); | 132 return GetSupportedScaleFactorsInternal(); |
| 131 } | 133 } |
| 132 | 134 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 157 return GetScaleFactorFromScale( | 159 return GetScaleFactorFromScale( |
| 158 root_window->compositor()->device_scale_factor()); | 160 root_window->compositor()->device_scale_factor()); |
| 159 #else | 161 #else |
| 160 NOTIMPLEMENTED(); | 162 NOTIMPLEMENTED(); |
| 161 return SCALE_FACTOR_NONE; | 163 return SCALE_FACTOR_NONE; |
| 162 #endif | 164 #endif |
| 163 } | 165 } |
| 164 #endif // !defined(OS_MACOSX) | 166 #endif // !defined(OS_MACOSX) |
| 165 | 167 |
| 166 } // namespace ui | 168 } // namespace ui |
| OLD | NEW |