Bug 972703 - Clamp massive transformed overflow areas to the middle of the representable range instead of the start. r=roc

This commit is contained in:
Matt Woodrow 2014-02-17 11:25:36 +13:00
parent f815da0685
commit 4b5fa21eca

View File

@ -1639,7 +1639,7 @@ nsLayoutUtils::ChangeMatrixBasis(const gfxPoint3D &aOrigin,
* *
* @param aVal The value to constrain (in/out) * @param aVal The value to constrain (in/out)
*/ */
static void ConstrainToCoordValues(gfxFloat &aVal) static void ConstrainToCoordValues(gfxFloat& aVal)
{ {
if (aVal <= nscoord_MIN) if (aVal <= nscoord_MIN)
aVal = nscoord_MIN; aVal = nscoord_MIN;
@ -1647,6 +1647,27 @@ static void ConstrainToCoordValues(gfxFloat &aVal)
aVal = nscoord_MAX; aVal = nscoord_MAX;
} }
static void ConstrainToCoordValues(gfxFloat& aStart, gfxFloat& aSize)
{
MOZ_ASSERT(aSize >= 0);
gfxFloat max = aStart + aSize;
// Clamp the end points to within nscoord range
ConstrainToCoordValues(aStart);
ConstrainToCoordValues(max);
aSize = max - aStart;
// If the width if still greater than the max nscoord, then bring both
// endpoints in by the same amount until it fits.
if (aSize > nscoord_MAX) {
gfxFloat excess = aSize - nscoord_MAX;
excess /= 2;
aStart += excess;
aSize = nscoord_MAX;
}
}
nsRect nsRect
nsLayoutUtils::RoundGfxRectToAppRect(const gfxRect &aRect, float aFactor) nsLayoutUtils::RoundGfxRectToAppRect(const gfxRect &aRect, float aFactor)
{ {
@ -1655,10 +1676,8 @@ nsLayoutUtils::RoundGfxRectToAppRect(const gfxRect &aRect, float aFactor)
scaledRect.ScaleRoundOut(aFactor); scaledRect.ScaleRoundOut(aFactor);
/* We now need to constrain our results to the max and min values for coords. */ /* We now need to constrain our results to the max and min values for coords. */
ConstrainToCoordValues(scaledRect.x); ConstrainToCoordValues(scaledRect.x, scaledRect.width);
ConstrainToCoordValues(scaledRect.y); ConstrainToCoordValues(scaledRect.y, scaledRect.height);
ConstrainToCoordValues(scaledRect.width);
ConstrainToCoordValues(scaledRect.height);
/* Now typecast everything back. This is guaranteed to be safe. */ /* Now typecast everything back. This is guaranteed to be safe. */
return nsRect(nscoord(scaledRect.X()), nscoord(scaledRect.Y()), return nsRect(nscoord(scaledRect.X()), nscoord(scaledRect.Y()),