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 <cmath> | 7 #include <cmath> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "ui/base/ui_base_switches.h" | 14 #include "ui/base/ui_base_switches.h" |
15 | 15 |
| 16 #if defined(USE_AURA) && !defined(OS_WIN) |
| 17 #include "ui/aura/root_window.h" |
| 18 #include "ui/compositor/compositor.h" |
| 19 #endif // defined(USE_AURA) && !defined(OS_WIN) |
| 20 |
16 #if defined(USE_AURA) && defined(USE_X11) | 21 #if defined(USE_AURA) && defined(USE_X11) |
17 #include "ui/base/touch/touch_factory.h" | 22 #include "ui/base/touch/touch_factory.h" |
18 #endif // defined(USE_AURA) && defined(USE_X11) | 23 #endif // defined(USE_AURA) && defined(USE_X11) |
19 | 24 |
20 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
21 #include "base/win/metro.h" | 26 #include "base/win/metro.h" |
22 #include <Windows.h> | 27 #include <Windows.h> |
23 #endif // defined(OS_WIN) | 28 #endif // defined(OS_WIN) |
24 | 29 |
25 namespace { | 30 namespace { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 | 71 |
67 return has_touch_device; | 72 return has_touch_device; |
68 #else | 73 #else |
69 return false; | 74 return false; |
70 #endif | 75 #endif |
71 } | 76 } |
72 | 77 |
73 const float kScaleFactorScales[] = {1.0, 2.0}; | 78 const float kScaleFactorScales[] = {1.0, 2.0}; |
74 const size_t kScaleFactorScalesLength = arraysize(kScaleFactorScales); | 79 const size_t kScaleFactorScalesLength = arraysize(kScaleFactorScales); |
75 | 80 |
76 #if defined(OS_MACOSX) | |
77 std::vector<ui::ScaleFactor>& GetSupportedScaleFactorsInternal() { | |
78 static std::vector<ui::ScaleFactor>* supported_scale_factors = | |
79 new std::vector<ui::ScaleFactor>(); | |
80 if (supported_scale_factors->empty()) { | |
81 supported_scale_factors->push_back(ui::SCALE_FACTOR_100P); | |
82 supported_scale_factors->push_back(ui::SCALE_FACTOR_200P); | |
83 } | |
84 return *supported_scale_factors; | |
85 } | |
86 #endif // OS_MACOSX | |
87 | |
88 } // namespace | 81 } // namespace |
89 | 82 |
90 namespace ui { | 83 namespace ui { |
91 | 84 |
92 // Note that this function should be extended to select | 85 // Note that this function should be extended to select |
93 // LAYOUT_TOUCH when appropriate on more platforms than just | 86 // LAYOUT_TOUCH when appropriate on more platforms than just |
94 // Windows and Ash. | 87 // Windows and Ash. |
95 DisplayLayout GetDisplayLayout() { | 88 DisplayLayout GetDisplayLayout() { |
96 #if defined(USE_ASH) | 89 #if defined(USE_ASH) |
97 if (UseTouchOptimizedUI()) | 90 if (UseTouchOptimizedUI()) |
(...skipping 18 matching lines...) Expand all Loading... |
116 smallest_diff = diff; | 109 smallest_diff = diff; |
117 } | 110 } |
118 } | 111 } |
119 return static_cast<ui::ScaleFactor>(closest_match); | 112 return static_cast<ui::ScaleFactor>(closest_match); |
120 } | 113 } |
121 | 114 |
122 float GetScaleFactorScale(ScaleFactor scale_factor) { | 115 float GetScaleFactorScale(ScaleFactor scale_factor) { |
123 return kScaleFactorScales[scale_factor]; | 116 return kScaleFactorScales[scale_factor]; |
124 } | 117 } |
125 | 118 |
126 #if defined(OS_MACOSX) | 119 #if !defined(OS_MACOSX) |
127 std::vector<ScaleFactor> GetSupportedScaleFactors() { | 120 ScaleFactor GetScaleFactorForNativeView(gfx::NativeView view) { |
128 return GetSupportedScaleFactorsInternal(); | 121 #if defined(USE_AURA) && !defined(OS_WIN) |
| 122 return GetScaleFactorFromScale( |
| 123 view->GetRootWindow()->compositor()->device_scale_factor()); |
| 124 #else |
| 125 NOTIMPLEMENTED(); |
| 126 return SCALE_FACTOR_NONE; |
| 127 #endif |
129 } | 128 } |
130 | 129 #endif // !defined(OS_MACOSX) |
131 namespace test { | |
132 | |
133 void SetSupportedScaleFactors( | |
134 const std::vector<ui::ScaleFactor>& scale_factors) { | |
135 std::vector<ui::ScaleFactor>& supported_scale_factors = | |
136 GetSupportedScaleFactorsInternal(); | |
137 supported_scale_factors.clear(); | |
138 | |
139 for (size_t i = 0; i < scale_factors.size(); ++i) | |
140 supported_scale_factors.push_back(scale_factors[i]); | |
141 } | |
142 | |
143 } // namespace test | |
144 | |
145 #endif // OS_MACOSX | |
146 | 130 |
147 } // namespace ui | 131 } // namespace ui |
OLD | NEW |