Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: third_party/WebKit/Source/core/paint/PaintPropertyTreeBuilderTest.cpp

Issue 2292273003: Define contentsProperties on ObjectPaintProperties, for use in paint invalidation. (Closed)
Patch Set: none Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "core/paint/PaintPropertyTreePrinter.h"
9 #include "platform/graphics/paint/GeometryMapper.h" 10 #include "platform/graphics/paint/GeometryMapper.h"
10 #include "platform/graphics/paint/TransformPaintPropertyNode.h" 11 #include "platform/graphics/paint/TransformPaintPropertyNode.h"
11 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h" 12 #include "platform/testing/RuntimeEnabledFeaturesTestHelpers.h"
12 #include "platform/testing/UnitTestHelpers.h" 13 #include "platform/testing/UnitTestHelpers.h"
13 #include "platform/text/TextStream.h" 14 #include "platform/text/TextStream.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 #include "wtf/HashMap.h" 16 #include "wtf/HashMap.h"
16 #include "wtf/Vector.h" 17 #include "wtf/Vector.h"
17 18
18 namespace blink { 19 namespace blink {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 97
97 #define CHECK_VISUAL_RECT(expected, sourceLayoutObject, ancestorLayoutObject, sl opFactor) \ 98 #define CHECK_VISUAL_RECT(expected, sourceLayoutObject, ancestorLayoutObject, sl opFactor) \
98 do { \ 99 do { \
99 GeometryMapper geometryMapper; \ 100 GeometryMapper geometryMapper; \
100 LayoutRect source((sourceLayoutObject)->localOverflowRectForPaintInvalidatio n()); \ 101 LayoutRect source((sourceLayoutObject)->localOverflowRectForPaintInvalidatio n()); \
101 source.moveBy((sourceLayoutObject)->objectPaintProperties()->localBorderBoxP roperties()->paintOffset); \ 102 source.moveBy((sourceLayoutObject)->objectPaintProperties()->localBorderBoxP roperties()->paintOffset); \
102 bool success = false; \ 103 bool success = false; \
103 FloatRect actual = geometryMapper.mapToVisualRectInDestinationSpace( \ 104 FloatRect actual = geometryMapper.mapToVisualRectInDestinationSpace( \
104 FloatRect(source), \ 105 FloatRect(source), \
105 (sourceLayoutObject)->objectPaintProperties()->localBorderBoxProperties( )->propertyTreeState, \ 106 (sourceLayoutObject)->objectPaintProperties()->localBorderBoxProperties( )->propertyTreeState, \
106 (ancestorLayoutObject)->objectPaintProperties()->localBorderBoxPropertie s()->propertyTreeState, success); \ 107 (ancestorLayoutObject)->objectPaintProperties()->contentsProperties(), s uccess); \
107 ASSERT_TRUE(success); \ 108 ASSERT_TRUE(success); \
108 EXPECT_EQ(expected, LayoutRect(actual)); \ 109 EXPECT_EQ(expected, LayoutRect(actual)) << "GeometryMapper: expected: " << e xpected.toString() << ", actual: " << actual.toString(); \
109 \ 110 \
110 if (slopFactor == LayoutUnit::max()) \ 111 if (slopFactor == LayoutUnit::max()) \
111 break; \ 112 break; \
112 LayoutRect slowPathRect = (sourceLayoutObject)->localOverflowRectForPaintInv alidation(); \ 113 LayoutRect slowPathRect = (sourceLayoutObject)->localOverflowRectForPaintInv alidation(); \
113 (sourceLayoutObject)->mapToVisualRectInAncestorSpace(ancestorLayoutObject, s lowPathRect); \ 114 (sourceLayoutObject)->mapToVisualRectInAncestorSpace(ancestorLayoutObject, s lowPathRect); \
114 if (slopFactor) { \ 115 if (slopFactor) { \
115 LayoutRect inflatedActual = LayoutRect(actual); \ 116 LayoutRect inflatedActual = LayoutRect(actual); \
116 inflatedActual.inflate(slopFactor); \ 117 inflatedActual.inflate(slopFactor); \
117 SCOPED_TRACE(String::format("Old path rect: %s, Actual: %s, Inflated act ual: %s", slowPathRect.toString().ascii().data(), actual.toString().ascii().data (), inflatedActual.toString().ascii().data())); \ 118 SCOPED_TRACE(String::format("Old path rect: %s, Actual: %s, Inflated act ual: %s", slowPathRect.toString().ascii().data(), actual.toString().ascii().data (), inflatedActual.toString().ascii().data())); \
118 EXPECT_TRUE(slowPathRect.contains(LayoutRect(actual))); \ 119 EXPECT_TRUE(slowPathRect.contains(LayoutRect(actual))); \
119 EXPECT_TRUE(inflatedActual.contains(slowPathRect)); \ 120 EXPECT_TRUE(inflatedActual.contains(slowPathRect)); \
120 } else { \ 121 } else { \
121 EXPECT_EQ(slowPathRect, LayoutRect(actual)); \ 122 EXPECT_EQ(expected, slowPathRect) << "Slow path: expected: " << slowPath Rect.toString() << ", actual: " << actual.toString().ascii().data(); \
122 } \ 123 } \
123 } while (0) 124 } while (0)
124 125
125 #define CHECK_EXACT_VISUAL_RECT(expected, sourceLayoutObject, ancestorLayoutObje ct) CHECK_VISUAL_RECT(expected, sourceLayoutObject, ancestorLayoutObject, 0) 126 #define CHECK_EXACT_VISUAL_RECT(expected, sourceLayoutObject, ancestorLayoutObje ct) CHECK_VISUAL_RECT(expected, sourceLayoutObject, ancestorLayoutObject, 0)
126 127
127 INSTANTIATE_TEST_CASE_P(All, PaintPropertyTreeBuilderTest, ::testing::Bool()); 128 INSTANTIATE_TEST_CASE_P(All, PaintPropertyTreeBuilderTest, ::testing::Bool());
128 129
129 TEST_P(PaintPropertyTreeBuilderTest, FixedPosition) 130 TEST_P(PaintPropertyTreeBuilderTest, FixedPosition)
130 { 131 {
131 loadTestData("fixed-position.html"); 132 loadTestData("fixed-position.html");
(...skipping 1449 matching lines...) Expand 10 before | Expand all | Expand 10 after
1581 1582
1582 EXPECT_EQ(cProperties, c->layoutObject()->objectPaintProperties()); 1583 EXPECT_EQ(cProperties, c->layoutObject()->objectPaintProperties());
1583 EXPECT_EQ(cTransformNode, cProperties->transform()); 1584 EXPECT_EQ(cTransformNode, cProperties->transform());
1584 EXPECT_EQ(bTransformNode, cTransformNode->parent()); 1585 EXPECT_EQ(bTransformNode, cTransformNode->parent());
1585 1586
1586 CHECK_EXACT_VISUAL_RECT(LayoutRect(33, 44, 50, 60), a->layoutObject(), frame View->layoutView()); 1587 CHECK_EXACT_VISUAL_RECT(LayoutRect(33, 44, 50, 60), a->layoutObject(), frame View->layoutView());
1587 CHECK_EXACT_VISUAL_RECT(LayoutRect(37, 49, 50, 20), b->layoutObject(), frame View->layoutView()); 1588 CHECK_EXACT_VISUAL_RECT(LayoutRect(37, 49, 50, 20), b->layoutObject(), frame View->layoutView());
1588 CHECK_EXACT_VISUAL_RECT(LayoutRect(114, 137, 10, 20), c->layoutObject(), fra meView->layoutView()); 1589 CHECK_EXACT_VISUAL_RECT(LayoutRect(114, 137, 10, 20), c->layoutObject(), fra meView->layoutView());
1589 } 1590 }
1590 1591
1592 TEST_P(PaintPropertyTreeBuilderTest, OverflowClipContentsProperties)
1593 {
1594 // This test verifies the tree builder correctly computes and records the pr operty tree context
1595 // for a (pseudo) stacking context that is scrolled by a containing block th at is not one of
1596 // the painting ancestors.
1597 setBodyInnerHTML(
1598 "<style>body { margin: 0; }</style>"
1599 "<div id='clipper' style='overflow:hidden; width:400px; height:300px;'>"
1600 " <div id='child' style='position:relative; width:500px; height: 600px; '></div>"
1601 "</div>"
1602 );
1603
1604 LayoutBoxModelObject* clipper = toLayoutBoxModelObject(document().getElement ById("clipper")->layoutObject());
1605 const ObjectPaintProperties* clipProperties = clipper->objectPaintProperties ();
1606 LayoutObject* child = document().getElementById("child")->layoutObject();
1607 const ObjectPaintProperties* childProperties = child->objectPaintProperties( );
1608
1609 EXPECT_EQ(frameScrollTranslation(), clipProperties->localBorderBoxProperties ()->propertyTreeState.transform);
1610 EXPECT_EQ(frameContentClip(), clipProperties->localBorderBoxProperties()->pr opertyTreeState.clip);
1611
1612 EXPECT_EQ(frameScrollTranslation(), clipProperties->contentsProperties().tra nsform);
1613 EXPECT_EQ(clipProperties->overflowClip(), clipProperties->contentsProperties ().clip);
1614
1615 EXPECT_EQ(frameScrollTranslation(), childProperties->localBorderBoxPropertie s()->propertyTreeState.transform);
1616 EXPECT_EQ(clipProperties->overflowClip(), childProperties->localBorderBoxPro perties()->propertyTreeState.clip);
1617
1618 EXPECT_NE(nullptr, childProperties->localBorderBoxProperties()->propertyTree State.effect);
1619 CHECK_EXACT_VISUAL_RECT(LayoutRect(0, 0, 500, 600), child, clipper);
1620 }
1621
1622 TEST_P(PaintPropertyTreeBuilderTest, OverflowScrollContentsProperties)
1623 {
1624 // This test verifies the tree builder correctly computes and records the pr operty tree context
1625 // for a (pseudo) stacking context that is scrolled by a containing block th at is not one of
1626 // the painting ancestors.
1627 setBodyInnerHTML(
1628 "<style>body { margin: 0; }</style>"
1629 "<div id='clipper' style='overflow:scroll; width:400px; height:300px;'>"
1630 " <div id='child' style='position:relative; width:500px; height: 600px; '></div>"
1631 " <div style='width: 200px; height: 10000px'>"
1632 "</div>"
1633 );
1634
1635 LayoutBoxModelObject* clipper = toLayoutBoxModelObject(document().getElement ById("clipper")->layoutObject());
szager1 2016/08/31 21:16:19 I'd like this test better if it had a call to docu
chrishtr 2016/09/01 16:56:22 Done.
1636 const ObjectPaintProperties* clipProperties = clipper->objectPaintProperties ();
1637 LayoutObject* child = document().getElementById("child")->layoutObject();
1638 const ObjectPaintProperties* childProperties = child->objectPaintProperties( );
1639
1640 EXPECT_EQ(frameScrollTranslation(), clipProperties->localBorderBoxProperties ()->propertyTreeState.transform);
1641 EXPECT_EQ(frameContentClip(), clipProperties->localBorderBoxProperties()->pr opertyTreeState.clip);
1642
1643 EXPECT_EQ(clipProperties->scrollTranslation(), clipProperties->contentsPrope rties().transform);
1644 EXPECT_EQ(clipProperties->overflowClip(), clipProperties->contentsProperties ().clip);
1645
1646 EXPECT_EQ(clipProperties->scrollTranslation(), childProperties->localBorderB oxProperties()->propertyTreeState.transform);
1647 EXPECT_EQ(clipProperties->overflowClip(), childProperties->localBorderBoxPro perties()->propertyTreeState.clip);
1648
1649 CHECK_EXACT_VISUAL_RECT(LayoutRect(0, 0, 500, 600), child, clipper);
1650 }
1651
1652 TEST_P(PaintPropertyTreeBuilderTest, CssClipContentsProperties)
1653 {
1654 // This test verifies the tree builder correctly computes and records the pr operty tree context
1655 // for a (pseudo) stacking context that is scrolled by a containing block th at is not one of
1656 // the painting ancestors.
1657 setBodyInnerHTML(
1658 "<style>body { margin: 0; }</style>"
1659 "<div id='clipper' style='position: absolute; clip: rect(10px, 80px, 70p x, 40px); width:400px; height:300px;'>"
1660 " <div id='child' style='position:relative; width:500px; height: 600px; '></div>"
1661 "</div>"
1662 );
1663
1664 LayoutBoxModelObject* clipper = toLayoutBoxModelObject(document().getElement ById("clipper")->layoutObject());
1665 const ObjectPaintProperties* clipProperties = clipper->objectPaintProperties ();
1666 LayoutObject* child = document().getElementById("child")->layoutObject();
1667
1668 EXPECT_EQ(frameScrollTranslation(), clipProperties->localBorderBoxProperties ()->propertyTreeState.transform);
1669 // CSS clip on an element causes it to clip itself, not just descendants.
1670 EXPECT_EQ(clipProperties->cssClip(), clipProperties->localBorderBoxPropertie s()->propertyTreeState.clip);
1671
1672 EXPECT_EQ(frameScrollTranslation(), clipProperties->contentsProperties().tra nsform);
1673 EXPECT_EQ(clipProperties->cssClip(), clipProperties->contentsProperties().cl ip);
1674
1675 CHECK_EXACT_VISUAL_RECT(LayoutRect(0, 0, 500, 600), child, clipper);
1676 }
1677
1678 TEST_P(PaintPropertyTreeBuilderTest, SvgLocalToBorderBoxTransformContentsPropert ies)
1679 {
1680 setBodyInnerHTML(
1681 "<style>"
1682 " body {"
1683 " margin: 0px;"
1684 " }"
1685 " svg {"
1686 " position: absolute;"
1687 " }"
1688 " rect {"
1689 " transform: translate(100px, 100px);"
1690 " }"
1691 "</style>"
1692 "<svg id='svgWithViewBox' width='100px' height='100px' viewBox='50 50 10 0 100'>"
1693 " <rect id='rect' width='100px' height='100px' />"
1694 "</svg>");
1695
1696 LayoutObject& svgWithViewBox = *document().getElementById("svgWithViewBox")- >layoutObject();
1697 const ObjectPaintProperties* svgWithViewBoxProperties = svgWithViewBox.objec tPaintProperties();
1698
1699 EXPECT_EQ(frameScrollTranslation(), svgWithViewBoxProperties->localBorderBox Properties()->propertyTreeState.transform);
1700 EXPECT_EQ(svgWithViewBoxProperties->svgLocalToBorderBoxTransform(), svgWithV iewBoxProperties->contentsProperties().transform);
1701 }
1702
1591 } // namespace blink 1703 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698