Skip to content

Commit

Permalink
fix: reposition traffic lights on theme change (#22559)
Browse files Browse the repository at this point in the history
Co-authored-by: Samuel Attard <[email protected]>
  • Loading branch information
MarshallOfSound and MarshallOfSound committed Mar 5, 2020
1 parent 8756ff0 commit b878a5e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion shell/browser/native_window_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "base/mac/scoped_nsobject.h"
#include "shell/browser/native_window.h"
#include "ui/native_theme/native_theme_observer.h"
#include "ui/views/controls/native/native_view_host.h"

@class ElectronNSWindow;
Expand All @@ -26,7 +27,7 @@ namespace electron {

class RootViewMac;

class NativeWindowMac : public NativeWindow {
class NativeWindowMac : public NativeWindow, public ui::NativeThemeObserver {
public:
NativeWindowMac(const mate::Dictionary& options, NativeWindow* parent);
~NativeWindowMac() override;
Expand Down Expand Up @@ -152,6 +153,7 @@ class NativeWindowMac : public NativeWindow {
// Custom traffic light positioning
void RepositionTrafficLights();
void SetExitingFullScreen(bool flag);
void OnNativeThemeUpdated(ui::NativeTheme* observed_theme) override;

enum class TitleBarStyle {
NORMAL,
Expand Down
12 changes: 12 additions & 0 deletions shell/browser/native_window_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@
#include "base/mac/scoped_cftyperef.h"
#include "base/numerics/ranges.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 "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 "native_mate/dictionary.h"
#include "shell/browser/native_browser_view_mac.h"
Expand Down Expand Up @@ -324,6 +327,8 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
NativeWindowMac::NativeWindowMac(const mate::Dictionary& options,
NativeWindow* parent)
: NativeWindow(options, parent), root_view_(new RootViewMac(this)) {
ui::NativeTheme::GetInstanceForNativeUi()->AddObserver(this);

int width = 800, height = 600;
options.Get(options::kWidth, &width);
options.Get(options::kHeight, &height);
Expand Down Expand Up @@ -513,6 +518,7 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
}

NativeWindowMac::~NativeWindowMac() {
ui::NativeTheme::GetInstanceForNativeUi()->RemoveObserver(this);
if (wheel_event_monitor_)
[NSEvent removeMonitor:wheel_event_monitor_];
}
Expand Down Expand Up @@ -704,6 +710,12 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
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() {
return [window_ attachedSheet] == nil;
}
Expand Down

0 comments on commit b878a5e

Please sign in to comment.