fix: reposition traffic lights on theme change (#22534)
This commit is contained in:
parent
b3e1134a1a
commit
3c19aee73c
2 changed files with 15 additions and 1 deletions
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
#include "base/mac/scoped_nsobject.h"
|
#include "base/mac/scoped_nsobject.h"
|
||||||
#include "shell/browser/native_window.h"
|
#include "shell/browser/native_window.h"
|
||||||
|
#include "ui/native_theme/native_theme_observer.h"
|
||||||
#include "ui/views/controls/native/native_view_host.h"
|
#include "ui/views/controls/native/native_view_host.h"
|
||||||
|
|
||||||
@class ElectronNSWindow;
|
@class ElectronNSWindow;
|
||||||
|
@ -26,7 +27,7 @@ namespace electron {
|
||||||
|
|
||||||
class RootViewMac;
|
class RootViewMac;
|
||||||
|
|
||||||
class NativeWindowMac : public NativeWindow {
|
class NativeWindowMac : public NativeWindow, public ui::NativeThemeObserver {
|
||||||
public:
|
public:
|
||||||
NativeWindowMac(const gin_helper::Dictionary& options, NativeWindow* parent);
|
NativeWindowMac(const gin_helper::Dictionary& options, NativeWindow* parent);
|
||||||
~NativeWindowMac() override;
|
~NativeWindowMac() override;
|
||||||
|
@ -152,6 +153,7 @@ class NativeWindowMac : public NativeWindow {
|
||||||
// Custom traffic light positioning
|
// Custom traffic light positioning
|
||||||
void RepositionTrafficLights();
|
void RepositionTrafficLights();
|
||||||
void SetExitingFullScreen(bool flag);
|
void SetExitingFullScreen(bool flag);
|
||||||
|
void OnNativeThemeUpdated(ui::NativeTheme* observed_theme) override;
|
||||||
|
|
||||||
enum class TitleBarStyle {
|
enum class TitleBarStyle {
|
||||||
NORMAL,
|
NORMAL,
|
||||||
|
|
|
@ -16,8 +16,11 @@
|
||||||
#include "base/mac/scoped_cftyperef.h"
|
#include "base/mac/scoped_cftyperef.h"
|
||||||
#include "base/numerics/ranges.h"
|
#include "base/numerics/ranges.h"
|
||||||
#include "base/strings/sys_string_conversions.h"
|
#include "base/strings/sys_string_conversions.h"
|
||||||
|
#include "base/task/post_task.h"
|
||||||
#include "components/remote_cocoa/app_shim/native_widget_ns_window_bridge.h"
|
#include "components/remote_cocoa/app_shim/native_widget_ns_window_bridge.h"
|
||||||
#include "content/public/browser/browser_accessibility_state.h"
|
#include "content/public/browser/browser_accessibility_state.h"
|
||||||
|
#include "content/public/browser/browser_task_traits.h"
|
||||||
|
#include "content/public/browser/browser_thread.h"
|
||||||
#include "content/public/browser/desktop_media_id.h"
|
#include "content/public/browser/desktop_media_id.h"
|
||||||
#include "shell/browser/native_browser_view_mac.h"
|
#include "shell/browser/native_browser_view_mac.h"
|
||||||
#include "shell/browser/ui/cocoa/electron_native_widget_mac.h"
|
#include "shell/browser/ui/cocoa/electron_native_widget_mac.h"
|
||||||
|
@ -324,6 +327,8 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
|
||||||
NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options,
|
NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options,
|
||||||
NativeWindow* parent)
|
NativeWindow* parent)
|
||||||
: NativeWindow(options, parent), root_view_(new RootViewMac(this)) {
|
: NativeWindow(options, parent), root_view_(new RootViewMac(this)) {
|
||||||
|
ui::NativeTheme::GetInstanceForNativeUi()->AddObserver(this);
|
||||||
|
|
||||||
int width = 800, height = 600;
|
int width = 800, height = 600;
|
||||||
options.Get(options::kWidth, &width);
|
options.Get(options::kWidth, &width);
|
||||||
options.Get(options::kHeight, &height);
|
options.Get(options::kHeight, &height);
|
||||||
|
@ -509,6 +514,7 @@ NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options,
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeWindowMac::~NativeWindowMac() {
|
NativeWindowMac::~NativeWindowMac() {
|
||||||
|
ui::NativeTheme::GetInstanceForNativeUi()->RemoveObserver(this);
|
||||||
if (wheel_event_monitor_)
|
if (wheel_event_monitor_)
|
||||||
[NSEvent removeMonitor:wheel_event_monitor_];
|
[NSEvent removeMonitor:wheel_event_monitor_];
|
||||||
}
|
}
|
||||||
|
@ -700,6 +706,12 @@ void NativeWindowMac::SetExitingFullScreen(bool flag) {
|
||||||
exiting_fullscreen_ = flag;
|
exiting_fullscreen_ = flag;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeWindowMac::OnNativeThemeUpdated(ui::NativeTheme* observed_theme) {
|
||||||
|
base::PostTask(FROM_HERE, {content::BrowserThread::UI},
|
||||||
|
base::BindOnce(&NativeWindowMac::RepositionTrafficLights,
|
||||||
|
base::Unretained(this)));
|
||||||
|
}
|
||||||
|
|
||||||
bool NativeWindowMac::IsEnabled() {
|
bool NativeWindowMac::IsEnabled() {
|
||||||
return [window_ attachedSheet] == nil;
|
return [window_ attachedSheet] == nil;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue