Cleanup the code of SetBounds

This commit is contained in:
Cheng Zhao 2016-07-07 20:02:18 +09:00
parent 43e9f30b21
commit d23c1bf917

View file

@ -737,21 +737,18 @@ bool NativeWindowMac::IsFullscreen() const {
} }
void NativeWindowMac::SetBounds(const gfx::Rect& bounds, bool animate) { void NativeWindowMac::SetBounds(const gfx::Rect& bounds, bool animate) {
gfx::Size bSize = gfx::Size(bounds.width(), bounds.height()); // Check size constraints since setFrame does not check it.
bSize.SetToMax(GetMinimumSize()); gfx::Size size = bounds.size();
size.SetToMax(GetMinimumSize());
gfx::Size max_size = GetMaximumSize();
if (!max_size.IsEmpty())
size.SetToMin(max_size);
gfx::Size maxSize = GetMaximumSize(); NSRect cocoa_bounds = NSMakeRect(bounds.x(), 0, size.width(), size.height());
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,
bSize.width(),
bSize.height());
// Flip coordinates based on the primary screen. // Flip coordinates based on the primary screen.
NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
cocoa_bounds.origin.y = cocoa_bounds.origin.y =
NSHeight([screen frame]) - bSize.height() - bounds.y(); NSHeight([screen frame]) - size.height() - bounds.y();
[window_ setFrame:cocoa_bounds display:YES animate:animate]; [window_ setFrame:cocoa_bounds display:YES animate:animate];
} }