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/paint/PaintPropertyTreeBuilderTest.h" | 5 #include "core/paint/PaintPropertyTreeBuilderTest.h" |
6 | 6 |
7 #include "core/html/HTMLIFrameElement.h" | 7 #include "core/html/HTMLIFrameElement.h" |
8 #include "core/layout/LayoutTreeAsText.h" | 8 #include "core/layout/LayoutTreeAsText.h" |
9 #include "core/paint/ObjectPaintProperties.h" | 9 #include "core/paint/ObjectPaintProperties.h" |
10 #include "core/paint/PaintPropertyTreePrinter.h" | 10 #include "core/paint/PaintPropertyTreePrinter.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 RenderingTest::SetUp(); | 73 RenderingTest::SetUp(); |
74 EnableCompositing(); | 74 EnableCompositing(); |
75 } | 75 } |
76 | 76 |
77 void PaintPropertyTreeBuilderTest::TearDown() { | 77 void PaintPropertyTreeBuilderTest::TearDown() { |
78 RenderingTest::TearDown(); | 78 RenderingTest::TearDown(); |
79 | 79 |
80 Settings::SetMockScrollbarsEnabled(false); | 80 Settings::SetMockScrollbarsEnabled(false); |
81 } | 81 } |
82 | 82 |
83 #define CHECK_VISUAL_RECT(expected, sourceObject, ancestorObject, slopFactor) \ | 83 #define CHECK_VISUAL_RECT(expected, source_object, ancestor, slop_factor) \ |
84 do { \ | 84 do { \ |
85 if ((sourceObject)->HasLayer() && (ancestorObject)->HasLayer()) { \ | 85 if ((source_object)->HasLayer() && (ancestor)->HasLayer()) { \ |
86 LayoutRect source((sourceObject)->LocalVisualRect()); \ | 86 LayoutRect source((source_object)->LocalVisualRect()); \ |
87 source.MoveBy((sourceObject)->PaintOffset()); \ | 87 source.MoveBy((source_object)->PaintOffset()); \ |
88 auto contents_properties = (ancestorObject)->ContentsProperties(); \ | 88 auto contents_properties = (ancestor)->ContentsProperties(); \ |
89 FloatClipRect actual_float_rect((FloatRect(source))); \ | 89 FloatClipRect actual_float_rect((FloatRect(source))); \ |
90 GeometryMapper::SourceToDestinationVisualRect( \ | 90 GeometryMapper::SourceToDestinationVisualRect( \ |
91 *(sourceObject)->LocalBorderBoxProperties(), contents_properties, \ | 91 *(source_object)->LocalBorderBoxProperties(), contents_properties, \ |
92 actual_float_rect); \ | 92 actual_float_rect); \ |
93 LayoutRect actual(actual_float_rect.Rect()); \ | 93 LayoutRect actual(actual_float_rect.Rect()); \ |
94 actual.MoveBy(-(ancestorObject)->PaintOffset()); \ | 94 actual.MoveBy(-(ancestor)->PaintOffset()); \ |
95 SCOPED_TRACE("GeometryMapper: "); \ | 95 SCOPED_TRACE("GeometryMapper: "); \ |
96 EXPECT_EQ(expected, actual); \ | 96 EXPECT_EQ(expected, actual); \ |
97 } \ | 97 } \ |
98 \ | 98 \ |
99 if (slopFactor == LayoutUnit::Max()) \ | 99 if (slop_factor == LayoutUnit::Max()) \ |
100 break; \ | 100 break; \ |
101 LayoutRect slow_path_rect = (sourceObject)->LocalVisualRect(); \ | 101 LayoutRect slow_path_rect = (source_object)->LocalVisualRect(); \ |
102 (sourceObject) \ | 102 (source_object)->MapToVisualRectInAncestorSpace(ancestor, slow_path_rect); \ |
103 ->MapToVisualRectInAncestorSpace(ancestorObject, slow_path_rect); \ | 103 if (slop_factor) { \ |
104 if (slopFactor) { \ | 104 LayoutRect inflated_expected = LayoutRect(expected); \ |
105 LayoutRect inflated_expected = LayoutRect(expected); \ | 105 inflated_expected.Inflate(slop_factor); \ |
106 inflated_expected.Inflate(slopFactor); \ | 106 SCOPED_TRACE(String::Format( \ |
107 SCOPED_TRACE(String::Format( \ | 107 "Slow path rect: %s, Expected: %s, Inflated expected: %s", \ |
108 "Old path rect: %s, Expected: %s, Inflated expected: %s", \ | 108 slow_path_rect.ToString().Ascii().data(), \ |
109 slow_path_rect.ToString().Ascii().data(), \ | 109 expected.ToString().Ascii().data(), \ |
110 expected.ToString().Ascii().data(), \ | 110 inflated_expected.ToString().Ascii().data())); \ |
111 inflated_expected.ToString().Ascii().data())); \ | 111 EXPECT_TRUE(LayoutRect(EnclosingIntRect(slow_path_rect)) \ |
112 EXPECT_TRUE(slow_path_rect.Contains(LayoutRect(expected))); \ | 112 .Contains(LayoutRect(expected))); \ |
113 EXPECT_TRUE(inflated_expected.Contains(slow_path_rect)); \ | 113 EXPECT_TRUE(inflated_expected.Contains(slow_path_rect)); \ |
114 } else { \ | 114 } else { \ |
115 SCOPED_TRACE("Slow path: "); \ | 115 SCOPED_TRACE("Slow path: "); \ |
116 EXPECT_EQ(expected, slow_path_rect); \ | 116 EXPECT_EQ(expected, slow_path_rect); \ |
117 } \ | 117 } \ |
118 } while (0) | 118 } while (0) |
119 | 119 |
120 #define CHECK_EXACT_VISUAL_RECT(expected, sourceObject, ancestorObject) \ | 120 #define CHECK_EXACT_VISUAL_RECT(expected, source_object, ancestor) \ |
121 CHECK_VISUAL_RECT(expected, sourceObject, ancestorObject, 0) | 121 CHECK_VISUAL_RECT(expected, source_object, ancestor, 0) |
122 | 122 |
123 INSTANTIATE_TEST_CASE_P(All, PaintPropertyTreeBuilderTest, ::testing::Bool()); | 123 INSTANTIATE_TEST_CASE_P(All, PaintPropertyTreeBuilderTest, ::testing::Bool()); |
124 | 124 |
125 TEST_P(PaintPropertyTreeBuilderTest, FixedPosition) { | 125 TEST_P(PaintPropertyTreeBuilderTest, FixedPosition) { |
126 LoadTestData("fixed-position.html"); | 126 LoadTestData("fixed-position.html"); |
127 | 127 |
128 Element* positioned_scroll = GetDocument().getElementById("positionedScroll"); | 128 Element* positioned_scroll = GetDocument().getElementById("positionedScroll"); |
129 positioned_scroll->setScrollTop(3); | 129 positioned_scroll->setScrollTop(3); |
130 Element* transformed_scroll = | 130 Element* transformed_scroll = |
131 GetDocument().getElementById("transformedScroll"); | 131 GetDocument().getElementById("transformedScroll"); |
(...skipping 1629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1761 // Visual rects via the non-paint properties system use enclosingIntRect | 1761 // Visual rects via the non-paint properties system use enclosingIntRect |
1762 // before applying transforms, because they are computed bottom-up and | 1762 // before applying transforms, because they are computed bottom-up and |
1763 // therefore can't apply pixel snapping. Therefore apply a slop of 1px. | 1763 // therefore can't apply pixel snapping. Therefore apply a slop of 1px. |
1764 CHECK_VISUAL_RECT(LayoutRect(LayoutUnit(0.7) + LayoutUnit(0.7), | 1764 CHECK_VISUAL_RECT(LayoutRect(LayoutUnit(0.7) + LayoutUnit(0.7), |
1765 LayoutUnit(0.7) + LayoutUnit(0.7), | 1765 LayoutUnit(0.7) + LayoutUnit(0.7), |
1766 LayoutUnit(40), LayoutUnit(40)), | 1766 LayoutUnit(40), LayoutUnit(40)), |
1767 c, frame_view->GetLayoutView(), 1); | 1767 c, frame_view->GetLayoutView(), 1); |
1768 } | 1768 } |
1769 | 1769 |
1770 TEST_P(PaintPropertyTreeBuilderTest, | 1770 TEST_P(PaintPropertyTreeBuilderTest, |
| 1771 NonTranslationTransformShouldResetSubpixelPaintOffset) { |
| 1772 SetBodyInnerHTML( |
| 1773 "<style>" |
| 1774 " * { margin: 0; }" |
| 1775 " div { position: relative; }" |
| 1776 " #a {" |
| 1777 " width: 70px;" |
| 1778 " height: 70px;" |
| 1779 " left: 0.9px;" |
| 1780 " top: 0.9px;" |
| 1781 " }" |
| 1782 " #b {" |
| 1783 " width: 40px;" |
| 1784 " height: 40px;" |
| 1785 " transform: scale(10);" |
| 1786 " transform-origin: 0 0;" |
| 1787 " }" |
| 1788 " #c {" |
| 1789 " width: 40px;" |
| 1790 " height: 40px;" |
| 1791 " left: 0.6px;" |
| 1792 " top: 0.6px;" |
| 1793 " }" |
| 1794 "</style>" |
| 1795 "<div id='a'>" |
| 1796 " <div id='b'>" |
| 1797 " <div id='c'></div>" |
| 1798 " </div>" |
| 1799 "</div>"); |
| 1800 FrameView* frame_view = GetDocument().View(); |
| 1801 |
| 1802 LayoutObject* b = GetDocument().getElementById("b")->GetLayoutObject(); |
| 1803 const ObjectPaintProperties* b_properties = b->PaintProperties(); |
| 1804 EXPECT_EQ(TransformationMatrix().Scale(10), |
| 1805 b_properties->Transform()->Matrix()); |
| 1806 // The paint offset transform should not be snapped. |
| 1807 EXPECT_EQ(TransformationMatrix().Translate(1, 1), |
| 1808 b_properties->Transform()->Parent()->Matrix()); |
| 1809 EXPECT_EQ(LayoutPoint(), b->PaintOffset()); |
| 1810 // Visual rects via the non-paint properties system use enclosingIntRect |
| 1811 // before applying transforms, because they are computed bottom-up and |
| 1812 // therefore can't apply pixel snapping. Therefore apply a slop of 1px. |
| 1813 CHECK_VISUAL_RECT(LayoutRect(LayoutUnit(1), LayoutUnit(1), LayoutUnit(400), |
| 1814 LayoutUnit(400)), |
| 1815 b, frame_view->GetLayoutView(), 1); |
| 1816 |
| 1817 // c's painting should start at c_offset. |
| 1818 LayoutObject* c = GetDocument().getElementById("c")->GetLayoutObject(); |
| 1819 LayoutUnit c_offset = LayoutUnit(0.6); |
| 1820 EXPECT_EQ(LayoutPoint(c_offset, c_offset), c->PaintOffset()); |
| 1821 // Visual rects via the non-paint properties system use enclosingIntRect |
| 1822 // before applying transforms, because they are computed bottom-up and |
| 1823 // therefore can't apply pixel snapping. Therefore apply a slop of 1px |
| 1824 // in the transformed space (c_offset * 10 in view space) and 1px in the |
| 1825 // view space. |
| 1826 CHECK_VISUAL_RECT(LayoutRect(c_offset * 10 + 1, c_offset * 10 + 1, |
| 1827 LayoutUnit(400), LayoutUnit(400)), |
| 1828 c, frame_view->GetLayoutView(), c_offset * 10 + 1); |
| 1829 } |
| 1830 |
| 1831 TEST_P(PaintPropertyTreeBuilderTest, |
1771 PaintOffsetWithPixelSnappingThroughMultipleTransforms) { | 1832 PaintOffsetWithPixelSnappingThroughMultipleTransforms) { |
1772 SetBodyInnerHTML( | 1833 SetBodyInnerHTML( |
1773 "<style>" | 1834 "<style>" |
1774 " * { margin: 0; }" | 1835 " * { margin: 0; }" |
1775 " div { position: relative; }" | 1836 " div { position: relative; }" |
1776 " #a {" | 1837 " #a {" |
1777 " width: 70px;" | 1838 " width: 70px;" |
1778 " height: 70px;" | 1839 " height: 70px;" |
1779 " left: 0.7px;" | 1840 " left: 0.7px;" |
1780 " top: 0.7px;" | 1841 " top: 0.7px;" |
(...skipping 1690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3471 | 3532 |
3472 LayoutObject& svg_root = | 3533 LayoutObject& svg_root = |
3473 *GetDocument().getElementById("svgroot")->GetLayoutObject(); | 3534 *GetDocument().getElementById("svgroot")->GetLayoutObject(); |
3474 const ObjectPaintProperties* svg_root_properties = svg_root.PaintProperties(); | 3535 const ObjectPaintProperties* svg_root_properties = svg_root.PaintProperties(); |
3475 EXPECT_TRUE(svg_root_properties->Effect()); | 3536 EXPECT_TRUE(svg_root_properties->Effect()); |
3476 EXPECT_EQ(EffectPaintPropertyNode::Root(), | 3537 EXPECT_EQ(EffectPaintPropertyNode::Root(), |
3477 svg_root_properties->Effect()->Parent()); | 3538 svg_root_properties->Effect()->Parent()); |
3478 } | 3539 } |
3479 | 3540 |
3480 } // namespace blink | 3541 } // namespace blink |
OLD | NEW |