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,
|
bool UpdateUserActivityState(const std::string& type,
|
||||||
base::Value::Dict user_info);
|
base::Value::Dict user_info);
|
||||||
|
|
||||||
|
void ApplyForcedRTL();
|
||||||
|
|
||||||
// Bounce the dock icon.
|
// Bounce the dock icon.
|
||||||
enum class BounceType {
|
enum class BounceType {
|
||||||
kCritical = 0, // NSCriticalRequest
|
kCritical = 0, // NSCriticalRequest
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include "base/i18n/rtl.h"
|
||||||
#include "base/mac/bundle_locations.h"
|
#include "base/mac/bundle_locations.h"
|
||||||
#include "base/mac/foundation_util.h"
|
#include "base/mac/foundation_util.h"
|
||||||
#include "base/mac/mac_util.h"
|
#include "base/mac/mac_util.h"
|
||||||
|
@ -15,6 +16,7 @@
|
||||||
#include "base/mac/scoped_cftyperef.h"
|
#include "base/mac/scoped_cftyperef.h"
|
||||||
#include "base/strings/string_number_conversions.h"
|
#include "base/strings/string_number_conversions.h"
|
||||||
#include "base/strings/sys_string_conversions.h"
|
#include "base/strings/sys_string_conversions.h"
|
||||||
|
#include "chrome/browser/browser_process.h"
|
||||||
#include "net/base/mac/url_conversions.h"
|
#include "net/base/mac/url_conversions.h"
|
||||||
#include "shell/browser/badging/badge_manager.h"
|
#include "shell/browser/badging/badge_manager.h"
|
||||||
#include "shell/browser/mac/dict_util.h"
|
#include "shell/browser/mac/dict_util.h"
|
||||||
|
@ -37,6 +39,13 @@ namespace electron {
|
||||||
|
|
||||||
namespace {
|
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) {
|
NSString* GetAppPathForProtocol(const GURL& url) {
|
||||||
NSURL* ns_url = [NSURL
|
NSURL* ns_url = [NSURL
|
||||||
URLWithString:base::SysUTF8ToNSString(url.possibly_invalid_spec())];
|
URLWithString:base::SysUTF8ToNSString(url.possibly_invalid_spec())];
|
||||||
|
@ -325,6 +334,32 @@ bool Browser::UpdateUserActivityState(const std::string& type,
|
||||||
return prevent_default;
|
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(
|
Browser::LoginItemSettings Browser::GetLoginItemSettings(
|
||||||
const LoginItemSettings& options) {
|
const LoginItemSettings& options) {
|
||||||
LoginItemSettings settings;
|
LoginItemSettings settings;
|
||||||
|
|
|
@ -382,6 +382,7 @@ int ElectronBrowserMainParts::PreCreateThreads() {
|
||||||
|
|
||||||
#if BUILDFLAG(IS_MAC)
|
#if BUILDFLAG(IS_MAC)
|
||||||
ui::InitIdleMonitor();
|
ui::InitIdleMonitor();
|
||||||
|
Browser::Get()->ApplyForcedRTL();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fake_browser_process_->PreCreateThreads();
|
fake_browser_process_->PreCreateThreads();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue