fix: RTL WindowButtonsProxy
buttons (#36839)
* fix: RTL WindowButtonsProxy buttons * chore: address review feedback
This commit is contained in:
parent
168726a052
commit
414791232a
3 changed files with 38 additions and 0 deletions
|
@ -202,6 +202,8 @@ class Browser : public WindowListObserver {
|
|||
bool UpdateUserActivityState(const std::string& type,
|
||||
base::Value::Dict user_info);
|
||||
|
||||
void ApplyForcedRTL();
|
||||
|
||||
// Bounce the dock icon.
|
||||
enum class BounceType {
|
||||
kCritical = 0, // NSCriticalRequest
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "base/i18n/rtl.h"
|
||||
#include "base/mac/bundle_locations.h"
|
||||
#include "base/mac/foundation_util.h"
|
||||
#include "base/mac/mac_util.h"
|
||||
|
@ -15,6 +16,7 @@
|
|||
#include "base/mac/scoped_cftyperef.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "base/strings/sys_string_conversions.h"
|
||||
#include "chrome/browser/browser_process.h"
|
||||
#include "net/base/mac/url_conversions.h"
|
||||
#include "shell/browser/badging/badge_manager.h"
|
||||
#include "shell/browser/mac/dict_util.h"
|
||||
|
@ -37,6 +39,13 @@ namespace electron {
|
|||
|
||||
namespace {
|
||||
|
||||
bool IsAppRTL() {
|
||||
const std::string& locale = g_browser_process->GetApplicationLocale();
|
||||
base::i18n::TextDirection text_direction =
|
||||
base::i18n::GetTextDirectionForLocaleInStartUp(locale.c_str());
|
||||
return text_direction == base::i18n::RIGHT_TO_LEFT;
|
||||
}
|
||||
|
||||
NSString* GetAppPathForProtocol(const GURL& url) {
|
||||
NSURL* ns_url = [NSURL
|
||||
URLWithString:base::SysUTF8ToNSString(url.possibly_invalid_spec())];
|
||||
|
@ -325,6 +334,32 @@ bool Browser::UpdateUserActivityState(const std::string& type,
|
|||
return prevent_default;
|
||||
}
|
||||
|
||||
// Modified from chrome/browser/ui/cocoa/l10n_util.mm.
|
||||
void Browser::ApplyForcedRTL() {
|
||||
NSUserDefaults* defaults = NSUserDefaults.standardUserDefaults;
|
||||
|
||||
auto dir = base::i18n::GetForcedTextDirection();
|
||||
|
||||
// An Electron app should respect RTL behavior of application locale over
|
||||
// system locale.
|
||||
auto should_be_rtl = dir == base::i18n::RIGHT_TO_LEFT || IsAppRTL();
|
||||
auto should_be_ltr = dir == base::i18n::LEFT_TO_RIGHT || !IsAppRTL();
|
||||
|
||||
// -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.
|
||||
if (should_be_rtl) {
|
||||
[defaults setBool:YES forKey:@"AppleTextDirection"];
|
||||
[defaults setBool:YES forKey:@"NSForceRightToLeftWritingDirection"];
|
||||
} else if (should_be_ltr) {
|
||||
[defaults setBool:YES forKey:@"AppleTextDirection"];
|
||||
[defaults setBool:NO forKey:@"NSForceRightToLeftWritingDirection"];
|
||||
} else {
|
||||
[defaults removeObjectForKey:@"AppleTextDirection"];
|
||||
[defaults removeObjectForKey:@"NSForceRightToLeftWritingDirection"];
|
||||
}
|
||||
}
|
||||
|
||||
Browser::LoginItemSettings Browser::GetLoginItemSettings(
|
||||
const LoginItemSettings& options) {
|
||||
LoginItemSettings settings;
|
||||
|
|
|
@ -382,6 +382,7 @@ int ElectronBrowserMainParts::PreCreateThreads() {
|
|||
|
||||
#if BUILDFLAG(IS_MAC)
|
||||
ui::InitIdleMonitor();
|
||||
Browser::Get()->ApplyForcedRTL();
|
||||
#endif
|
||||
|
||||
fake_browser_process_->PreCreateThreads();
|
||||
|
|
Loading…
Reference in a new issue