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 <cmath> | 8 #include <cmath> |
8 #include <limits> | 9 #include <limits> |
9 | 10 |
10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "build/build_config.h" | 14 #include "build/build_config.h" |
14 #include "ui/base/ui_base_switches.h" | 15 #include "ui/base/ui_base_switches.h" |
15 | 16 |
16 #if defined(USE_AURA) && !defined(OS_WIN) | 17 #if defined(USE_AURA) && !defined(OS_WIN) |
17 #include "ui/aura/root_window.h" | 18 #include "ui/aura/root_window.h" |
18 #include "ui/compositor/compositor.h" | 19 #include "ui/compositor/compositor.h" |
19 #endif // defined(USE_AURA) && !defined(OS_WIN) | 20 #endif // defined(USE_AURA) && !defined(OS_WIN) |
20 | 21 |
21 #if defined(USE_AURA) && defined(USE_X11) | 22 #if defined(USE_AURA) && defined(USE_X11) |
22 #include "ui/base/touch/touch_factory.h" | 23 #include "ui/base/touch/touch_factory.h" |
23 #endif // defined(USE_AURA) && defined(USE_X11) | 24 #endif // defined(USE_AURA) && defined(USE_X11) |
24 | 25 |
| 26 #if defined(OS_MACOSX) |
| 27 #include "base/mac/mac_util.h" |
| 28 #endif |
| 29 |
25 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
26 #include "base/win/metro.h" | 31 #include "base/win/metro.h" |
27 #include <Windows.h> | 32 #include <Windows.h> |
28 #endif // defined(OS_WIN) | 33 #endif // defined(OS_WIN) |
29 | 34 |
30 namespace { | 35 namespace { |
31 | 36 |
32 // Helper function that determines whether we want to optimize the UI for touch. | 37 // Helper function that determines whether we want to optimize the UI for touch. |
33 bool UseTouchOptimizedUI() { | 38 bool UseTouchOptimizedUI() { |
34 // If --touch-optimized-ui is specified and not set to "auto", then override | 39 // If --touch-optimized-ui is specified and not set to "auto", then override |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 76 |
72 return has_touch_device; | 77 return has_touch_device; |
73 #else | 78 #else |
74 return false; | 79 return false; |
75 #endif | 80 #endif |
76 } | 81 } |
77 | 82 |
78 const float kScaleFactorScales[] = {1.0, 2.0}; | 83 const float kScaleFactorScales[] = {1.0, 2.0}; |
79 const size_t kScaleFactorScalesLength = arraysize(kScaleFactorScales); | 84 const size_t kScaleFactorScalesLength = arraysize(kScaleFactorScales); |
80 | 85 |
| 86 std::vector<ui::ScaleFactor>& GetSupportedScaleFactorsInternal() { |
| 87 static std::vector<ui::ScaleFactor>* supported_scale_factors = |
| 88 new std::vector<ui::ScaleFactor>(); |
| 89 if (supported_scale_factors->empty()) { |
| 90 supported_scale_factors->push_back(ui::SCALE_FACTOR_100P); |
| 91 #if defined(OS_MACOSX) && defined(ENABLE_HIDPI) |
| 92 if (base::mac::IsOSLionOrLater()) |
| 93 supported_scale_factors->push_back(ui::SCALE_FACTOR_200P); |
| 94 #elif defined(USE_ASH) |
| 95 supported_scale_factors->push_back(ui::SCALE_FACTOR_200P); |
| 96 #endif |
| 97 } |
| 98 return *supported_scale_factors; |
| 99 } |
| 100 |
81 } // namespace | 101 } // namespace |
82 | 102 |
83 namespace ui { | 103 namespace ui { |
84 | 104 |
85 // Note that this function should be extended to select | 105 // Note that this function should be extended to select |
86 // LAYOUT_TOUCH when appropriate on more platforms than just | 106 // LAYOUT_TOUCH when appropriate on more platforms than just |
87 // Windows and Ash. | 107 // Windows and Ash. |
88 DisplayLayout GetDisplayLayout() { | 108 DisplayLayout GetDisplayLayout() { |
89 #if defined(USE_ASH) | 109 #if defined(USE_ASH) |
90 if (UseTouchOptimizedUI()) | 110 if (UseTouchOptimizedUI()) |
(...skipping 18 matching lines...) Expand all Loading... |
109 smallest_diff = diff; | 129 smallest_diff = diff; |
110 } | 130 } |
111 } | 131 } |
112 return static_cast<ui::ScaleFactor>(closest_match); | 132 return static_cast<ui::ScaleFactor>(closest_match); |
113 } | 133 } |
114 | 134 |
115 float GetScaleFactorScale(ScaleFactor scale_factor) { | 135 float GetScaleFactorScale(ScaleFactor scale_factor) { |
116 return kScaleFactorScales[scale_factor]; | 136 return kScaleFactorScales[scale_factor]; |
117 } | 137 } |
118 | 138 |
| 139 std::vector<ScaleFactor> GetSupportedScaleFactors() { |
| 140 return GetSupportedScaleFactorsInternal(); |
| 141 } |
| 142 |
| 143 bool IsScaleFactorSupported(ScaleFactor scale_factor) { |
| 144 const std::vector<ScaleFactor>& supported = |
| 145 GetSupportedScaleFactorsInternal(); |
| 146 return std::find(supported.begin(), supported.end(), scale_factor) != |
| 147 supported.end(); |
| 148 } |
| 149 |
| 150 namespace test { |
| 151 |
| 152 void SetSupportedScaleFactors( |
| 153 const std::vector<ui::ScaleFactor>& scale_factors) { |
| 154 std::vector<ui::ScaleFactor>& supported_scale_factors = |
| 155 GetSupportedScaleFactorsInternal(); |
| 156 supported_scale_factors = scale_factors; |
| 157 } |
| 158 |
| 159 } // namespace test |
| 160 |
119 #if !defined(OS_MACOSX) | 161 #if !defined(OS_MACOSX) |
120 ScaleFactor GetScaleFactorForNativeView(gfx::NativeView view) { | 162 ScaleFactor GetScaleFactorForNativeView(gfx::NativeView view) { |
121 #if defined(USE_AURA) && !defined(OS_WIN) | 163 #if defined(USE_AURA) && !defined(OS_WIN) |
122 return GetScaleFactorFromScale( | 164 return GetScaleFactorFromScale( |
123 view->GetRootWindow()->compositor()->device_scale_factor()); | 165 view->GetRootWindow()->compositor()->device_scale_factor()); |
124 #else | 166 #else |
125 NOTIMPLEMENTED(); | 167 NOTIMPLEMENTED(); |
126 return SCALE_FACTOR_NONE; | 168 return SCALE_FACTOR_NONE; |
127 #endif | 169 #endif |
128 } | 170 } |
129 #endif // !defined(OS_MACOSX) | 171 #endif // !defined(OS_MACOSX) |
130 | 172 |
131 } // namespace ui | 173 } // namespace ui |
OLD | NEW |