Index: third_party/WebKit/Source/core/layout/LayoutObjectTest.cpp |
diff --git a/third_party/WebKit/Source/core/layout/LayoutObjectTest.cpp b/third_party/WebKit/Source/core/layout/LayoutObjectTest.cpp |
index ca38e7dbde378cc0ca7de8fdf33e9bedec7527f2..cc2054f97e0eab0128c08262b2526c7e18d28ad5 100644 |
--- a/third_party/WebKit/Source/core/layout/LayoutObjectTest.cpp |
+++ b/third_party/WebKit/Source/core/layout/LayoutObjectTest.cpp |
@@ -122,4 +122,60 @@ TEST_F(LayoutObjectTest, MapToVisibleRectInAncestorSpace) |
EXPECT_TRUE(rect == LayoutRect(0, 10, 20, 20)); |
} |
+TEST_F(LayoutObjectTest, LocalToAbsoluteTransform) |
chrishtr
2016/03/10 16:53:39
Put this in MapCoordinatesTest instead. The logic
dmazzoni
2016/03/14 20:10:37
Done.
|
+{ |
+ setBodyInnerHTML( |
+ "<div id='container' style='position: absolute; left: 0; top: 0;'>" |
+ " <div id='scale' style='transform: scale(2.0); transform-origin: left top;'>" |
+ " <div id='child'></div>" |
+ " </div>" |
+ "</div>"); |
+ LayoutBoxModelObject* container = toLayoutBoxModelObject(getLayoutObjectByElementId("container")); |
+ TransformationMatrix containerMatrix = container->localToAbsoluteTransform(); |
+ EXPECT_TRUE(containerMatrix.isIdentity()); |
+ |
+ LayoutObject* child = getLayoutObjectByElementId("child"); |
+ TransformationMatrix childMatrix = child->localToAbsoluteTransform(); |
+ EXPECT_FALSE(childMatrix.isIdentityOrTranslation()); |
+ EXPECT_TRUE(childMatrix.isAffine()); |
+ EXPECT_EQ(0.0, childMatrix.projectPoint(FloatPoint(0.0, 0.0)).x()); |
+ EXPECT_EQ(0.0, childMatrix.projectPoint(FloatPoint(0.0, 0.0)).y()); |
+ EXPECT_EQ(20.0, childMatrix.projectPoint(FloatPoint(10.0, 20.0)).x()); |
+ EXPECT_EQ(40.0, childMatrix.projectPoint(FloatPoint(10.0, 20.0)).y()); |
+} |
+ |
+TEST_F(LayoutObjectTest, LocalToAncestorTransform) |
+{ |
+ setBodyInnerHTML( |
+ "<div id='container'>" |
+ " <div id='rotate1' style='transform: rotate(45deg); transform-origin: left top;'>" |
+ " <div id='rotate2' style='transform: rotate(90deg); transform-origin: left top;'>" |
+ " <div id='child'></div>" |
+ " </div>" |
+ " </div>" |
+ "</div>"); |
+ LayoutBoxModelObject* container = toLayoutBoxModelObject(getLayoutObjectByElementId("container")); |
+ LayoutBoxModelObject* rotate1 = toLayoutBoxModelObject(getLayoutObjectByElementId("rotate1")); |
+ LayoutBoxModelObject* rotate2 = toLayoutBoxModelObject(getLayoutObjectByElementId("rotate2")); |
+ LayoutObject* child = getLayoutObjectByElementId("child"); |
+ TransformationMatrix matrix; |
+ |
+ matrix = child->localToAncestorTransform(rotate2); |
+ EXPECT_TRUE(matrix.isIdentity()); |
+ |
+ // Rotate (100, 0) 90 degrees to (0, 100) |
+ matrix = child->localToAncestorTransform(rotate1); |
+ EXPECT_FALSE(matrix.isIdentity()); |
+ EXPECT_TRUE(matrix.isAffine()); |
+ EXPECT_NEAR(0.0, matrix.projectPoint(FloatPoint(100.0, 0.0)).x(), LayoutUnit::epsilon()); |
+ EXPECT_NEAR(100.0, matrix.projectPoint(FloatPoint(100.0, 0.0)).y(), LayoutUnit::epsilon()); |
+ |
+ // Rotate (100, 0) 135 degrees to (-70.7, 70.7) |
+ matrix = child->localToAncestorTransform(container); |
+ EXPECT_FALSE(matrix.isIdentity()); |
+ EXPECT_TRUE(matrix.isAffine()); |
+ EXPECT_NEAR(-100.0 * sqrt(2.0) / 2.0, matrix.projectPoint(FloatPoint(100.0, 0.0)).x(), LayoutUnit::epsilon()); |
+ EXPECT_NEAR(100.0 * sqrt(2.0) / 2.0, matrix.projectPoint(FloatPoint(100.0, 0.0)).y(), LayoutUnit::epsilon()); |
+} |
+ |
} // namespace blink |