Bug 1447292: Handle constraining non popup windows properly in cocoa. r?mstange
MozReview-Commit-ID: LmbKi4YR3d3
--- a/widget/cocoa/nsCocoaWindow.mm
+++ b/widget/cocoa/nsCocoaWindow.mm
@@ -1253,16 +1253,42 @@ void nsCocoaWindow::SetSizeConstraints(c
FLT_MAX : nsCocoaUtils::DevPixelsToCocoaPoints(c.mMaxSize.width, scaleFactor),
c.mMaxSize.height == NS_MAXSIZE ?
FLT_MAX : nsCocoaUtils::DevPixelsToCocoaPoints(c.mMaxSize.height, scaleFactor)
};
[mWindow setMaxSize:maxSize];
nsBaseWidget::SetSizeConstraints(c);
+ // Popups are constrained during layout, and we don't want to synchronously
+ // paint from reflow, so bail out... This is not great, but it's no worse than
+ // what we used to do.
+ //
+ // The right fix here is probably making constraint changes go through the
+ // view manager and such.
+ if (mWindowType == eWindowType_popup) {
+ return;
+ }
+
+ // Otherwise figure out if we need to actually apply the constraints.
+ NSRect frame = [mWindow frame];
+ NSRect clampedFrame = frame;
+ clampedFrame.size.height =
+ std::max(minSize.height, std::min(maxSize.height, frame.size.height));
+ clampedFrame.size.width =
+ std::max(minSize.width, std::min(maxSize.width, frame.size.width));
+
+ if (clampedFrame.size.width != frame.size.width ||
+ clampedFrame.size.height != frame.size.height) {
+ // The origin in the cocoa coordinate space is in the bottom left, so we
+ // need to do some math to avoid changing the origin Gecko cares about.
+ clampedFrame.origin.y += frame.size.height - clampedFrame.size.height;
+ [mWindow setFrame:clampedFrame display:YES];
+ }
+
NS_OBJC_END_TRY_ABORT_BLOCK;
}
// Coordinates are desktop pixels
void
nsCocoaWindow::Move(double aX, double aY)
{
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;