override SetAspectRatio for NativeWindowMac

This commit is contained in:
leethomas 2016-05-22 16:50:50 -07:00
parent 8f7a04f9c3
commit 7aaf974362
3 changed files with 24 additions and 3 deletions

View file

@ -190,7 +190,7 @@ class NativeWindow : public base::SupportsUserData,
// Set the aspect ratio when resizing window. // Set the aspect ratio when resizing window.
double GetAspectRatio(); double GetAspectRatio();
gfx::Size GetAspectRatioExtraSize(); 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<NativeWindow> GetWeakPtr() { base::WeakPtr<NativeWindow> GetWeakPtr() {
return weak_factory_.GetWeakPtr(); return weak_factory_.GetWeakPtr();

View file

@ -49,6 +49,8 @@ class NativeWindowMac : public NativeWindow {
void SetResizable(bool resizable) override; void SetResizable(bool resizable) override;
bool IsResizable() override; bool IsResizable() override;
void SetMovable(bool movable) override; void SetMovable(bool movable) override;
void SetAspectRatio(double aspect_ratio, const gfx::Size& extra_size)
override;
bool IsMovable() override; bool IsMovable() override;
void SetMinimizable(bool minimizable) override; void SetMinimizable(bool minimizable) override;
bool IsMinimizable() override; bool IsMinimizable() override;

View file

@ -144,8 +144,6 @@ bool ScopedDisableResize::disable_resize_ = false;
newSize.height = newSize.height =
roundf((newSize.width - extraWidthPlusFrame) / aspectRatio + roundf((newSize.width - extraWidthPlusFrame) / aspectRatio +
extraHeightPlusFrame); extraHeightPlusFrame);
[sender setAspectRatio:NSMakeSize(newSize.width, newSize.height)];
} }
return newSize; return newSize;
@ -708,6 +706,27 @@ bool NativeWindowMac::IsResizable() {
return [window_ styleMask] & NSResizableWindowMask; 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) { void NativeWindowMac::SetMovable(bool movable) {
[window_ setMovable:movable]; [window_ setMovable:movable];
} }