Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(545)

Unified Diff: third_party/WebKit/Source/core/layout/VisualRectMappingTest.cpp

Issue 2744743003: Add support for flattening in GeometryMapper. (Closed)
Patch Set: none Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 4020dfa38809c7f7df9ce382a976a86b22a6754d..485bd87c47605eac0b573f17e73e5d59f3022a7c 100644
--- a/third_party/WebKit/Source/core/layout/VisualRectMappingTest.cpp
+++ b/third_party/WebKit/Source/core/layout/VisualRectMappingTest.cpp
@@ -6,6 +6,7 @@
#include "core/layout/LayoutView.h"
#include "core/layout/PaintInvalidationState.h"
#include "core/paint/PaintLayer.h"
+#include "core/paint/PaintPropertyTreePrinter.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace blink {
@@ -24,16 +25,39 @@ class VisualRectMappingTest : public RenderingTest {
toLayoutBox(object).flipForWritingMode(rect);
const LayoutBoxModelObject& paintInvalidationContainer =
object.containerForPaintInvalidation();
- object.mapToVisualRectInAncestorSpace(&paintInvalidationContainer, rect);
- if (rect.isEmpty() && object.visualRect().isEmpty())
+
+ checkVisualRect(object, paintInvalidationContainer, rect,
+ object.visualRect());
+ }
+
+ void checkVisualRect(const LayoutObject& object,
+ const LayoutBoxModelObject& ancestor,
+ const LayoutRect& localRect,
+ const LayoutRect& expectedVisualRect) {
+ LayoutRect slowMapRect = localRect;
+ object.mapToVisualRectInAncestorSpace(&ancestor, slowMapRect);
+ if (slowMapRect.isEmpty() && object.visualRect().isEmpty())
return;
+
// The following condition can be false if paintInvalidationContainer is
// a LayoutView and compositing is not enabled.
- if (paintInvalidationContainer.isPaintInvalidationContainer()) {
- PaintLayer::mapRectInPaintInvalidationContainerToBacking(
- paintInvalidationContainer, rect);
+ if (ancestor.isPaintInvalidationContainer()) {
+ PaintLayer::mapRectInPaintInvalidationContainerToBacking(ancestor,
+ slowMapRect);
+ }
+ EXPECT_TRUE(enclosingIntRect(slowMapRect)
+ .contains(enclosingIntRect(expectedVisualRect)));
+
+ if (object.paintProperties()) {
+ FloatRect geometryMapperRect(localRect);
+ document().view()->geometryMapper().sourceToDestinationVisualRect(
+ *object.paintProperties()->localBorderBoxProperties(),
+ *ancestor.paintProperties()->contentsProperties(),
+ geometryMapperRect);
+
+ EXPECT_EQ(enclosingIntRect(expectedVisualRect),
+ enclosingIntRect(geometryMapperRect));
}
- EXPECT_EQ(enclosingIntRect(rect), enclosingIntRect(object.visualRect()));
}
};
@@ -696,6 +720,10 @@ TEST_F(VisualRectMappingTest, FloatUnderInline) {
EXPECT_EQ(rect, target->visualRect());
rect = targetVisualRect;
+
+ // TODO(chrishtr): fix and re-enable: crbug.com/700563.
+ // checkVisualRect(*target, *span, rect, LayoutRect(-200, -100, 33, 44));
chrishtr 2017/03/10 23:29:54 Property trees are off by 200px.
+
EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(span, rect));
EXPECT_EQ(LayoutRect(-200, -100, 33, 44), rect);
}
@@ -722,13 +750,40 @@ TEST_F(VisualRectMappingTest, ShouldAccountForPreserve3d) {
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));
+ matrix *= target->layer()->currentTransform();
+ LayoutRect output(matrix.mapRect(FloatRect(originalRect)));
- EXPECT_TRUE(
- target->mapToVisualRectInAncestorSpace(target->view(), originalRect));
- EXPECT_EQ(LayoutRect(enclosingIntRect(output)), originalRect);
+ checkVisualRect(*target, *target->view(), originalRect, output);
+}
+
+TEST_F(VisualRectMappingTest, ShouldAccountForPreserve3dNested) {
+ enableCompositing();
+ setBodyInnerHTML(
+ "<style>"
+ "* { margin: 0; }"
+ "#container {"
+ " transform-style: preserve-3d;"
+ " 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();
+ LayoutRect output(matrix.mapRect(FloatRect(originalRect)));
+
+ checkVisualRect(*target, *target->view(), originalRect, output);
}
TEST_F(VisualRectMappingTest, ShouldAccountForPerspective) {
@@ -752,17 +807,47 @@ TEST_F(VisualRectMappingTest, ShouldAccountForPerspective) {
LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target"));
LayoutRect originalRect(0, 0, 100, 100);
TransformationMatrix matrix = container->layer()->currentTransform();
+ matrix.flattenTo2d();
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));
+ LayoutRect output(matrix.mapRect(FloatRect(originalRect)));
- EXPECT_TRUE(
- target->mapToVisualRectInAncestorSpace(target->view(), originalRect));
- EXPECT_EQ(LayoutRect(enclosingIntRect(output)), originalRect);
+ checkVisualRect(*target, *target->view(), originalRect, output);
+}
+
+TEST_F(VisualRectMappingTest, ShouldAccountForPerspectiveNested) {
+ enableCompositing();
+ setBodyInnerHTML(
+ "<style>"
+ "* { margin: 0; }"
+ "#container {"
+ " transform-style: preserve-3d;"
+ " 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;
+ LayoutRect output(matrix.mapRect(FloatRect(originalRect)));
+
+ checkVisualRect(*target, *target->view(), originalRect, output);
}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698