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 "config.h" | 5 #include "config.h" |
6 | 6 |
7 #include "core/layout/LayoutTestHelper.h" | 7 #include "core/layout/LayoutTestHelper.h" |
8 #include "core/layout/LayoutTreeAsText.h" | 8 #include "core/layout/LayoutTreeAsText.h" |
9 #include "core/layout/LayoutView.h" | 9 #include "core/layout/LayoutView.h" |
10 #include "core/paint/ObjectPaintProperties.h" | 10 #include "core/paint/ObjectPaintProperties.h" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 } | 185 } |
186 | 186 |
187 TEST_F(PaintPropertyTreeBuilderTest, NestedOpacityEffect) | 187 TEST_F(PaintPropertyTreeBuilderTest, NestedOpacityEffect) |
188 { | 188 { |
189 setBodyInnerHTML( | 189 setBodyInnerHTML( |
190 "<div id='nodeWithoutOpacity'>" | 190 "<div id='nodeWithoutOpacity'>" |
191 " <div id='childWithOpacity' style='opacity: 0.5'>" | 191 " <div id='childWithOpacity' style='opacity: 0.5'>" |
192 " <div id='grandChildWithoutOpacity'>" | 192 " <div id='grandChildWithoutOpacity'>" |
193 " <div id='greatGrandChildWithOpacity' style='opacity: 0.2'/>" | 193 " <div id='greatGrandChildWithOpacity' style='opacity: 0.2'/>" |
194 " </div>" | 194 " </div>" |
195 " </div" | 195 " </div>" |
196 "</div>"); | 196 "</div>"); |
197 | 197 |
198 LayoutObject& nodeWithoutOpacity = *document().getElementById("nodeWithoutOp acity")->layoutObject(); | 198 LayoutObject& nodeWithoutOpacity = *document().getElementById("nodeWithoutOp acity")->layoutObject(); |
199 ObjectPaintProperties* nodeWithoutOpacityProperties = nodeWithoutOpacity.obj ectPaintProperties(); | 199 ObjectPaintProperties* nodeWithoutOpacityProperties = nodeWithoutOpacity.obj ectPaintProperties(); |
200 EXPECT_EQ(nullptr, nodeWithoutOpacityProperties); | 200 EXPECT_EQ(nullptr, nodeWithoutOpacityProperties); |
201 | 201 |
202 LayoutObject& childWithOpacity = *document().getElementById("childWithOpacit y")->layoutObject(); | 202 LayoutObject& childWithOpacity = *document().getElementById("childWithOpacit y")->layoutObject(); |
203 ObjectPaintProperties* childWithOpacityProperties = childWithOpacity.objectP aintProperties(); | 203 ObjectPaintProperties* childWithOpacityProperties = childWithOpacity.objectP aintProperties(); |
204 EXPECT_EQ(0.5f, childWithOpacityProperties->effect()->opacity()); | 204 EXPECT_EQ(0.5f, childWithOpacityProperties->effect()->opacity()); |
205 // childWithOpacity is the root effect node. | 205 // childWithOpacity is the root effect node. |
206 EXPECT_EQ(nullptr, childWithOpacityProperties->effect()->parent()); | 206 EXPECT_EQ(nullptr, childWithOpacityProperties->effect()->parent()); |
207 | 207 |
208 LayoutObject& grandChildWithoutOpacity = *document().getElementById("grandCh ildWithoutOpacity")->layoutObject(); | 208 LayoutObject& grandChildWithoutOpacity = *document().getElementById("grandCh ildWithoutOpacity")->layoutObject(); |
209 EXPECT_EQ(nullptr, grandChildWithoutOpacity.objectPaintProperties()); | 209 EXPECT_EQ(nullptr, grandChildWithoutOpacity.objectPaintProperties()); |
210 | 210 |
211 LayoutObject& greatGrandChildWithOpacity = *document().getElementById("great GrandChildWithOpacity")->layoutObject(); | 211 LayoutObject& greatGrandChildWithOpacity = *document().getElementById("great GrandChildWithOpacity")->layoutObject(); |
212 ObjectPaintProperties* greatGrandChildWithOpacityProperties = greatGrandChil dWithOpacity.objectPaintProperties(); | 212 ObjectPaintProperties* greatGrandChildWithOpacityProperties = greatGrandChil dWithOpacity.objectPaintProperties(); |
213 EXPECT_EQ(0.2f, greatGrandChildWithOpacityProperties->effect()->opacity()); | 213 EXPECT_EQ(0.2f, greatGrandChildWithOpacityProperties->effect()->opacity()); |
214 EXPECT_EQ(childWithOpacityProperties->effect(), greatGrandChildWithOpacityPr operties->effect()->parent()); | 214 EXPECT_EQ(childWithOpacityProperties->effect(), greatGrandChildWithOpacityPr operties->effect()->parent()); |
215 } | 215 } |
216 | 216 |
217 TEST_F(PaintPropertyTreeBuilderTest, TransformNodeDoesNotAffectEffectNodes) | 217 TEST_F(PaintPropertyTreeBuilderTest, TransformNodeDoesNotAffectEffectNodes) |
218 { | 218 { |
219 setBodyInnerHTML( | 219 setBodyInnerHTML( |
220 "<div id='nodeWithOpacity' style='opacity: 0.6'>" | 220 "<div id='nodeWithOpacity' style='opacity: 0.6'>" |
221 " <div id='childWithTransform' style='transform: translate3d(10px, 10px , 0px);'>" | 221 " <div id='childWithTransform' style='transform: translate3d(10px, 10px , 0px);'>" |
222 " <div id='grandChildWithOpacity' style='opacity: 0.4'/>" | 222 " <div id='grandChildWithOpacity' style='opacity: 0.4'/>" |
223 " </div" | 223 " </div>" |
224 "</div>"); | 224 "</div>"); |
225 | 225 |
226 LayoutObject& nodeWithOpacity = *document().getElementById("nodeWithOpacity" )->layoutObject(); | 226 LayoutObject& nodeWithOpacity = *document().getElementById("nodeWithOpacity" )->layoutObject(); |
227 ObjectPaintProperties* nodeWithOpacityProperties = nodeWithOpacity.objectPai ntProperties(); | 227 ObjectPaintProperties* nodeWithOpacityProperties = nodeWithOpacity.objectPai ntProperties(); |
228 EXPECT_EQ(0.6f, nodeWithOpacityProperties->effect()->opacity()); | 228 EXPECT_EQ(0.6f, nodeWithOpacityProperties->effect()->opacity()); |
229 EXPECT_EQ(nullptr, nodeWithOpacityProperties->effect()->parent()); | 229 EXPECT_EQ(nullptr, nodeWithOpacityProperties->effect()->parent()); |
230 EXPECT_EQ(nullptr, nodeWithOpacityProperties->transform()); | 230 EXPECT_EQ(nullptr, nodeWithOpacityProperties->transform()); |
231 | 231 |
232 LayoutObject& childWithTransform = *document().getElementById("childWithTran sform")->layoutObject(); | 232 LayoutObject& childWithTransform = *document().getElementById("childWithTran sform")->layoutObject(); |
233 ObjectPaintProperties* childWithTransformProperties = childWithTransform.obj ectPaintProperties(); | 233 ObjectPaintProperties* childWithTransformProperties = childWithTransform.obj ectPaintProperties(); |
234 EXPECT_EQ(nullptr, childWithTransformProperties->effect()); | 234 EXPECT_EQ(nullptr, childWithTransformProperties->effect()); |
235 EXPECT_EQ(TransformationMatrix().translate(10, 10), childWithTransformProper ties->transform()->matrix()); | 235 EXPECT_EQ(TransformationMatrix().translate(10, 10), childWithTransformProper ties->transform()->matrix()); |
236 | 236 |
237 LayoutObject& grandChildWithOpacity = *document().getElementById("grandChild WithOpacity")->layoutObject(); | 237 LayoutObject& grandChildWithOpacity = *document().getElementById("grandChild WithOpacity")->layoutObject(); |
238 ObjectPaintProperties* grandChildWithOpacityProperties = grandChildWithOpaci ty.objectPaintProperties(); | 238 ObjectPaintProperties* grandChildWithOpacityProperties = grandChildWithOpaci ty.objectPaintProperties(); |
239 EXPECT_EQ(0.4f, grandChildWithOpacityProperties->effect()->opacity()); | 239 EXPECT_EQ(0.4f, grandChildWithOpacityProperties->effect()->opacity()); |
240 EXPECT_EQ(nodeWithOpacityProperties->effect(), grandChildWithOpacityProperti es->effect()->parent()); | 240 EXPECT_EQ(nodeWithOpacityProperties->effect(), grandChildWithOpacityProperti es->effect()->parent()); |
241 EXPECT_EQ(nullptr, grandChildWithOpacityProperties->transform()); | 241 EXPECT_EQ(nullptr, grandChildWithOpacityProperties->transform()); |
242 } | 242 } |
243 | 243 |
244 TEST_F(PaintPropertyTreeBuilderTest, EffectNodesAcrossStackingContext) | 244 TEST_F(PaintPropertyTreeBuilderTest, EffectNodesAcrossStackingContext) |
245 { | 245 { |
246 setBodyInnerHTML( | 246 setBodyInnerHTML( |
247 "<div id='nodeWithOpacity' style='opacity: 0.6'>" | 247 "<div id='nodeWithOpacity' style='opacity: 0.6'>" |
248 " <div id='childWithStackingContext' style='position:absolute;'>" | 248 " <div id='childWithStackingContext' style='position:absolute;'>" |
249 " <div id='grandChildWithOpacity' style='opacity: 0.4'/>" | 249 " <div id='grandChildWithOpacity' style='opacity: 0.4'/>" |
250 " </div" | 250 " </div>" |
251 "</div>"); | 251 "</div>"); |
252 | 252 |
253 LayoutObject& nodeWithOpacity = *document().getElementById("nodeWithOpacity" )->layoutObject(); | 253 LayoutObject& nodeWithOpacity = *document().getElementById("nodeWithOpacity" )->layoutObject(); |
254 ObjectPaintProperties* nodeWithOpacityProperties = nodeWithOpacity.objectPai ntProperties(); | 254 ObjectPaintProperties* nodeWithOpacityProperties = nodeWithOpacity.objectPai ntProperties(); |
255 EXPECT_EQ(0.6f, nodeWithOpacityProperties->effect()->opacity()); | 255 EXPECT_EQ(0.6f, nodeWithOpacityProperties->effect()->opacity()); |
256 EXPECT_EQ(nullptr, nodeWithOpacityProperties->effect()->parent()); | 256 EXPECT_EQ(nullptr, nodeWithOpacityProperties->effect()->parent()); |
257 EXPECT_EQ(nullptr, nodeWithOpacityProperties->transform()); | 257 EXPECT_EQ(nullptr, nodeWithOpacityProperties->transform()); |
258 | 258 |
259 LayoutObject& childWithStackingContext = *document().getElementById("childWi thStackingContext")->layoutObject(); | 259 LayoutObject& childWithStackingContext = *document().getElementById("childWi thStackingContext")->layoutObject(); |
260 EXPECT_EQ(nullptr, childWithStackingContext.objectPaintProperties()); | 260 EXPECT_EQ(nullptr, childWithStackingContext.objectPaintProperties()); |
261 | 261 |
262 LayoutObject& grandChildWithOpacity = *document().getElementById("grandChild WithOpacity")->layoutObject(); | 262 LayoutObject& grandChildWithOpacity = *document().getElementById("grandChild WithOpacity")->layoutObject(); |
263 ObjectPaintProperties* grandChildWithOpacityProperties = grandChildWithOpaci ty.objectPaintProperties(); | 263 ObjectPaintProperties* grandChildWithOpacityProperties = grandChildWithOpaci ty.objectPaintProperties(); |
264 EXPECT_EQ(0.4f, grandChildWithOpacityProperties->effect()->opacity()); | 264 EXPECT_EQ(0.4f, grandChildWithOpacityProperties->effect()->opacity()); |
265 EXPECT_EQ(nodeWithOpacityProperties->effect(), grandChildWithOpacityProperti es->effect()->parent()); | 265 EXPECT_EQ(nodeWithOpacityProperties->effect(), grandChildWithOpacityProperti es->effect()->parent()); |
266 EXPECT_EQ(nullptr, grandChildWithOpacityProperties->transform()); | 266 EXPECT_EQ(nullptr, grandChildWithOpacityProperties->transform()); |
267 } | 267 } |
268 | 268 |
269 TEST_F(PaintPropertyTreeBuilderTest, EffectNodesInSVG) | |
270 { | |
271 setBodyInnerHTML( | |
272 "<svg id='svgRoot'>" | |
273 " <g id='groupWithOpacity' opacity='0.6'>" | |
274 " <rect id='rectWithoutOpacity' />" | |
275 " <rect id='rectWithOpacity' opacity='0.4' />" | |
276 " <text id='textWithOpacity' opacity='0.2'>" | |
277 " <tspan id='tspanWithOpacity' opacity='0.1' />" | |
278 " </text>" | |
279 " </g>" | |
280 "</svg>"); | |
281 | |
282 LayoutObject& groupWithOpacity = *document().getElementById("groupWithOpacit y")->layoutObject(); | |
283 ObjectPaintProperties* groupWithOpacityProperties = groupWithOpacity.objectP aintProperties(); | |
284 EXPECT_EQ(0.6f, groupWithOpacityProperties->effect()->opacity()); | |
285 EXPECT_EQ(nullptr, groupWithOpacityProperties->effect()->parent()); | |
286 | |
287 LayoutObject& rectWithoutOpacity = *document().getElementById("rectWithoutOp acity")->layoutObject(); | |
288 ObjectPaintProperties* rectWithoutOpacityProperties = rectWithoutOpacity.obj ectPaintProperties(); | |
289 EXPECT_EQ(nullptr, rectWithoutOpacityProperties); | |
290 | |
291 LayoutObject& rectWithOpacity = *document().getElementById("rectWithOpacity" )->layoutObject(); | |
292 ObjectPaintProperties* rectWithOpacityProperties = rectWithOpacity.objectPai ntProperties(); | |
293 EXPECT_EQ(0.4f, rectWithOpacityProperties->effect()->opacity()); | |
294 EXPECT_EQ(groupWithOpacityProperties->effect(), rectWithOpacityProperties->e ffect()->parent()); | |
295 | |
296 // Ensure that opacity nodes are created for LayoutSVGText which inherits fr om LayoutSVGBlock instead of LayoutSVGModelObject. | |
297 LayoutObject& textWithOpacity = *document().getElementById("textWithOpacity" )->layoutObject(); | |
298 ObjectPaintProperties* textWithOpacityProperties = textWithOpacity.objectPai ntProperties(); | |
299 EXPECT_EQ(0.2f, textWithOpacityProperties->effect()->opacity()); | |
300 EXPECT_EQ(groupWithOpacityProperties->effect(), textWithOpacityProperties->e ffect()->parent()); | |
301 | |
302 // Ensure that opacity nodes are created for LayoutSVGTSpan which inherits f rom LayoutSVGInline instead of LayoutSVGModelObject. | |
303 LayoutObject& tspanWithOpacity = *document().getElementById("tspanWithOpacit y")->layoutObject(); | |
304 ObjectPaintProperties* tspanWithOpacityProperties = tspanWithOpacity.objectP aintProperties(); | |
305 EXPECT_EQ(0.1f, tspanWithOpacityProperties->effect()->opacity()); | |
306 EXPECT_EQ(textWithOpacityProperties->effect(), tspanWithOpacityProperties->e ffect()->parent()); | |
307 } | |
308 | |
309 TEST_F(PaintPropertyTreeBuilderTest, EffectNodesAcrossHTMLSVGBoundary) | |
310 { | |
311 setBodyInnerHTML( | |
312 "<div id='divWithOpacity' style='opacity: 0.2;'>" | |
313 " <svg id='svgRootWithOpacity' style='opacity: 0.3;'>" | |
314 " <rect id='rectWithOpacity' opacity='0.4' />" | |
315 " </svg>" | |
316 "</div>"); | |
317 | |
318 LayoutObject& divWithOpacity = *document().getElementById("divWithOpacity")- >layoutObject(); | |
319 ObjectPaintProperties* divWithOpacityProperties = divWithOpacity.objectPaint Properties(); | |
320 EXPECT_EQ(0.2f, divWithOpacityProperties->effect()->opacity()); | |
321 EXPECT_EQ(nullptr, divWithOpacityProperties->effect()->parent()); | |
322 | |
323 LayoutObject& svgRootWithOpacity = *document().getElementById("svgRootWithOp acity")->layoutObject(); | |
324 ObjectPaintProperties* svgRootWithOpacityProperties = svgRootWithOpacity.obj ectPaintProperties(); | |
325 EXPECT_EQ(0.3f, svgRootWithOpacityProperties->effect()->opacity()); | |
326 EXPECT_EQ(divWithOpacityProperties->effect(), svgRootWithOpacityProperties-> effect()->parent()); | |
327 | |
328 LayoutObject& rectWithOpacity = *document().getElementById("rectWithOpacity" )->layoutObject(); | |
329 ObjectPaintProperties* rectWithOpacityProperties = rectWithOpacity.objectPai ntProperties(); | |
330 EXPECT_EQ(0.4f, rectWithOpacityProperties->effect()->opacity()); | |
331 EXPECT_EQ(svgRootWithOpacityProperties->effect(), rectWithOpacityProperties- >effect()->parent()); | |
332 } | |
333 | |
334 TEST_F(PaintPropertyTreeBuilderTest, EffectNodesAcrossSVGHTMLBoundary) | |
335 { | |
336 setBodyInnerHTML( | |
337 "<svg id='svgRootWithOpacity' style='opacity: 0.3;'>" | |
338 " <foreignObject id='foreignObjectWithOpacity' opacity='0.4'>" | |
339 " <body>" | |
340 " <span id='spanWithOpacity' style='opacity: 0.5'/>" | |
341 " </body>" | |
342 " </foreignObject>" | |
343 "</svg>"); | |
344 | |
345 LayoutObject& svgRootWithOpacity = *document().getElementById("svgRootWithOp acity")->layoutObject(); | |
346 ObjectPaintProperties* svgRootWithOpacityProperties = svgRootWithOpacity.obj ectPaintProperties(); | |
347 EXPECT_EQ(0.3f, svgRootWithOpacityProperties->effect()->opacity()); | |
348 EXPECT_EQ(nullptr, svgRootWithOpacityProperties->effect()->parent()); | |
349 | |
350 LayoutObject& foreignObjectWithOpacity = *document().getElementById("foreign ObjectWithOpacity")->layoutObject(); | |
351 ObjectPaintProperties* foreignObjectWithOpacityProperties = foreignObjectWit hOpacity.objectPaintProperties(); | |
352 EXPECT_EQ(0.4f, foreignObjectWithOpacityProperties->effect()->opacity()); | |
353 EXPECT_EQ(svgRootWithOpacityProperties->effect(), foreignObjectWithOpacityPr operties->effect()->parent()); | |
354 | |
355 LayoutObject& spanWithOpacity = *document().getElementById("spanWithOpacity" )->layoutObject(); | |
356 ObjectPaintProperties* spanWithOpacityProperties = spanWithOpacity.objectPai ntProperties(); | |
357 EXPECT_EQ(0.5f, spanWithOpacityProperties->effect()->opacity()); | |
358 EXPECT_EQ(foreignObjectWithOpacityProperties->effect(), spanWithOpacityPrope rties->effect()->parent()); | |
359 } | |
360 | |
361 TEST_F(PaintPropertyTreeBuilderTest, TransformNodesInSVG) | |
362 { | |
363 setBodyInnerHTML( | |
364 "<style>" | |
365 " body {" | |
366 " margin: 0px;" | |
367 " }" | |
368 " svg {" | |
369 " margin-left: 50px;" | |
370 " transform: translate3D(1px, 2px, 3px);" | |
jbroman
2015/11/20 19:09:20
super-nit: technically, "translate3d" (with a lowe
pdr.
2015/11/20 19:33:41
3done.
| |
371 " position: absolute;" | |
372 " left: 20px;" | |
373 " top: 25px;" | |
374 " }" | |
375 " rect {" | |
376 " transform: translate(100px, 100px) rotate(45deg);" | |
377 " transform-origin: 50px 25px;" | |
378 " }" | |
379 "</style>" | |
380 "<svg id='svgRootWith3dTransform' width='100px' height='100px'>" | |
381 " <rect id='rectWith2dTransform' width='100px' height='100px' />" | |
382 "</svg>"); | |
383 | |
384 LayoutObject& svgRootWith3dTransform = *document().getElementById("svgRootWi th3dTransform")->layoutObject(); | |
385 ObjectPaintProperties* svgRootWith3dTransformProperties = svgRootWith3dTrans form.objectPaintProperties(); | |
386 EXPECT_EQ(TransformationMatrix().translate3d(1, 2, 3), svgRootWith3dTransfor mProperties->transform()->matrix()); | |
387 EXPECT_EQ(FloatPoint3D(50, 50, 0), svgRootWith3dTransformProperties->transfo rm()->origin()); | |
388 EXPECT_EQ(svgRootWith3dTransformProperties->paintOffsetTranslation(), svgRoo tWith3dTransformProperties->transform()->parent()); | |
389 EXPECT_EQ(TransformationMatrix().translate(70, 25), svgRootWith3dTransformPr operties->paintOffsetTranslation()->matrix()); | |
390 EXPECT_EQ(document().view()->scrollTranslation(), svgRootWith3dTransformProp erties->paintOffsetTranslation()->parent()); | |
391 | |
392 LayoutObject& rectWith2dTransform = *document().getElementById("rectWith2dTr ansform")->layoutObject(); | |
393 ObjectPaintProperties* rectWith2dTransformProperties = rectWith2dTransform.o bjectPaintProperties(); | |
394 TransformationMatrix matrix; | |
395 matrix.translate(100, 100); | |
396 matrix.rotate(45); | |
397 // SVG's transform origin is baked into the transform. | |
398 matrix.applyTransformOrigin(50, 25, 0); | |
399 EXPECT_EQ(matrix, rectWith2dTransformProperties->transform()->matrix()); | |
400 EXPECT_EQ(FloatPoint3D(0, 0, 0), rectWith2dTransformProperties->transform()- >origin()); | |
401 // SVG does not use paint offset. | |
402 EXPECT_EQ(nullptr, rectWith2dTransformProperties->paintOffsetTranslation()); | |
403 } | |
404 | |
405 TEST_F(PaintPropertyTreeBuilderTest, SVGRootPaintOffsetTransformNode) | |
406 { | |
407 setBodyInnerHTML( | |
408 "<style>body { margin: 0px; }</style>" | |
409 "<svg id='svg' style='margin-left: 50px; margin-top: 25px; width: 100px; height: 100px;' />"); | |
410 | |
411 LayoutObject& svg = *document().getElementById("svg")->layoutObject(); | |
412 ObjectPaintProperties* svgProperties = svg.objectPaintProperties(); | |
413 // Ensure that a paint offset transform is emitted for SVG, even without a C SS transform. | |
414 EXPECT_EQ(nullptr, svgProperties->transform()); | |
415 EXPECT_EQ(TransformationMatrix().translate(50, 25), svgProperties->paintOffs etTranslation()->matrix()); | |
416 EXPECT_EQ(document().view()->scrollTranslation(), svgProperties->paintOffset Translation()->parent()); | |
417 } | |
418 | |
419 // TODO(pdr): Create a test for transform nodes crossing the svg->foreignObject boundary. | |
pdr.
2015/11/20 19:33:41
I'd like to do this (crbug.com/87072 will finally
| |
420 | |
269 } // namespace blink | 421 } // namespace blink |
OLD | NEW |