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.
5 #include "ui/base/layout.h"
7 #include <Cocoa/Cocoa.h>
9 #if !defined(MAC_OS_X_VERSION_10_7) || \
10 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7
12 @interface NSScreen (LionAPI)
13 - (CGFloat)backingScaleFactor;
16 @interface NSWindow (LionAPI)
17 - (CGFloat)backingScaleFactor;
24 float GetScaleFactorScaleForNativeView(gfx::NativeView view) {
25 if (NSWindow* window = [view window]) {
26 if ([window respondsToSelector:@selector(backingScaleFactor)])
27 return [window backingScaleFactor];
28 return [window userSpaceScaleFactor];
31 NSArray* screens = [NSScreen screens];
35 NSScreen* screen = [screens objectAtIndex:0];
36 if ([screen respondsToSelector:@selector(backingScaleFactor)])
37 return [screen backingScaleFactor];
38 return [screen userSpaceScaleFactor];
45 ScaleFactor GetScaleFactorForNativeView(gfx::NativeView view) {
46 return GetScaleFactorFromScale(GetScaleFactorScaleForNativeView(view));