Skip to content
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

fix: disabling and enabling resizability on macOS #31013

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions shell/browser/native_window_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class NativeWindowMac : public NativeWindow,
protected:
// views::WidgetDelegate:
views::View* GetContentsView() override;
bool CanMaximize() const override;

// ui::NativeThemeObserver:
void OnNativeThemeUpdated(ui::NativeTheme* observed_theme) override;
Expand Down
12 changes: 8 additions & 4 deletions shell/browser/native_window_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1714,31 +1714,35 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
// we explicitly disable resizing while setting it.
ScopedDisableResize disable_resize;

bool was_maximizable = IsMaximizable();
if (on)
[window_ setStyleMask:[window_ styleMask] | flag];
else
[window_ setStyleMask:[window_ styleMask] & (~flag)];

// Change style mask will make the zoom button revert to default, probably
// a bug of Cocoa or macOS.
SetMaximizable(was_maximizable);
SetMaximizable(maximizable_);
}

void NativeWindowMac::SetCollectionBehavior(bool on, NSUInteger flag) {
bool was_maximizable = IsMaximizable();
if (on)
[window_ setCollectionBehavior:[window_ collectionBehavior] | flag];
else
[window_ setCollectionBehavior:[window_ collectionBehavior] & (~flag)];

// Change collectionBehavior will make the zoom button revert to default,
// probably a bug of Cocoa or macOS.
SetMaximizable(was_maximizable);
SetMaximizable(maximizable_);
}

views::View* NativeWindowMac::GetContentsView() {
return root_view_.get();
}

bool NativeWindowMac::CanMaximize() const {
return maximizable_;
}

void NativeWindowMac::OnNativeThemeUpdated(ui::NativeTheme* observed_theme) {
base::PostTask(
FROM_HERE, {content::BrowserThread::UI},
Expand Down
12 changes: 12 additions & 0 deletions spec-main/api-browser-window-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3682,6 +3682,18 @@ describe('BrowserWindow module', () => {
}
});

// On Linux there is no "resizable" property of a window.
ifit(process.platform !== 'linux')('does affect maximizability when disabled and enabled', () => {
const w = new BrowserWindow({ show: false });
expect(w.resizable).to.be.true('resizable');

expect(w.maximizable).to.be.true('maximizable');
w.resizable = false;
expect(w.maximizable).to.be.false('not maximizable');
w.resizable = true;
expect(w.maximizable).to.be.true('maximizable');
});

ifit(process.platform === 'win32')('works for a window smaller than 64x64', () => {
const w = new BrowserWindow({
show: false,
Expand Down