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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/layout/LayoutTestHelper.h" 5 #include "core/layout/LayoutTestHelper.h"
6 #include "core/layout/LayoutView.h" 6 #include "core/layout/LayoutView.h"
7 #include "core/layout/PaintInvalidationState.h" 7 #include "core/layout/PaintInvalidationState.h"
8 #include "core/paint/PaintLayer.h" 8 #include "core/paint/PaintLayer.h"
9 #include "core/paint/PaintPropertyTreePrinter.h"
9 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
10 11
11 namespace blink { 12 namespace blink {
12 13
13 class VisualRectMappingTest : public RenderingTest { 14 class VisualRectMappingTest : public RenderingTest {
14 public: 15 public:
15 VisualRectMappingTest() 16 VisualRectMappingTest()
16 : RenderingTest(SingleChildLocalFrameClient::create()) {} 17 : RenderingTest(SingleChildLocalFrameClient::create()) {}
17 18
18 protected: 19 protected:
19 LayoutView& layoutView() const { return *document().layoutView(); } 20 LayoutView& layoutView() const { return *document().layoutView(); }
20 21
21 void checkPaintInvalidationVisualRect(const LayoutObject& object) { 22 void checkPaintInvalidationVisualRect(const LayoutObject& object) {
22 LayoutRect rect = object.localVisualRect(); 23 LayoutRect rect = object.localVisualRect();
23 if (object.isBox()) 24 if (object.isBox())
24 toLayoutBox(object).flipForWritingMode(rect); 25 toLayoutBox(object).flipForWritingMode(rect);
25 const LayoutBoxModelObject& paintInvalidationContainer = 26 const LayoutBoxModelObject& paintInvalidationContainer =
26 object.containerForPaintInvalidation(); 27 object.containerForPaintInvalidation();
27 object.mapToVisualRectInAncestorSpace(&paintInvalidationContainer, rect); 28
28 if (rect.isEmpty() && object.visualRect().isEmpty()) 29 checkVisualRect(object, paintInvalidationContainer, rect,
30 object.visualRect());
31 }
32
33 void checkVisualRect(const LayoutObject& object,
34 const LayoutBoxModelObject& ancestor,
35 const LayoutRect& localRect,
36 const LayoutRect& expectedVisualRect) {
37 LayoutRect slowMapRect = localRect;
38 object.mapToVisualRectInAncestorSpace(&ancestor, slowMapRect);
39 if (slowMapRect.isEmpty() && object.visualRect().isEmpty())
29 return; 40 return;
41
30 // The following condition can be false if paintInvalidationContainer is 42 // The following condition can be false if paintInvalidationContainer is
31 // a LayoutView and compositing is not enabled. 43 // a LayoutView and compositing is not enabled.
32 if (paintInvalidationContainer.isPaintInvalidationContainer()) { 44 if (ancestor.isPaintInvalidationContainer()) {
33 PaintLayer::mapRectInPaintInvalidationContainerToBacking( 45 PaintLayer::mapRectInPaintInvalidationContainerToBacking(ancestor,
34 paintInvalidationContainer, rect); 46 slowMapRect);
35 } 47 }
36 EXPECT_EQ(enclosingIntRect(rect), enclosingIntRect(object.visualRect())); 48 EXPECT_TRUE(enclosingIntRect(slowMapRect)
49 .contains(enclosingIntRect(expectedVisualRect)));
50
51 if (object.paintProperties()) {
52 FloatRect geometryMapperRect(localRect);
53 document().view()->geometryMapper().sourceToDestinationVisualRect(
54 *object.paintProperties()->localBorderBoxProperties(),
55 *ancestor.paintProperties()->contentsProperties(),
56 geometryMapperRect);
57
58 EXPECT_EQ(enclosingIntRect(expectedVisualRect),
59 enclosingIntRect(geometryMapperRect));
60 }
37 } 61 }
38 }; 62 };
39 63
40 TEST_F(VisualRectMappingTest, LayoutText) { 64 TEST_F(VisualRectMappingTest, LayoutText) {
41 setBodyInnerHTML( 65 setBodyInnerHTML(
42 "<style>body { margin: 0; }</style>" 66 "<style>body { margin: 0; }</style>"
43 "<div id='container' style='overflow: scroll; width: 50px; height: 50px'>" 67 "<div id='container' style='overflow: scroll; width: 50px; height: 50px'>"
44 " <span><img style='width: 20px; height: 100px'></span>" 68 " <span><img style='width: 20px; height: 100px'></span>"
45 " text text text text text text text" 69 " text text text text text text text"
46 "</div>"); 70 "</div>");
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after
689 713
690 LayoutRect targetVisualRect = target->localVisualRect(); 714 LayoutRect targetVisualRect = target->localVisualRect();
691 EXPECT_EQ(LayoutRect(0, 0, 33, 44), targetVisualRect); 715 EXPECT_EQ(LayoutRect(0, 0, 33, 44), targetVisualRect);
692 716
693 LayoutRect rect = targetVisualRect; 717 LayoutRect rect = targetVisualRect;
694 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); 718 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect));
695 EXPECT_EQ(LayoutRect(66, 55, 33, 44), rect); 719 EXPECT_EQ(LayoutRect(66, 55, 33, 44), rect);
696 EXPECT_EQ(rect, target->visualRect()); 720 EXPECT_EQ(rect, target->visualRect());
697 721
698 rect = targetVisualRect; 722 rect = targetVisualRect;
723
724 // TODO(chrishtr): fix and re-enable: crbug.com/700563.
725 // checkVisualRect(*target, *span, rect, LayoutRect(-200, -100, 33, 44));
chrishtr 2017/03/10 23:29:54 Property trees are off by 200px.
726
699 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(span, rect)); 727 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(span, rect));
700 EXPECT_EQ(LayoutRect(-200, -100, 33, 44), rect); 728 EXPECT_EQ(LayoutRect(-200, -100, 33, 44), rect);
701 } 729 }
702 730
703 TEST_F(VisualRectMappingTest, ShouldAccountForPreserve3d) { 731 TEST_F(VisualRectMappingTest, ShouldAccountForPreserve3d) {
704 enableCompositing(); 732 enableCompositing();
705 setBodyInnerHTML( 733 setBodyInnerHTML(
706 "<style>" 734 "<style>"
707 "* { margin: 0; }" 735 "* { margin: 0; }"
708 "#container {" 736 "#container {"
709 " transform: rotateX(-45deg);" 737 " transform: rotateX(-45deg);"
710 " width: 100px; height: 100px;" 738 " width: 100px; height: 100px;"
711 "}" 739 "}"
712 "#target {" 740 "#target {"
713 " transform-style: preserve-3d; transform: rotateX(45deg);" 741 " transform-style: preserve-3d; transform: rotateX(45deg);"
714 " background: lightblue;" 742 " background: lightblue;"
715 " width: 100px; height: 100px;" 743 " width: 100px; height: 100px;"
716 "}" 744 "}"
717 "</style>" 745 "</style>"
718 "<div id='container'><div id='target'></div></div>"); 746 "<div id='container'><div id='target'></div></div>");
719 LayoutBlock* container = 747 LayoutBlock* container =
720 toLayoutBlock(getLayoutObjectByElementId("container")); 748 toLayoutBlock(getLayoutObjectByElementId("container"));
721 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); 749 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target"));
722 LayoutRect originalRect(0, 0, 100, 100); 750 LayoutRect originalRect(0, 0, 100, 100);
723 // Multiply both matrices together before flattening. 751 // Multiply both matrices together before flattening.
724 TransformationMatrix matrix = container->layer()->currentTransform(); 752 TransformationMatrix matrix = container->layer()->currentTransform();
753 matrix.flattenTo2d();
754 matrix *= target->layer()->currentTransform();
755 LayoutRect output(matrix.mapRect(FloatRect(originalRect)));
756
757 checkVisualRect(*target, *target->view(), originalRect, output);
758 }
759
760 TEST_F(VisualRectMappingTest, ShouldAccountForPreserve3dNested) {
761 enableCompositing();
762 setBodyInnerHTML(
763 "<style>"
764 "* { margin: 0; }"
765 "#container {"
766 " transform-style: preserve-3d;"
767 " transform: rotateX(-45deg);"
768 " width: 100px; height: 100px;"
769 "}"
770 "#target {"
771 " transform-style: preserve-3d; transform: rotateX(45deg);"
772 " background: lightblue;"
773 " width: 100px; height: 100px;"
774 "}"
775 "</style>"
776 "<div id='container'><div id='target'></div></div>");
777 LayoutBlock* container =
778 toLayoutBlock(getLayoutObjectByElementId("container"));
779 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target"));
780 LayoutRect originalRect(0, 0, 100, 100);
781 // Multiply both matrices together before flattening.
782 TransformationMatrix matrix = container->layer()->currentTransform();
725 matrix *= target->layer()->currentTransform(); 783 matrix *= target->layer()->currentTransform();
726 matrix.flattenTo2d(); 784 LayoutRect output(matrix.mapRect(FloatRect(originalRect)));
727 FloatRect output = matrix.mapRect(FloatRect(originalRect));
728 785
729 EXPECT_TRUE( 786 checkVisualRect(*target, *target->view(), originalRect, output);
730 target->mapToVisualRectInAncestorSpace(target->view(), originalRect));
731 EXPECT_EQ(LayoutRect(enclosingIntRect(output)), originalRect);
732 } 787 }
733 788
734 TEST_F(VisualRectMappingTest, ShouldAccountForPerspective) { 789 TEST_F(VisualRectMappingTest, ShouldAccountForPerspective) {
735 enableCompositing(); 790 enableCompositing();
736 setBodyInnerHTML( 791 setBodyInnerHTML(
737 "<style>" 792 "<style>"
738 "* { margin: 0; }" 793 "* { margin: 0; }"
739 "#container {" 794 "#container {"
740 " transform: rotateX(-45deg); perspective: 100px;" 795 " transform: rotateX(-45deg); perspective: 100px;"
741 " width: 100px; height: 100px;" 796 " width: 100px; height: 100px;"
742 "}" 797 "}"
743 "#target {" 798 "#target {"
744 " transform-style: preserve-3d; transform: rotateX(45deg);" 799 " transform-style: preserve-3d; transform: rotateX(45deg);"
745 " background: lightblue;" 800 " background: lightblue;"
746 " width: 100px; height: 100px;" 801 " width: 100px; height: 100px;"
747 "}" 802 "}"
748 "</style>" 803 "</style>"
749 "<div id='container'><div id='target'></div></div>"); 804 "<div id='container'><div id='target'></div></div>");
750 LayoutBlock* container = 805 LayoutBlock* container =
751 toLayoutBlock(getLayoutObjectByElementId("container")); 806 toLayoutBlock(getLayoutObjectByElementId("container"));
752 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); 807 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target"));
753 LayoutRect originalRect(0, 0, 100, 100); 808 LayoutRect originalRect(0, 0, 100, 100);
754 TransformationMatrix matrix = container->layer()->currentTransform(); 809 TransformationMatrix matrix = container->layer()->currentTransform();
810 matrix.flattenTo2d();
811 TransformationMatrix targetMatrix;
812 // getTransformfromContainter includes transform and perspective matrix
813 // of the container.
814 target->getTransformFromContainer(container, LayoutSize(), targetMatrix);
815 matrix *= targetMatrix;
816 LayoutRect output(matrix.mapRect(FloatRect(originalRect)));
817
818 checkVisualRect(*target, *target->view(), originalRect, output);
819 }
820
821 TEST_F(VisualRectMappingTest, ShouldAccountForPerspectiveNested) {
822 enableCompositing();
823 setBodyInnerHTML(
824 "<style>"
825 "* { margin: 0; }"
826 "#container {"
827 " transform-style: preserve-3d;"
828 " transform: rotateX(-45deg); perspective: 100px;"
829 " width: 100px; height: 100px;"
830 "}"
831 "#target {"
832 " transform-style: preserve-3d; transform: rotateX(45deg);"
833 " background: lightblue;"
834 " width: 100px; height: 100px;"
835 "}"
836 "</style>"
837 "<div id='container'><div id='target'></div></div>");
838 LayoutBlock* container =
839 toLayoutBlock(getLayoutObjectByElementId("container"));
840 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target"));
841 LayoutRect originalRect(0, 0, 100, 100);
842 TransformationMatrix matrix = container->layer()->currentTransform();
755 TransformationMatrix targetMatrix; 843 TransformationMatrix targetMatrix;
756 // getTransformfromContainter includes transform and perspective matrix 844 // getTransformfromContainter includes transform and perspective matrix
757 // of the container. 845 // of the container.
758 target->getTransformFromContainer(container, LayoutSize(), targetMatrix); 846 target->getTransformFromContainer(container, LayoutSize(), targetMatrix);
759 matrix *= targetMatrix; 847 matrix *= targetMatrix;
760 matrix.flattenTo2d(); 848 LayoutRect output(matrix.mapRect(FloatRect(originalRect)));
761 FloatRect output = matrix.mapRect(FloatRect(originalRect));
762 849
763 EXPECT_TRUE( 850 checkVisualRect(*target, *target->view(), originalRect, output);
764 target->mapToVisualRectInAncestorSpace(target->view(), originalRect));
765 EXPECT_EQ(LayoutRect(enclosingIntRect(output)), originalRect);
766 } 851 }
767 852
768 } // namespace blink 853 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698