OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/LayoutInline.h" | 5 #include "core/layout/LayoutInline.h" |
6 #include "core/layout/LayoutTestHelper.h" | 6 #include "core/layout/LayoutTestHelper.h" |
7 #include "core/layout/LayoutView.h" | 7 #include "core/layout/LayoutView.h" |
8 #include "platform/geometry/TransformState.h" | 8 #include "platform/geometry/TransformState.h" |
9 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" | 9 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 mappedPoint = mapAncestorToLocal(container, view, mappedPoint); | 681 mappedPoint = mapAncestorToLocal(container, view, mappedPoint); |
682 EXPECT_EQ(FloatPoint(), mappedPoint); | 682 EXPECT_EQ(FloatPoint(), mappedPoint); |
683 } | 683 } |
684 | 684 |
685 // TODO(chrishtr): add more multi-frame tests. | 685 // TODO(chrishtr): add more multi-frame tests. |
686 TEST_P(MapCoordinatesTest, FixedPosInIFrameWhenMainFrameScrolled) { | 686 TEST_P(MapCoordinatesTest, FixedPosInIFrameWhenMainFrameScrolled) { |
687 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); | 687 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); |
688 setBodyInnerHTML( | 688 setBodyInnerHTML( |
689 "<style>body { margin: 0; }</style>" | 689 "<style>body { margin: 0; }</style>" |
690 "<div style='width: 200; height: 8000px'></div>" | 690 "<div style='width: 200; height: 8000px'></div>" |
691 "<iframe id=frame src='http://test.com' width='500' height='500' " | 691 "<iframe src='http://test.com' width='500' height='500' " |
692 "frameBorder='0'>" | 692 "frameBorder='0'>" |
693 "</iframe>"); | 693 "</iframe>"); |
694 | 694 setChildFrameHTML( |
695 Document& frameDocument = setupChildIframe( | |
696 "frame", | |
697 "<style>body { margin: 0; } #target { width: 200px; height: 200px; " | 695 "<style>body { margin: 0; } #target { width: 200px; height: 200px; " |
698 "position:fixed}</style><div id=target></div>"); | 696 "position:fixed}</style><div id=target></div>"); |
699 | 697 |
700 document().view()->layoutViewportScrollableArea()->setScrollOffset( | 698 document().view()->layoutViewportScrollableArea()->setScrollOffset( |
701 ScrollOffset(0.0, 1000), ProgrammaticScroll); | 699 ScrollOffset(0.0, 1000), ProgrammaticScroll); |
702 document().view()->updateAllLifecyclePhases(); | 700 document().view()->updateAllLifecyclePhases(); |
703 | 701 |
704 Element* target = frameDocument.getElementById("target"); | 702 Element* target = childDocument().getElementById("target"); |
705 ASSERT_TRUE(target); | 703 ASSERT_TRUE(target); |
706 FloatPoint mappedPoint = | 704 FloatPoint mappedPoint = |
707 mapAncestorToLocal(target->layoutObject(), nullptr, FloatPoint(10, 70), | 705 mapAncestorToLocal(target->layoutObject(), nullptr, FloatPoint(10, 70), |
708 TraverseDocumentBoundaries); | 706 TraverseDocumentBoundaries); |
709 | 707 |
710 // y = 70 - 8000, since the iframe is offset by 8000px from the main frame. | 708 // y = 70 - 8000, since the iframe is offset by 8000px from the main frame. |
711 // The scroll is not taken into account because the element is not fixed to | 709 // The scroll is not taken into account because the element is not fixed to |
712 // the root LayoutView, and the space of the root LayoutView does not include | 710 // the root LayoutView, and the space of the root LayoutView does not include |
713 // scroll. | 711 // scroll. |
714 EXPECT_EQ(FloatPoint(10, -7930), adjustForFrameScroll(mappedPoint)); | 712 EXPECT_EQ(FloatPoint(10, -7930), adjustForFrameScroll(mappedPoint)); |
715 } | 713 } |
716 | 714 |
717 TEST_P(MapCoordinatesTest, IFrameTransformed) { | 715 TEST_P(MapCoordinatesTest, IFrameTransformed) { |
718 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); | 716 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); |
719 setBodyInnerHTML( | 717 setBodyInnerHTML( |
720 "<style>body { margin: 0; }</style>" | 718 "<style>body { margin: 0; }</style>" |
721 "<iframe style='transform: scale(2)' id=frame src='http://test.com' " | 719 "<iframe style='transform: scale(2)' src='http://test.com' " |
722 "width='500' height='500' frameBorder='0'>" | 720 "width='500' height='500' frameBorder='0'>" |
723 "</iframe>"); | 721 "</iframe>"); |
724 | 722 setChildFrameHTML( |
725 Document& frameDocument = | 723 "<style>body { margin: 0; } #target { width: 200px; " |
726 setupChildIframe("frame", | 724 "height: 8000px}</style><div id=target></div>"); |
727 "<style>body { margin: 0; } #target { width: 200px; " | |
728 "height: 8000px}</style><div id=target></div>"); | |
729 | 725 |
730 document().view()->updateAllLifecyclePhases(); | 726 document().view()->updateAllLifecyclePhases(); |
731 | 727 |
732 frameDocument.view()->layoutViewportScrollableArea()->setScrollOffset( | 728 childDocument().view()->layoutViewportScrollableArea()->setScrollOffset( |
733 ScrollOffset(0.0, 1000), ProgrammaticScroll); | 729 ScrollOffset(0.0, 1000), ProgrammaticScroll); |
734 frameDocument.view()->updateAllLifecyclePhases(); | 730 childDocument().view()->updateAllLifecyclePhases(); |
735 | 731 |
736 Element* target = frameDocument.getElementById("target"); | 732 Element* target = childDocument().getElementById("target"); |
737 ASSERT_TRUE(target); | 733 ASSERT_TRUE(target); |
738 FloatPoint mappedPoint = | 734 FloatPoint mappedPoint = |
739 mapAncestorToLocal(target->layoutObject(), nullptr, FloatPoint(200, 200), | 735 mapAncestorToLocal(target->layoutObject(), nullptr, FloatPoint(200, 200), |
740 TraverseDocumentBoundaries | UseTransforms); | 736 TraverseDocumentBoundaries | UseTransforms); |
741 | 737 |
742 // Derivation: | 738 // Derivation: |
743 // (200, 200) -> (-50, -50) (Adjust for transform origin of scale, which is | 739 // (200, 200) -> (-50, -50) (Adjust for transform origin of scale, which is |
744 // at the center of the 500x500 iframe) | 740 // at the center of the 500x500 iframe) |
745 // (-50, -50) -> (-25, -25) (Divide by 2 to invert the scale) | 741 // (-50, -50) -> (-25, -25) (Divide by 2 to invert the scale) |
746 // (-25, -25) -> (225, 225) (Add the origin back in) | 742 // (-25, -25) -> (225, 225) (Add the origin back in) |
747 // (225, 225) -> (225, 1225) (Adjust by scroll offset of y=1000) | 743 // (225, 225) -> (225, 1225) (Adjust by scroll offset of y=1000) |
748 EXPECT_EQ(FloatPoint(225, 1225), mappedPoint); | 744 EXPECT_EQ(FloatPoint(225, 1225), mappedPoint); |
749 } | 745 } |
750 | 746 |
751 TEST_P(MapCoordinatesTest, FixedPosInScrolledIFrameWithTransform) { | 747 TEST_P(MapCoordinatesTest, FixedPosInScrolledIFrameWithTransform) { |
752 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); | 748 document().setBaseURLOverride(KURL(ParsedURLString, "http://test.com")); |
753 setBodyInnerHTML( | 749 setBodyInnerHTML( |
754 "<style>* { margin: 0; }</style>" | 750 "<style>* { margin: 0; }</style>" |
755 "<div style='position: absolute; left: 0px; top: 0px; width: 1024px; " | 751 "<div style='position: absolute; left: 0px; top: 0px; width: 1024px; " |
756 "height: 768px; transform-origin: 0 0; transform: scale(0.5, 0.5);'>" | 752 "height: 768px; transform-origin: 0 0; transform: scale(0.5, 0.5);'>" |
757 " <iframe id='frame' frameborder=0 src='http://test.com' " | 753 " <iframe frameborder=0 src='http://test.com' " |
758 "class='frame' sandbox='allow-same-origin' width='1024' " | 754 "sandbox='allow-same-origin' width='1024' height='768'></iframe>" |
759 "height='768'></iframe>" | |
760 "</div>"); | 755 "</div>"); |
761 | 756 setChildFrameHTML( |
762 Document& frameDocument = setupChildIframe( | |
763 "frame", | |
764 "<style>* { margin: 0; } #target { width: 200px; height: 200px; " | 757 "<style>* { margin: 0; } #target { width: 200px; height: 200px; " |
765 "position:fixed}</style><div id=target></div>" | 758 "position:fixed}</style><div id=target></div>" |
766 "<div style='width: 200; height: 8000px'></div>"); | 759 "<div style='width: 200; height: 8000px'></div>"); |
767 | 760 |
768 document().view()->updateAllLifecyclePhases(); | 761 document().view()->updateAllLifecyclePhases(); |
769 frameDocument.view()->layoutViewportScrollableArea()->setScrollOffset( | 762 childDocument().view()->layoutViewportScrollableArea()->setScrollOffset( |
770 ScrollOffset(0.0, 1000), ProgrammaticScroll); | 763 ScrollOffset(0.0, 1000), ProgrammaticScroll); |
771 document().view()->updateAllLifecyclePhases(); | 764 document().view()->updateAllLifecyclePhases(); |
772 | 765 |
773 Element* target = frameDocument.getElementById("target"); | 766 Element* target = childDocument().getElementById("target"); |
774 ASSERT_TRUE(target); | 767 ASSERT_TRUE(target); |
775 FloatPoint mappedPoint = | 768 FloatPoint mappedPoint = |
776 mapAncestorToLocal(target->layoutObject(), nullptr, FloatPoint(0, 0), | 769 mapAncestorToLocal(target->layoutObject(), nullptr, FloatPoint(0, 0), |
777 UseTransforms | TraverseDocumentBoundaries); | 770 UseTransforms | TraverseDocumentBoundaries); |
778 | 771 |
779 EXPECT_EQ(FloatPoint(0, 0), mappedPoint); | 772 EXPECT_EQ(FloatPoint(0, 0), mappedPoint); |
780 } | 773 } |
781 | 774 |
782 TEST_P(MapCoordinatesTest, MulticolWithText) { | 775 TEST_P(MapCoordinatesTest, MulticolWithText) { |
783 setBodyInnerHTML( | 776 setBodyInnerHTML( |
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1559 LayoutUnit::epsilon()); | 1552 LayoutUnit::epsilon()); |
1560 EXPECT_NEAR(50.0, matrix.projectPoint(FloatPoint(100.0, 50.0)).y(), | 1553 EXPECT_NEAR(50.0, matrix.projectPoint(FloatPoint(100.0, 50.0)).y(), |
1561 LayoutUnit::epsilon()); | 1554 LayoutUnit::epsilon()); |
1562 EXPECT_NEAR(25.0, matrix.projectPoint(FloatPoint(50.0, 100.0)).x(), | 1555 EXPECT_NEAR(25.0, matrix.projectPoint(FloatPoint(50.0, 100.0)).x(), |
1563 LayoutUnit::epsilon()); | 1556 LayoutUnit::epsilon()); |
1564 EXPECT_NEAR(100.0, matrix.projectPoint(FloatPoint(50.0, 100.0)).y(), | 1557 EXPECT_NEAR(100.0, matrix.projectPoint(FloatPoint(50.0, 100.0)).y(), |
1565 LayoutUnit::epsilon()); | 1558 LayoutUnit::epsilon()); |
1566 } | 1559 } |
1567 | 1560 |
1568 } // namespace blink | 1561 } // namespace blink |
OLD | NEW |