OLD | NEW |
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 "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 LayoutRect rect = targetVisualRect; | 693 LayoutRect rect = targetVisualRect; |
694 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); | 694 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(&layoutView(), rect)); |
695 EXPECT_EQ(LayoutRect(66, 55, 33, 44), rect); | 695 EXPECT_EQ(LayoutRect(66, 55, 33, 44), rect); |
696 EXPECT_EQ(rect, target->visualRect()); | 696 EXPECT_EQ(rect, target->visualRect()); |
697 | 697 |
698 rect = targetVisualRect; | 698 rect = targetVisualRect; |
699 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(span, rect)); | 699 EXPECT_TRUE(target->mapToVisualRectInAncestorSpace(span, rect)); |
700 EXPECT_EQ(LayoutRect(-200, -100, 33, 44), rect); | 700 EXPECT_EQ(LayoutRect(-200, -100, 33, 44), rect); |
701 } | 701 } |
702 | 702 |
| 703 TEST_F(VisualRectMappingTest, ShouldAccountForPreserve3d) { |
| 704 enableCompositing(); |
| 705 setBodyInnerHTML( |
| 706 "<style>" |
| 707 "* { margin: 0; }" |
| 708 "#container {" |
| 709 " transform: rotateX(-45deg);" |
| 710 " width: 100px; height: 100px;" |
| 711 "}" |
| 712 "#target {" |
| 713 " transform-style: preserve-3d; transform: rotateX(45deg);" |
| 714 " background: lightblue;" |
| 715 " width: 100px; height: 100px;" |
| 716 "}" |
| 717 "</style>" |
| 718 "<div id='container'><div id='target'></div></div>"); |
| 719 LayoutBlock* container = |
| 720 toLayoutBlock(getLayoutObjectByElementId("container")); |
| 721 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); |
| 722 LayoutRect originalRect(0, 0, 100, 100); |
| 723 // Multiply both matrices together before flattening. |
| 724 TransformationMatrix matrix = container->layer()->currentTransform(); |
| 725 matrix *= target->layer()->currentTransform(); |
| 726 matrix.flattenTo2d(); |
| 727 FloatRect output = matrix.mapRect(FloatRect(originalRect)); |
| 728 |
| 729 EXPECT_TRUE( |
| 730 target->mapToVisualRectInAncestorSpace(target->view(), originalRect)); |
| 731 EXPECT_EQ(LayoutRect(enclosingIntRect(output)), originalRect); |
| 732 } |
| 733 |
| 734 TEST_F(VisualRectMappingTest, ShouldAccountForPerspective) { |
| 735 enableCompositing(); |
| 736 setBodyInnerHTML( |
| 737 "<style>" |
| 738 "* { margin: 0; }" |
| 739 "#container {" |
| 740 " transform: rotateX(-45deg); perspective: 100px;" |
| 741 " width: 100px; height: 100px;" |
| 742 "}" |
| 743 "#target {" |
| 744 " transform-style: preserve-3d; transform: rotateX(45deg);" |
| 745 " background: lightblue;" |
| 746 " width: 100px; height: 100px;" |
| 747 "}" |
| 748 "</style>" |
| 749 "<div id='container'><div id='target'></div></div>"); |
| 750 LayoutBlock* container = |
| 751 toLayoutBlock(getLayoutObjectByElementId("container")); |
| 752 LayoutBlock* target = toLayoutBlock(getLayoutObjectByElementId("target")); |
| 753 LayoutRect originalRect(0, 0, 100, 100); |
| 754 TransformationMatrix matrix = container->layer()->currentTransform(); |
| 755 TransformationMatrix targetMatrix; |
| 756 // getTransformfromContainter includes transform and perspective matrix |
| 757 // of the container. |
| 758 target->getTransformFromContainer(container, LayoutSize(), targetMatrix); |
| 759 matrix *= targetMatrix; |
| 760 matrix.flattenTo2d(); |
| 761 FloatRect output = matrix.mapRect(FloatRect(originalRect)); |
| 762 |
| 763 EXPECT_TRUE( |
| 764 target->mapToVisualRectInAncestorSpace(target->view(), originalRect)); |
| 765 EXPECT_EQ(LayoutRect(enclosingIntRect(output)), originalRect); |
| 766 } |
| 767 |
703 } // namespace blink | 768 } // namespace blink |
OLD | NEW |