When Retrier succeeds, record errors it encountered.
[chromium-blink-merge.git] / ui / base / layout_mac.mm
blobd799c65dc47573cf71dfe35a04cef32fffae7c5e
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;
14 @end
16 @interface NSWindow (LionAPI)
17 - (CGFloat)backingScaleFactor;
18 @end
20 #endif  // 10.7
22 namespace {
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];
29   }
31   NSArray* screens = [NSScreen screens];
32   if (![screens count])
33     return 1.0f;
35   NSScreen* screen = [screens objectAtIndex:0];
36   if ([screen respondsToSelector:@selector(backingScaleFactor)])
37     return [screen backingScaleFactor];
38   return [screen userSpaceScaleFactor];
41 }  // namespace
43 namespace ui {
45 ScaleFactor GetScaleFactorForNativeView(gfx::NativeView view) {
46   return GetScaleFactorFromScale(GetScaleFactorScaleForNativeView(view));
49 }  // namespace ui