8000 fix: persist maximizable state through theme change by codebytere · Pull Request #22677 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: persist maximizable state through theme change #22677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion shell/browser/native_window_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class NativeWindowMac : public NativeWindow, public ui::NativeThemeObserver {
void SetWindowLevel(int level);

// Custom traffic light positioning
void RepositionTrafficLights();
void RedrawTrafficLights();
void SetExitingFullScreen(bool flag);
void SetTrafficLightPosition(const gfx::Point& position) override;
gfx::Point GetTrafficLightPosition() const override;
Expand Down Expand Up @@ -222,6 +222,9 @@ class NativeWindowMac : public NativeWindow, public ui::NativeThemeObserver {
// setWindowButtonVisibility().
base::Optional<bool> window_button_visibility_;

// Maximizable window state; necessary for persistence through redraws.
bool maximizable_ = true;

// Simple (pre-Lion) Fullscreen Settings
bool always_simple_fullscreen_ = false;
bool is_simple_fullscreen_ = false;
Expand Down
23 changes: 13 additions & 10 deletions shell/browser/native_window_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@
// This view would inform Chromium to resize the hosted views::View.
//
// The overrided methods should behave the same with BridgedContentView.
@interface ElectronAdapatedContentView : NSView {
@interface ElectronAdaptedContentView : NSView {
@private
views::NativeWidgetMacNSWindowHost* bridge_host_;
}
@end

@implementation ElectronAdapatedContentView
@implementation ElectronAdaptedContentView

- (id)initWithShell:(electron::NativeWindowMac*)shell {
if ((self = [self init])) {
Expand Down Expand Up @@ -519,7 +519,10 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
[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()) {
return;
}
Expand Down Expand Up @@ -708,7 +711,7 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {

void NativeWindowMac::OnNativeThemeUpdated(ui::NativeTheme* observed_theme) {
base::PostTask(FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(&NativeWindowMac::RepositionTrafficLights,
base::BindOnce(&NativeWindowMac::RedrawTrafficLights,
base::Unretained(this)));
}

Expand Down Expand Up @@ -930,6 +933,7 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
}

void NativeWindowMac::SetMaximizable(bool maximizable) {
maximizable_ = maximizable;
[[window_ standardWindowButton:NSWindowZoomButton] setEnabled:maximizable];
}

Expand Down Expand Up @@ -1009,8 +1013,7 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {

// Set level will make the zoom button revert to default, probably
// a bug of Cocoa or macOS.
[[window_ standardWindowButton:NSWindowZoomButton]
setEnabled:was_maximizable_];
SetMaximizable(was_maximizable_);

// This must be notified at the very end or IsAlwaysOnTop
// will not yet have been updated to reflect the new status
Expand All @@ -1034,7 +1037,7 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
void NativeWindowMac::SetTitle(const std::string& title) {
[window_ setTitle:base::SysUTF8ToNSString(title)];
if (title_bar_style_ == TitleBarStyle::HIDDEN) {
RepositionTrafficLights();
RedrawTrafficLights();
}
}

Expand Down Expand Up @@ -1554,7 +1557,7 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {

void NativeWindowMac::SetTrafficLightPosition(const gfx::Point& position) {
traffic_light_position_ = position;
RepositionTrafficLights();
RedrawTrafficLights();
}

gfx::Point NativeWindowMac::GetTrafficLightPosition() const {
Expand Down Expand Up @@ -1683,7 +1686,7 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
// 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
// prevent them from doing so in a frameless app window.
[[window_ standardWindowButton:NSWindowZoomButton] setEnabled:NO];
SetMaximizable(false);
}
}

Expand Down Expand Up @@ -1722,7 +1725,7 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
// content view with a simple NSView.
if (has_frame()) {
container_view_.reset(
[[ElectronAdapatedContentView alloc] initWithShell:this]);
[[ElectronAdaptedContentView alloc] initWithShell:this]);
} else {
container_view_.reset([[FullSizeContentView alloc] init]);
[container_view_ setFrame:[[[window_ contentView] superview] bounds]];
Expand Down
6 changes: 3 additions & 3 deletions shell/browser/ui/cocoa/electron_ns_window_delegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ - (void)windowDidResize:(NSNotification*)notification {
[super windowDidResize:notification];
shell_->NotifyWindowResize();
if (shell_->title_bar_style() == TitleBarStyle::HIDDEN) {
shell_->RepositionTrafficLights();
shell_->RedrawTrafficLights();
}
}

Expand Down Expand Up @@ -254,7 +254,7 @@ - (void)windowWillExitFullScreen:(NSNotification*)notification {
}
shell_->SetExitingFullScreen(true);
if (shell_->title_bar_style() == TitleBarStyle::HIDDEN) {
shell_->RepositionTrafficLights();
shell_->RedrawTrafficLights();
}
}

Expand All @@ -263,7 +263,7 @@ - (void)windowDidExitFullScreen:(NSNotification*)notification {
shell_->NotifyWindowLeaveFullScreen();
shell_->SetExitingFullScreen(false);
if (shell_->title_bar_style() == TitleBarStyle::HIDDEN) {
shell_->RepositionTrafficLights();
shell_->RedrawTrafficLights();
}
}

Expand Down
0