Move size bounding logic to SetBounds

This commit is contained in:
Samuel Attard 2016-07-07 20:55:10 +12:00
parent 6bd343b112
commit ceb2864881
2 changed files with 11 additions and 15 deletions

View file

@ -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;

View file

@ -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) {