Commit 49226d7b authored by Leonard Grey's avatar Leonard Grey Committed by Commit Bot

Remove MacRTL flag and associated machinery

Also removes some obsolete Cocoa l10n helper functions.

Bug: 912132
Change-Id: I0157f1ea6e615a16e973c2ad283fa35d1cb644bf
Reviewed-on: https://chromium-review.googlesource.com/c/1367906Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Commit-Queue: Leonard Grey <lgrey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#614827}
parent 84fa2678
......@@ -3285,12 +3285,6 @@ const FeatureEntry kFeatureEntries[] = {
FEATURE_VALUE_TYPE(features::kUseGoogleLocalNtp)},
#endif // !defined(OS_ANDROID)
#if defined(OS_MACOSX)
{"mac-rtl", flag_descriptions::kMacRTLName,
flag_descriptions::kMacRTLDescription, kOsMac,
FEATURE_VALUE_TYPE(features::kMacRTL)},
#endif // defined(OS_MACOSX)
#if defined(OS_CHROMEOS)
{"enable-stylus-virtual-keyboard",
flag_descriptions::kEnableStylusVirtualKeyboardName,
......
......@@ -3031,9 +3031,6 @@ const char kCreateAppWindowsInAppShimProcessDescription[] =
"Create native windows the app shim process, instead of of the browser "
"process.";
const char kMacRTLName[] = "Enable RTL";
const char kMacRTLDescription[] = "Mirrors the UI for RTL language users";
const char kMacTouchBarName[] = "Hardware Touch Bar";
const char kMacTouchBarDescription[] = "Control the use of the Touch Bar.";
......
......@@ -1801,9 +1801,6 @@ extern const char kHostedAppsInWindowsDescription[];
extern const char kCreateAppWindowsInAppShimProcessName[];
extern const char kCreateAppWindowsInAppShimProcessDescription[];
extern const char kMacRTLName[];
extern const char kMacRTLDescription[];
extern const char kMacTouchBarName[];
extern const char kMacTouchBarDescription[];
......
......@@ -8,7 +8,6 @@
#import <Cocoa/Cocoa.h>
#include <stddef.h>
#include "base/feature_list.h"
#include "base/strings/string16.h"
namespace cocoa_l10n_util {
......@@ -28,55 +27,15 @@ NSSize WrapOrSizeToFit(NSView* view);
// coordinates.
CGFloat VerticallyReflowGroup(NSArray* views);
// Like |base::ReplaceStringPlaceholders(const base::string16&,
// const base::string16&, size_t*)|, but for a NSString formatString.
NSString* ReplaceNSStringPlaceholders(NSString* formatString,
const base::string16& a,
size_t* offset);
// Generates a tooltip string for a given URL and title.
NSString* TooltipForURLAndTitle(NSString* url, NSString* title);
// Returns whether both:
// 1) Mac RTL support is enabled via the MacRTL feature;
// 2) The browser UI is in RTL mode.
// If MacRTL becomes the default, this function can be replaced with
// uses of base::i18n::IsRTL().
bool ShouldDoExperimentalRTLLayout();
// Returns true if ShouldDoExperimentalRTLLayout() is true and the OS is
// 10.12 or above. macOS 10.12 is the first OS where the native stoplight
// buttons are reversed in RTL, so manually reversing them in previous
// OSes would make Chrome stick out.
bool ShouldFlipWindowControlsInRTL();
// Set or clear the keys in NSUserDefaults which control UI direction based on
// whether direction is forced by a Chrome flag. This should be early in
// Chrome's launch, before any views or windows have been created, because it's
// cached by AppKit.
void ApplyForcedRTL();
// Returns NSImageLeading when available (10.12+), otherwise
// NSImageLeft for LTR and NSImageRight in RTL.
NSCellImagePosition LeadingCellImagePosition();
// Returns NSImageTrailing when available (10.12+), otherwise
// NSImageRight for LTR and NSImageLeft in RTL.
NSCellImagePosition TrailingCellImagePosition();
// Returns NSMinXEdge for LTR and NSMaxXEdge for RTL.
NSRectEdge LeadingEdge();
// Returns NSMaxXEdge for LTR and NSMinXEdge for RTL.
NSRectEdge TrailingEdge();
// Returns an autoreleased image containing |image| flipped
// across the x axis.
NSImage* FlippedImage(NSImage* image);
// In RTL, mirrors all subviews of |view|. Additionally,
// reverses horizontal margin autoresizing masks.
// This method is *not* recursive.
// In LTR, this is a no-op.
void FlipAllSubviewsIfNecessary(NSView* view);
} // namespace cocoa_l10n_util
#endif // CHROME_BROWSER_UI_COCOA_L10N_UTIL_H_
......@@ -9,7 +9,6 @@
#include "base/mac/mac_util.h"
#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h"
#include "chrome/common/chrome_features.h"
#import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTweaker.h"
namespace cocoa_l10n_util {
......@@ -70,13 +69,6 @@ CGFloat VerticallyReflowGroup(NSArray* views) {
return localVerticalShift;
}
NSString* ReplaceNSStringPlaceholders(NSString* formatString,
const base::string16& a,
size_t* offset) {
return base::SysUTF16ToNSString(base::ReplaceStringPlaceholders(
base::SysNSStringToUTF16(formatString), a, offset));
}
NSString* TooltipForURLAndTitle(NSString* url, NSString* title) {
if ([title length] == 0)
return url;
......@@ -86,14 +78,6 @@ NSString* TooltipForURLAndTitle(NSString* url, NSString* title) {
return [NSString stringWithFormat:@"%@\n%@", title, url];
}
bool ShouldDoExperimentalRTLLayout() {
return base::i18n::IsRTL() && base::FeatureList::IsEnabled(features::kMacRTL);
}
bool ShouldFlipWindowControlsInRTL() {
return ShouldDoExperimentalRTLLayout() && base::mac::IsAtLeastOS10_12();
}
void ApplyForcedRTL() {
NSUserDefaults* defaults = NSUserDefaults.standardUserDefaults;
......@@ -116,86 +100,4 @@ void ApplyForcedRTL() {
}
}
// TODO(lgrey): Remove these when deployment target is 10.12.
#if defined(MAC_OS_X_VERSION_10_12) && \
(MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12)
#warning LeadingCellImagePosition/TrailingCellImagePosition \
should be removed since the deployment target is >= 10.12
#endif
NSCellImagePosition LeadingCellImagePosition() {
#if defined(MAC_OS_X_VERSION_10_12) && \
MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12
if (@available(macOS 10.12, *)) {
return NSImageLeading;
}
#endif
return ShouldDoExperimentalRTLLayout() ? NSImageRight : NSImageLeft;
}
NSCellImagePosition TrailingCellImagePosition() {
#if defined(MAC_OS_X_VERSION_10_12) && \
MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_12
if (@available(macOS 10.12, *)) {
return NSImageTrailing;
}
#endif
return ShouldDoExperimentalRTLLayout() ? NSImageLeft : NSImageRight;
}
NSRectEdge LeadingEdge() {
return ShouldDoExperimentalRTLLayout() ? NSMaxXEdge : NSMinXEdge;
}
NSRectEdge TrailingEdge() {
return ShouldDoExperimentalRTLLayout() ? NSMinXEdge : NSMaxXEdge;
}
// 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;
}
void FlipAllSubviewsIfNecessary(NSView* view) {
if (!ShouldDoExperimentalRTLLayout())
return;
CGFloat width = NSWidth([view frame]);
for (NSView* subview in [view subviews]) {
NSRect subviewFrame = [subview frame];
subviewFrame.origin.x =
width - NSWidth(subviewFrame) - NSMinX(subviewFrame);
[subview setFrame:subviewFrame];
BOOL hasMinXMargin = subview.autoresizingMask & NSViewMinXMargin;
BOOL hasMaxXMargin = subview.autoresizingMask & NSViewMaxXMargin;
if (hasMinXMargin && hasMaxXMargin) {
// No-op. Skip reversing autoresizing mask if both horizontal margins
// are flexible.
} else if (hasMinXMargin) {
subview.autoresizingMask &= ~NSViewMinXMargin;
subview.autoresizingMask |= NSViewMaxXMargin;
} else if (hasMaxXMargin) {
subview.autoresizingMask &= ~NSViewMaxXMargin;
subview.autoresizingMask |= NSViewMinXMargin;
}
}
}
} // namespace cocoa_l10n_util
......@@ -334,9 +334,6 @@ const base::Feature kLsdPermissionPrompt{"LsdPermissionPrompt",
base::FEATURE_ENABLED_BY_DEFAULT};
#if defined(OS_MACOSX)
// Enables RTL layout in macOS top chrome.
const base::Feature kMacRTL{"MacRTL", base::FEATURE_ENABLED_BY_DEFAULT};
// Uses NSFullSizeContentViewWindowMask where available instead of adding our
// own views to the window frame. This is a temporary kill switch, it can be
// removed once we feel okay about leaving it on.
......
......@@ -224,7 +224,6 @@ COMPONENT_EXPORT(CHROME_FEATURES)
extern const base::Feature kLsdPermissionPrompt;
#if defined(OS_MACOSX)
COMPONENT_EXPORT(CHROME_FEATURES) extern const base::Feature kMacRTL;
COMPONENT_EXPORT(CHROME_FEATURES)
extern const base::Feature kMacFullSizeContentView;
#endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment