Bug 572317. Allow snapped rectangles to snap even if there's a 90 degree rotation. r=jrmuizel

This commit is contained in:
Robert O'Callahan 2010-06-28 12:29:57 +12:00
Родитель e41d32eebd
Коммит d179d068ce
4 изменённых файлов: 58 добавлений и 24 удалений

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

@ -220,11 +220,7 @@ gfxContext::Rectangle(const gfxRect& rect, PRBool snapToPixels)
if (snapToPixels) {
gfxRect snappedRect(rect);
#ifdef MOZ_GFX_OPTIMIZE_MOBILE
if (UserToDevicePixelSnapped(snappedRect, PR_TRUE))
#else
if (UserToDevicePixelSnapped(snappedRect))
#endif
{
cairo_matrix_t mat;
cairo_get_matrix(mCairo, &mat);
@ -402,32 +398,31 @@ gfxContext::UserToDevicePixelSnapped(gfxRect& rect, PRBool ignoreScale) const
// never snap.
cairo_matrix_t mat;
cairo_get_matrix(mCairo, &mat);
if ((!ignoreScale && (mat.xx != 1.0 || mat.yy != 1.0)) ||
(mat.xy != 0.0 || mat.yx != 0.0))
if (!ignoreScale &&
(mat.xx != 1.0 || mat.yy != 1.0 || mat.xy != 0.0 || mat.yx != 0.0))
return PR_FALSE;
gfxPoint p1 = UserToDevice(rect.pos);
gfxPoint p2 = UserToDevice(rect.pos + rect.size);
gfxPoint p2 = UserToDevice(rect.pos + gfxSize(rect.size.width, 0.0));
gfxPoint p3 = UserToDevice(rect.pos + rect.size);
gfxPoint p3 = UserToDevice(rect.pos + gfxSize(rect.size.width, 0.0));
gfxPoint p4 = UserToDevice(rect.pos + gfxSize(0.0, rect.size.height));
// Check that the rectangle is axis-aligned. For an axis-aligned rectangle,
// two opposite corners define the entire rectangle. So check if
// the axis-aligned rectangle with opposite corners p1 and p3
// define an axis-aligned rectangle whose other corners are p2 and p4.
// We actually only need to check one of p2 and p4, since an affine
// transform maps parallelograms to parallelograms.
if (p2 == gfxPoint(p1.x, p3.y) || p2 == gfxPoint(p3.x, p1.y)) {
p1.Round();
p3.Round();
// rectangle is no longer axis-aligned after transforming, so we can't snap
if (p1.x != p4.x ||
p2.x != p3.x ||
p1.y != p3.y ||
p2.y != p4.y)
return PR_FALSE;
rect.pos = gfxPoint(NS_MIN(p1.x, p3.x), NS_MIN(p1.y, p3.y));
rect.size = gfxSize(NS_MAX(p1.x, p3.x) - rect.pos.x,
NS_MAX(p1.y, p3.y) - rect.pos.y);
return PR_TRUE;
}
p1.Round();
p2.Round();
gfxPoint pd = p2 - p1;
rect.pos = p1;
rect.size = gfxSize(pd.x, pd.y);
return PR_TRUE;
return PR_FALSE;
}
PRBool

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

@ -72,6 +72,8 @@ random == rotate-1e.html rotate-1-ref.html
== origin-name-2c.html origin-name-2-ref.html
== origin-name-3a.html origin-name-3-ref.html
== origin-name-3b.html origin-name-3-ref.html
# Snapping still applies after 90 degree rotations.
== snapping-1.html snapping-1-ref.html
# SVG effects should work on transforms.
== transform-svg-1a.xhtml transform-svg-1-ref.xhtml
== transform-svg-2a.xhtml transform-svg-2-ref.xhtml

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

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html>
<head>
<style>
div {
background: red;
position: relative;
left: 0.5px;
top: 100px;
height: 100px;
width: 100px;
}
</style>
</head>
<body>
<div></div>
</body>
</html>

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

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<style>
div {
background: red;
margin-left: 100.5px;
height: 100px;
width: 100px;
-moz-transform-origin: bottom left;
-moz-transform: rotate(-90deg) translate(-100px, 0);
transform-origin: bottom left;
transform: rotate(-90deg) translate(-100px, 0);
}
</style>
</head>
<body>
<div></div>
</html>