Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: ui/base/layout_mac.mm

Issue 10823067: Add a function to layout.h for getting ScaleFactor of the native view. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address comment Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/base/layout.cc ('k') | ui/ui.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
OLDNEW
« no previous file with comments | « ui/base/layout.cc ('k') | ui/ui.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698