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