Chromium Code Reviews| Index: ui/base/layout_mac.mm |
| diff --git a/ui/base/layout_mac.mm b/ui/base/layout_mac.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e4584b6e107227380c814e0ea49fc92e928bca70 |
| --- /dev/null |
| +++ b/ui/base/layout_mac.mm |
| @@ -0,0 +1,70 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ui/base/layout.h" |
| + |
| +#include <Cocoa/Cocoa.h> |
| + |
| +@interface NSScreen (LionAPI) |
| +- (CGFloat)backingScaleFactor; |
| +@end |
| + |
| +@interface NSWindow (LionAPI) |
| +- (CGFloat)backingScaleFactor; |
| +@end |
| + |
| +namespace { |
| + |
| +std::vector<ui::ScaleFactor>& GetSupportedScaleFactorsInternal() { |
| + static std::vector<ui::ScaleFactor>* supported_scale_factors = |
| + new std::vector<ui::ScaleFactor>(); |
| + if (supported_scale_factors->empty()) { |
| + supported_scale_factors->push_back(ui::SCALE_FACTOR_100P); |
| + supported_scale_factors->push_back(ui::SCALE_FACTOR_200P); |
| + } |
| + return *supported_scale_factors; |
| +} |
| + |
| +float GetScaleFactorScaleForNativeView(gfx::NativeView view) { |
| + float scale_factor = 1.0f; |
| + if (NSWindow* window = [view window]) { |
| + if ([window respondsToSelector:@selector(backingScaleFactor)]) |
| + return [window backingScaleFactor]; |
| + scale_factor = [window userSpaceScaleFactor]; |
| + } |
| + if (NSScreen* screen = [NSScreen mainScreen]) { |
| + if ([screen respondsToSelector:@selector(backingScaleFactor)]) |
| + return [screen backingScaleFactor]; |
| + return [screen userSpaceScaleFactor]; |
| + } |
| + return 1.0f; |
| +} |
| + |
| +} // namespace |
| + |
| +namespace ui { |
| + |
| +ScaleFactor GetScaleFactorForNativeView(gfx::NativeView view) { |
| + return GetScaleFactorFromScale(GetScaleFactorScaleForNativeView(view)); |
| +} |
| + |
| +std::vector<ScaleFactor> GetSupportedScaleFactors() { |
| + return GetSupportedScaleFactorsInternal(); |
| +} |
| + |
| +namespace test { |
| + |
| +void SetSupportedScaleFactors( |
| + const std::vector<ui::ScaleFactor>& scale_factors) { |
| + std::vector<ui::ScaleFactor>& supported_scale_factors = |
| + GetSupportedScaleFactorsInternal(); |
| + supported_scale_factors.clear(); |
|
sky
2012/08/02 21:10:14
Can you replace 62-66 with supported_scale_factors
mazda
2012/08/02 22:42:24
Done.
|
| + |
| + for (size_t i = 0; i < scale_factors.size(); ++i) |
| + supported_scale_factors.push_back(scale_factors[i]); |
| +} |
| + |
| +} // namespace test |
| + |
| +} // namespace ui |