OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "core/paint/PaintControllerPaintTest.h" | |
6 #include "core/paint/PaintLayerPainter.h" | |
7 | |
8 namespace blink { | |
9 | |
10 using TableCellPainterTest = PaintControllerPaintTest; | |
11 | |
12 TEST_F(TableCellPainterTest, Background) { | |
13 setBodyInnerHTML( | |
14 "<style>" | |
15 " td { width: 200px; height: 200px; border: none; }" | |
16 " tr { background-color: blue; }" | |
17 " table { border: none; border-spacing: 0; border-collapse: collapse; }" | |
18 "</style>" | |
19 "<table>" | |
20 " <tr><td id='cell1'></td></tr>" | |
21 " <tr><td id='cell2'></td></tr>" | |
22 "</table>"); | |
23 | |
24 LayoutView& layoutView = *document().layoutView(); | |
25 LayoutObject& cell1 = *getLayoutObjectByElementId("cell1"); | |
26 LayoutObject& cell2 = *getLayoutObjectByElementId("cell2"); | |
27 | |
28 rootPaintController().invalidateAll(); | |
29 document().view()->updateAllLifecyclePhasesExceptPaint(); | |
30 IntRect interestRect(0, 0, 200, 200); | |
31 paint(&interestRect); | |
32 | |
33 EXPECT_DISPLAY_LIST( | |
34 rootPaintController().getDisplayItemList(), 2, | |
35 TestDisplayItem(layoutView, DisplayItem::kDocumentBackground), | |
36 TestDisplayItem(cell1, DisplayItem::kTableCellBackgroundFromRow)); | |
37 | |
38 document().view()->updateAllLifecyclePhasesExceptPaint(); | |
39 interestRect = IntRect(0, 300, 200, 1000); | |
40 paint(&interestRect); | |
41 | |
42 EXPECT_DISPLAY_LIST( | |
43 rootPaintController().getDisplayItemList(), 2, | |
44 TestDisplayItem(layoutView, DisplayItem::kDocumentBackground), | |
45 TestDisplayItem(cell2, DisplayItem::kTableCellBackgroundFromRow)); | |
46 } | |
47 | |
48 TEST_F(TableCellPainterTest, BackgroundWithCellSpacing) { | |
49 setBodyInnerHTML( | |
50 "<style>" | |
51 " body { margin: 0; }" | |
52 " td { width: 200px; height: 150px; border: 0; background-color: green; " | |
53 "}" | |
54 " tr { background-color: blue; }" | |
55 " table { border: none; border-spacing: 100px; border-collapse: " | |
56 "separate; }" | |
57 "</style>" | |
58 "<table>" | |
59 " <tr><td id='cell1'></td></tr>" | |
60 " <tr><td id='cell2'></td></tr>" | |
61 "</table>"); | |
62 | |
63 LayoutView& layoutView = *document().layoutView(); | |
64 LayoutObject& cell1 = *getLayoutObjectByElementId("cell1"); | |
65 LayoutObject& cell2 = *getLayoutObjectByElementId("cell2"); | |
66 | |
67 rootPaintController().invalidateAll(); | |
68 document().view()->updateAllLifecyclePhasesExceptPaint(); | |
69 // Intersects cell1 and the spacing between cell1 and cell2. | |
70 IntRect interestRect(0, 200, 200, 150); | |
71 paint(&interestRect); | |
72 | |
73 EXPECT_DISPLAY_LIST( | |
74 rootPaintController().getDisplayItemList(), 3, | |
75 TestDisplayItem(layoutView, DisplayItem::kDocumentBackground), | |
76 TestDisplayItem(cell1, DisplayItem::kTableCellBackgroundFromRow), | |
77 TestDisplayItem(cell1, DisplayItem::kBoxDecorationBackground)); | |
78 | |
79 document().view()->updateAllLifecyclePhasesExceptPaint(); | |
80 // Intersects the spacing only. | |
81 interestRect = IntRect(0, 250, 100, 100); | |
82 paint(&interestRect); | |
83 | |
84 EXPECT_DISPLAY_LIST( | |
85 rootPaintController().getDisplayItemList(), 1, | |
86 TestDisplayItem(layoutView, DisplayItem::kDocumentBackground)); | |
87 | |
88 document().view()->updateAllLifecyclePhasesExceptPaint(); | |
89 // Intersects cell2 only. | |
90 interestRect = IntRect(0, 350, 200, 150); | |
91 paint(&interestRect); | |
92 | |
93 EXPECT_DISPLAY_LIST( | |
94 rootPaintController().getDisplayItemList(), 3, | |
95 TestDisplayItem(layoutView, DisplayItem::kDocumentBackground), | |
96 TestDisplayItem(cell2, DisplayItem::kTableCellBackgroundFromRow), | |
97 TestDisplayItem(cell2, DisplayItem::kBoxDecorationBackground)); | |
98 } | |
99 | |
100 TEST_F(TableCellPainterTest, BackgroundInSelfPaintingRow) { | |
101 setBodyInnerHTML( | |
102 "<style>" | |
103 " body { margin: 0 }" | |
104 " td { width: 200px; height: 200px; border: 0; background-color: green; " | |
105 "}" | |
106 " tr { background-color: blue; opacity: 0.5; }" | |
107 " table { border: none; border-spacing: 100px; border-collapse: " | |
108 "separate; }" | |
109 "</style>" | |
110 "<table>" | |
111 " <tr id='row'><td id='cell1'><td id='cell2'></td></tr>" | |
112 "</table>"); | |
113 | |
114 LayoutView& layoutView = *document().layoutView(); | |
115 LayoutObject& cell1 = *getLayoutObjectByElementId("cell1"); | |
116 LayoutObject& cell2 = *getLayoutObjectByElementId("cell2"); | |
117 LayoutObject& row = *getLayoutObjectByElementId("row"); | |
118 PaintLayer& htmlLayer = | |
119 *toLayoutBoxModelObject(document().documentElement()->layoutObject()) | |
120 ->layer(); | |
121 | |
122 rootPaintController().invalidateAll(); | |
123 document().view()->updateAllLifecyclePhasesExceptPaint(); | |
124 // Intersects cell1 and the spacing between cell1 and cell2. | |
125 IntRect interestRect(200, 0, 200, 200); | |
126 paint(&interestRect); | |
127 | |
128 EXPECT_DISPLAY_LIST( | |
129 rootPaintController().getDisplayItemList(), 7, | |
130 TestDisplayItem(layoutView, DisplayItem::kDocumentBackground), | |
131 TestDisplayItem(htmlLayer, DisplayItem::kSubsequence), | |
132 TestDisplayItem(row, DisplayItem::kBeginCompositing), | |
133 TestDisplayItem(cell1, DisplayItem::kTableCellBackgroundFromRow), | |
134 TestDisplayItem(cell1, DisplayItem::kBoxDecorationBackground), | |
135 TestDisplayItem(row, DisplayItem::kEndCompositing), | |
136 TestDisplayItem(htmlLayer, DisplayItem::kEndSubsequence)); | |
137 | |
138 document().view()->updateAllLifecyclePhasesExceptPaint(); | |
139 // Intersects the spacing only. | |
140 interestRect = IntRect(300, 0, 100, 100); | |
141 paint(&interestRect); | |
142 | |
143 EXPECT_DISPLAY_LIST( | |
144 rootPaintController().getDisplayItemList(), 3, | |
145 TestDisplayItem(layoutView, DisplayItem::kDocumentBackground), | |
146 TestDisplayItem(htmlLayer, DisplayItem::kSubsequence), | |
147 TestDisplayItem(htmlLayer, DisplayItem::kEndSubsequence)); | |
148 | |
149 document().view()->updateAllLifecyclePhasesExceptPaint(); | |
150 // Intersects cell2 only. | |
151 interestRect = IntRect(450, 0, 200, 200); | |
152 paint(&interestRect); | |
153 | |
154 EXPECT_DISPLAY_LIST( | |
155 rootPaintController().getDisplayItemList(), 7, | |
156 TestDisplayItem(layoutView, DisplayItem::kDocumentBackground), | |
157 TestDisplayItem(htmlLayer, DisplayItem::kSubsequence), | |
158 TestDisplayItem(row, DisplayItem::kBeginCompositing), | |
159 TestDisplayItem(cell2, DisplayItem::kTableCellBackgroundFromRow), | |
160 TestDisplayItem(cell2, DisplayItem::kBoxDecorationBackground), | |
161 TestDisplayItem(row, DisplayItem::kEndCompositing), | |
162 TestDisplayItem(htmlLayer, DisplayItem::kEndSubsequence)); | |
163 } | |
164 | |
165 TEST_F(TableCellPainterTest, CollapsedBorderAndOverflow) { | |
166 setBodyInnerHTML( | |
167 "<style>" | |
168 " body { margin: 0 }" | |
169 " td { width: 100px; height: 100px; border: 100px solid blue; outline: " | |
170 "100px solid yellow; background: green; }" | |
171 " table { margin: 100px; border-collapse: collapse; }" | |
172 "</style>" | |
173 "<table>" | |
174 " <tr><td id='cell'></td></tr>" | |
175 "</table>"); | |
176 | |
177 LayoutView& layoutView = *document().layoutView(); | |
178 LayoutObject& cell = *getLayoutObjectByElementId("cell"); | |
179 | |
180 rootPaintController().invalidateAll(); | |
181 document().view()->updateAllLifecyclePhasesExceptPaint(); | |
182 // Intersects the overflowing part of cell but not border box. | |
183 IntRect interestRect(0, 0, 100, 100); | |
184 paint(&interestRect); | |
185 | |
186 // We should paint all display items of cell. | |
187 EXPECT_DISPLAY_LIST( | |
188 rootPaintController().getDisplayItemList(), 4, | |
189 TestDisplayItem(layoutView, DisplayItem::kDocumentBackground), | |
190 TestDisplayItem(cell, DisplayItem::kBoxDecorationBackground), | |
191 TestDisplayItem(cell, DisplayItem::kTableCollapsedBorderLast), | |
192 TestDisplayItem(cell, DisplayItem::paintPhaseToDrawingType( | |
193 PaintPhaseSelfOutlineOnly))); | |
194 } | |
195 | |
196 } // namespace blink | |
OLD | NEW |