| 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.4f, 1.8f, 2.0f}; | 67 const float kScaleFactorScales[] = {1.0f, 1.0f, 1.4f, 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 std::vector<ScaleFactor>& GetSupportedScaleFactorsInternal() { | 72 std::vector<ScaleFactor>& GetSupportedScaleFactorsInternal() { |
| 73 static std::vector<ScaleFactor>* supported_scale_factors = | 73 static std::vector<ScaleFactor>* supported_scale_factors = |
| 74 new std::vector<ScaleFactor>(); | 74 new std::vector<ScaleFactor>(); |
| 75 if (supported_scale_factors->empty()) { | 75 if (supported_scale_factors->empty()) { |
| 76 // 100P is always a supported scale factor. | 76 // 100P is always a supported scale factor. |
| 77 supported_scale_factors->push_back(SCALE_FACTOR_100P); | 77 supported_scale_factors->push_back(SCALE_FACTOR_100P); |
| 78 | 78 |
| 79 #if defined(OS_IOS) | 79 #if defined(OS_IOS) |
| 80 // TODO(ios): 100p should not be necessary on iOS retina devices. However | 80 // TODO(ios): 100p should not be necessary on iOS retina devices. However |
| 81 // the sync service only supports syncing 100p favicons. Until sync supports | 81 // the sync service only supports syncing 100p favicons. Until sync supports |
| 82 // other scales 100p is needed in the list of scale factors to retrieve and | 82 // other scales 100p is needed in the list of scale factors to retrieve and |
| 83 // store the favicons in both 100p for sync and 200p for display. cr/160503. | 83 // store the favicons in both 100p for sync and 200p for display. cr/160503. |
| 84 gfx::Display display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 84 gfx::Display display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
| 85 if (display.device_scale_factor() > 1.0) { | 85 if (display.device_scale_factor() > 1.0) { |
| 86 DCHECK_EQ(2.0, display.device_scale_factor()); | 86 DCHECK_EQ(2.0, display.device_scale_factor()); |
| 87 supported_scale_factors->push_back(SCALE_FACTOR_200P); | 87 supported_scale_factors->push_back(SCALE_FACTOR_200P); |
| 88 } | 88 } |
| 89 #elif defined(OS_MACOSX) | 89 #elif defined(OS_MACOSX) |
| 90 if (base::mac::IsOSLionOrLater()) | 90 if (base::mac::IsOSLionOrLater()) |
| 91 supported_scale_factors->push_back(SCALE_FACTOR_200P); | 91 supported_scale_factors->push_back(SCALE_FACTOR_200P); |
| 92 #elif defined(OS_WIN) && defined(ENABLE_HIDPI) | 92 #elif defined(OS_WIN) && defined(ENABLE_HIDPI) |
| 93 if (base::win::IsMetroProcess() && base::win::IsTouchEnabled()) { | 93 if (base::win::IsMetroProcess() && base::win::IsTouchEnabled()) { |
| 94 supported_scale_factors->push_back(SCALE_FACTOR_140P); | 94 supported_scale_factors->push_back(SCALE_FACTOR_140P); |
| 95 supported_scale_factors->push_back(SCALE_FACTOR_180P); | 95 supported_scale_factors->push_back(SCALE_FACTOR_180P); |
| 96 } | 96 } |
| 97 #elif defined(USE_ASH) | 97 #elif defined(OS_CHROMEOS) |
| 98 // TODO(oshima): Include 200P only if the device support 200P |
| 98 supported_scale_factors->push_back(SCALE_FACTOR_200P); | 99 supported_scale_factors->push_back(SCALE_FACTOR_200P); |
| 99 #endif | 100 #endif |
| 100 std::sort(supported_scale_factors->begin(), | 101 std::sort(supported_scale_factors->begin(), |
| 101 supported_scale_factors->end(), | 102 supported_scale_factors->end(), |
| 102 ScaleFactorComparator); | 103 ScaleFactorComparator); |
| 103 } | 104 } |
| 104 return *supported_scale_factors; | 105 return *supported_scale_factors; |
| 105 } | 106 } |
| 106 | 107 |
| 107 } // namespace | 108 } // namespace |
| (...skipping 19 matching lines...) Expand all Loading... |
| 127 const std::vector<ScaleFactor>& supported = | 128 const std::vector<ScaleFactor>& supported = |
| 128 GetSupportedScaleFactorsInternal(); | 129 GetSupportedScaleFactorsInternal(); |
| 129 for (size_t i = 0; i < supported.size(); ++i) { | 130 for (size_t i = 0; i < supported.size(); ++i) { |
| 130 ScaleFactor scale_factor = supported[i]; | 131 ScaleFactor scale_factor = supported[i]; |
| 131 float diff = std::abs(kScaleFactorScales[scale_factor] - scale); | 132 float diff = std::abs(kScaleFactorScales[scale_factor] - scale); |
| 132 if (diff < smallest_diff) { | 133 if (diff < smallest_diff) { |
| 133 closest_match = scale_factor; | 134 closest_match = scale_factor; |
| 134 smallest_diff = diff; | 135 smallest_diff = diff; |
| 135 } | 136 } |
| 136 } | 137 } |
| 138 DCHECK_NE(closest_match, SCALE_FACTOR_NONE); |
| 137 return closest_match; | 139 return closest_match; |
| 138 } | 140 } |
| 139 | 141 |
| 140 float GetScaleFactorScale(ScaleFactor scale_factor) { | 142 float GetScaleFactorScale(ScaleFactor scale_factor) { |
| 141 return kScaleFactorScales[scale_factor]; | 143 return kScaleFactorScales[scale_factor]; |
| 142 } | 144 } |
| 143 | 145 |
| 144 ScaleFactor GetMaxScaleFactor() { | 146 ScaleFactor GetMaxScaleFactor() { |
| 145 #if defined(OS_CHROMEOS) | 147 #if defined(OS_CHROMEOS) |
| 146 return ResourceBundle::GetSharedInstance().max_scale_factor(); | 148 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); | 181 gfx::Screen* screen = gfx::Screen::GetScreenFor(view); |
| 180 if (screen->IsDIPEnabled()) { | 182 if (screen->IsDIPEnabled()) { |
| 181 gfx::Display display = screen->GetDisplayNearestWindow(view); | 183 gfx::Display display = screen->GetDisplayNearestWindow(view); |
| 182 return GetScaleFactorFromScale(display.device_scale_factor()); | 184 return GetScaleFactorFromScale(display.device_scale_factor()); |
| 183 } | 185 } |
| 184 return ui::SCALE_FACTOR_100P; | 186 return ui::SCALE_FACTOR_100P; |
| 185 } | 187 } |
| 186 #endif // !defined(OS_MACOSX) | 188 #endif // !defined(OS_MACOSX) |
| 187 | 189 |
| 188 } // namespace ui | 190 } // namespace ui |
| OLD | NEW |