From ceb2864881db905bacb82d5e1210f01196dbd78f Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Thu, 7 Jul 2016 20:55:10 +1200 Subject: [PATCH] Move size bounding logic to SetBounds --- atom/browser/native_window_mac.h | 1 - atom/browser/native_window_mac.mm | 25 +++++++++++-------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index f357663fd1e5..d07d586a8439 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -46,7 +46,6 @@ class NativeWindowMac : public NativeWindow { bool IsFullscreen() const override; void SetBounds(const gfx::Rect& bounds, bool animate = false) override; gfx::Rect GetBounds() override; - void SetSize(const gfx::Size& size, bool animate = false) override; void SetContentSizeConstraints( const extensions::SizeConstraints& size_constraints) override; void SetResizable(bool resizable) override; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 58836c4ea4e3..b398e04ac0c6 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -737,13 +737,21 @@ bool NativeWindowMac::IsFullscreen() const { } void NativeWindowMac::SetBounds(const gfx::Rect& bounds, bool animate) { + gfx::Size bSize = gfx::Size(bounds.width(), bounds.height()); + bSize.SetToMax(GetMinimumSize()); + + gfx::Size maxSize = GetMaximumSize(); + maxSize = gfx::Size(maxSize.width() == 0 ? bSize.width() : maxSize.width(), + maxSize.height() == 0 ? bSize.height() : maxSize.height()); + bSize.SetToMin(maxSize); + NSRect cocoa_bounds = NSMakeRect(bounds.x(), 0, - bounds.width(), - bounds.height()); + bSize.width(), + bSize.height()); // Flip coordinates based on the primary screen. NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; cocoa_bounds.origin.y = - NSHeight([screen frame]) - bounds.height() - bounds.y(); + NSHeight([screen frame]) - bSize.height() - bounds.y(); [window_ setFrame:cocoa_bounds display:YES animate:animate]; } @@ -756,17 +764,6 @@ gfx::Rect NativeWindowMac::GetBounds() { return bounds; } -void NativeWindowMac::SetSize(const gfx::Size& size, bool animate) { - gfx::Size minSize = GetMinimumSize(); - gfx::Size maxSize = GetMaximumSize(); - // Bound the supplied width and height values with max and min sizes - int bWidth = fmax(minSize.width(), size.width()); - bWidth = maxSize.width() == 0 ? bWidth : fmin(maxSize.width(), bWidth); - int bHeight = fmax(minSize.height(), size.height()); - bHeight = maxSize.height() == 0 ? bHeight : fmin(maxSize.height(), bHeight); - SetBounds(gfx::Rect(GetPosition(), gfx::Size(bWidth, bHeight)), animate); -} - void NativeWindowMac::SetContentSizeConstraints( const extensions::SizeConstraints& size_constraints) { auto convertSize = [this](const gfx::Size& size) {