Bug 725897 - Remove the inaccurate nsSVGUtils::ToAppPixelRect, and use nsLayoutUtils::RoundGfxRectToAppRect instead. r=longsonr.

This commit is contained in:
Jonathan Watt 2012-02-10 12:33:18 +00:00
parent 166055b759
commit 989bcc0208
7 changed files with 30 additions and 64 deletions

View File

@ -35,11 +35,9 @@ Rect.prototype.roundOut = function()
this.top = Math.floor(this.top);
}
var delta = 1;
function isApproximately(a, b, message)
function isWithAbsTolerance(a, b, tolerance, message)
{
ok(delta >= Math.abs(a - b), message + " - got " + a + ", expected " + b + " ± " + delta);
ok(tolerance >= Math.abs(a - b), message + " - got " + a + ", expected " + b + " ± " + tolerance);
}
function runTest()
@ -54,7 +52,7 @@ function runTest()
var sin45 = Math.sin(Math.PI / 4);
isApproximately(text1Bounds.left, 24, "text1.getBoundingClientRect().left");
isWithAbsTolerance(text1Bounds.left, 24, 1, "text1.getBoundingClientRect().left");
is(text2Bounds.left, text1Bounds.left + 100, "text2.getBoundingClientRect().left");
is(text2Bounds.top, text1Bounds.top, "text2.getBoundingClientRect().top");
@ -62,8 +60,8 @@ function runTest()
is(text2Bounds.height, text1Bounds.height, "text2.getBoundingClientRect().height");
var r = (text1Bounds.width + text1Bounds.height) * sin45;
isApproximately(text3Bounds.width, Math.ceil(r), "text3.getBoundingClientRect().width");
isApproximately(text3Bounds.height, Math.ceil(r), "text3.getBoundingClientRect().height");
isWithAbsTolerance(text3Bounds.width, Math.ceil(r), 1, "text3.getBoundingClientRect().width");
isWithAbsTolerance(text3Bounds.height, Math.ceil(r), 1, "text3.getBoundingClientRect().height");
var rect1Bounds = doc.getElementById("rect1").getBoundingClientRect();
var rect2Bounds = doc.getElementById("rect2").getBoundingClientRect();
@ -76,11 +74,10 @@ function runTest()
is(rect1Bounds.height, 50, "rect1.getBoundingClientRect().height");
rect = new Rect(175 - 50 * sin45, 75 - 50 * sin45, 50 * sin45 * 2, 50 * sin45 * 2);
rect.roundOut();
is(rect2Bounds.left, rect.left, "rect2.getBoundingClientRect().left");
is(rect2Bounds.top, rect.top, "rect2.getBoundingClientRect().top");
is(rect2Bounds.width, rect.width, "rect2.getBoundingClientRect().width");
is(rect2Bounds.height, rect.height, "rect2.getBoundingClientRect().height");
isWithAbsTolerance(rect2Bounds.left, rect.left, 0.1, "rect2.getBoundingClientRect().left");
isWithAbsTolerance(rect2Bounds.top, rect.top, 0.1, "rect2.getBoundingClientRect().top");
isWithAbsTolerance(rect2Bounds.width, rect.width, 0.1, "rect2.getBoundingClientRect().width");
isWithAbsTolerance(rect2Bounds.height, rect.height, 0.1, "rect2.getBoundingClientRect().height");
is(rect3Bounds.left, 50, "rect3.getBoundingClientRect().left");
is(rect3Bounds.top, 160, "rect3.getBoundingClientRect().top");
@ -88,11 +85,10 @@ function runTest()
is(rect3Bounds.height, 100, "rect3.getBoundingClientRect().height");
rect = new Rect(350 - 100 * sin45, 150 - 100 * sin45, 100 * sin45 * 2, 100 * sin45 * 2);
rect.roundOut();
is(rect4Bounds.left, rect.left, "rect4.getBoundingClientRect().left");
is(rect4Bounds.top, rect.top, "rect4.getBoundingClientRect().top");
is(rect4Bounds.width, rect.width, "rect4.getBoundingClientRect().width");
is(rect4Bounds.height, rect.height, "rect4.getBoundingClientRect().height");
isWithAbsTolerance(rect4Bounds.left, rect.left, 0.1, "rect4.getBoundingClientRect().left");
isWithAbsTolerance(rect4Bounds.top, rect.top, 0.1, "rect4.getBoundingClientRect().top");
isWithAbsTolerance(rect4Bounds.width, rect.width, 0.1, "rect4.getBoundingClientRect().width");
isWithAbsTolerance(rect4Bounds.height, rect.height, 0.1, "rect4.getBoundingClientRect().height");
var rect1aBounds = doc.getElementById("rect1a").getBoundingClientRect();
var rect2aBounds = doc.getElementById("rect2a").getBoundingClientRect();
@ -105,11 +101,10 @@ function runTest()
is(rect1aBounds.height, 54, "rect1a.getBoundingClientRect().height");
rect = new Rect(175 - 54 * sin45, 75 - 54 * sin45, 54 * sin45 * 2, 54 * sin45 * 2);
rect.roundOut();
is(rect2aBounds.left, rect.left, "rect2a.getBoundingClientRect().left");
is(rect2aBounds.top, rect.top, "rect2a.getBoundingClientRect().top");
is(rect2aBounds.width, rect.width, "rect2a.getBoundingClientRect().width");
is(rect2aBounds.height, rect.height, "rect2a.getBoundingClientRect().height");
isWithAbsTolerance(rect2aBounds.left, rect.left, 0.1, "rect2a.getBoundingClientRect().left");
isWithAbsTolerance(rect2aBounds.top, rect.top, 0.1, "rect2a.getBoundingClientRect().top");
isWithAbsTolerance(rect2aBounds.width, rect.width, 0.1, "rect2a.getBoundingClientRect().width");
isWithAbsTolerance(rect2aBounds.height, rect.height, 0.1, "rect2a.getBoundingClientRect().height");
is(rect3aBounds.left, 46, "rect3a.getBoundingClientRect().left");
is(rect3aBounds.top, 156, "rect3a.getBoundingClientRect().top");
@ -117,18 +112,17 @@ function runTest()
is(rect3aBounds.height, 108, "rect3a.getBoundingClientRect().height");
rect = new Rect(350 - 108 * sin45, 150 - 108 * sin45, 108 * sin45 * 2, 108 * sin45 * 2);
rect.roundOut();
is(rect4aBounds.left, rect.left, "rect4a.getBoundingClientRect().left");
is(rect4aBounds.top, rect.top, "rect4a.getBoundingClientRect().top");
is(rect4aBounds.width, rect.width, "rect4a.getBoundingClientRect().width");
is(rect4aBounds.height, rect.height, "rect4a.getBoundingClientRect().height");
isWithAbsTolerance(rect4aBounds.left, rect.left, 0.1, "rect4a.getBoundingClientRect().left");
isWithAbsTolerance(rect4aBounds.top, rect.top, 0.1, "rect4a.getBoundingClientRect().top");
isWithAbsTolerance(rect4aBounds.width, rect.width, 0.1, "rect4a.getBoundingClientRect().width");
isWithAbsTolerance(rect4aBounds.height, rect.height, 0.1, "rect4a.getBoundingClientRect().height");
var text1a = doc.getElementById("text1a");
var text1aBounds = text1a.getBoundingClientRect();
var text2aBounds = doc.getElementById("text2a").getBoundingClientRect();
isApproximately(text1aBounds.left, 82, "text1a.getBoundingClientRect().left");
isWithAbsTolerance(text1aBounds.left, 82, 1, "text1a.getBoundingClientRect().left");
is(text1aBounds.width, text1Bounds.width + 4, "text1a.getBoundingClientRect().width");
is(text2aBounds.left, text1aBounds.left + 100 - 3, "text2a.getBoundingClientRect().left");

View File

@ -264,13 +264,9 @@ nsSVGForeignObjectFrame::PaintSVG(nsSVGRenderState *aContext,
aDirtyRect->width, aDirtyRect->height);
transDirtyRect = invmatrix.TransformBounds(transDirtyRect);
transDirtyRect.Scale(nsPresContext::AppUnitsPerCSSPixel());
nsPoint tl(NSToCoordFloor(transDirtyRect.X()),
NSToCoordFloor(transDirtyRect.Y()));
nsPoint br(NSToCoordCeil(transDirtyRect.XMost()),
NSToCoordCeil(transDirtyRect.YMost()));
kidDirtyRect.IntersectRect(kidDirtyRect,
nsRect(tl.x, tl.y, br.x - tl.x, br.y - tl.y));
nsLayoutUtils::RoundGfxRectToAppRect(transDirtyRect,
PresContext()->AppUnitsPerCSSPixel()));
}
PRUint32 flags = nsLayoutUtils::PAINT_IN_TRANSFORM;

View File

@ -491,7 +491,8 @@ nsSVGGlyphFrame::UpdateCoveredRegion()
}
if (!extent.IsEmpty()) {
mRect = nsSVGUtils::ToAppPixelRect(PresContext(), extent);
mRect = nsLayoutUtils::RoundGfxRectToAppRect(extent,
PresContext()->AppUnitsPerDevPixel());
}
return NS_OK;

View File

@ -489,7 +489,8 @@ nsSVGImageFrame::UpdateCoveredRegion()
gfxRect extent = context.GetUserPathExtent();
if (!extent.IsEmpty()) {
mRect = nsSVGUtils::ToAppPixelRect(PresContext(), extent);
mRect = nsLayoutUtils::RoundGfxRectToAppRect(extent,
PresContext()->AppUnitsPerDevPixel());
}
return NS_OK;

View File

@ -206,7 +206,8 @@ nsSVGPathGeometryFrame::UpdateCoveredRegion()
nsSVGUtils::eBBoxIncludeFill | nsSVGUtils::eBBoxIgnoreFillIfNone |
nsSVGUtils::eBBoxIncludeStroke | nsSVGUtils::eBBoxIgnoreStrokeIfNone |
nsSVGUtils::eBBoxIncludeMarkers);
mRect = nsSVGUtils::ToAppPixelRect(PresContext(), extent);
mRect = nsLayoutUtils::RoundGfxRectToAppRect(extent,
PresContext()->AppUnitsPerDevPixel());
return NS_OK;
}

View File

@ -1178,24 +1178,6 @@ nsSVGUtils::GetCoveredRegion(const nsFrameList &aFrames)
return rect;
}
nsRect
nsSVGUtils::ToAppPixelRect(nsPresContext *aPresContext,
double xmin, double ymin,
double xmax, double ymax)
{
return ToAppPixelRect(aPresContext,
gfxRect(xmin, ymin, xmax - xmin, ymax - ymin));
}
nsRect
nsSVGUtils::ToAppPixelRect(nsPresContext *aPresContext, const gfxRect& rect)
{
return nsRect(aPresContext->DevPixelsToAppUnits(NSToIntFloor(rect.X())),
aPresContext->DevPixelsToAppUnits(NSToIntFloor(rect.Y())),
aPresContext->DevPixelsToAppUnits(NSToIntCeil(rect.XMost()) - NSToIntFloor(rect.X())),
aPresContext->DevPixelsToAppUnits(NSToIntCeil(rect.YMost()) - NSToIntFloor(rect.Y())));
}
gfxIntSize
nsSVGUtils::ConvertToSurfaceSize(const gfxSize& aSize,
bool *aResultOverflows)

View File

@ -447,15 +447,6 @@ public:
static nsRect
GetCoveredRegion(const nsFrameList &aFrames);
/*
* Convert a rect from device pixel units to app pixel units by inflation.
*/
static nsRect
ToAppPixelRect(nsPresContext *aPresContext,
double xmin, double ymin, double xmax, double ymax);
static nsRect
ToAppPixelRect(nsPresContext *aPresContext, const gfxRect& rect);
/*
* Convert a surface size to an integer for use by thebes
* possibly making it smaller in the process so the surface does not