Commit 2c524456 authored by Sidney San Martín's avatar Sidney San Martín Committed by Commit Bot

Apply chrome://flags/#force-ui-direction to AppKit.

Bug: 820348
Change-Id: Id9c8ff9878f6595f99d4630a18aa023b55cc8467
Reviewed-on: https://chromium-review.googlesource.com/956297Reviewed-by: default avatarJungshik Shin <jshin@chromium.org>
Reviewed-by: default avatarLeonard Grey <lgrey@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Sidney San Martín <sdy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542995}
parent e0452921
......@@ -84,30 +84,6 @@ base::i18n::TextDirection GetCharacterDirection(UChar32 character) {
return base::i18n::UNKNOWN_DIRECTION;
}
// Gets the explicitly forced text direction for debugging. If no forcing is
// applied, returns UNKNOWN_DIRECTION.
base::i18n::TextDirection GetForcedTextDirection() {
// On iOS, check for RTL forcing.
#if defined(OS_IOS)
if (base::ios::IsInForcedRTL())
return base::i18n::RIGHT_TO_LEFT;
#endif
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kForceUIDirection)) {
std::string force_flag =
command_line->GetSwitchValueASCII(switches::kForceUIDirection);
if (force_flag == switches::kForceDirectionLTR)
return base::i18n::LEFT_TO_RIGHT;
if (force_flag == switches::kForceDirectionRTL)
return base::i18n::RIGHT_TO_LEFT;
}
return base::i18n::UNKNOWN_DIRECTION;
}
} // namespace
namespace base {
......@@ -186,6 +162,28 @@ bool ICUIsRTL() {
return g_icu_text_direction == RIGHT_TO_LEFT;
}
TextDirection GetForcedTextDirection() {
// On iOS, check for RTL forcing.
#if defined(OS_IOS)
if (base::ios::IsInForcedRTL())
return base::i18n::RIGHT_TO_LEFT;
#endif
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kForceUIDirection)) {
std::string force_flag =
command_line->GetSwitchValueASCII(switches::kForceUIDirection);
if (force_flag == switches::kForceDirectionLTR)
return base::i18n::LEFT_TO_RIGHT;
if (force_flag == switches::kForceDirectionRTL)
return base::i18n::RIGHT_TO_LEFT;
}
return base::i18n::UNKNOWN_DIRECTION;
}
TextDirection GetTextDirectionForLocaleInStartUp(const char* locale_name) {
// Check for direction forcing.
TextDirection forced_direction = GetForcedTextDirection();
......
......@@ -60,6 +60,10 @@ BASE_I18N_EXPORT bool IsRTL();
// NOTE: Generally, you should call IsRTL() instead of this.
BASE_I18N_EXPORT bool ICUIsRTL();
// Gets the explicitly forced text direction for debugging. If no forcing is
// applied, returns UNKNOWN_DIRECTION.
BASE_I18N_EXPORT TextDirection GetForcedTextDirection();
// Returns the text direction for |locale_name|.
// As a startup optimization, this method checks the locale against a list of
// Chrome-supported RTL locales.
......
......@@ -13,6 +13,7 @@
#include "base/trace_event/trace_event.h"
#import "chrome/browser/app_controller_mac.h"
#import "chrome/browser/mac/exception_processor.h"
#include "chrome/browser/ui/cocoa/l10n_util.h"
#include "chrome/common/chrome_switches.h"
#include "components/crash/core/common/crash_key.h"
#import "components/crash/core/common/objc_zombie.h"
......@@ -48,6 +49,8 @@ void CancelTerminate() {
ObjcEvilDoers::ZombieEnable(true, 10000);
chrome::InstallObjcExceptionPreprocessor();
cocoa_l10n_util::ApplyForcedRTL();
}
- (id)init {
......
......@@ -50,6 +50,12 @@ bool ShouldDoExperimentalRTLLayout();
// 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();
......
......@@ -94,6 +94,28 @@ bool ShouldFlipWindowControlsInRTL() {
return ShouldDoExperimentalRTLLayout() && base::mac::IsAtLeastOS10_12();
}
void ApplyForcedRTL() {
NSUserDefaults* defaults = NSUserDefaults.standardUserDefaults;
// -registerDefaults: won't do the trick here because these defaults exist
// (in the global domain) to reflect the system locale. They need to be set
// in Chrome's domain to supersede the system value.
switch (base::i18n::GetForcedTextDirection()) {
case base::i18n::RIGHT_TO_LEFT:
[defaults setBool:YES forKey:@"AppleTextDirection"];
[defaults setBool:YES forKey:@"NSForceRightToLeftWritingDirection"];
break;
case base::i18n::LEFT_TO_RIGHT:
[defaults setBool:YES forKey:@"AppleTextDirection"];
[defaults setBool:NO forKey:@"NSForceRightToLeftWritingDirection"];
break;
default:
[defaults removeObjectForKey:@"AppleTextDirection"];
[defaults removeObjectForKey:@"NSForceRightToLeftWritingDirection"];
break;
}
}
// 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)
......
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