Chromium Code Reviews| 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) | |
|
chrishtr
2016/03/10 16:53:39
Put this in MapCoordinatesTest instead. The logic
dmazzoni
2016/03/14 20:10:37
Done.
| |
| 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 // Rotate (100, 0) 90 degrees to (0, 100) | |
| 167 matrix = child->localToAncestorTransform(rotate1); | |
| 168 EXPECT_FALSE(matrix.isIdentity()); | |
| 169 EXPECT_TRUE(matrix.isAffine()); | |
| 170 EXPECT_NEAR(0.0, matrix.projectPoint(FloatPoint(100.0, 0.0)).x(), LayoutUnit ::epsilon()); | |
| 171 EXPECT_NEAR(100.0, matrix.projectPoint(FloatPoint(100.0, 0.0)).y(), LayoutUn it::epsilon()); | |
| 172 | |
| 173 // Rotate (100, 0) 135 degrees to (-70.7, 70.7) | |
| 174 matrix = child->localToAncestorTransform(container); | |
| 175 EXPECT_FALSE(matrix.isIdentity()); | |
| 176 EXPECT_TRUE(matrix.isAffine()); | |
| 177 EXPECT_NEAR(-100.0 * sqrt(2.0) / 2.0, matrix.projectPoint(FloatPoint(100.0, 0.0)).x(), LayoutUnit::epsilon()); | |
| 178 EXPECT_NEAR(100.0 * sqrt(2.0) / 2.0, matrix.projectPoint(FloatPoint(100.0, 0 .0)).y(), LayoutUnit::epsilon()); | |
| 179 } | |
| 180 | |
| 125 } // namespace blink | 181 } // namespace blink |
| OLD | NEW |