Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6040)

Unified Diff: chrome/browser/ui/cocoa/l10n_util.mm

Issue 2710123002: [Mac] Flip toolbar button images in RTL (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/cocoa/l10n_util.h ('k') | chrome/browser/ui/cocoa/toolbar/toolbar_button_cocoa.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..1479c1729d2e37debcc94390888ac07582d2fec9 100644
--- a/chrome/browser/ui/cocoa/l10n_util.mm
+++ b/chrome/browser/ui/cocoa/l10n_util.mm
@@ -96,4 +96,28 @@ bool ShouldFlipWindowControlsInRTL() {
return ShouldDoExperimentalRTLLayout() && base::mac::IsAtLeastOS10_12();
}
+// Adapted from Apple's RTL docs (goo.gl/cBaFnT)
+NSImage* FlippedImage(NSImage* image) {
+ const NSSize size = [image size];
+ NSImage* flipped_image = [[[NSImage alloc] initWithSize:size] autorelease];
+
+ [flipped_image lockFocus];
+ [[NSGraphicsContext currentContext]
+ setImageInterpolation:NSImageInterpolationHigh];
+
+ NSAffineTransform* transform = [NSAffineTransform transform];
+ [transform translateXBy:size.width yBy:0];
+ [transform scaleXBy:-1 yBy:1];
+ [transform concat];
+
+ [image drawAtPoint:NSZeroPoint
+ fromRect:NSMakeRect(0, 0, size.width, size.height)
+ operation:NSCompositeSourceOver
+ fraction:1.0];
+
+ [flipped_image unlockFocus];
+
+ return flipped_image;
+}
+
} // namespace cocoa_l10n_util
« no previous file with comments | « chrome/browser/ui/cocoa/l10n_util.h ('k') | chrome/browser/ui/cocoa/toolbar/toolbar_button_cocoa.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698