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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 81 supported_scale_factors->push_back(ui::SCALE_FACTOR_140P); | 81 supported_scale_factors->push_back(ui::SCALE_FACTOR_140P); |
| 82 supported_scale_factors->push_back(ui::SCALE_FACTOR_180P); | 82 supported_scale_factors->push_back(ui::SCALE_FACTOR_180P); |
| 83 } | 83 } |
| 84 #elif defined(USE_ASH) | 84 #elif defined(USE_ASH) |
| 85 supported_scale_factors->push_back(ui::SCALE_FACTOR_200P); | 85 supported_scale_factors->push_back(ui::SCALE_FACTOR_200P); |
| 86 #endif | 86 #endif |
| 87 } | 87 } |
| 88 return *supported_scale_factors; | 88 return *supported_scale_factors; |
| 89 } | 89 } |
| 90 | 90 |
| 91 ui::ScaleFactor GetScaleFactorFromScaleInternal(float scale, | |
| 92 bool includeUnsupported) { | |
|
pkotwicz
2012/09/19 14:22:10
Nit: use camel case for variable include_unsupport
| |
| 93 size_t closest_match = 0; | |
| 94 float smallest_diff = std::numeric_limits<float>::max(); | |
| 95 for (size_t i = 0; i < kScaleFactorScalesLength; ++i) { | |
| 96 if (!includeUnsupported && | |
| 97 !ui::IsScaleFactorSupported(static_cast<ui::ScaleFactor>(i))) | |
| 98 continue; | |
| 99 float diff = std::abs(kScaleFactorScales[i] - scale); | |
| 100 if (diff < smallest_diff) { | |
| 101 closest_match = i; | |
| 102 smallest_diff = diff; | |
| 103 } | |
| 104 } | |
| 105 return static_cast<ui::ScaleFactor>(closest_match); | |
| 106 } | |
| 107 | |
| 91 } // namespace | 108 } // namespace |
| 92 | 109 |
| 93 namespace ui { | 110 namespace ui { |
| 94 | 111 |
| 95 // Note that this function should be extended to select | 112 // Note that this function should be extended to select |
| 96 // LAYOUT_TOUCH when appropriate on more platforms than just | 113 // LAYOUT_TOUCH when appropriate on more platforms than just |
| 97 // Windows and Ash. | 114 // Windows and Ash. |
| 98 DisplayLayout GetDisplayLayout() { | 115 DisplayLayout GetDisplayLayout() { |
| 99 #if defined(USE_ASH) | 116 #if defined(USE_ASH) |
| 100 if (UseTouchOptimizedUI()) | 117 if (UseTouchOptimizedUI()) |
| 101 return LAYOUT_TOUCH; | 118 return LAYOUT_TOUCH; |
| 102 return LAYOUT_ASH; | 119 return LAYOUT_ASH; |
| 103 #elif defined(OS_WIN) | 120 #elif defined(OS_WIN) |
| 104 if (UseTouchOptimizedUI()) | 121 if (UseTouchOptimizedUI()) |
| 105 return LAYOUT_TOUCH; | 122 return LAYOUT_TOUCH; |
| 106 return LAYOUT_DESKTOP; | 123 return LAYOUT_DESKTOP; |
| 107 #else | 124 #else |
| 108 return LAYOUT_DESKTOP; | 125 return LAYOUT_DESKTOP; |
| 109 #endif | 126 #endif |
| 110 } | 127 } |
| 111 | 128 |
| 112 ScaleFactor GetScaleFactorFromScale(float scale) { | 129 ScaleFactor GetScaleFactorFromScale(float scale) { |
| 113 size_t closest_match = 0; | 130 return GetScaleFactorFromScaleInternal(scale, true); |
| 114 float smallest_diff = std::numeric_limits<float>::max(); | 131 } |
| 115 for (size_t i = 0; i < kScaleFactorScalesLength; ++i) { | 132 |
| 116 float diff = std::abs(kScaleFactorScales[i] - scale); | 133 ScaleFactor GetSupportedScaleFactorFromScale(float scale) { |
| 117 if (diff < smallest_diff) { | 134 return GetScaleFactorFromScaleInternal(scale, false); |
| 118 closest_match = i; | |
| 119 smallest_diff = diff; | |
| 120 } | |
| 121 } | |
| 122 return static_cast<ui::ScaleFactor>(closest_match); | |
| 123 } | 135 } |
| 124 | 136 |
| 125 float GetScaleFactorScale(ScaleFactor scale_factor) { | 137 float GetScaleFactorScale(ScaleFactor scale_factor) { |
| 126 return kScaleFactorScales[scale_factor]; | 138 return kScaleFactorScales[scale_factor]; |
| 127 } | 139 } |
| 128 | 140 |
| 129 std::vector<ScaleFactor> GetSupportedScaleFactors() { | 141 std::vector<ScaleFactor> GetSupportedScaleFactors() { |
| 130 return GetSupportedScaleFactorsInternal(); | 142 return GetSupportedScaleFactorsInternal(); |
| 131 } | 143 } |
| 132 | 144 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 157 return GetScaleFactorFromScale( | 169 return GetScaleFactorFromScale( |
| 158 root_window->compositor()->device_scale_factor()); | 170 root_window->compositor()->device_scale_factor()); |
| 159 #else | 171 #else |
| 160 NOTIMPLEMENTED(); | 172 NOTIMPLEMENTED(); |
| 161 return SCALE_FACTOR_NONE; | 173 return SCALE_FACTOR_NONE; |
| 162 #endif | 174 #endif |
| 163 } | 175 } |
| 164 #endif // !defined(OS_MACOSX) | 176 #endif // !defined(OS_MACOSX) |
| 165 | 177 |
| 166 } // namespace ui | 178 } // namespace ui |
| OLD | NEW |