| 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/LayoutView.h" | 7 #include "core/layout/LayoutView.h" |
| 8 #include "core/paint/ObjectPaintProperties.h" | 8 #include "core/paint/ObjectPaintProperties.h" |
| 9 #include "platform/graphics/paint/TransformPaintPropertyNode.h" | 9 #include "platform/graphics/paint/TransformPaintPropertyNode.h" |
| 10 #include "platform/testing/UnitTestHelpers.h" | 10 #include "platform/testing/UnitTestHelpers.h" |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 EXPECT_EQ(TransformationMatrix().translate(70, 25), svgRootWith3dTransformPr
operties->paintOffsetTranslation()->matrix()); | 410 EXPECT_EQ(TransformationMatrix().translate(70, 25), svgRootWith3dTransformPr
operties->paintOffsetTranslation()->matrix()); |
| 411 EXPECT_EQ(document().view()->scrollTranslation(), svgRootWith3dTransformProp
erties->paintOffsetTranslation()->parent()); | 411 EXPECT_EQ(document().view()->scrollTranslation(), svgRootWith3dTransformProp
erties->paintOffsetTranslation()->parent()); |
| 412 | 412 |
| 413 LayoutObject& rectWith2dTransform = *document().getElementById("rectWith2dTr
ansform")->layoutObject(); | 413 LayoutObject& rectWith2dTransform = *document().getElementById("rectWith2dTr
ansform")->layoutObject(); |
| 414 ObjectPaintProperties* rectWith2dTransformProperties = rectWith2dTransform.o
bjectPaintProperties(); | 414 ObjectPaintProperties* rectWith2dTransformProperties = rectWith2dTransform.o
bjectPaintProperties(); |
| 415 TransformationMatrix matrix; | 415 TransformationMatrix matrix; |
| 416 matrix.translate(100, 100); | 416 matrix.translate(100, 100); |
| 417 matrix.rotate(45); | 417 matrix.rotate(45); |
| 418 // SVG's transform origin is baked into the transform. | 418 // SVG's transform origin is baked into the transform. |
| 419 matrix.applyTransformOrigin(50, 25, 0); | 419 matrix.applyTransformOrigin(50, 25, 0); |
| 420 EXPECT_EQ(matrix, rectWith2dTransformProperties->svgLocalTransform()->matrix
()); | 420 EXPECT_EQ(matrix, rectWith2dTransformProperties->transform()->matrix()); |
| 421 EXPECT_EQ(FloatPoint3D(0, 0, 0), rectWith2dTransformProperties->svgLocalTran
sform()->origin()); | 421 EXPECT_EQ(FloatPoint3D(0, 0, 0), rectWith2dTransformProperties->transform()-
>origin()); |
| 422 // SVG does not use paint offset. | 422 // SVG does not use paint offset. |
| 423 EXPECT_EQ(nullptr, rectWith2dTransformProperties->paintOffsetTranslation()); | 423 EXPECT_EQ(nullptr, rectWith2dTransformProperties->paintOffsetTranslation()); |
| 424 } | 424 } |
| 425 | 425 |
| 426 TEST_F(PaintPropertyTreeBuilderTest, SVGViewBoxTransform) | 426 TEST_F(PaintPropertyTreeBuilderTest, SVGViewBoxTransform) |
| 427 { | 427 { |
| 428 setBodyInnerHTML( | 428 setBodyInnerHTML( |
| 429 "<style>" | 429 "<style>" |
| 430 " body {" | 430 " body {" |
| 431 " margin: 0px;" | 431 " margin: 0px;" |
| 432 " }" | 432 " }" |
| 433 " svg {" | 433 " svg {" |
| 434 " transform: translate3d(1px, 2px, 3px);" | 434 " transform: translate3d(1px, 2px, 3px);" |
| 435 " position: absolute;" | 435 " position: absolute;" |
| 436 " }" | 436 " }" |
| 437 " rect {" | 437 " rect {" |
| 438 " transform: translate(100px, 100px);" | 438 " transform: translate(100px, 100px);" |
| 439 " }" | 439 " }" |
| 440 "</style>" | 440 "</style>" |
| 441 "<svg id='svgWithViewBox' width='100px' height='100px' viewBox='50 50 10
0 100'>" | 441 "<svg id='svgWithViewBox' width='100px' height='100px' viewBox='50 50 10
0 100'>" |
| 442 " <rect id='rect' width='100px' height='100px' />" | 442 " <rect id='rect' width='100px' height='100px' />" |
| 443 "</svg>"); | 443 "</svg>"); |
| 444 | 444 |
| 445 LayoutObject& svgWithViewBox = *document().getElementById("svgWithViewBox")-
>layoutObject(); | 445 LayoutObject& svgWithViewBox = *document().getElementById("svgWithViewBox")-
>layoutObject(); |
| 446 ObjectPaintProperties* svgWithViewBoxProperties = svgWithViewBox.objectPaint
Properties(); | 446 ObjectPaintProperties* svgWithViewBoxProperties = svgWithViewBox.objectPaint
Properties(); |
| 447 EXPECT_EQ(TransformationMatrix().translate3d(1, 2, 3), svgWithViewBoxPropert
ies->transform()->matrix()); | 447 EXPECT_EQ(TransformationMatrix().translate3d(1, 2, 3), svgWithViewBoxPropert
ies->transform()->matrix()); |
| 448 EXPECT_EQ(TransformationMatrix().translate(-50, -50), svgWithViewBoxProperti
es->svgLocalTransform()->matrix()); | 448 EXPECT_EQ(TransformationMatrix().translate(-50, -50), svgWithViewBoxProperti
es->svgLocalToBorderBoxTransform()->matrix()); |
| 449 EXPECT_EQ(svgWithViewBoxProperties->svgLocalTransform()->parent(), svgWithVi
ewBoxProperties->transform()); | 449 EXPECT_EQ(svgWithViewBoxProperties->svgLocalToBorderBoxTransform()->parent()
, svgWithViewBoxProperties->transform()); |
| 450 | 450 |
| 451 LayoutObject& rect = *document().getElementById("rect")->layoutObject(); | 451 LayoutObject& rect = *document().getElementById("rect")->layoutObject(); |
| 452 ObjectPaintProperties* rectProperties = rect.objectPaintProperties(); | 452 ObjectPaintProperties* rectProperties = rect.objectPaintProperties(); |
| 453 EXPECT_EQ(TransformationMatrix().translate(100, 100), rectProperties->svgLoc
alTransform()->matrix()); | 453 EXPECT_EQ(TransformationMatrix().translate(100, 100), rectProperties->transf
orm()->matrix()); |
| 454 EXPECT_EQ(svgWithViewBoxProperties->svgLocalTransform(), rectProperties->svg
LocalTransform()->parent()); | 454 EXPECT_EQ(svgWithViewBoxProperties->svgLocalToBorderBoxTransform(), rectProp
erties->transform()->parent()); |
| 455 } | 455 } |
| 456 | 456 |
| 457 TEST_F(PaintPropertyTreeBuilderTest, SVGRootPaintOffsetTransformNode) | 457 TEST_F(PaintPropertyTreeBuilderTest, SVGRootPaintOffsetTransformNode) |
| 458 { | 458 { |
| 459 setBodyInnerHTML( | 459 setBodyInnerHTML( |
| 460 "<style>body { margin: 0px; } </style>" | 460 "<style>body { margin: 0px; } </style>" |
| 461 "<svg id='svg' style='margin-left: 50px; margin-top: 25px; width: 100px;
height: 100px;' />"); | 461 "<svg id='svg' style='margin-left: 50px; margin-top: 25px; width: 100px;
height: 100px;' />"); |
| 462 | 462 |
| 463 LayoutObject& svg = *document().getElementById("svg")->layoutObject(); | 463 LayoutObject& svg = *document().getElementById("svg")->layoutObject(); |
| 464 ObjectPaintProperties* svgProperties = svg.objectPaintProperties(); | 464 ObjectPaintProperties* svgProperties = svg.objectPaintProperties(); |
| 465 // Ensure that a paint offset transform is emitted for SVG, even without a C
SS transform. | 465 // Ensure that a paint offset transform is not unnecessarily emitted. |
| 466 EXPECT_EQ(nullptr, svgProperties->transform()); | 466 EXPECT_EQ(nullptr, svgProperties->paintOffsetTranslation()); |
| 467 EXPECT_EQ(TransformationMatrix().translate(50, 25), svgProperties->paintOffs
etTranslation()->matrix()); | 467 EXPECT_EQ(TransformationMatrix().translate(50, 25), svgProperties->svgLocalT
oBorderBoxTransform()->matrix()); |
| 468 EXPECT_EQ(document().view()->scrollTranslation(), svgProperties->paintOffset
Translation()->parent()); | 468 EXPECT_EQ(document().view()->scrollTranslation(), svgProperties->svgLocalToB
orderBoxTransform()->parent()); |
| 469 } |
| 470 |
| 471 TEST_F(PaintPropertyTreeBuilderTest, SVGRootLocalToBorderBoxTransformNode) |
| 472 { |
| 473 setBodyInnerHTML( |
| 474 "<style>" |
| 475 " body { margin: 0px; }" |
| 476 " svg { margin-left: 2px; margin-top: 3px; transform: translate(5px, 7p
x); border: 11px solid green; }" |
| 477 "</style>" |
| 478 "<svg id='svg' width='100px' height='100px' viewBox='0 0 13 13'>" |
| 479 " <rect id='rect' transform='translate(17 19)' />" |
| 480 "</svg>"); |
| 481 |
| 482 LayoutObject& svg = *document().getElementById("svg")->layoutObject(); |
| 483 ObjectPaintProperties* svgProperties = svg.objectPaintProperties(); |
| 484 EXPECT_EQ(TransformationMatrix().translate(2, 3), svgProperties->paintOffset
Translation()->matrix()); |
| 485 EXPECT_EQ(TransformationMatrix().translate(5, 7), svgProperties->transform()
->matrix()); |
| 486 EXPECT_EQ(TransformationMatrix().translate(11, 11).scale(100.0 / 13.0), svgP
roperties->svgLocalToBorderBoxTransform()->matrix()); |
| 487 EXPECT_EQ(svgProperties->paintOffsetTranslation(), svgProperties->transform(
)->parent()); |
| 488 EXPECT_EQ(svgProperties->transform(), svgProperties->svgLocalToBorderBoxTran
sform()->parent()); |
| 489 |
| 490 // Ensure the rect's transform is a child of the local to border box transfo
rm. |
| 491 LayoutObject& rect = *document().getElementById("rect")->layoutObject(); |
| 492 ObjectPaintProperties* rectProperties = rect.objectPaintProperties(); |
| 493 EXPECT_EQ(TransformationMatrix().translate(17, 19), rectProperties->transfor
m()->matrix()); |
| 494 EXPECT_EQ(svgProperties->svgLocalToBorderBoxTransform(), rectProperties->tra
nsform()->parent()); |
| 495 } |
| 496 |
| 497 TEST_F(PaintPropertyTreeBuilderTest, SVGNestedViewboxTransforms) |
| 498 { |
| 499 setBodyInnerHTML( |
| 500 "<style>body { margin: 0px; } </style>" |
| 501 "<svg id='svg' width='100px' height='100px' viewBox='0 0 50 50' style='t
ransform: translate(11px, 11px);'>" |
| 502 " <svg id='nestedSvg' width='50px' height='50px' viewBox='0 0 5 5'>" |
| 503 " <rect id='rect' transform='translate(13 13)' />" |
| 504 " </svg>" |
| 505 "</svg>"); |
| 506 |
| 507 LayoutObject& svg = *document().getElementById("svg")->layoutObject(); |
| 508 ObjectPaintProperties* svgProperties = svg.objectPaintProperties(); |
| 509 EXPECT_EQ(TransformationMatrix().translate(11, 11), svgProperties->transform
()->matrix()); |
| 510 EXPECT_EQ(TransformationMatrix().scale(2), svgProperties->svgLocalToBorderBo
xTransform()->matrix()); |
| 511 |
| 512 LayoutObject& nestedSvg = *document().getElementById("nestedSvg")->layoutObj
ect(); |
| 513 ObjectPaintProperties* nestedSvgProperties = nestedSvg.objectPaintProperties
(); |
| 514 EXPECT_EQ(TransformationMatrix().scale(10), nestedSvgProperties->transform()
->matrix()); |
| 515 EXPECT_EQ(nullptr, nestedSvgProperties->svgLocalToBorderBoxTransform()); |
| 516 EXPECT_EQ(svgProperties->svgLocalToBorderBoxTransform(), nestedSvgProperties
->transform()->parent()); |
| 517 |
| 518 LayoutObject& rect = *document().getElementById("rect")->layoutObject(); |
| 519 ObjectPaintProperties* rectProperties = rect.objectPaintProperties(); |
| 520 EXPECT_EQ(TransformationMatrix().translate(13, 13), rectProperties->transfor
m()->matrix()); |
| 521 EXPECT_EQ(nestedSvgProperties->transform(), rectProperties->transform()->par
ent()); |
| 469 } | 522 } |
| 470 | 523 |
| 471 TEST_F(PaintPropertyTreeBuilderTest, TransformNodesAcrossSVGHTMLBoundary) | 524 TEST_F(PaintPropertyTreeBuilderTest, TransformNodesAcrossSVGHTMLBoundary) |
| 472 { | 525 { |
| 473 setBodyInnerHTML( | 526 setBodyInnerHTML( |
| 474 "<style> body { margin: 0px; } </style>" | 527 "<style> body { margin: 0px; } </style>" |
| 475 "<svg id='svgWithTransform' style='transform: translate3d(1px, 2px, 3px)
;'>" | 528 "<svg id='svgWithTransform' style='transform: translate3d(1px, 2px, 3px)
;'>" |
| 476 " <foreignObject>" | 529 " <foreignObject>" |
| 477 " <body>" | 530 " <body>" |
| 478 " <div id='divWithTransform' style='transform: translate3d(3px, 4px
, 5px);'></div>" | 531 " <div id='divWithTransform' style='transform: translate3d(3px, 4px
, 5px);'></div>" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 504 " </foreignObject>" | 557 " </foreignObject>" |
| 505 " </g>" | 558 " </g>" |
| 506 "</svg>"); | 559 "</svg>"); |
| 507 | 560 |
| 508 LayoutObject& svg = *document().getElementById("svg")->layoutObject(); | 561 LayoutObject& svg = *document().getElementById("svg")->layoutObject(); |
| 509 ObjectPaintProperties* svgProperties = svg.objectPaintProperties(); | 562 ObjectPaintProperties* svgProperties = svg.objectPaintProperties(); |
| 510 EXPECT_EQ(TransformationMatrix().translate3d(1, 2, 3), svgProperties->transf
orm()->matrix()); | 563 EXPECT_EQ(TransformationMatrix().translate3d(1, 2, 3), svgProperties->transf
orm()->matrix()); |
| 511 | 564 |
| 512 LayoutObject& container = *document().getElementById("container")->layoutObj
ect(); | 565 LayoutObject& container = *document().getElementById("container")->layoutObj
ect(); |
| 513 ObjectPaintProperties* containerProperties = container.objectPaintProperties
(); | 566 ObjectPaintProperties* containerProperties = container.objectPaintProperties
(); |
| 514 EXPECT_EQ(TransformationMatrix().translate(20, 30), containerProperties->svg
LocalTransform()->matrix()); | 567 EXPECT_EQ(TransformationMatrix().translate(20, 30), containerProperties->tra
nsform()->matrix()); |
| 515 EXPECT_EQ(svgProperties->transform(), containerProperties->svgLocalTransform
()->parent()); | 568 EXPECT_EQ(svgProperties->transform(), containerProperties->transform()->pare
nt()); |
| 516 | 569 |
| 517 Element* fixed = document().getElementById("fixed"); | 570 Element* fixed = document().getElementById("fixed"); |
| 518 ObjectPaintProperties* fixedProperties = fixed->layoutObject()->objectPaintP
roperties(); | 571 ObjectPaintProperties* fixedProperties = fixed->layoutObject()->objectPaintP
roperties(); |
| 519 EXPECT_EQ(TransformationMatrix().translate(200, 150), fixedProperties->paint
OffsetTranslation()->matrix()); | 572 EXPECT_EQ(TransformationMatrix().translate(200, 150), fixedProperties->paint
OffsetTranslation()->matrix()); |
| 520 // Ensure the fixed position element is rooted at the nearest transform cont
ainer. | 573 // Ensure the fixed position element is rooted at the nearest transform cont
ainer. |
| 521 EXPECT_EQ(containerProperties->svgLocalTransform(), fixedProperties->paintOf
fsetTranslation()->parent()); | 574 EXPECT_EQ(containerProperties->transform(), fixedProperties->paintOffsetTran
slation()->parent()); |
| 522 } | 575 } |
| 523 | 576 |
| 524 TEST_F(PaintPropertyTreeBuilderTest, ControlClip) | 577 TEST_F(PaintPropertyTreeBuilderTest, ControlClip) |
| 525 { | 578 { |
| 526 setBodyInnerHTML( | 579 setBodyInnerHTML( |
| 527 "<style>" | 580 "<style>" |
| 528 " body {" | 581 " body {" |
| 529 " margin: 0;" | 582 " margin: 0;" |
| 530 " }" | 583 " }" |
| 531 " input {" | 584 " input {" |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 " <div id='spanner' style='column-span: all; opacity: 0.5; width: 100
px; height: 100px;'></div>" | 912 " <div id='spanner' style='column-span: all; opacity: 0.5; width: 100
px; height: 100px;'></div>" |
| 860 " </div>" | 913 " </div>" |
| 861 "</div>" | 914 "</div>" |
| 862 ); | 915 ); |
| 863 | 916 |
| 864 LayoutObject& spanner = *getLayoutObjectByElementId("spanner"); | 917 LayoutObject& spanner = *getLayoutObjectByElementId("spanner"); |
| 865 EXPECT_EQ(LayoutPoint(55, 44), spanner.objectPaintProperties()->localBorderB
oxProperties()->paintOffset); | 918 EXPECT_EQ(LayoutPoint(55, 44), spanner.objectPaintProperties()->localBorderB
oxProperties()->paintOffset); |
| 866 } | 919 } |
| 867 | 920 |
| 868 } // namespace blink | 921 } // namespace blink |
| OLD | NEW |