From 7aaf97436218fb93988e658d83dd6394bfad52ab Mon Sep 17 00:00:00 2001 From: leethomas Date: Sun, 22 May 2016 16:50:50 -0700 Subject: [PATCH] override SetAspectRatio for NativeWindowMac --- atom/browser/native_window.h | 2 +- atom/browser/native_window_mac.h | 2 ++ atom/browser/native_window_mac.mm | 23 +++++++++++++++++++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 7317a7ba6f76..8776e3d00652 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -190,7 +190,7 @@ class NativeWindow : public base::SupportsUserData, // Set the aspect ratio when resizing window. double GetAspectRatio(); gfx::Size GetAspectRatioExtraSize(); - void SetAspectRatio(double aspect_ratio, const gfx::Size& extra_size); + virtual void SetAspectRatio(double aspect_ratio, const gfx::Size& extra_size); base::WeakPtr GetWeakPtr() { return weak_factory_.GetWeakPtr(); diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index cfb3141ede66..c1694c3c784a 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -49,6 +49,8 @@ class NativeWindowMac : public NativeWindow { void SetResizable(bool resizable) override; bool IsResizable() override; void SetMovable(bool movable) override; + void SetAspectRatio(double aspect_ratio, const gfx::Size& extra_size) + override; bool IsMovable() override; void SetMinimizable(bool minimizable) override; bool IsMinimizable() override; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 434919dde117..f7cd4d42281e 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -144,8 +144,6 @@ bool ScopedDisableResize::disable_resize_ = false; newSize.height = roundf((newSize.width - extraWidthPlusFrame) / aspectRatio + extraHeightPlusFrame); - - [sender setAspectRatio:NSMakeSize(newSize.width, newSize.height)]; } return newSize; @@ -708,6 +706,27 @@ bool NativeWindowMac::IsResizable() { return [window_ styleMask] & NSResizableWindowMask; } +void NativeWindowMac::SetAspectRatio(double aspect_ratio, + const gfx::Size& extra_size) { + + gfx::Size windowSize = this->GetSize(); + gfx::Size contentSize = this->GetContentSize(); + + double extraWidthPlusFrame = + windowSize.width() - contentSize.width() + extra_size.width(); + double extraHeightPlusFrame = + windowSize.height() - contentSize.height() + extra_size.height(); + + double width = + roundf(([window_ frame].size.height - extraHeightPlusFrame) * + aspect_ratio + extraWidthPlusFrame); + double height = + roundf((width - extraWidthPlusFrame) / + aspect_ratio + extraHeightPlusFrame); + + [window_ setAspectRatio:NSMakeSize(width, height)]; +} + void NativeWindowMac::SetMovable(bool movable) { [window_ setMovable:movable]; }