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 10 matching lines...) Expand all Loading... |
21 #if defined(OS_WIN) | 21 #if defined(OS_WIN) |
22 #include "base/win/metro.h" | 22 #include "base/win/metro.h" |
23 #include "ui/gfx/win/dpi.h" | 23 #include "ui/gfx/win/dpi.h" |
24 #include <Windows.h> | 24 #include <Windows.h> |
25 #endif // defined(OS_WIN) | 25 #endif // defined(OS_WIN) |
26 | 26 |
27 namespace ui { | 27 namespace ui { |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 bool ScaleFactorComparator(const ScaleFactor& lhs, const ScaleFactor& rhs){ | |
32 return GetScaleForScaleFactor(lhs) < GetScaleForScaleFactor(rhs); | |
33 } | |
34 | |
35 std::vector<ScaleFactor>* g_supported_scale_factors = NULL; | 31 std::vector<ScaleFactor>* g_supported_scale_factors = NULL; |
36 | 32 |
37 const float kScaleFactorScales[] = {1.0f, 1.0f, 1.25f, 1.33f, 1.4f, 1.5f, 1.8f, | 33 const float kScaleFactorScales[] = {1.0f, 1.0f, 1.25f, 1.33f, 1.4f, 1.5f, 1.8f, |
38 2.0f, 2.5f, 3.0f}; | 34 2.0f, 2.5f, 3.0f}; |
39 COMPILE_ASSERT(NUM_SCALE_FACTORS == arraysize(kScaleFactorScales), | 35 COMPILE_ASSERT(NUM_SCALE_FACTORS == arraysize(kScaleFactorScales), |
40 kScaleFactorScales_incorrect_size); | 36 kScaleFactorScales_incorrect_size); |
41 | 37 |
42 } // namespace | 38 } // namespace |
43 | 39 |
44 void SetSupportedScaleFactors( | 40 void SetSupportedScaleFactors( |
45 const std::vector<ui::ScaleFactor>& scale_factors) { | 41 const std::vector<ui::ScaleFactor>& scale_factors) { |
46 if (g_supported_scale_factors != NULL) | 42 if (g_supported_scale_factors != NULL) |
47 delete g_supported_scale_factors; | 43 delete g_supported_scale_factors; |
48 | 44 |
49 g_supported_scale_factors = new std::vector<ScaleFactor>(scale_factors); | 45 g_supported_scale_factors = new std::vector<ScaleFactor>(scale_factors); |
50 std::sort(g_supported_scale_factors->begin(), | 46 std::sort(g_supported_scale_factors->begin(), |
51 g_supported_scale_factors->end(), | 47 g_supported_scale_factors->end(), |
52 ScaleFactorComparator); | 48 [](ScaleFactor lhs, ScaleFactor rhs) { |
| 49 return GetScaleForScaleFactor(lhs) < GetScaleForScaleFactor(rhs); |
| 50 }); |
53 | 51 |
54 // Set ImageSkia's supported scales. | 52 // Set ImageSkia's supported scales. |
55 std::vector<float> scales; | 53 std::vector<float> scales; |
56 for (std::vector<ScaleFactor>::const_iterator it = | 54 for (std::vector<ScaleFactor>::const_iterator it = |
57 g_supported_scale_factors->begin(); | 55 g_supported_scale_factors->begin(); |
58 it != g_supported_scale_factors->end(); ++it) { | 56 it != g_supported_scale_factors->end(); ++it) { |
59 scales.push_back(kScaleFactorScales[*it]); | 57 scales.push_back(kScaleFactorScales[*it]); |
60 } | 58 } |
61 gfx::ImageSkia::SetSupportedScales(scales); | 59 gfx::ImageSkia::SetSupportedScales(scales); |
62 } | 60 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 119 |
122 #if !defined(OS_MACOSX) | 120 #if !defined(OS_MACOSX) |
123 float GetScaleFactorForNativeView(gfx::NativeView view) { | 121 float GetScaleFactorForNativeView(gfx::NativeView view) { |
124 gfx::Screen* screen = gfx::Screen::GetScreenFor(view); | 122 gfx::Screen* screen = gfx::Screen::GetScreenFor(view); |
125 gfx::Display display = screen->GetDisplayNearestWindow(view); | 123 gfx::Display display = screen->GetDisplayNearestWindow(view); |
126 return display.device_scale_factor(); | 124 return display.device_scale_factor(); |
127 } | 125 } |
128 #endif // !defined(OS_MACOSX) | 126 #endif // !defined(OS_MACOSX) |
129 | 127 |
130 } // namespace ui | 128 } // namespace ui |
OLD | NEW |