Index: chrome/browser/ui/cocoa/l10n_util.mm |
diff --git a/chrome/browser/ui/cocoa/l10n_util.mm b/chrome/browser/ui/cocoa/l10n_util.mm |
index 73db01d423dc3cc07cc90f4444bb793e6e918b41..49f47c7fcb92cf88e0368d880306b98dd5478aa6 100644 |
--- a/chrome/browser/ui/cocoa/l10n_util.mm |
+++ b/chrome/browser/ui/cocoa/l10n_util.mm |
@@ -96,4 +96,47 @@ bool ShouldFlipWindowControlsInRTL() { |
return ShouldDoExperimentalRTLLayout() && base::mac::IsAtLeastOS10_12(); |
} |
+#if !defined(MAC_OS_X_VERSION_10_12) || \ |
+ MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12 |
+NSCellImagePosition LeadingCellImagePosition() { |
+ return ShouldDoExperimentalRTLLayout() ? NSImageRight : NSImageLeft; |
+} |
+NSCellImagePosition TrailingCellImagePosition() { |
+ return ShouldDoExperimentalRTLLayout() ? NSImageLeft : NSImageRight; |
+} |
+#else |
+NSCellImagePosition LeadingCellImagePosition() { |
+ return NSImageLeading; |
+} |
+NSCellImagePosition TrailingCellImagePosition() { |
+ return NSImageTrailing; |
+} |
+#endif // MAC_OS_X_VERSION_10_12 |
+ |
+// Adapted from Apple's RTL docs (goo.gl/cBaFnT) |
+NSImage* FlippedImage(NSImage* image) { |
+ NSImage* existingImage = image; |
+ NSSize existingSize = [existingImage size]; |
+ NSSize newSize = NSMakeSize(existingSize.width, existingSize.height); |
+ NSImage* flippedImage = [[[NSImage alloc] initWithSize:newSize] autorelease]; |
+ |
+ [flippedImage lockFocus]; |
+ [[NSGraphicsContext currentContext] |
+ setImageInterpolation:NSImageInterpolationHigh]; |
+ |
+ NSAffineTransform* transform = [NSAffineTransform transform]; |
+ [transform translateXBy:existingSize.width yBy:0]; |
+ [transform scaleXBy:-1 yBy:1]; |
+ [transform concat]; |
+ |
+ [existingImage drawAtPoint:NSZeroPoint |
+ fromRect:NSMakeRect(0, 0, newSize.width, newSize.height) |
+ operation:NSCompositeSourceOver |
+ fraction:1.0]; |
+ |
+ [flippedImage unlockFocus]; |
+ |
+ return flippedImage; |
+} |
+ |
} // namespace cocoa_l10n_util |