| 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 16 matching lines...) Expand all Loading... |
| 27 namespace ui { | 27 namespace ui { |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 bool ScaleFactorComparator(const ScaleFactor& lhs, const ScaleFactor& rhs){ | 31 bool ScaleFactorComparator(const ScaleFactor& lhs, const ScaleFactor& rhs){ |
| 32 return GetImageScale(lhs) < GetImageScale(rhs); | 32 return GetImageScale(lhs) < GetImageScale(rhs); |
| 33 } | 33 } |
| 34 | 34 |
| 35 std::vector<ScaleFactor>* g_supported_scale_factors = NULL; | 35 std::vector<ScaleFactor>* g_supported_scale_factors = NULL; |
| 36 | 36 |
| 37 #if defined(OS_WIN) | |
| 38 // Helper function that determines whether we want to optimize the UI for touch. | |
| 39 bool UseTouchOptimizedUI() { | |
| 40 // If --touch-optimized-ui is specified and not set to "auto", then override | |
| 41 // the hardware-determined setting (eg. for testing purposes). | |
| 42 static bool has_touch_optimized_ui = CommandLine::ForCurrentProcess()-> | |
| 43 HasSwitch(switches::kTouchOptimizedUI); | |
| 44 if (has_touch_optimized_ui) { | |
| 45 const std::string switch_value = CommandLine::ForCurrentProcess()-> | |
| 46 GetSwitchValueASCII(switches::kTouchOptimizedUI); | |
| 47 | |
| 48 // Note that simply specifying the switch is the same as enabled. | |
| 49 if (switch_value.empty() || | |
| 50 switch_value == switches::kTouchOptimizedUIEnabled) { | |
| 51 return true; | |
| 52 } else if (switch_value == switches::kTouchOptimizedUIDisabled) { | |
| 53 return false; | |
| 54 } else if (switch_value != switches::kTouchOptimizedUIAuto) { | |
| 55 LOG(ERROR) << "Invalid --touch-optimized-ui option: " << switch_value; | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 // We use the touch layout only when we are running in Metro mode. | |
| 60 return base::win::IsMetroProcess() && ui::IsTouchDevicePresent(); | |
| 61 } | |
| 62 #endif // defined(OS_WIN) | |
| 63 | |
| 64 const float kScaleFactorScales[] = {1.0f, 1.0f, 1.25f, 1.33f, 1.4f, 1.5f, 1.8f, | 37 const float kScaleFactorScales[] = {1.0f, 1.0f, 1.25f, 1.33f, 1.4f, 1.5f, 1.8f, |
| 65 2.0f, 3.0f}; | 38 2.0f, 3.0f}; |
| 66 COMPILE_ASSERT(NUM_SCALE_FACTORS == arraysize(kScaleFactorScales), | 39 COMPILE_ASSERT(NUM_SCALE_FACTORS == arraysize(kScaleFactorScales), |
| 67 kScaleFactorScales_incorrect_size); | 40 kScaleFactorScales_incorrect_size); |
| 68 | 41 |
| 69 } // namespace | 42 } // namespace |
| 70 | 43 |
| 71 DisplayLayout GetDisplayLayout() { | |
| 72 #if defined(OS_WIN) | |
| 73 if (UseTouchOptimizedUI()) | |
| 74 return LAYOUT_TOUCH; | |
| 75 #endif | |
| 76 return LAYOUT_DESKTOP; | |
| 77 } | |
| 78 | |
| 79 void SetSupportedScaleFactors( | 44 void SetSupportedScaleFactors( |
| 80 const std::vector<ui::ScaleFactor>& scale_factors) { | 45 const std::vector<ui::ScaleFactor>& scale_factors) { |
| 81 if (g_supported_scale_factors != NULL) | 46 if (g_supported_scale_factors != NULL) |
| 82 delete g_supported_scale_factors; | 47 delete g_supported_scale_factors; |
| 83 | 48 |
| 84 g_supported_scale_factors = new std::vector<ScaleFactor>(scale_factors); | 49 g_supported_scale_factors = new std::vector<ScaleFactor>(scale_factors); |
| 85 std::sort(g_supported_scale_factors->begin(), | 50 std::sort(g_supported_scale_factors->begin(), |
| 86 g_supported_scale_factors->end(), | 51 g_supported_scale_factors->end(), |
| 87 ScaleFactorComparator); | 52 ScaleFactorComparator); |
| 88 | 53 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 gfx::Screen* screen = gfx::Screen::GetScreenFor(view); | 148 gfx::Screen* screen = gfx::Screen::GetScreenFor(view); |
| 184 if (screen->IsDIPEnabled()) { | 149 if (screen->IsDIPEnabled()) { |
| 185 gfx::Display display = screen->GetDisplayNearestWindow(view); | 150 gfx::Display display = screen->GetDisplayNearestWindow(view); |
| 186 return GetSupportedScaleFactor(display.device_scale_factor()); | 151 return GetSupportedScaleFactor(display.device_scale_factor()); |
| 187 } | 152 } |
| 188 return ui::SCALE_FACTOR_100P; | 153 return ui::SCALE_FACTOR_100P; |
| 189 } | 154 } |
| 190 #endif // !defined(OS_MACOSX) | 155 #endif // !defined(OS_MACOSX) |
| 191 | 156 |
| 192 } // namespace ui | 157 } // namespace ui |
| OLD | NEW |