OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/base/layout.h" |
| 6 |
| 7 #include <Cocoa/Cocoa.h> |
| 8 |
| 9 @interface NSScreen (LionAPI) |
| 10 - (CGFloat)backingScaleFactor; |
| 11 @end |
| 12 |
| 13 @interface NSWindow (LionAPI) |
| 14 - (CGFloat)backingScaleFactor; |
| 15 @end |
| 16 |
| 17 namespace { |
| 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) { |
| 30 float scale_factor = 1.0f; |
| 31 if (NSWindow* window = [view window]) { |
| 32 if ([window respondsToSelector:@selector(backingScaleFactor)]) |
| 33 return [window backingScaleFactor]; |
| 34 scale_factor = [window userSpaceScaleFactor]; |
| 35 } |
| 36 if (NSScreen* screen = [NSScreen mainScreen]) { |
| 37 if ([screen respondsToSelector:@selector(backingScaleFactor)]) |
| 38 return [screen backingScaleFactor]; |
| 39 return [screen userSpaceScaleFactor]; |
| 40 } |
| 41 return 1.0f; |
| 42 } |
| 43 |
| 44 } // namespace |
| 45 |
| 46 namespace ui { |
| 47 |
| 48 ScaleFactor GetScaleFactorForNativeView(gfx::NativeView view) { |
| 49 return GetScaleFactorFromScale(GetScaleFactorScaleForNativeView(view)); |
| 50 } |
| 51 |
| 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 |
OLD | NEW |