OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #import "chrome/browser/ui/cocoa/l10n_util.h" | 5 #import "chrome/browser/ui/cocoa/l10n_util.h" |
6 | 6 |
7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
8 #include "base/mac/mac_util.h" | 8 #include "base/mac/mac_util.h" |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 89 |
90 bool ShouldDoExperimentalRTLLayout() { | 90 bool ShouldDoExperimentalRTLLayout() { |
91 return base::i18n::IsRTL() && | 91 return base::i18n::IsRTL() && |
92 base::FeatureList::IsEnabled(kExperimentalMacRTL); | 92 base::FeatureList::IsEnabled(kExperimentalMacRTL); |
93 } | 93 } |
94 | 94 |
95 bool ShouldFlipWindowControlsInRTL() { | 95 bool ShouldFlipWindowControlsInRTL() { |
96 return ShouldDoExperimentalRTLLayout() && base::mac::IsAtLeastOS10_12(); | 96 return ShouldDoExperimentalRTLLayout() && base::mac::IsAtLeastOS10_12(); |
97 } | 97 } |
98 | 98 |
| 99 // TODO(lgrey): Remove these when all builds are on 10.12 SDK. |
| 100 #if defined(MAC_OS_X_VERSION_10_12) && \ |
| 101 (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12) |
| 102 #warning LeadingCellImagePosition/TrailingCellImagePosition \ |
| 103 should be removed since the deployment target is >= 10.12 |
| 104 #endif |
| 105 |
| 106 #if !defined(MAC_OS_X_VERSION_10_12) || \ |
| 107 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12 |
| 108 NSCellImagePosition LeadingCellImagePosition() { |
| 109 return ShouldDoExperimentalRTLLayout() ? NSImageRight : NSImageLeft; |
| 110 } |
| 111 NSCellImagePosition TrailingCellImagePosition() { |
| 112 return ShouldDoExperimentalRTLLayout() ? NSImageLeft : NSImageRight; |
| 113 } |
| 114 #else |
| 115 NSCellImagePosition LeadingCellImagePosition() { |
| 116 return NSImageLeading; |
| 117 } |
| 118 NSCellImagePosition TrailingCellImagePosition() { |
| 119 return NSImageTrailing; |
| 120 } |
| 121 #endif // MAC_OS_X_VERSION_10_12 |
| 122 |
99 // Adapted from Apple's RTL docs (goo.gl/cBaFnT) | 123 // Adapted from Apple's RTL docs (goo.gl/cBaFnT) |
100 NSImage* FlippedImage(NSImage* image) { | 124 NSImage* FlippedImage(NSImage* image) { |
101 const NSSize size = [image size]; | 125 const NSSize size = [image size]; |
102 NSImage* flipped_image = [[[NSImage alloc] initWithSize:size] autorelease]; | 126 NSImage* flipped_image = [[[NSImage alloc] initWithSize:size] autorelease]; |
103 | 127 |
104 [flipped_image lockFocus]; | 128 [flipped_image lockFocus]; |
105 [[NSGraphicsContext currentContext] | 129 [[NSGraphicsContext currentContext] |
106 setImageInterpolation:NSImageInterpolationHigh]; | 130 setImageInterpolation:NSImageInterpolationHigh]; |
107 | 131 |
108 NSAffineTransform* transform = [NSAffineTransform transform]; | 132 NSAffineTransform* transform = [NSAffineTransform transform]; |
109 [transform translateXBy:size.width yBy:0]; | 133 [transform translateXBy:size.width yBy:0]; |
110 [transform scaleXBy:-1 yBy:1]; | 134 [transform scaleXBy:-1 yBy:1]; |
111 [transform concat]; | 135 [transform concat]; |
112 | 136 |
113 [image drawAtPoint:NSZeroPoint | 137 [image drawAtPoint:NSZeroPoint |
114 fromRect:NSMakeRect(0, 0, size.width, size.height) | 138 fromRect:NSMakeRect(0, 0, size.width, size.height) |
115 operation:NSCompositeSourceOver | 139 operation:NSCompositeSourceOver |
116 fraction:1.0]; | 140 fraction:1.0]; |
117 | 141 |
118 [flipped_image unlockFocus]; | 142 [flipped_image unlockFocus]; |
119 | 143 |
120 return flipped_image; | 144 return flipped_image; |
121 } | 145 } |
122 | 146 |
123 } // namespace cocoa_l10n_util | 147 } // namespace cocoa_l10n_util |
OLD | NEW |