fix: disabling and enabling resizability on macOS (#30999)
This commit is contained in:
parent
8d8fcd88f5
commit
6fdf350bea
3 changed files with 21 additions and 4 deletions
|
@ -191,6 +191,7 @@ class NativeWindowMac : public NativeWindow,
|
||||||
protected:
|
protected:
|
||||||
// views::WidgetDelegate:
|
// views::WidgetDelegate:
|
||||||
views::View* GetContentsView() override;
|
views::View* GetContentsView() override;
|
||||||
|
bool CanMaximize() const override;
|
||||||
|
|
||||||
// ui::NativeThemeObserver:
|
// ui::NativeThemeObserver:
|
||||||
void OnNativeThemeUpdated(ui::NativeTheme* observed_theme) override;
|
void OnNativeThemeUpdated(ui::NativeTheme* observed_theme) override;
|
||||||
|
|
|
@ -1715,31 +1715,35 @@ void NativeWindowMac::SetStyleMask(bool on, NSUInteger flag) {
|
||||||
// we explicitly disable resizing while setting it.
|
// we explicitly disable resizing while setting it.
|
||||||
ScopedDisableResize disable_resize;
|
ScopedDisableResize disable_resize;
|
||||||
|
|
||||||
bool was_maximizable = IsMaximizable();
|
|
||||||
if (on)
|
if (on)
|
||||||
[window_ setStyleMask:[window_ styleMask] | flag];
|
[window_ setStyleMask:[window_ styleMask] | flag];
|
||||||
else
|
else
|
||||||
[window_ setStyleMask:[window_ styleMask] & (~flag)];
|
[window_ setStyleMask:[window_ styleMask] & (~flag)];
|
||||||
|
|
||||||
// Change style mask will make the zoom button revert to default, probably
|
// Change style mask will make the zoom button revert to default, probably
|
||||||
// a bug of Cocoa or macOS.
|
// a bug of Cocoa or macOS.
|
||||||
SetMaximizable(was_maximizable);
|
SetMaximizable(maximizable_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::SetCollectionBehavior(bool on, NSUInteger flag) {
|
void NativeWindowMac::SetCollectionBehavior(bool on, NSUInteger flag) {
|
||||||
bool was_maximizable = IsMaximizable();
|
|
||||||
if (on)
|
if (on)
|
||||||
[window_ setCollectionBehavior:[window_ collectionBehavior] | flag];
|
[window_ setCollectionBehavior:[window_ collectionBehavior] | flag];
|
||||||
else
|
else
|
||||||
[window_ setCollectionBehavior:[window_ collectionBehavior] & (~flag)];
|
[window_ setCollectionBehavior:[window_ collectionBehavior] & (~flag)];
|
||||||
|
|
||||||
// Change collectionBehavior will make the zoom button revert to default,
|
// Change collectionBehavior will make the zoom button revert to default,
|
||||||
// probably a bug of Cocoa or macOS.
|
// probably a bug of Cocoa or macOS.
|
||||||
SetMaximizable(was_maximizable);
|
SetMaximizable(maximizable_);
|
||||||
}
|
}
|
||||||
|
|
||||||
views::View* NativeWindowMac::GetContentsView() {
|
views::View* NativeWindowMac::GetContentsView() {
|
||||||
return root_view_.get();
|
return root_view_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NativeWindowMac::CanMaximize() const {
|
||||||
|
return maximizable_;
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindowMac::OnNativeThemeUpdated(ui::NativeTheme* observed_theme) {
|
void NativeWindowMac::OnNativeThemeUpdated(ui::NativeTheme* observed_theme) {
|
||||||
base::PostTask(
|
base::PostTask(
|
||||||
FROM_HERE, {content::BrowserThread::UI},
|
FROM_HERE, {content::BrowserThread::UI},
|
||||||
|
|
|
@ -3669,6 +3669,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', () => {
|
ifit(process.platform === 'win32')('works for a window smaller than 64x64', () => {
|
||||||
const w = new BrowserWindow({
|
const w = new BrowserWindow({
|
||||||
show: false,
|
show: false,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue