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 #if !defined(MAC_OS_X_VERSION_10_12) || \ |
| 100 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12 |
| 101 NSCellImagePosition LeadingCellImagePosition() { |
| 102 return ShouldDoExperimentalRTLLayout() ? NSImageRight : NSImageLeft; |
| 103 } |
| 104 NSCellImagePosition TrailingCellImagePosition() { |
| 105 return ShouldDoExperimentalRTLLayout() ? NSImageLeft : NSImageRight; |
| 106 } |
| 107 #else |
| 108 NSCellImagePosition LeadingCellImagePosition() { |
| 109 return NSImageLeading; |
| 110 } |
| 111 NSCellImagePosition TrailingCellImagePosition() { |
| 112 return NSImageTrailing; |
| 113 } |
| 114 #endif // MAC_OS_X_VERSION_10_12 |
| 115 |
| 116 // Adapted from Apple's RTL docs (goo.gl/cBaFnT) |
| 117 NSImage* FlippedImage(NSImage* image) { |
| 118 NSImage* existingImage = image; |
| 119 NSSize existingSize = [existingImage size]; |
| 120 NSSize newSize = NSMakeSize(existingSize.width, existingSize.height); |
| 121 NSImage* flippedImage = [[[NSImage alloc] initWithSize:newSize] autorelease]; |
| 122 |
| 123 [flippedImage lockFocus]; |
| 124 [[NSGraphicsContext currentContext] |
| 125 setImageInterpolation:NSImageInterpolationHigh]; |
| 126 |
| 127 NSAffineTransform* transform = [NSAffineTransform transform]; |
| 128 [transform translateXBy:existingSize.width yBy:0]; |
| 129 [transform scaleXBy:-1 yBy:1]; |
| 130 [transform concat]; |
| 131 |
| 132 [existingImage drawAtPoint:NSZeroPoint |
| 133 fromRect:NSMakeRect(0, 0, newSize.width, newSize.height) |
| 134 operation:NSCompositeSourceOver |
| 135 fraction:1.0]; |
| 136 |
| 137 [flippedImage unlockFocus]; |
| 138 |
| 139 return flippedImage; |
| 140 } |
| 141 |
99 } // namespace cocoa_l10n_util | 142 } // namespace cocoa_l10n_util |
OLD | NEW |