Index: third_party/WebKit/Source/core/layout/VisualRectMappingTest.cpp |
diff --git a/third_party/WebKit/Source/core/layout/VisualRectMappingTest.cpp b/third_party/WebKit/Source/core/layout/VisualRectMappingTest.cpp |
index af9aa37f8a27a0a6f34c160f1fe73449611d5583..4020dfa38809c7f7df9ce382a976a86b22a6754d 100644 |
--- a/third_party/WebKit/Source/core/layout/VisualRectMappingTest.cpp |
+++ b/third_party/WebKit/Source/core/layout/VisualRectMappingTest.cpp |
@@ -700,4 +700,69 @@ TEST_F(VisualRectMappingTest, FloatUnderInline) { |
EXPECT_EQ(LayoutRect(-200, -100, 33, 44), rect); |
} |
+TEST_F(VisualRectMappingTest, ShouldAccountForPreserve3d) { |
+ enableCompositing(); |
+ setBodyInnerHTML( |
+ "<style>" |
+ "* { margin: 0; }" |
+ "#container {" |
+ " transform: rotateX(-45deg);" |
+ " width: 100px; height: 100px;" |
+ "}" |
+ "#target {" |
+ " transform-style: preserve-3d; transform: rotateX(45deg);" |
+ " background: lightblue;" |
+ " width: 100px; height: 100px;" |
+ "}" |
+ "</style>" |
+ "<div id='container'><div id='target'></div></div>"); |
+ LayoutBlock* container = |
+ toLayoutBlock(getLayoutObjectByElementId("container")); |
+ LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); |
+ LayoutRect originalRect(0, 0, 100, 100); |
+ // Multiply both matrices together before flattening. |
+ TransformationMatrix matrix = container->layer()->currentTransform(); |
+ matrix *= target->layer()->currentTransform(); |
+ matrix.flattenTo2d(); |
+ FloatRect output = matrix.mapRect(FloatRect(originalRect)); |
+ |
+ EXPECT_TRUE( |
+ target->mapToVisualRectInAncestorSpace(target->view(), originalRect)); |
+ EXPECT_EQ(LayoutRect(enclosingIntRect(output)), originalRect); |
+} |
+ |
+TEST_F(VisualRectMappingTest, ShouldAccountForPerspective) { |
+ enableCompositing(); |
+ setBodyInnerHTML( |
+ "<style>" |
+ "* { margin: 0; }" |
+ "#container {" |
+ " transform: rotateX(-45deg); perspective: 100px;" |
+ " width: 100px; height: 100px;" |
+ "}" |
+ "#target {" |
+ " transform-style: preserve-3d; transform: rotateX(45deg);" |
+ " background: lightblue;" |
+ " width: 100px; height: 100px;" |
+ "}" |
+ "</style>" |
+ "<div id='container'><div id='target'></div></div>"); |
+ LayoutBlock* container = |
+ toLayoutBlock(getLayoutObjectByElementId("container")); |
+ LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); |
+ LayoutRect originalRect(0, 0, 100, 100); |
+ TransformationMatrix matrix = container->layer()->currentTransform(); |
+ TransformationMatrix targetMatrix; |
+ // getTransformfromContainter includes transform and perspective matrix |
+ // of the container. |
+ target->getTransformFromContainer(container, LayoutSize(), targetMatrix); |
+ matrix *= targetMatrix; |
+ matrix.flattenTo2d(); |
+ FloatRect output = matrix.mapRect(FloatRect(originalRect)); |
+ |
+ EXPECT_TRUE( |
+ target->mapToVisualRectInAncestorSpace(target->view(), originalRect)); |
+ EXPECT_EQ(LayoutRect(enclosingIntRect(output)), originalRect); |
+} |
+ |
} // namespace blink |