Bound the target width and height of window when calling SetSize

This commit is contained in:
Samuel Attard 2016-07-07 00:13:14 +12:00
parent 92b97d3576
commit 6bd343b112
2 changed files with 12 additions and 0 deletions

View file

@ -46,6 +46,7 @@ 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;

View file

@ -756,6 +756,17 @@ 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) {