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/LayoutObject.h" | 5 #include "core/layout/LayoutObject.h" |
6 | 6 |
7 #include "core/layout/LayoutTestHelper.h" | 7 #include "core/layout/LayoutTestHelper.h" |
8 #include "core/layout/LayoutView.h" | 8 #include "core/layout/LayoutView.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 "</div>"); | 115 "</div>"); |
116 LayoutBlock* container = toLayoutBlock(getLayoutObjectByElementId("container ")); | 116 LayoutBlock* container = toLayoutBlock(getLayoutObjectByElementId("container ")); |
117 LayoutText* text = toLayoutText(container->lastChild()); | 117 LayoutText* text = toLayoutText(container->lastChild()); |
118 | 118 |
119 container->setScrollTop(LayoutUnit(50)); | 119 container->setScrollTop(LayoutUnit(50)); |
120 LayoutRect rect(0, 60, 20, 20); | 120 LayoutRect rect(0, 60, 20, 20); |
121 text->mapToVisibleRectInAncestorSpace(container, rect, nullptr); | 121 text->mapToVisibleRectInAncestorSpace(container, rect, nullptr); |
122 EXPECT_TRUE(rect == LayoutRect(0, 10, 20, 20)); | 122 EXPECT_TRUE(rect == LayoutRect(0, 10, 20, 20)); |
123 } | 123 } |
124 | 124 |
125 TEST_F(LayoutObjectTest, LocalToAbsoluteTransform) | |
126 { | |
127 setBodyInnerHTML( | |
128 "<div id='container' style='position: absolute; left: 0; top: 0;'>" | |
129 " <div id='scale' style='transform: scale(2.0); transform-origin: left top;'>" | |
130 " <div id='child'></div>" | |
131 " </div>" | |
132 "</div>"); | |
133 LayoutBoxModelObject* container = toLayoutBoxModelObject(getLayoutObjectByEl ementId("container")); | |
134 TransformationMatrix containerMatrix = container->localToAbsoluteTransform() ; | |
135 EXPECT_TRUE(containerMatrix.isIdentity()); | |
136 | |
137 LayoutObject* child = getLayoutObjectByElementId("child"); | |
138 TransformationMatrix childMatrix = child->localToAbsoluteTransform(); | |
139 EXPECT_FALSE(childMatrix.isIdentityOrTranslation()); | |
140 EXPECT_TRUE(childMatrix.isAffine()); | |
141 EXPECT_EQ(0.0, childMatrix.projectPoint(FloatPoint(0.0, 0.0)).x()); | |
142 EXPECT_EQ(0.0, childMatrix.projectPoint(FloatPoint(0.0, 0.0)).y()); | |
143 EXPECT_EQ(20.0, childMatrix.projectPoint(FloatPoint(10.0, 20.0)).x()); | |
144 EXPECT_EQ(40.0, childMatrix.projectPoint(FloatPoint(10.0, 20.0)).y()); | |
145 } | |
146 | |
147 TEST_F(LayoutObjectTest, LocalToAncestorTransform) | |
148 { | |
149 setBodyInnerHTML( | |
150 "<div id='container'>" | |
151 " <div id='rotate1' style='transform: rotate(45deg); transform-origin: left top;'>" | |
152 " <div id='rotate2' style='transform: rotate(90deg); transform-origin : left top;'>" | |
153 " <div id='child'></div>" | |
154 " </div>" | |
155 " </div>" | |
156 "</div>"); | |
157 LayoutBoxModelObject* container = toLayoutBoxModelObject(getLayoutObjectByEl ementId("container")); | |
158 LayoutBoxModelObject* rotate1 = toLayoutBoxModelObject(getLayoutObjectByElem entId("rotate1")); | |
159 LayoutBoxModelObject* rotate2 = toLayoutBoxModelObject(getLayoutObjectByElem entId("rotate2")); | |
160 LayoutObject* child = getLayoutObjectByElementId("child"); | |
161 TransformationMatrix matrix; | |
162 | |
163 matrix = child->localToAncestorTransform(rotate2); | |
164 EXPECT_TRUE(matrix.isIdentity()); | |
165 | |
166 // Allow a maximum error of half a pixel. | |
167 const float kMaxError = 0.5; | |
szager1
2016/03/08 23:34:15
Internally, TransformState uses LayoutUnit's. I k
dmazzoni
2016/03/09 18:14:59
Done.
| |
168 | |
169 // Sotate (100, 0) 90 degrees to (0, 100) | |
szager1
2016/03/08 23:34:15
typo
dmazzoni
2016/03/09 18:14:59
Done.
| |
170 matrix = child->localToAncestorTransform(rotate1); | |
171 EXPECT_FALSE(matrix.isIdentity()); | |
172 EXPECT_TRUE(matrix.isAffine()); | |
173 EXPECT_NEAR(0.0, matrix.projectPoint(FloatPoint(100.0, 0.0)).x(), kMaxError) ; | |
174 EXPECT_NEAR(100.0, matrix.projectPoint(FloatPoint(100.0, 0.0)).y(), kMaxErro r); | |
175 | |
176 // Rotate (100, 0) 135 degrees to (-70.7, 70.7) | |
177 matrix = child->localToAncestorTransform(container); | |
178 EXPECT_FALSE(matrix.isIdentity()); | |
179 EXPECT_TRUE(matrix.isAffine()); | |
180 EXPECT_NEAR(-70.7, matrix.projectPoint(FloatPoint(100.0, 0.0)).x(), kMaxErro r); | |
181 EXPECT_NEAR(70.7, matrix.projectPoint(FloatPoint(100.0, 0.0)).y(), kMaxError ); | |
182 } | |
183 | |
125 } // namespace blink | 184 } // namespace blink |
OLD | NEW |