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/LayoutTestHelper.h" | 5 #include "core/layout/LayoutTestHelper.h" |
6 #include "core/layout/LayoutTreeAsText.h" | 6 #include "core/layout/LayoutTreeAsText.h" |
7 #include "core/layout/api/LayoutViewItem.h" | 7 #include "core/layout/api/LayoutViewItem.h" |
8 #include "core/paint/ObjectPaintProperties.h" | 8 #include "core/paint/ObjectPaintProperties.h" |
9 #include "platform/graphics/paint/GeometryMapper.h" | 9 #include "platform/graphics/paint/GeometryMapper.h" |
10 #include "platform/graphics/paint/TransformPaintPropertyNode.h" | 10 #include "platform/graphics/paint/TransformPaintPropertyNode.h" |
(...skipping 1091 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 EXPECT_EQ(nullptr, svgWithTransformProperties->svgLocalToBorderBoxTransform(
)); | 1102 EXPECT_EQ(nullptr, svgWithTransformProperties->svgLocalToBorderBoxTransform(
)); |
1103 | 1103 |
1104 LayoutObject& rectWithTransform = *document().getElementById("rect")->layout
Object(); | 1104 LayoutObject& rectWithTransform = *document().getElementById("rect")->layout
Object(); |
1105 ObjectPaintProperties* rectWithTransformProperties = rectWithTransform.objec
tPaintProperties(); | 1105 ObjectPaintProperties* rectWithTransformProperties = rectWithTransform.objec
tPaintProperties(); |
1106 EXPECT_EQ(TransformationMatrix().translate(1, 1), rectWithTransformPropertie
s->transform()->matrix()); | 1106 EXPECT_EQ(TransformationMatrix().translate(1, 1), rectWithTransformPropertie
s->transform()->matrix()); |
1107 | 1107 |
1108 // Ensure there is no PaintOffset transform between the rect and the svg's t
ransform. | 1108 // Ensure there is no PaintOffset transform between the rect and the svg's t
ransform. |
1109 EXPECT_EQ(svgWithTransformProperties->transform(), rectWithTransformProperti
es->transform()->parent()); | 1109 EXPECT_EQ(svgWithTransformProperties->transform(), rectWithTransformProperti
es->transform()->parent()); |
1110 } | 1110 } |
1111 | 1111 |
| 1112 TEST_F(PaintPropertyTreeBuilderTest, NoRenderingContextByDefault) |
| 1113 { |
| 1114 setBodyInnerHTML("<div style=\"transform: translateZ(0)\"></div>"); |
| 1115 |
| 1116 ObjectPaintProperties* properties = document().body()->firstChild()->layoutO
bject()->objectPaintProperties(); |
| 1117 ASSERT_TRUE(properties->transform()); |
| 1118 EXPECT_FALSE(properties->transform()->hasRenderingContext()); |
| 1119 } |
| 1120 |
| 1121 TEST_F(PaintPropertyTreeBuilderTest, Preserve3DCreatesSharedRenderingContext) |
| 1122 { |
| 1123 setBodyInnerHTML( |
| 1124 "<div style=\"transform-style: preserve-3d\">" |
| 1125 " <div id=\"a\" style=\"transform: translateZ(0)\"></div>" |
| 1126 " <div id=\"b\" style=\"transform: translateZ(0)\"></div>" |
| 1127 "</div>"); |
| 1128 |
| 1129 ObjectPaintProperties* aProperties = document().getElementById("a")->layoutO
bject()->objectPaintProperties(); |
| 1130 ObjectPaintProperties* bProperties = document().getElementById("b")->layoutO
bject()->objectPaintProperties(); |
| 1131 ASSERT_TRUE(aProperties->transform() && bProperties->transform()); |
| 1132 EXPECT_NE(aProperties->transform(), bProperties->transform()); |
| 1133 EXPECT_TRUE(aProperties->transform()->hasRenderingContext()); |
| 1134 EXPECT_TRUE(bProperties->transform()->hasRenderingContext()); |
| 1135 EXPECT_EQ(aProperties->transform()->renderingContextID(), bProperties->trans
form()->renderingContextID()); |
| 1136 } |
| 1137 |
| 1138 TEST_F(PaintPropertyTreeBuilderTest, FlatTransformStyleEndsRenderingContext) |
| 1139 { |
| 1140 setBodyInnerHTML( |
| 1141 "<div style=\"transform-style: preserve-3d\">" |
| 1142 " <div id=\"a\" style=\"transform: translateZ(0)\">" |
| 1143 " <div id=\"b\" style=\"transform: translateZ(0)\"></div>" |
| 1144 " </div>" |
| 1145 "</div>"); |
| 1146 |
| 1147 ASSERT_FALSE(document().getElementById("a")->layoutObject()->styleRef().pres
erves3D()); |
| 1148 ObjectPaintProperties* aProperties = document().getElementById("a")->layoutO
bject()->objectPaintProperties(); |
| 1149 ObjectPaintProperties* bProperties = document().getElementById("b")->layoutO
bject()->objectPaintProperties(); |
| 1150 ASSERT_TRUE(aProperties->transform() && bProperties->transform()); |
| 1151 |
| 1152 // #a should participate in a rendering context (due to its parent), but its |
| 1153 // child #b should not. |
| 1154 EXPECT_TRUE(aProperties->transform()->hasRenderingContext()); |
| 1155 EXPECT_FALSE(bProperties->transform()->hasRenderingContext()); |
| 1156 } |
| 1157 |
| 1158 TEST_F(PaintPropertyTreeBuilderTest, NestedRenderingContexts) |
| 1159 { |
| 1160 setBodyInnerHTML( |
| 1161 "<div style=\"transform-style: preserve-3d\">" |
| 1162 " <div id=\"a\" style=\"transform: translateZ(0)\">" |
| 1163 " <div style=\"transform-style: preserve-3d\">" |
| 1164 " <div id=\"b\" style=\"transform: translateZ(0)\">" |
| 1165 " </div>" |
| 1166 " </div>" |
| 1167 "</div>"); |
| 1168 |
| 1169 ASSERT_FALSE(document().getElementById("a")->layoutObject()->styleRef().pres
erves3D()); |
| 1170 ObjectPaintProperties* aProperties = document().getElementById("a")->layoutO
bject()->objectPaintProperties(); |
| 1171 ObjectPaintProperties* bProperties = document().getElementById("b")->layoutO
bject()->objectPaintProperties(); |
| 1172 ASSERT_TRUE(aProperties->transform() && bProperties->transform()); |
| 1173 |
| 1174 // #a should participate in a rendering context (due to its parent). Its |
| 1175 // child does preserve 3D, but since #a does not, #a's rendering context is |
| 1176 // not passed on to its children. Thus #b ends up in a separate rendering |
| 1177 // context rooted at its parent. |
| 1178 EXPECT_TRUE(aProperties->transform()->hasRenderingContext()); |
| 1179 EXPECT_TRUE(bProperties->transform()->hasRenderingContext()); |
| 1180 EXPECT_NE(aProperties->transform()->renderingContextID(), bProperties->trans
form()->renderingContextID()); |
| 1181 } |
| 1182 |
| 1183 // Returns true if the first node has the second as an ancestor. |
| 1184 static bool nodeHasAncestor(const TransformPaintPropertyNode* node, const Transf
ormPaintPropertyNode* ancestor) |
| 1185 { |
| 1186 while (node) { |
| 1187 if (node == ancestor) |
| 1188 return true; |
| 1189 node = node->parent(); |
| 1190 } |
| 1191 return false; |
| 1192 } |
| 1193 |
| 1194 // Returns true if some node will flatten the transform due to |node| before it |
| 1195 // is inherited by |node| (including if node->flattensInheritedTransform()). |
| 1196 static bool someNodeFlattensTransform(const TransformPaintPropertyNode* node, co
nst TransformPaintPropertyNode* ancestor) |
| 1197 { |
| 1198 while (node != ancestor) { |
| 1199 if (node->flattensInheritedTransform()) |
| 1200 return true; |
| 1201 node = node->parent(); |
| 1202 } |
| 1203 return false; |
| 1204 } |
| 1205 |
| 1206 TEST_F(PaintPropertyTreeBuilderTest, FlatTransformStylePropagatesToChildren) |
| 1207 { |
| 1208 setBodyInnerHTML( |
| 1209 "<div id=\"a\" style=\"transform: translateZ(0); transform-style: flat\"
>" |
| 1210 " <div id=\"b\" style=\"transform: translateZ(0)\"></div>" |
| 1211 "</div>"); |
| 1212 |
| 1213 const auto* aTransform = document().getElementById("a")->layoutObject()->obj
ectPaintProperties()->transform(); |
| 1214 ASSERT_TRUE(aTransform); |
| 1215 const auto* bTransform = document().getElementById("b")->layoutObject()->obj
ectPaintProperties()->transform(); |
| 1216 ASSERT_TRUE(bTransform); |
| 1217 ASSERT_TRUE(nodeHasAncestor(bTransform, aTransform)); |
| 1218 |
| 1219 // Some node must flatten the inherited transform from #a before it reaches |
| 1220 // #b's transform. |
| 1221 EXPECT_TRUE(someNodeFlattensTransform(bTransform, aTransform)); |
| 1222 } |
| 1223 |
| 1224 TEST_F(PaintPropertyTreeBuilderTest, Preserve3DTransformStylePropagatesToChildre
n) |
| 1225 { |
| 1226 setBodyInnerHTML( |
| 1227 "<div id=\"a\" style=\"transform: translateZ(0); transform-style: preser
ve-3d\">" |
| 1228 " <div id=\"b\" style=\"transform: translateZ(0)\"></div>" |
| 1229 "</div>"); |
| 1230 |
| 1231 const auto* aTransform = document().getElementById("a")->layoutObject()->obj
ectPaintProperties()->transform(); |
| 1232 ASSERT_TRUE(aTransform); |
| 1233 const auto* bTransform = document().getElementById("b")->layoutObject()->obj
ectPaintProperties()->transform(); |
| 1234 ASSERT_TRUE(bTransform); |
| 1235 ASSERT_TRUE(nodeHasAncestor(bTransform, aTransform)); |
| 1236 |
| 1237 // No node may flatten the inherited transform from #a before it reaches |
| 1238 // #b's transform. |
| 1239 EXPECT_FALSE(someNodeFlattensTransform(bTransform, aTransform)); |
| 1240 } |
| 1241 |
| 1242 TEST_F(PaintPropertyTreeBuilderTest, PerspectiveIsNotFlattened) |
| 1243 { |
| 1244 // It's necessary to make nodes from the one that applies perspective to |
| 1245 // ones that combine with it preserve 3D. Otherwise, the perspective doesn't |
| 1246 // do anything. |
| 1247 setBodyInnerHTML( |
| 1248 "<div id=\"a\" style=\"perspective: 800px\">" |
| 1249 " <div id=\"b\" style=\"transform: translateZ(0)\"></div>" |
| 1250 "</div>"); |
| 1251 |
| 1252 ObjectPaintProperties* aProperties = document().getElementById("a")->layoutO
bject()->objectPaintProperties(); |
| 1253 ObjectPaintProperties* bProperties = document().getElementById("b")->layoutO
bject()->objectPaintProperties(); |
| 1254 const TransformPaintPropertyNode* aPerspective = aProperties->perspective(); |
| 1255 ASSERT_TRUE(aPerspective); |
| 1256 const TransformPaintPropertyNode* bTransform = bProperties->transform(); |
| 1257 ASSERT_TRUE(bTransform); |
| 1258 ASSERT_TRUE(nodeHasAncestor(bTransform, aPerspective)); |
| 1259 EXPECT_FALSE(someNodeFlattensTransform(bTransform, aPerspective)); |
| 1260 } |
| 1261 |
| 1262 TEST_F(PaintPropertyTreeBuilderTest, PerspectiveDoesNotEstablishRenderingContext
) |
| 1263 { |
| 1264 // It's necessary to make nodes from the one that applies perspective to |
| 1265 // ones that combine with it preserve 3D. Otherwise, the perspective doesn't |
| 1266 // do anything. |
| 1267 setBodyInnerHTML( |
| 1268 "<div id=\"a\" style=\"perspective: 800px\">" |
| 1269 " <div id=\"b\" style=\"transform: translateZ(0)\"></div>" |
| 1270 "</div>"); |
| 1271 |
| 1272 ObjectPaintProperties* aProperties = document().getElementById("a")->layoutO
bject()->objectPaintProperties(); |
| 1273 ObjectPaintProperties* bProperties = document().getElementById("b")->layoutO
bject()->objectPaintProperties(); |
| 1274 const TransformPaintPropertyNode* aPerspective = aProperties->perspective(); |
| 1275 ASSERT_TRUE(aPerspective); |
| 1276 EXPECT_FALSE(aPerspective->hasRenderingContext()); |
| 1277 const TransformPaintPropertyNode* bTransform = bProperties->transform(); |
| 1278 ASSERT_TRUE(bTransform); |
| 1279 EXPECT_FALSE(bTransform->hasRenderingContext()); |
| 1280 } |
| 1281 |
1112 TEST_F(PaintPropertyTreeBuilderTest, CachedProperties) | 1282 TEST_F(PaintPropertyTreeBuilderTest, CachedProperties) |
1113 { | 1283 { |
1114 setBodyInnerHTML( | 1284 setBodyInnerHTML( |
1115 "<div id='a' style='transform: translate(33px, 44px)'>" | 1285 "<div id='a' style='transform: translate(33px, 44px)'>" |
1116 " <div id='b' style='transform: translate(55px, 66px)'>" | 1286 " <div id='b' style='transform: translate(55px, 66px)'>" |
1117 " <div id='c' style='transform: translate(77px, 88px)'>C<div>" | 1287 " <div id='c' style='transform: translate(77px, 88px)'>C<div>" |
1118 " </div>" | 1288 " </div>" |
1119 "</div>"); | 1289 "</div>"); |
1120 | 1290 |
1121 Element* a = document().getElementById("a"); | 1291 Element* a = document().getElementById("a"); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1177 bTransformNode = bProperties->transform(); | 1347 bTransformNode = bProperties->transform(); |
1178 EXPECT_EQ(TransformationMatrix().translate(4, 5), bTransformNode->matrix()); | 1348 EXPECT_EQ(TransformationMatrix().translate(4, 5), bTransformNode->matrix()); |
1179 EXPECT_EQ(aTransformNode, bTransformNode->parent()); | 1349 EXPECT_EQ(aTransformNode, bTransformNode->parent()); |
1180 | 1350 |
1181 EXPECT_EQ(cProperties, c->layoutObject()->objectPaintProperties()); | 1351 EXPECT_EQ(cProperties, c->layoutObject()->objectPaintProperties()); |
1182 EXPECT_EQ(cTransformNode, cProperties->transform()); | 1352 EXPECT_EQ(cTransformNode, cProperties->transform()); |
1183 EXPECT_EQ(bTransformNode, cTransformNode->parent()); | 1353 EXPECT_EQ(bTransformNode, cTransformNode->parent()); |
1184 } | 1354 } |
1185 | 1355 |
1186 } // namespace blink | 1356 } // namespace blink |
OLD | NEW |