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

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

Issue 2511973002: Reverse bookmark buttons and menus in RTL (Closed)
Patch Set: Increase cell size to account for gradient button's inset Created 4 years, 1 month 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
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 77139739d6a4fe501c0b114991bcaeca395e1f4d..c8849207fa3897ae3a6ecc3b5f7776eb319f22c3 100644
--- a/chrome/browser/ui/cocoa/l10n_util.mm
+++ b/chrome/browser/ui/cocoa/l10n_util.mm
@@ -5,6 +5,7 @@
#import "chrome/browser/ui/cocoa/l10n_util.h"
#include "base/i18n/rtl.h"
+#include "base/mac/mac_util.h"
#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h"
#import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTweaker.h"
@@ -91,4 +92,47 @@ bool ShouldDoExperimentalRTLLayout() {
base::FeatureList::IsEnabled(kExperimentalMacRTL);
}
+#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

Powered by Google App Engine
This is Rietveld 408576698