fix: apply size constraints to NSWindow (#39975)
This commit is contained in:
parent
e613595982
commit
ad57867594
3 changed files with 17 additions and 0 deletions
|
@ -354,10 +354,14 @@ void NativeWindow::SetContentSizeConstraints(
|
|||
size_constraints_.reset();
|
||||
}
|
||||
|
||||
// Windows/Linux:
|
||||
// The return value of GetContentSizeConstraints will be passed to Chromium
|
||||
// to set min/max sizes of window. Note that we are returning content size
|
||||
// instead of window size because that is what Chromium expects, see the
|
||||
// comment of |WidgetSizeIsClientSize| in Chromium's codebase to learn more.
|
||||
//
|
||||
// macOS:
|
||||
// The min/max sizes are set directly by calling NSWindow's methods.
|
||||
extensions::SizeConstraints NativeWindow::GetContentSizeConstraints() const {
|
||||
if (content_size_constraints_)
|
||||
return *content_size_constraints_;
|
||||
|
|
|
@ -58,6 +58,8 @@ class NativeWindowMac : public NativeWindow,
|
|||
gfx::Rect GetBounds() override;
|
||||
bool IsNormal() override;
|
||||
gfx::Rect GetNormalBounds() override;
|
||||
void SetSizeConstraints(
|
||||
const extensions::SizeConstraints& window_constraints) override;
|
||||
void SetContentSizeConstraints(
|
||||
const extensions::SizeConstraints& size_constraints) override;
|
||||
void SetResizable(bool resizable) override;
|
||||
|
|
|
@ -761,6 +761,16 @@ gfx::Rect NativeWindowMac::GetNormalBounds() {
|
|||
// return widget()->GetRestoredBounds();
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetSizeConstraints(
|
||||
const extensions::SizeConstraints& window_constraints) {
|
||||
// Apply the size constraints to NSWindow.
|
||||
if (window_constraints.HasMinimumSize())
|
||||
[window_ setMinSize:window_constraints.GetMinimumSize().ToCGSize()];
|
||||
if (window_constraints.HasMaximumSize())
|
||||
[window_ setMaxSize:window_constraints.GetMaximumSize().ToCGSize()];
|
||||
NativeWindow::SetSizeConstraints(window_constraints);
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetContentSizeConstraints(
|
||||
const extensions::SizeConstraints& size_constraints) {
|
||||
auto convertSize = [this](const gfx::Size& size) {
|
||||
|
@ -775,6 +785,7 @@ void NativeWindowMac::SetContentSizeConstraints(
|
|||
}
|
||||
};
|
||||
|
||||
// Apply the size constraints to NSWindow.
|
||||
NSView* content = [window_ contentView];
|
||||
if (size_constraints.HasMinimumSize()) {
|
||||
NSSize min_size = convertSize(size_constraints.GetMinimumSize());
|
||||
|
|
Loading…
Reference in a new issue