override SetAspectRatio for NativeWindowMac
This commit is contained in:
parent
8f7a04f9c3
commit
7aaf974362
3 changed files with 24 additions and 3 deletions
|
@ -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<NativeWindow> GetWeakPtr() {
|
||||
return weak_factory_.GetWeakPtr();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue