| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 } else if (switch_value != switches::kTouchOptimizedUIAuto) { | 57 } else if (switch_value != switches::kTouchOptimizedUIAuto) { |
| 58 LOG(ERROR) << "Invalid --touch-optimized-ui option: " << switch_value; | 58 LOG(ERROR) << "Invalid --touch-optimized-ui option: " << switch_value; |
| 59 } | 59 } |
| 60 } | 60 } |
| 61 | 61 |
| 62 // We use the touch layout only when we are running in Metro mode. | 62 // We use the touch layout only when we are running in Metro mode. |
| 63 return base::win::IsMetroProcess() && base::win::IsTouchEnabled(); | 63 return base::win::IsMetroProcess() && base::win::IsTouchEnabled(); |
| 64 } | 64 } |
| 65 #endif // defined(OS_WIN) | 65 #endif // defined(OS_WIN) |
| 66 | 66 |
| 67 const float kScaleFactorScales[] = {1.0f, 1.0f, 1.4f, 1.8f, 2.0f}; | 67 const float kScaleFactorScales[] = {1.0f, 1.0f, 1.4f, 1.5f, 1.8f, 2.0f}; |
| 68 COMPILE_ASSERT(NUM_SCALE_FACTORS == arraysize(kScaleFactorScales), | 68 COMPILE_ASSERT(NUM_SCALE_FACTORS == arraysize(kScaleFactorScales), |
| 69 kScaleFactorScales_incorrect_size); | 69 kScaleFactorScales_incorrect_size); |
| 70 const size_t kScaleFactorScalesLength = arraysize(kScaleFactorScales); | 70 const size_t kScaleFactorScalesLength = arraysize(kScaleFactorScales); |
| 71 | 71 |
| 72 namespace { |
| 73 |
| 74 // Returns the scale factor closest to |scale| from the full list of factors. |
| 75 // Note that it does NOT rely on the list of supported scale factors. |
| 76 // Finding the closest match is inefficient and shouldn't be done frequently. |
| 77 ScaleFactor FindClosestScaleFactorUnsafe(float scale) { |
| 78 float smallest_diff = std::numeric_limits<float>::max(); |
| 79 ScaleFactor closest_match = SCALE_FACTOR_100P; |
| 80 for (int i = SCALE_FACTOR_100P; i < NUM_SCALE_FACTORS; ++i) { |
| 81 const ScaleFactor scale_factor = static_cast<ScaleFactor>(i); |
| 82 float diff = std::abs(kScaleFactorScales[scale_factor] - scale); |
| 83 if (diff < smallest_diff) { |
| 84 closest_match = scale_factor; |
| 85 smallest_diff = diff; |
| 86 } |
| 87 } |
| 88 return closest_match; |
| 89 } |
| 90 |
| 91 } // namespace |
| 92 |
| 72 std::vector<ScaleFactor>& GetSupportedScaleFactorsInternal() { | 93 std::vector<ScaleFactor>& GetSupportedScaleFactorsInternal() { |
| 73 static std::vector<ScaleFactor>* supported_scale_factors = | 94 static std::vector<ScaleFactor>* supported_scale_factors = |
| 74 new std::vector<ScaleFactor>(); | 95 new std::vector<ScaleFactor>(); |
| 75 if (supported_scale_factors->empty()) { | 96 if (supported_scale_factors->empty()) { |
| 76 #if !defined(OS_IOS) | 97 #if !defined(OS_IOS) |
| 77 // On platforms other than iOS, 100P is always a supported scale factor. | 98 // On platforms other than iOS, 100P is always a supported scale factor. |
| 78 supported_scale_factors->push_back(SCALE_FACTOR_100P); | 99 supported_scale_factors->push_back(SCALE_FACTOR_100P); |
| 79 #endif | 100 #endif |
| 80 | 101 |
| 81 #if defined(OS_IOS) | 102 #if defined(OS_ANDROID) |
| 103 const gfx::Display display = |
| 104 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
| 105 const float display_density = display.device_scale_factor(); |
| 106 const ScaleFactor closest = FindClosestScaleFactorUnsafe(display_density); |
| 107 if (closest != SCALE_FACTOR_100P) |
| 108 supported_scale_factors->push_back(closest); |
| 109 #elif defined(OS_IOS) |
| 82 gfx::Display display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 110 gfx::Display display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
| 83 if (display.device_scale_factor() > 1.0) { | 111 if (display.device_scale_factor() > 1.0) { |
| 84 DCHECK_EQ(2.0, display.device_scale_factor()); | 112 DCHECK_EQ(2.0, display.device_scale_factor()); |
| 85 supported_scale_factors->push_back(SCALE_FACTOR_200P); | 113 supported_scale_factors->push_back(SCALE_FACTOR_200P); |
| 86 } else { | 114 } else { |
| 87 supported_scale_factors->push_back(SCALE_FACTOR_100P); | 115 supported_scale_factors->push_back(SCALE_FACTOR_100P); |
| 88 } | 116 } |
| 89 #elif defined(OS_MACOSX) | 117 #elif defined(OS_MACOSX) |
| 90 if (base::mac::IsOSLionOrLater()) | 118 if (base::mac::IsOSLionOrLater()) |
| 91 supported_scale_factors->push_back(SCALE_FACTOR_200P); | 119 supported_scale_factors->push_back(SCALE_FACTOR_200P); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 gfx::Screen* screen = gfx::Screen::GetScreenFor(view); | 209 gfx::Screen* screen = gfx::Screen::GetScreenFor(view); |
| 182 if (screen->IsDIPEnabled()) { | 210 if (screen->IsDIPEnabled()) { |
| 183 gfx::Display display = screen->GetDisplayNearestWindow(view); | 211 gfx::Display display = screen->GetDisplayNearestWindow(view); |
| 184 return GetScaleFactorFromScale(display.device_scale_factor()); | 212 return GetScaleFactorFromScale(display.device_scale_factor()); |
| 185 } | 213 } |
| 186 return ui::SCALE_FACTOR_100P; | 214 return ui::SCALE_FACTOR_100P; |
| 187 } | 215 } |
| 188 #endif // !defined(OS_MACOSX) | 216 #endif // !defined(OS_MACOSX) |
| 189 | 217 |
| 190 } // namespace ui | 218 } // namespace ui |
| OLD | NEW |