From 62d1425e0b7d7333ed9907beb671a4cd1033b9c5 Mon Sep 17 00:00:00 2001 From: Matt Woodrow Date: Wed, 3 Aug 2011 15:04:23 +1200 Subject: [PATCH] Bug 505115 - Part 11b - Layout changes to use a z component for -moz-transform-origin. r=roc --- gfx/thebes/gfx3DMatrix.cpp | 11 +++++++++++ gfx/thebes/gfx3DMatrix.h | 1 + layout/base/nsDisplayList.cpp | 19 +++++++++++-------- layout/base/nsLayoutUtils.cpp | 10 ++++------ layout/base/nsLayoutUtils.h | 2 +- 5 files changed, 28 insertions(+), 15 deletions(-) diff --git a/gfx/thebes/gfx3DMatrix.cpp b/gfx/thebes/gfx3DMatrix.cpp index d03a7d2b522..710d94459ae 100644 --- a/gfx/thebes/gfx3DMatrix.cpp +++ b/gfx/thebes/gfx3DMatrix.cpp @@ -147,6 +147,17 @@ gfx3DMatrix::Translation(float aX, float aY, float aZ) return matrix; } +gfx3DMatrix +gfx3DMatrix::Translation(const gfxPoint3D& aPoint) +{ + gfx3DMatrix matrix; + + matrix._41 = aPoint.x; + matrix._42 = aPoint.y; + matrix._43 = aPoint.z; + return matrix; +} + gfx3DMatrix gfx3DMatrix::Scale(float aFactor) { diff --git a/gfx/thebes/gfx3DMatrix.h b/gfx/thebes/gfx3DMatrix.h index f1d594a5d7b..afb8b638c3a 100644 --- a/gfx/thebes/gfx3DMatrix.h +++ b/gfx/thebes/gfx3DMatrix.h @@ -153,6 +153,7 @@ public: * \param aZ Translation on Z-axis. */ static gfx3DMatrix Translation(float aX, float aY, float aZ); + static gfx3DMatrix Translation(const gfxPoint3D& aPoint); /** * Create a scale matrix. Scales uniformly along all axes. diff --git a/layout/base/nsDisplayList.cpp b/layout/base/nsDisplayList.cpp index 3cb51fdd3c6..151e59ce88c 100644 --- a/layout/base/nsDisplayList.cpp +++ b/layout/base/nsDisplayList.cpp @@ -2298,9 +2298,9 @@ nsDisplayTransform::GetFrameBoundsForTransform(const nsIFrame* aFrame) * to get from (0, 0) of the frame to the transform origin. */ static -gfxPoint GetDeltaToMozTransformOrigin(const nsIFrame* aFrame, - float aFactor, - const nsRect* aBoundsOverride) +gfxPoint3D GetDeltaToMozTransformOrigin(const nsIFrame* aFrame, + float aFactor, + const nsRect* aBoundsOverride) { NS_PRECONDITION(aFrame, "Can't get delta for a null frame!"); NS_PRECONDITION(aFrame->GetStyleDisplay()->HasTransform(), @@ -2315,8 +2315,8 @@ gfxPoint GetDeltaToMozTransformOrigin(const nsIFrame* aFrame, nsDisplayTransform::GetFrameBoundsForTransform(aFrame)); /* Allows us to access named variables by index. */ - gfxPoint result; - gfxFloat* coords[2] = {&result.x, &result.y}; + gfxPoint3D result; + gfxFloat* coords[3] = {&result.x, &result.y, &result.z}; const nscoord* dimensions[2] = {&boundingRect.width, &boundingRect.height}; @@ -2338,6 +2338,8 @@ gfxPoint GetDeltaToMozTransformOrigin(const nsIFrame* aFrame, *coords[index] = NSAppUnitsToFloatPixels(coord.GetCoordValue(), aFactor); } } + + *coords[2] = NSAppUnitsToFloatPixels(display->mTransformOrigin[2].GetCoordValue(), aFactor); /* Adjust based on the origin of the rectangle. */ result.x += NSAppUnitsToFloatPixels(boundingRect.x, aFactor); @@ -2363,9 +2365,10 @@ nsDisplayTransform::GetResultingTransformMatrix(const nsIFrame* aFrame, /* Account for the -moz-transform-origin property by translating the * coordinate space to the new origin. */ - gfxPoint toMozOrigin = GetDeltaToMozTransformOrigin(aFrame, aFactor, aBoundsOverride); - gfxPoint newOrigin = gfxPoint(NSAppUnitsToFloatPixels(aOrigin.x, aFactor), - NSAppUnitsToFloatPixels(aOrigin.y, aFactor)); + gfxPoint3D toMozOrigin = GetDeltaToMozTransformOrigin(aFrame, aFactor, aBoundsOverride); + gfxPoint3D newOrigin = gfxPoint3D(NSAppUnitsToFloatPixels(aOrigin.x, aFactor), + NSAppUnitsToFloatPixels(aOrigin.y, aFactor), + 0.0f); /* Get the underlying transform matrix. This requires us to get the * bounds of the frame. diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index d8977ba8ddf..2bc81129e99 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -1002,16 +1002,14 @@ nsLayoutUtils::GetPopupFrameForEventCoordinates(nsPresContext* aPresContext, } gfx3DMatrix -nsLayoutUtils::ChangeMatrixBasis(const gfxPoint &aOrigin, +nsLayoutUtils::ChangeMatrixBasis(const gfxPoint3D &aOrigin, const gfx3DMatrix &aMatrix) { /* These are translation matrices from world-to-origin of relative frame and - * vice-versa. Although I could use the gfxMatrix::Translate function to - * accomplish this, I'm hoping to reduce the overall number of matrix - * operations by hardcoding as many of the matrices as possible. + * vice-versa. */ - gfx3DMatrix worldToOrigin = gfx3DMatrix::From2D(gfxMatrix(1.0, 0.0, 0.0, 1.0, -aOrigin.x, -aOrigin.y)); - gfx3DMatrix originToWorld = gfx3DMatrix::From2D(gfxMatrix(1.0, 0.0, 0.0, 1.0, aOrigin.x, aOrigin.y)); + gfx3DMatrix worldToOrigin = gfx3DMatrix::Translation(-aOrigin); + gfx3DMatrix originToWorld = gfx3DMatrix::Translation(aOrigin); /* Multiply all three to get the transform! */ return worldToOrigin * aMatrix * originToWorld; diff --git a/layout/base/nsLayoutUtils.h b/layout/base/nsLayoutUtils.h index 6bab2c00683..fb470d56969 100644 --- a/layout/base/nsLayoutUtils.h +++ b/layout/base/nsLayoutUtils.h @@ -461,7 +461,7 @@ public: * @return A matrix equivalent to aMatrix, but operating in the coordinate system with * origin aOrigin. */ - static gfx3DMatrix ChangeMatrixBasis(const gfxPoint &aOrigin, const gfx3DMatrix &aMatrix); + static gfx3DMatrix ChangeMatrixBasis(const gfxPoint3D &aOrigin, const gfx3DMatrix &aMatrix); /** * Find IDs corresponding to a scrollable content element in the child process.