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

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
« no previous file with comments | « third_party/WebKit/Source/core/paint/PaintInvalidator.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 Settings::setMockScrollbarsEnabled(false); 94 Settings::setMockScrollbarsEnabled(false);
94 } 95 }
95 }; 96 };
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; \
104 PropertyTreeState contentsProperties; \
105 (ancestorLayoutObject)->objectPaintProperties()->getContentsProperties(conte ntsProperties); \
103 FloatRect actual = geometryMapper.mapToVisualRectInDestinationSpace( \ 106 FloatRect actual = geometryMapper.mapToVisualRectInDestinationSpace( \
104 FloatRect(source), \ 107 FloatRect(source), \
105 (sourceLayoutObject)->objectPaintProperties()->localBorderBoxProperties( )->propertyTreeState, \ 108 (sourceLayoutObject)->objectPaintProperties()->localBorderBoxProperties( )->propertyTreeState, \
106 (ancestorLayoutObject)->objectPaintProperties()->localBorderBoxPropertie s()->propertyTreeState, success); \ 109 contentsProperties, success); \
107 ASSERT_TRUE(success); \ 110 ASSERT_TRUE(success); \
108 EXPECT_EQ(expected, LayoutRect(actual)); \ 111 EXPECT_EQ(expected, LayoutRect(actual)) << "GeometryMapper: expected: " << e xpected.toString() << ", actual: " << actual.toString(); \
109 \ 112 \
110 if (slopFactor == LayoutUnit::max()) \ 113 if (slopFactor == LayoutUnit::max()) \
111 break; \ 114 break; \
112 LayoutRect slowPathRect = (sourceLayoutObject)->localOverflowRectForPaintInv alidation(); \ 115 LayoutRect slowPathRect = (sourceLayoutObject)->localOverflowRectForPaintInv alidation(); \
113 (sourceLayoutObject)->mapToVisualRectInAncestorSpace(ancestorLayoutObject, s lowPathRect); \ 116 (sourceLayoutObject)->mapToVisualRectInAncestorSpace(ancestorLayoutObject, s lowPathRect); \
114 if (slopFactor) { \ 117 if (slopFactor) { \
115 LayoutRect inflatedActual = LayoutRect(actual); \ 118 LayoutRect inflatedActual = LayoutRect(actual); \
116 inflatedActual.inflate(slopFactor); \ 119 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())); \ 120 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))); \ 121 EXPECT_TRUE(slowPathRect.contains(LayoutRect(actual))); \
119 EXPECT_TRUE(inflatedActual.contains(slowPathRect)); \ 122 EXPECT_TRUE(inflatedActual.contains(slowPathRect)); \
120 } else { \ 123 } else { \
121 EXPECT_EQ(slowPathRect, LayoutRect(actual)); \ 124 EXPECT_EQ(expected, slowPathRect) << "Slow path: expected: " << slowPath Rect.toString() << ", actual: " << actual.toString().ascii().data(); \
122 } \ 125 } \
123 } while (0) 126 } while (0)
124 127
125 #define CHECK_EXACT_VISUAL_RECT(expected, sourceLayoutObject, ancestorLayoutObje ct) CHECK_VISUAL_RECT(expected, sourceLayoutObject, ancestorLayoutObject, 0) 128 #define CHECK_EXACT_VISUAL_RECT(expected, sourceLayoutObject, ancestorLayoutObje ct) CHECK_VISUAL_RECT(expected, sourceLayoutObject, ancestorLayoutObject, 0)
126 129
127 INSTANTIATE_TEST_CASE_P(All, PaintPropertyTreeBuilderTest, ::testing::Bool()); 130 INSTANTIATE_TEST_CASE_P(All, PaintPropertyTreeBuilderTest, ::testing::Bool());
128 131
129 TEST_P(PaintPropertyTreeBuilderTest, FixedPosition) 132 TEST_P(PaintPropertyTreeBuilderTest, FixedPosition)
130 { 133 {
131 loadTestData("fixed-position.html"); 134 loadTestData("fixed-position.html");
(...skipping 1449 matching lines...) Expand 10 before | Expand all | Expand 10 after
1581 1584
1582 EXPECT_EQ(cProperties, c->layoutObject()->objectPaintProperties()); 1585 EXPECT_EQ(cProperties, c->layoutObject()->objectPaintProperties());
1583 EXPECT_EQ(cTransformNode, cProperties->transform()); 1586 EXPECT_EQ(cTransformNode, cProperties->transform());
1584 EXPECT_EQ(bTransformNode, cTransformNode->parent()); 1587 EXPECT_EQ(bTransformNode, cTransformNode->parent());
1585 1588
1586 CHECK_EXACT_VISUAL_RECT(LayoutRect(33, 44, 50, 60), a->layoutObject(), frame View->layoutView()); 1589 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()); 1590 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()); 1591 CHECK_EXACT_VISUAL_RECT(LayoutRect(114, 137, 10, 20), c->layoutObject(), fra meView->layoutView());
1589 } 1592 }
1590 1593
1594 TEST_P(PaintPropertyTreeBuilderTest, OverflowClipContentsProperties)
1595 {
1596 // This test verifies the tree builder correctly computes and records the pr operty tree context
1597 // for a (pseudo) stacking context that is scrolled by a containing block th at is not one of
1598 // the painting ancestors.
1599 setBodyInnerHTML(
1600 "<style>body { margin: 0; }</style>"
1601 "<div id='clipper' style='overflow:hidden; width:400px; height:300px;'>"
1602 " <div id='child' style='position:relative; width:500px; height: 600px; '></div>"
1603 "</div>"
1604 );
1605
1606 LayoutBoxModelObject* clipper = toLayoutBoxModelObject(document().getElement ById("clipper")->layoutObject());
1607 const ObjectPaintProperties* clipProperties = clipper->objectPaintProperties ();
1608 LayoutObject* child = document().getElementById("child")->layoutObject();
1609 const ObjectPaintProperties* childProperties = child->objectPaintProperties( );
1610
1611 EXPECT_EQ(frameScrollTranslation(), clipProperties->localBorderBoxProperties ()->propertyTreeState.transform);
1612 EXPECT_EQ(frameContentClip(), clipProperties->localBorderBoxProperties()->pr opertyTreeState.clip);
1613
1614 PropertyTreeState contentsProperties;
1615 clipProperties->getContentsProperties(contentsProperties);
1616 EXPECT_EQ(frameScrollTranslation(), contentsProperties.transform);
1617 EXPECT_EQ(clipProperties->overflowClip(), contentsProperties.clip);
1618
1619 EXPECT_EQ(frameScrollTranslation(), childProperties->localBorderBoxPropertie s()->propertyTreeState.transform);
1620 EXPECT_EQ(clipProperties->overflowClip(), childProperties->localBorderBoxPro perties()->propertyTreeState.clip);
1621
1622 EXPECT_NE(nullptr, childProperties->localBorderBoxProperties()->propertyTree State.effect);
1623 CHECK_EXACT_VISUAL_RECT(LayoutRect(0, 0, 500, 600), child, clipper);
1624 }
1625
1626 TEST_P(PaintPropertyTreeBuilderTest, OverflowScrollContentsProperties)
1627 {
1628 // This test verifies the tree builder correctly computes and records the pr operty tree context
1629 // for a (pseudo) stacking context that is scrolled by a containing block th at is not one of
1630 // the painting ancestors.
1631 setBodyInnerHTML(
1632 "<style>body { margin: 0; }</style>"
1633 "<div id='clipper' style='overflow:scroll; width:400px; height:300px;'>"
1634 " <div id='child' style='position:relative; width:500px; height: 600px; '></div>"
1635 " <div style='width: 200px; height: 10000px'>"
1636 "</div>"
1637 );
1638
1639 Element* clipperElement = document().getElementById("clipper");
1640 clipperElement->scrollTo(1, 2);
1641
1642 LayoutBoxModelObject* clipper = toLayoutBoxModelObject(clipperElement->layou tObject());
1643 const ObjectPaintProperties* clipProperties = clipper->objectPaintProperties ();
1644 LayoutObject* child = document().getElementById("child")->layoutObject();
1645 const ObjectPaintProperties* childProperties = child->objectPaintProperties( );
1646
1647 EXPECT_EQ(frameScrollTranslation(), clipProperties->localBorderBoxProperties ()->propertyTreeState.transform);
1648 EXPECT_EQ(frameContentClip(), clipProperties->localBorderBoxProperties()->pr opertyTreeState.clip);
1649
1650 PropertyTreeState contentsProperties;
1651 clipProperties->getContentsProperties(contentsProperties);
1652 EXPECT_EQ(clipProperties->scrollTranslation(), contentsProperties.transform) ;
1653 EXPECT_EQ(clipProperties->overflowClip(), contentsProperties.clip);
1654
1655 EXPECT_EQ(clipProperties->scrollTranslation(), childProperties->localBorderB oxProperties()->propertyTreeState.transform);
1656 EXPECT_EQ(clipProperties->overflowClip(), childProperties->localBorderBoxPro perties()->propertyTreeState.clip);
1657
1658 CHECK_EXACT_VISUAL_RECT(LayoutRect(0, 0, 500, 600), child, clipper);
1659 }
1660
1661 TEST_P(PaintPropertyTreeBuilderTest, CssClipContentsProperties)
1662 {
1663 // This test verifies the tree builder correctly computes and records the pr operty tree context
1664 // for a (pseudo) stacking context that is scrolled by a containing block th at is not one of
1665 // the painting ancestors.
1666 setBodyInnerHTML(
1667 "<style>body { margin: 0; }</style>"
1668 "<div id='clipper' style='position: absolute; clip: rect(10px, 80px, 70p x, 40px); width:400px; height:300px;'>"
1669 " <div id='child' style='position:relative; width:500px; height: 600px; '></div>"
1670 "</div>"
1671 );
1672
1673 LayoutBoxModelObject* clipper = toLayoutBoxModelObject(document().getElement ById("clipper")->layoutObject());
1674 const ObjectPaintProperties* clipProperties = clipper->objectPaintProperties ();
1675 LayoutObject* child = document().getElementById("child")->layoutObject();
1676
1677 EXPECT_EQ(frameScrollTranslation(), clipProperties->localBorderBoxProperties ()->propertyTreeState.transform);
1678 // CSS clip on an element causes it to clip itself, not just descendants.
1679 EXPECT_EQ(clipProperties->cssClip(), clipProperties->localBorderBoxPropertie s()->propertyTreeState.clip);
1680
1681 PropertyTreeState contentsProperties;
1682 clipProperties->getContentsProperties(contentsProperties);
1683 EXPECT_EQ(frameScrollTranslation(), contentsProperties.transform);
1684 EXPECT_EQ(clipProperties->cssClip(), contentsProperties.clip);
1685
1686 CHECK_EXACT_VISUAL_RECT(LayoutRect(0, 0, 500, 600), child, clipper);
1687 }
1688
1689 TEST_P(PaintPropertyTreeBuilderTest, SvgLocalToBorderBoxTransformContentsPropert ies)
1690 {
1691 setBodyInnerHTML(
1692 "<style>"
1693 " body {"
1694 " margin: 0px;"
1695 " }"
1696 " svg {"
1697 " position: absolute;"
1698 " }"
1699 " rect {"
1700 " transform: translate(100px, 100px);"
1701 " }"
1702 "</style>"
1703 "<svg id='svgWithViewBox' width='100px' height='100px' viewBox='50 50 10 0 100'>"
1704 " <rect id='rect' width='100px' height='100px' />"
1705 "</svg>");
1706
1707 LayoutObject& svgWithViewBox = *document().getElementById("svgWithViewBox")- >layoutObject();
1708 const ObjectPaintProperties* svgWithViewBoxProperties = svgWithViewBox.objec tPaintProperties();
1709
1710 EXPECT_EQ(frameScrollTranslation(), svgWithViewBoxProperties->localBorderBox Properties()->propertyTreeState.transform);
1711
1712 PropertyTreeState contentsProperties;
1713 svgWithViewBoxProperties->getContentsProperties(contentsProperties);
1714 EXPECT_EQ(svgWithViewBoxProperties->svgLocalToBorderBoxTransform(), contents Properties.transform);
1715 }
1716
1591 } // namespace blink 1717 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/paint/PaintInvalidator.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698