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 11 matching lines...) Expand all Loading... | |
| 22 | 22 |
| 23 #if defined(OS_WIN) | 23 #if defined(OS_WIN) |
| 24 #include "base/win/metro.h" | 24 #include "base/win/metro.h" |
| 25 #include <Windows.h> | 25 #include <Windows.h> |
| 26 #endif // defined(OS_WIN) | 26 #endif // defined(OS_WIN) |
| 27 | 27 |
| 28 #if defined(OS_CHROMEOS) | 28 #if defined(OS_CHROMEOS) |
| 29 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" |
| 30 #endif | 30 #endif |
| 31 | 31 |
| 32 #include "base/debug/stack_trace.h" | |
|
sky
2012/11/09 23:02:17
remove this
oshima
2012/11/09 23:49:37
Done.
| |
| 33 | |
| 32 namespace ui { | 34 namespace ui { |
| 33 | 35 |
| 34 namespace { | 36 namespace { |
| 35 | 37 |
| 36 bool ScaleFactorComparator(const ScaleFactor& lhs, const ScaleFactor& rhs){ | 38 bool ScaleFactorComparator(const ScaleFactor& lhs, const ScaleFactor& rhs){ |
| 37 return GetScaleFactorScale(lhs) < GetScaleFactorScale(rhs); | 39 return GetScaleFactorScale(lhs) < GetScaleFactorScale(rhs); |
| 38 } | 40 } |
| 39 | 41 |
| 40 #if defined(OS_WIN) | 42 #if defined(OS_WIN) |
| 41 // Helper function that determines whether we want to optimize the UI for touch. | 43 // Helper function that determines whether we want to optimize the UI for touch. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 57 } else if (switch_value != switches::kTouchOptimizedUIAuto) { | 59 } else if (switch_value != switches::kTouchOptimizedUIAuto) { |
| 58 LOG(ERROR) << "Invalid --touch-optimized-ui option: " << switch_value; | 60 LOG(ERROR) << "Invalid --touch-optimized-ui option: " << switch_value; |
| 59 } | 61 } |
| 60 } | 62 } |
| 61 | 63 |
| 62 // We use the touch layout only when we are running in Metro mode. | 64 // We use the touch layout only when we are running in Metro mode. |
| 63 return base::win::IsMetroProcess() && base::win::IsTouchEnabled(); | 65 return base::win::IsMetroProcess() && base::win::IsTouchEnabled(); |
| 64 } | 66 } |
| 65 #endif // defined(OS_WIN) | 67 #endif // defined(OS_WIN) |
| 66 | 68 |
| 67 const float kScaleFactorScales[] = {1.0f, 1.4f, 1.8f, 2.0f}; | 69 const float kScaleFactorScales[] = {1.0f, 1.0f, 1.4f, 1.8f, 2.0f}; |
| 68 COMPILE_ASSERT(NUM_SCALE_FACTORS == arraysize(kScaleFactorScales), | 70 COMPILE_ASSERT(NUM_SCALE_FACTORS == arraysize(kScaleFactorScales), |
| 69 kScaleFactorScales_incorrect_size); | 71 kScaleFactorScales_incorrect_size); |
| 70 const size_t kScaleFactorScalesLength = arraysize(kScaleFactorScales); | 72 const size_t kScaleFactorScalesLength = arraysize(kScaleFactorScales); |
| 71 | 73 |
| 72 std::vector<ScaleFactor>& GetSupportedScaleFactorsInternal() { | 74 std::vector<ScaleFactor>& GetSupportedScaleFactorsInternal() { |
| 73 static std::vector<ScaleFactor>* supported_scale_factors = | 75 static std::vector<ScaleFactor>* supported_scale_factors = |
| 74 new std::vector<ScaleFactor>(); | 76 new std::vector<ScaleFactor>(); |
| 75 if (supported_scale_factors->empty()) { | 77 if (supported_scale_factors->empty()) { |
| 76 #if !defined(OS_IOS) | 78 #if !defined(OS_IOS) |
| 77 // On platforms other than iOS, 100P is always a supported scale factor. | 79 // On platforms other than iOS, 100P is always a supported scale factor. |
| 78 supported_scale_factors->push_back(SCALE_FACTOR_100P); | 80 supported_scale_factors->push_back(SCALE_FACTOR_100P); |
| 79 #endif | 81 #endif |
| 80 | 82 |
| 81 #if defined(OS_IOS) | 83 #if defined(OS_IOS) |
| 82 gfx::Display display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 84 gfx::Display display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
| 83 if (display.device_scale_factor() > 1.0) { | 85 if (display.device_scale_factor() > 1.0) { |
| 84 DCHECK_EQ(2.0, display.device_scale_factor()); | 86 DCHECK_EQ(2.0, display.device_scale_factor()); |
| 85 supported_scale_factors->push_back(SCALE_FACTOR_200P); | 87 supported_scale_factors->push_back(SCALE_FACTOR_200P); |
| 86 } else { | 88 } else { |
| 87 supported_scale_factors->push_back(SCALE_FACTOR_100P); | 89 supported_scale_factors->push_back(SCALE_FACTOR_100P); |
| 88 } | 90 } |
| 89 #elif defined(OS_MACOSX) | 91 #elif defined(OS_MACOSX) |
| 90 if (base::mac::IsOSLionOrLater()) | 92 if (base::mac::IsOSLionOrLater()) |
| 91 supported_scale_factors->push_back(SCALE_FACTOR_200P); | 93 supported_scale_factors->push_back(SCALE_FACTOR_200P); |
| 92 #elif defined(OS_WIN) && defined(ENABLE_HIDPI) | 94 #elif defined(OS_WIN) && defined(ENABLE_HIDPI) |
| 93 if (base::win::IsMetroProcess() && base::win::IsTouchEnabled()) { | 95 if (base::win::IsMetroProcess() && base::win::IsTouchEnabled()) { |
| 94 supported_scale_factors->push_back(SCALE_FACTOR_140P); | 96 supported_scale_factors->push_back(SCALE_FACTOR_140P); |
| 95 supported_scale_factors->push_back(SCALE_FACTOR_180P); | 97 supported_scale_factors->push_back(SCALE_FACTOR_180P); |
| 96 } | 98 } |
| 97 #elif defined(USE_ASH) | 99 #elif defined(OS_CHROMEOS) |
| 100 // TODO(oshima): Include 200P only if the device support 200P | |
| 98 supported_scale_factors->push_back(SCALE_FACTOR_200P); | 101 supported_scale_factors->push_back(SCALE_FACTOR_200P); |
| 99 #endif | 102 #endif |
| 100 std::sort(supported_scale_factors->begin(), | 103 std::sort(supported_scale_factors->begin(), |
| 101 supported_scale_factors->end(), | 104 supported_scale_factors->end(), |
| 102 ScaleFactorComparator); | 105 ScaleFactorComparator); |
| 103 } | 106 } |
| 104 return *supported_scale_factors; | 107 return *supported_scale_factors; |
| 105 } | 108 } |
| 106 | 109 |
| 107 } // namespace | 110 } // namespace |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 127 const std::vector<ScaleFactor>& supported = | 130 const std::vector<ScaleFactor>& supported = |
| 128 GetSupportedScaleFactorsInternal(); | 131 GetSupportedScaleFactorsInternal(); |
| 129 for (size_t i = 0; i < supported.size(); ++i) { | 132 for (size_t i = 0; i < supported.size(); ++i) { |
| 130 ScaleFactor scale_factor = supported[i]; | 133 ScaleFactor scale_factor = supported[i]; |
| 131 float diff = std::abs(kScaleFactorScales[scale_factor] - scale); | 134 float diff = std::abs(kScaleFactorScales[scale_factor] - scale); |
| 132 if (diff < smallest_diff) { | 135 if (diff < smallest_diff) { |
| 133 closest_match = scale_factor; | 136 closest_match = scale_factor; |
| 134 smallest_diff = diff; | 137 smallest_diff = diff; |
| 135 } | 138 } |
| 136 } | 139 } |
| 140 DCHECK_NE(closest_match, SCALE_FACTOR_NONE); | |
| 137 return closest_match; | 141 return closest_match; |
| 138 } | 142 } |
| 139 | 143 |
| 140 float GetScaleFactorScale(ScaleFactor scale_factor) { | 144 float GetScaleFactorScale(ScaleFactor scale_factor) { |
| 141 return kScaleFactorScales[scale_factor]; | 145 return kScaleFactorScales[scale_factor]; |
| 142 } | 146 } |
| 143 | 147 |
| 144 ScaleFactor GetMaxScaleFactor() { | 148 ScaleFactor GetMaxScaleFactor() { |
| 145 #if defined(OS_CHROMEOS) | 149 #if defined(OS_CHROMEOS) |
| 146 return ResourceBundle::GetSharedInstance().max_scale_factor(); | 150 return ResourceBundle::GetSharedInstance().max_scale_factor(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 gfx::Screen* screen = gfx::Screen::GetScreenFor(view); | 183 gfx::Screen* screen = gfx::Screen::GetScreenFor(view); |
| 180 if (screen->IsDIPEnabled()) { | 184 if (screen->IsDIPEnabled()) { |
| 181 gfx::Display display = screen->GetDisplayNearestWindow(view); | 185 gfx::Display display = screen->GetDisplayNearestWindow(view); |
| 182 return GetScaleFactorFromScale(display.device_scale_factor()); | 186 return GetScaleFactorFromScale(display.device_scale_factor()); |
| 183 } | 187 } |
| 184 return ui::SCALE_FACTOR_100P; | 188 return ui::SCALE_FACTOR_100P; |
| 185 } | 189 } |
| 186 #endif // !defined(OS_MACOSX) | 190 #endif // !defined(OS_MACOSX) |
| 187 | 191 |
| 188 } // namespace ui | 192 } // namespace ui |
| OLD | NEW |