fix: persist maximizable state through theme change (#22677)
This commit is contained in:
parent
9583f7dabb
commit
f4868c9a28
3 changed files with 20 additions and 14 deletions
|
@ -151,7 +151,7 @@ class NativeWindowMac : public NativeWindow, public ui::NativeThemeObserver {
|
||||||
void SetWindowLevel(int level);
|
void SetWindowLevel(int level);
|
||||||
|
|
||||||
// Custom traffic light positioning
|
// Custom traffic light positioning
|
||||||
void RepositionTrafficLights();
|
void RedrawTrafficLights();
|
||||||
void SetExitingFullScreen(bool flag);
|
void SetExitingFullScreen(bool flag);
|
||||||
void SetTrafficLightPosition(const gfx::Point& position) override;
|
void SetTrafficLightPosition(const gfx::Point& position) override;
|
||||||
gfx::Point GetTrafficLightPosition() const override;
|
gfx::Point GetTrafficLightPosition() const override;
|
||||||
|
@ -222,6 +222,9 @@ class NativeWindowMac : public NativeWindow, public ui::NativeThemeObserver {
|
||||||
// setWindowButtonVisibility().
|
// setWindowButtonVisibility().
|
||||||
base::Optional<bool> window_button_visibility_;
|
base::Optional<bool> window_button_visibility_;
|
||||||
|
|
||||||
|
// Maximizable window state; necessary for persistence through redraws.
|
||||||
|
bool maximizable_ = true;
|
||||||
|
|
||||||
// Simple (pre-Lion) Fullscreen Settings
|
// Simple (pre-Lion) Fullscreen Settings
|
||||||
bool always_simple_fullscreen_ = false;
|
bool always_simple_fullscreen_ = false;
|
||||||
bool is_simple_fullscreen_ = false;
|
bool is_simple_fullscreen_ = false;
|
||||||
|
|
|
@ -47,13 +47,13 @@
|
||||||
// This view would inform Chromium to resize the hosted views::View.
|
// This view would inform Chromium to resize the hosted views::View.
|
||||||
//
|
//
|
||||||
// The overrided methods should behave the same with BridgedContentView.
|
// The overrided methods should behave the same with BridgedContentView.
|
||||||
@interface ElectronAdapatedContentView : NSView {
|
@interface ElectronAdaptedContentView : NSView {
|
||||||
@private
|
@private
|
||||||
views::NativeWidgetMacNSWindowHost* bridge_host_;
|
views::NativeWidgetMacNSWindowHost* bridge_host_;
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation ElectronAdapatedContentView
|
@implementation ElectronAdaptedContentView
|
||||||
|
|
||||||
- (id)initWithShell:(electron::NativeWindowMac*)shell {
|
- (id)initWithShell:(electron::NativeWindowMac*)shell {
|
||||||
if ((self = [self init])) {
|
if ((self = [self init])) {
|
||||||
|
@ -519,7 +519,10 @@ NativeWindowMac::~NativeWindowMac() {
|
||||||
[NSEvent removeMonitor:wheel_event_monitor_];
|
[NSEvent removeMonitor:wheel_event_monitor_];
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::RepositionTrafficLights() {
|
void NativeWindowMac::RedrawTrafficLights() {
|
||||||
|
// Ensure maximizable options retain pre-existing state.
|
||||||
|
SetMaximizable(maximizable_);
|
||||||
|
|
||||||
if (!traffic_light_position_.x() && !traffic_light_position_.y()) {
|
if (!traffic_light_position_.x() && !traffic_light_position_.y()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -708,7 +711,7 @@ void NativeWindowMac::SetExitingFullScreen(bool flag) {
|
||||||
|
|
||||||
void NativeWindowMac::OnNativeThemeUpdated(ui::NativeTheme* observed_theme) {
|
void NativeWindowMac::OnNativeThemeUpdated(ui::NativeTheme* observed_theme) {
|
||||||
base::PostTask(FROM_HERE, {content::BrowserThread::UI},
|
base::PostTask(FROM_HERE, {content::BrowserThread::UI},
|
||||||
base::BindOnce(&NativeWindowMac::RepositionTrafficLights,
|
base::BindOnce(&NativeWindowMac::RedrawTrafficLights,
|
||||||
base::Unretained(this)));
|
base::Unretained(this)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -930,6 +933,7 @@ bool NativeWindowMac::IsMinimizable() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::SetMaximizable(bool maximizable) {
|
void NativeWindowMac::SetMaximizable(bool maximizable) {
|
||||||
|
maximizable_ = maximizable;
|
||||||
[[window_ standardWindowButton:NSWindowZoomButton] setEnabled:maximizable];
|
[[window_ standardWindowButton:NSWindowZoomButton] setEnabled:maximizable];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1009,8 +1013,7 @@ void NativeWindowMac::SetWindowLevel(int unbounded_level) {
|
||||||
|
|
||||||
// Set level will make the zoom button revert to default, probably
|
// Set level will make the zoom button revert to default, probably
|
||||||
// a bug of Cocoa or macOS.
|
// a bug of Cocoa or macOS.
|
||||||
[[window_ standardWindowButton:NSWindowZoomButton]
|
SetMaximizable(was_maximizable_);
|
||||||
setEnabled:was_maximizable_];
|
|
||||||
|
|
||||||
// This must be notified at the very end or IsAlwaysOnTop
|
// This must be notified at the very end or IsAlwaysOnTop
|
||||||
// will not yet have been updated to reflect the new status
|
// will not yet have been updated to reflect the new status
|
||||||
|
@ -1034,7 +1037,7 @@ void NativeWindowMac::Invalidate() {
|
||||||
void NativeWindowMac::SetTitle(const std::string& title) {
|
void NativeWindowMac::SetTitle(const std::string& title) {
|
||||||
[window_ setTitle:base::SysUTF8ToNSString(title)];
|
[window_ setTitle:base::SysUTF8ToNSString(title)];
|
||||||
if (title_bar_style_ == TitleBarStyle::HIDDEN) {
|
if (title_bar_style_ == TitleBarStyle::HIDDEN) {
|
||||||
RepositionTrafficLights();
|
RedrawTrafficLights();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1554,7 +1557,7 @@ void NativeWindowMac::SetVibrancy(const std::string& type) {
|
||||||
|
|
||||||
void NativeWindowMac::SetTrafficLightPosition(const gfx::Point& position) {
|
void NativeWindowMac::SetTrafficLightPosition(const gfx::Point& position) {
|
||||||
traffic_light_position_ = position;
|
traffic_light_position_ = position;
|
||||||
RepositionTrafficLights();
|
RedrawTrafficLights();
|
||||||
}
|
}
|
||||||
|
|
||||||
gfx::Point NativeWindowMac::GetTrafficLightPosition() const {
|
gfx::Point NativeWindowMac::GetTrafficLightPosition() const {
|
||||||
|
@ -1683,7 +1686,7 @@ void NativeWindowMac::AddContentViewLayers(bool minimizable, bool closable) {
|
||||||
// Some third-party macOS utilities check the zoom button's enabled state to
|
// Some third-party macOS utilities check the zoom button's enabled state to
|
||||||
// determine whether to show custom UI on hover, so we disable it here to
|
// determine whether to show custom UI on hover, so we disable it here to
|
||||||
// prevent them from doing so in a frameless app window.
|
// prevent them from doing so in a frameless app window.
|
||||||
[[window_ standardWindowButton:NSWindowZoomButton] setEnabled:NO];
|
SetMaximizable(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1722,7 +1725,7 @@ void NativeWindowMac::OverrideNSWindowContentView() {
|
||||||
// content view with a simple NSView.
|
// content view with a simple NSView.
|
||||||
if (has_frame()) {
|
if (has_frame()) {
|
||||||
container_view_.reset(
|
container_view_.reset(
|
||||||
[[ElectronAdapatedContentView alloc] initWithShell:this]);
|
[[ElectronAdaptedContentView alloc] initWithShell:this]);
|
||||||
} else {
|
} else {
|
||||||
container_view_.reset([[FullSizeContentView alloc] init]);
|
container_view_.reset([[FullSizeContentView alloc] init]);
|
||||||
[container_view_ setFrame:[[[window_ contentView] superview] bounds]];
|
[container_view_ setFrame:[[[window_ contentView] superview] bounds]];
|
||||||
|
|
|
@ -137,7 +137,7 @@ using TitleBarStyle = electron::NativeWindowMac::TitleBarStyle;
|
||||||
[super windowDidResize:notification];
|
[super windowDidResize:notification];
|
||||||
shell_->NotifyWindowResize();
|
shell_->NotifyWindowResize();
|
||||||
if (shell_->title_bar_style() == TitleBarStyle::HIDDEN) {
|
if (shell_->title_bar_style() == TitleBarStyle::HIDDEN) {
|
||||||
shell_->RepositionTrafficLights();
|
shell_->RedrawTrafficLights();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,7 +254,7 @@ using TitleBarStyle = electron::NativeWindowMac::TitleBarStyle;
|
||||||
}
|
}
|
||||||
shell_->SetExitingFullScreen(true);
|
shell_->SetExitingFullScreen(true);
|
||||||
if (shell_->title_bar_style() == TitleBarStyle::HIDDEN) {
|
if (shell_->title_bar_style() == TitleBarStyle::HIDDEN) {
|
||||||
shell_->RepositionTrafficLights();
|
shell_->RedrawTrafficLights();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,7 +263,7 @@ using TitleBarStyle = electron::NativeWindowMac::TitleBarStyle;
|
||||||
shell_->NotifyWindowLeaveFullScreen();
|
shell_->NotifyWindowLeaveFullScreen();
|
||||||
shell_->SetExitingFullScreen(false);
|
shell_->SetExitingFullScreen(false);
|
||||||
if (shell_->title_bar_style() == TitleBarStyle::HIDDEN) {
|
if (shell_->title_bar_style() == TitleBarStyle::HIDDEN) {
|
||||||
shell_->RepositionTrafficLights();
|
shell_->RedrawTrafficLights();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue