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 "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 EXPECT_FLOAT_QUAD_EQ(initialQuad, mappedQuad); | 872 EXPECT_FLOAT_QUAD_EQ(initialQuad, mappedQuad); |
873 | 873 |
874 initialQuad = FloatQuad(FloatPoint(100, -41.42), FloatPoint(241.42, 100), Fl
oatPoint(100, 241.42), FloatPoint(-41.42, 100)); | 874 initialQuad = FloatQuad(FloatPoint(100, -41.42), FloatPoint(241.42, 100), Fl
oatPoint(100, 241.42), FloatPoint(-41.42, 100)); |
875 mappedQuad = mapLocalToAncestor(outerTransform, container, initialQuad, UseT
ransforms); | 875 mappedQuad = mapLocalToAncestor(outerTransform, container, initialQuad, UseT
ransforms); |
876 // Another clockwise rotation by 45 degrees. So now 90 degrees in total. | 876 // Another clockwise rotation by 45 degrees. So now 90 degrees in total. |
877 EXPECT_FLOAT_QUAD_EQ(FloatQuad(FloatPoint(200, 0), FloatPoint(200, 200), Flo
atPoint(0, 200), FloatPoint(0, 0)), mappedQuad); | 877 EXPECT_FLOAT_QUAD_EQ(FloatQuad(FloatPoint(200, 0), FloatPoint(200, 200), Flo
atPoint(0, 200), FloatPoint(0, 0)), mappedQuad); |
878 mappedQuad = mapAncestorToLocal(outerTransform, container, mappedQuad, UseTr
ansforms); | 878 mappedQuad = mapAncestorToLocal(outerTransform, container, mappedQuad, UseTr
ansforms); |
879 EXPECT_FLOAT_QUAD_EQ(initialQuad, mappedQuad); | 879 EXPECT_FLOAT_QUAD_EQ(initialQuad, mappedQuad); |
880 } | 880 } |
881 | 881 |
| 882 TEST_F(MapCoordinatesTest, SVGShape) |
| 883 { |
| 884 setBodyInnerHTML( |
| 885 "<svg id='container'>" |
| 886 " <g transform='translate(100 200)'>" |
| 887 " <rect id='target' width='100' height='100'/>" |
| 888 " </g>" |
| 889 "</svg>"); |
| 890 |
| 891 LayoutObject* target = getLayoutObjectByElementId("target"); |
| 892 LayoutBox* container = toLayoutBox(getLayoutObjectByElementId("container")); |
| 893 |
| 894 FloatPoint mappedPoint = mapLocalToAncestor(target, container, FloatPoint())
; |
| 895 EXPECT_EQ(FloatPoint(100, 200), mappedPoint); |
| 896 mappedPoint = mapAncestorToLocal(target, container, mappedPoint); |
| 897 EXPECT_EQ(FloatPoint(), mappedPoint); |
| 898 } |
| 899 |
| 900 TEST_F(MapCoordinatesTest, SVGShapeScale) |
| 901 { |
| 902 setBodyInnerHTML( |
| 903 "<svg id='container'>" |
| 904 " <g transform='scale(2) translate(50 40)'>" |
| 905 " <rect id='target' transform='translate(50 80)' x='66' y='77' wi
dth='100' height='100'/>" |
| 906 " </g>" |
| 907 "</svg>"); |
| 908 |
| 909 LayoutObject* target = getLayoutObjectByElementId("target"); |
| 910 LayoutBox* container = toLayoutBox(getLayoutObjectByElementId("container")); |
| 911 |
| 912 FloatPoint mappedPoint = mapLocalToAncestor(target, container, FloatPoint())
; |
| 913 EXPECT_EQ(FloatPoint(200, 240), mappedPoint); |
| 914 mappedPoint = mapAncestorToLocal(target, container, mappedPoint); |
| 915 EXPECT_EQ(FloatPoint(), mappedPoint); |
| 916 } |
| 917 |
| 918 TEST_F(MapCoordinatesTest, SVGShapeWithViewBoxWithoutScale) |
| 919 { |
| 920 setBodyInnerHTML( |
| 921 "<svg id='container' viewBox='0 0 200 200' width='400' height='200'>" |
| 922 " <g transform='translate(100 50)'>" |
| 923 " <rect id='target' width='100' height='100'/>" |
| 924 " </g>" |
| 925 "</svg>"); |
| 926 |
| 927 LayoutObject* target = getLayoutObjectByElementId("target"); |
| 928 LayoutBox* container = toLayoutBox(getLayoutObjectByElementId("container")); |
| 929 |
| 930 FloatPoint mappedPoint = mapLocalToAncestor(target, container, FloatPoint())
; |
| 931 EXPECT_EQ(FloatPoint(200, 50), mappedPoint); |
| 932 mappedPoint = mapAncestorToLocal(target, container, mappedPoint); |
| 933 EXPECT_EQ(FloatPoint(), mappedPoint); |
| 934 } |
| 935 |
| 936 TEST_F(MapCoordinatesTest, SVGShapeWithViewBoxWithScale) |
| 937 { |
| 938 setBodyInnerHTML( |
| 939 "<svg id='container' viewBox='0 0 100 100' width='400' height='200'>" |
| 940 " <g transform='translate(50 50)'>" |
| 941 " <rect id='target' width='100' height='100'/>" |
| 942 " </g>" |
| 943 "</svg>"); |
| 944 |
| 945 LayoutObject* target = getLayoutObjectByElementId("target"); |
| 946 LayoutBox* container = toLayoutBox(getLayoutObjectByElementId("container")); |
| 947 |
| 948 FloatPoint mappedPoint = mapLocalToAncestor(target, container, FloatPoint())
; |
| 949 EXPECT_EQ(FloatPoint(200, 100), mappedPoint); |
| 950 mappedPoint = mapAncestorToLocal(target, container, mappedPoint); |
| 951 EXPECT_EQ(FloatPoint(), mappedPoint); |
| 952 } |
| 953 |
| 954 TEST_F(MapCoordinatesTest, SVGForeignObject) |
| 955 { |
| 956 setBodyInnerHTML( |
| 957 "<svg id='container' viewBox='0 0 100 100' width='400' height='200'>" |
| 958 " <g transform='translate(50 50)'>" |
| 959 " <foreignObject transform='translate(-25 -25)'>" |
| 960 " <div xmlns='http://www.w3.org/1999/xhtml' id='target' style
='margin-left: 50px; border: 42px; padding: 84px; width: 50px; height: 50px'>" |
| 961 " </div>" |
| 962 " </foreignObject>" |
| 963 " </g>" |
| 964 "</svg>"); |
| 965 |
| 966 LayoutObject* target = getLayoutObjectByElementId("target"); |
| 967 LayoutBox* container = toLayoutBox(getLayoutObjectByElementId("container")); |
| 968 |
| 969 FloatPoint mappedPoint = mapLocalToAncestor(target, container, FloatPoint())
; |
| 970 EXPECT_EQ(FloatPoint(250, 50), mappedPoint); |
| 971 // <svg> |
| 972 mappedPoint = mapAncestorToLocal(target->parent()->parent()->parent(), conta
iner, FloatPoint(250, 50)); |
| 973 EXPECT_EQ(FloatPoint(250, 50), mappedPoint); |
| 974 // <g> |
| 975 mappedPoint = mapAncestorToLocal(target->parent()->parent(), container, Floa
tPoint(250, 50)); |
| 976 EXPECT_EQ(FloatPoint(25, -25), mappedPoint); |
| 977 // <foreignObject> |
| 978 mappedPoint = mapAncestorToLocal(target->parent(), container, FloatPoint(250
, 50)); |
| 979 EXPECT_EQ(FloatPoint(50, 0), mappedPoint); |
| 980 // <div> |
| 981 mappedPoint = mapAncestorToLocal(target, container, FloatPoint(250, 50)); |
| 982 EXPECT_EQ(FloatPoint(), mappedPoint); |
| 983 } |
| 984 |
882 } // namespace blink | 985 } // namespace blink |
OLD | NEW |