Bug 526394. Part 23: Make nsRect::IntersectRect preserve height and width if possible even when the intersection of two rectangles is empty. r=mats

This commit is contained in:
Robert O'Callahan 2010-01-12 10:45:16 +13:00
parent 11acff4c6e
commit ef60e5fbb0
3 changed files with 11 additions and 9 deletions

View File

@ -78,20 +78,20 @@ PRBool nsRect::IntersectRect(const nsRect &aRect1, const nsRect &aRect2)
// Compute the destination width
temp = PR_MIN(xmost1, xmost2);
if (temp <= x) {
Empty();
return PR_FALSE;
width = 0;
} else {
width = temp - x;
}
width = temp - x;
// Compute the destination height
temp = PR_MIN(ymost1, ymost2);
if (temp <= y) {
Empty();
return PR_FALSE;
height = 0;
} else {
height = temp - y;
}
height = temp - y;
return PR_TRUE;
return !IsEmpty();
}
// Computes the smallest rectangle that contains both aRect1 and aRect2 and

View File

@ -2021,7 +2021,9 @@ nsCSSRendering::PaintGradient(nsPresContext* aPresContext,
// up by drawing tiles into temporary surfaces and copying those to the
// destination, but after pixel-snapping tiles may not all be the same size.
nsRect dirty;
dirty.IntersectRect(aDirtyRect, aFillArea);
if (!dirty.IntersectRect(aDirtyRect, aFillArea))
return;
gfxRect areaToFill = RectToGfxRect(aFillArea, appUnitsPerPixel);
gfxMatrix ctm = ctx->CurrentMatrix();

View File

@ -1050,8 +1050,8 @@ nsMenuPopupFrame::SetPopupPosition(nsIFrame* aAnchorFrame)
// ensure that anchorRect is on screen
if (!anchorRect.IntersectRect(anchorRect, screenRect)) {
anchorRect.width = anchorRect.height = 0;
// if the anchor isn't within the screen, move it to the edge of the screen.
// IntersectRect will have set both the width and height of anchorRect to 0.
if (anchorRect.x < screenRect.x)
anchorRect.x = screenRect.x;
if (anchorRect.XMost() > screenRect.XMost())