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 5c5e3de5e8
commit 0dd8a83d9d

View File

@ -1639,7 +1639,7 @@ nsLayoutUtils::ChangeMatrixBasis(const gfxPoint3D &aOrigin,
*
* @param aVal The value to constrain (in/out)
*/
static void ConstrainToCoordValues(gfxFloat &aVal)
static void ConstrainToCoordValues(gfxFloat& aVal)
{
if (aVal <= nscoord_MIN)
aVal = nscoord_MIN;
@ -1647,6 +1647,27 @@ static void ConstrainToCoordValues(gfxFloat &aVal)
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
nsLayoutUtils::RoundGfxRectToAppRect(const gfxRect &aRect, float aFactor)
{
@ -1655,10 +1676,8 @@ nsLayoutUtils::RoundGfxRectToAppRect(const gfxRect &aRect, float aFactor)
scaledRect.ScaleRoundOut(aFactor);
/* We now need to constrain our results to the max and min values for coords. */
ConstrainToCoordValues(scaledRect.x);
ConstrainToCoordValues(scaledRect.y);
ConstrainToCoordValues(scaledRect.width);
ConstrainToCoordValues(scaledRect.height);
ConstrainToCoordValues(scaledRect.x, scaledRect.width);
ConstrainToCoordValues(scaledRect.y, scaledRect.height);
/* Now typecast everything back. This is guaranteed to be safe. */
return nsRect(nscoord(scaledRect.X()), nscoord(scaledRect.Y()),