Bug 400813. Prevent nsRect::Deflate from creating negative-sized rectangles. r+sr=mats

This commit is contained in:
roc+%cs.cmu.edu 2008-01-21 01:36:12 +00:00
Родитель 6539671b66
Коммит 65fe0173b1
1 изменённых файлов: 20 добавлений и 33 удалений

Просмотреть файл

@ -39,19 +39,6 @@
#include "nsString.h"
#include "nsIDeviceContext.h"
#ifdef MIN
#undef MIN
#endif
#ifdef MAX
#undef MAX
#endif
#define MIN(a,b)\
((a) < (b) ? (a) : (b))
#define MAX(a,b)\
((a) > (b) ? (a) : (b))
// Containment
PRBool nsRect::Contains(nscoord aX, nscoord aY) const
{
@ -85,11 +72,11 @@ PRBool nsRect::IntersectRect(const nsRect &aRect1, const nsRect &aRect2)
nscoord ymost2 = aRect2.YMost();
nscoord temp;
x = MAX(aRect1.x, aRect2.x);
y = MAX(aRect1.y, aRect2.y);
x = PR_MAX(aRect1.x, aRect2.x);
y = PR_MAX(aRect1.y, aRect2.y);
// Compute the destination width
temp = MIN(xmost1, xmost2);
temp = PR_MIN(xmost1, xmost2);
if (temp <= x) {
Empty();
return PR_FALSE;
@ -97,7 +84,7 @@ PRBool nsRect::IntersectRect(const nsRect &aRect1, const nsRect &aRect2)
width = temp - x;
// Compute the destination height
temp = MIN(ymost1, ymost2);
temp = PR_MIN(ymost1, ymost2);
if (temp <= y) {
Empty();
return PR_FALSE;
@ -134,12 +121,12 @@ PRBool nsRect::UnionRect(const nsRect &aRect1, const nsRect &aRect2)
nscoord ymost2 = aRect2.YMost();
// Compute the origin
x = MIN(aRect1.x, aRect2.x);
y = MIN(aRect1.y, aRect2.y);
x = PR_MIN(aRect1.x, aRect2.x);
y = PR_MIN(aRect1.y, aRect2.y);
// Compute the size
width = MAX(xmost1, xmost2) - x;
height = MAX(ymost1, ymost2) - y;
width = PR_MAX(xmost1, xmost2) - x;
height = PR_MAX(ymost1, ymost2) - y;
}
return result;
@ -168,8 +155,8 @@ void nsRect::Deflate(nscoord aDx, nscoord aDy)
{
x += aDx;
y += aDy;
width -= 2 * aDx;
height -= 2 * aDy;
width = PR_MAX(0, width - 2 * aDx);
height = PR_MAX(0, height - 2 * aDy);
}
// Deflate the rect by the specified margin
@ -177,8 +164,8 @@ void nsRect::Deflate(const nsMargin &aMargin)
{
x += aMargin.left;
y += aMargin.top;
width -= aMargin.left + aMargin.right;
height -= aMargin.top + aMargin.bottom;
width = PR_MAX(0, width - aMargin.LeftRight());
height = PR_MAX(0, height - aMargin.TopBottom());
}
// scale the rect but round to smallest containing rect
@ -252,11 +239,11 @@ PRBool nsIntRect::IntersectRect(const nsIntRect &aRect1, const nsIntRect &aRect2
PRInt32 ymost2 = aRect2.YMost();
PRInt32 temp;
x = MAX(aRect1.x, aRect2.x);
y = MAX(aRect1.y, aRect2.y);
x = PR_MAX(aRect1.x, aRect2.x);
y = PR_MAX(aRect1.y, aRect2.y);
// Compute the destination width
temp = MIN(xmost1, xmost2);
temp = PR_MIN(xmost1, xmost2);
if (temp <= x) {
Empty();
return PR_FALSE;
@ -264,7 +251,7 @@ PRBool nsIntRect::IntersectRect(const nsIntRect &aRect1, const nsIntRect &aRect2
width = temp - x;
// Compute the destination height
temp = MIN(ymost1, ymost2);
temp = PR_MIN(ymost1, ymost2);
if (temp <= y) {
Empty();
return PR_FALSE;
@ -301,12 +288,12 @@ PRBool nsIntRect::UnionRect(const nsIntRect &aRect1, const nsIntRect &aRect2)
PRInt32 ymost2 = aRect2.YMost();
// Compute the origin
x = MIN(aRect1.x, aRect2.x);
y = MIN(aRect1.y, aRect2.y);
x = PR_MIN(aRect1.x, aRect2.x);
y = PR_MIN(aRect1.y, aRect2.y);
// Compute the size
width = MAX(xmost1, xmost2) - x;
height = MAX(ymost1, ymost2) - y;
width = PR_MAX(xmost1, xmost2) - x;
height = PR_MAX(ymost1, ymost2) - y;
}
return result;