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 <Cocoa/Cocoa.h> | 7 #include <Cocoa/Cocoa.h> |
8 | 8 |
9 @interface NSScreen (LionAPI) | 9 @interface NSScreen (LionAPI) |
10 - (CGFloat)backingScaleFactor; | 10 - (CGFloat)backingScaleFactor; |
11 @end | 11 @end |
12 | 12 |
13 @interface NSWindow (LionAPI) | 13 @interface NSWindow (LionAPI) |
14 - (CGFloat)backingScaleFactor; | 14 - (CGFloat)backingScaleFactor; |
15 @end | 15 @end |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 std::vector<ui::ScaleFactor>& GetSupportedScaleFactorsInternal() { | |
20 static std::vector<ui::ScaleFactor>* supported_scale_factors = | |
21 new std::vector<ui::ScaleFactor>(); | |
22 if (supported_scale_factors->empty()) { | |
23 supported_scale_factors->push_back(ui::SCALE_FACTOR_100P); | |
24 supported_scale_factors->push_back(ui::SCALE_FACTOR_200P); | |
25 } | |
26 return *supported_scale_factors; | |
27 } | |
28 | |
29 float GetScaleFactorScaleForNativeView(gfx::NativeView view) { | 19 float GetScaleFactorScaleForNativeView(gfx::NativeView view) { |
30 float scale_factor = 1.0f; | 20 float scale_factor = 1.0f; |
31 if (NSWindow* window = [view window]) { | 21 if (NSWindow* window = [view window]) { |
32 if ([window respondsToSelector:@selector(backingScaleFactor)]) | 22 if ([window respondsToSelector:@selector(backingScaleFactor)]) |
33 return [window backingScaleFactor]; | 23 return [window backingScaleFactor]; |
34 scale_factor = [window userSpaceScaleFactor]; | 24 scale_factor = [window userSpaceScaleFactor]; |
35 } | 25 } |
36 if (NSScreen* screen = [NSScreen mainScreen]) { | 26 if (NSScreen* screen = [NSScreen mainScreen]) { |
37 if ([screen respondsToSelector:@selector(backingScaleFactor)]) | 27 if ([screen respondsToSelector:@selector(backingScaleFactor)]) |
38 return [screen backingScaleFactor]; | 28 return [screen backingScaleFactor]; |
39 return [screen userSpaceScaleFactor]; | 29 return [screen userSpaceScaleFactor]; |
40 } | 30 } |
41 return 1.0f; | 31 return 1.0f; |
42 } | 32 } |
43 | 33 |
44 } // namespace | 34 } // namespace |
45 | 35 |
46 namespace ui { | 36 namespace ui { |
47 | 37 |
48 ScaleFactor GetScaleFactorForNativeView(gfx::NativeView view) { | 38 ScaleFactor GetScaleFactorForNativeView(gfx::NativeView view) { |
49 return GetScaleFactorFromScale(GetScaleFactorScaleForNativeView(view)); | 39 return GetScaleFactorFromScale(GetScaleFactorScaleForNativeView(view)); |
50 } | 40 } |
51 | 41 |
52 std::vector<ScaleFactor> GetSupportedScaleFactors() { | |
53 return GetSupportedScaleFactorsInternal(); | |
54 } | |
55 | |
56 namespace test { | |
57 | |
58 void SetSupportedScaleFactors( | |
59 const std::vector<ui::ScaleFactor>& scale_factors) { | |
60 std::vector<ui::ScaleFactor>& supported_scale_factors = | |
61 GetSupportedScaleFactorsInternal(); | |
62 supported_scale_factors = scale_factors; | |
63 } | |
64 | |
65 } // namespace test | |
66 | |
67 } // namespace ui | 42 } // namespace ui |
OLD | NEW |