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

Side by Side Diff: third_party/WebKit/Source/core/layout/MapCoordinatesTest.cpp

Issue 1777613002: Add localToAbsoluteTransform and localToAncestorTransform. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback about comments Created 4 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 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 1027 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 mappedPoint = mapAncestorToLocal(target->parent()->parent(), container, Floa tPoint(250, 50)); 1038 mappedPoint = mapAncestorToLocal(target->parent()->parent(), container, Floa tPoint(250, 50));
1039 EXPECT_EQ(FloatPoint(25, -25), mappedPoint); 1039 EXPECT_EQ(FloatPoint(25, -25), mappedPoint);
1040 // <foreignObject> 1040 // <foreignObject>
1041 mappedPoint = mapAncestorToLocal(target->parent(), container, FloatPoint(250 , 50)); 1041 mappedPoint = mapAncestorToLocal(target->parent(), container, FloatPoint(250 , 50));
1042 EXPECT_EQ(FloatPoint(50, 0), mappedPoint); 1042 EXPECT_EQ(FloatPoint(50, 0), mappedPoint);
1043 // <div> 1043 // <div>
1044 mappedPoint = mapAncestorToLocal(target, container, FloatPoint(250, 50)); 1044 mappedPoint = mapAncestorToLocal(target, container, FloatPoint(250, 50));
1045 EXPECT_EQ(FloatPoint(), mappedPoint); 1045 EXPECT_EQ(FloatPoint(), mappedPoint);
1046 } 1046 }
1047 1047
1048 TEST_F(MapCoordinatesTest, LocalToAbsoluteTransform)
1049 {
1050 setBodyInnerHTML(
1051 "<div id='container' style='position: absolute; left: 0; top: 0;'>"
1052 " <div id='scale' style='transform: scale(2.0); transform-origin: left top;'>"
1053 " <div id='child'></div>"
1054 " </div>"
1055 "</div>");
1056 LayoutBoxModelObject* container = toLayoutBoxModelObject(getLayoutObjectByEl ementId("container"));
1057 TransformationMatrix containerMatrix = container->localToAbsoluteTransform() ;
1058 EXPECT_TRUE(containerMatrix.isIdentity());
1059
1060 LayoutObject* child = getLayoutObjectByElementId("child");
1061 TransformationMatrix childMatrix = child->localToAbsoluteTransform();
1062 EXPECT_FALSE(childMatrix.isIdentityOrTranslation());
1063 EXPECT_TRUE(childMatrix.isAffine());
1064 EXPECT_EQ(0.0, childMatrix.projectPoint(FloatPoint(0.0, 0.0)).x());
1065 EXPECT_EQ(0.0, childMatrix.projectPoint(FloatPoint(0.0, 0.0)).y());
1066 EXPECT_EQ(20.0, childMatrix.projectPoint(FloatPoint(10.0, 20.0)).x());
1067 EXPECT_EQ(40.0, childMatrix.projectPoint(FloatPoint(10.0, 20.0)).y());
1068 }
1069
1070 TEST_F(MapCoordinatesTest, LocalToAncestorTransform)
1071 {
1072 setBodyInnerHTML(
1073 "<div id='container'>"
1074 " <div id='rotate1' style='transform: rotate(45deg); transform-origin: left top;'>"
1075 " <div id='rotate2' style='transform: rotate(90deg); transform-origin : left top;'>"
1076 " <div id='child'></div>"
1077 " </div>"
1078 " </div>"
1079 "</div>");
1080 LayoutBoxModelObject* container = toLayoutBoxModelObject(getLayoutObjectByEl ementId("container"));
1081 LayoutBoxModelObject* rotate1 = toLayoutBoxModelObject(getLayoutObjectByElem entId("rotate1"));
1082 LayoutBoxModelObject* rotate2 = toLayoutBoxModelObject(getLayoutObjectByElem entId("rotate2"));
1083 LayoutObject* child = getLayoutObjectByElementId("child");
1084 TransformationMatrix matrix;
1085
1086 matrix = child->localToAncestorTransform(rotate2);
1087 EXPECT_TRUE(matrix.isIdentity());
1088
1089 // Rotate (100, 0) 90 degrees to (0, 100)
1090 matrix = child->localToAncestorTransform(rotate1);
1091 EXPECT_FALSE(matrix.isIdentity());
1092 EXPECT_TRUE(matrix.isAffine());
1093 EXPECT_NEAR(0.0, matrix.projectPoint(FloatPoint(100.0, 0.0)).x(), LayoutUnit ::epsilon());
1094 EXPECT_NEAR(100.0, matrix.projectPoint(FloatPoint(100.0, 0.0)).y(), LayoutUn it::epsilon());
1095
1096 // Rotate (100, 0) 135 degrees to (-70.7, 70.7)
1097 matrix = child->localToAncestorTransform(container);
1098 EXPECT_FALSE(matrix.isIdentity());
1099 EXPECT_TRUE(matrix.isAffine());
1100 EXPECT_NEAR(-100.0 * sqrt(2.0) / 2.0, matrix.projectPoint(FloatPoint(100.0, 0.0)).x(), LayoutUnit::epsilon());
1101 EXPECT_NEAR(100.0 * sqrt(2.0) / 2.0, matrix.projectPoint(FloatPoint(100.0, 0 .0)).y(), LayoutUnit::epsilon());
1102 }
1103
1104 TEST_F(MapCoordinatesTest, LocalToAbsoluteTransformFlattens)
1105 {
1106 document().frame()->settings()->setAcceleratedCompositingEnabled(true);
1107 setBodyInnerHTML(
1108 "<div style='position: absolute; left: 0; top: 0;'>"
1109 " <div style='transform: rotateY(45deg); -webkit-transform-style:preser ve-3d;'>"
1110 " <div style='transform: rotateY(-45deg); -webkit-transform-style:pre serve-3d;'>"
1111 " <div id='child1'></div>"
1112 " </div>"
1113 " </div>"
1114 " <div style='transform: rotateY(45deg);'>"
1115 " <div style='transform: rotateY(-45deg);'>"
1116 " <div id='child2'></div>"
1117 " </div>"
1118 " </div>"
1119 "</div>");
1120 LayoutObject* child1 = getLayoutObjectByElementId("child1");
1121 LayoutObject* child2 = getLayoutObjectByElementId("child2");
1122 TransformationMatrix matrix;
1123
1124 matrix = child1->localToAbsoluteTransform();
1125
1126 // With child1, the rotations cancel and points should map basically back to themselves.
1127 EXPECT_NEAR(100.0, matrix.projectPoint(FloatPoint(100.0, 50.0)).x(), LayoutU nit::epsilon());
1128 EXPECT_NEAR(50.0, matrix.projectPoint(FloatPoint(100.0, 50.0)).y(), LayoutUn it::epsilon());
1129 EXPECT_NEAR(50.0, matrix.projectPoint(FloatPoint(50.0, 100.0)).x(), LayoutUn it::epsilon());
1130 EXPECT_NEAR(100.0, matrix.projectPoint(FloatPoint(50.0, 100.0)).y(), LayoutU nit::epsilon());
1131
1132 // With child2, each rotation gets flattened and the end result is approxima tely a 90-degree rotation.
1133 matrix = child2->localToAbsoluteTransform();
1134 EXPECT_NEAR(50.0, matrix.projectPoint(FloatPoint(100.0, 50.0)).x(), LayoutUn it::epsilon());
1135 EXPECT_NEAR(50.0, matrix.projectPoint(FloatPoint(100.0, 50.0)).y(), LayoutUn it::epsilon());
1136 EXPECT_NEAR(25.0, matrix.projectPoint(FloatPoint(50.0, 100.0)).x(), LayoutUn it::epsilon());
1137 EXPECT_NEAR(100.0, matrix.projectPoint(FloatPoint(50.0, 100.0)).y(), LayoutU nit::epsilon());
1138 }
1139
1048 } // namespace blink 1140 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/LayoutObject.cpp ('k') | third_party/WebKit/Source/platform/geometry/TransformState.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698