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

Side by Side Diff: LayoutTests/compositing/overflow/build-paint-order-list-where-opt-in-decisions-can-affect-each-other.html

Issue 13467028: Add an intermediate function to generate 2 paint-order lists. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: fix rebase mistake Created 7 years, 8 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 <!DOCTYPE html>
2
3 <html><head>
4 <style>
5 .filler {
6 background-color: #CC9900;
7 margin: 20px;
8 border-style: solid;
9 border-width: 1px;
10 width: 400px;
11 height: 100px;
12 }
13
14 .negativechild {
15 z-index: -1;
16 position: relative;
17 }
18
19 #parentscrollinglayer {
20 background-color: #CC9999;
21 height: 200px;
22 width: 500px;
23 overflow-y: scroll;
24 }
25
26 #childscrollinglayer {
27 margin: 30px;
28 position: relative;
29 left: 20px;
30 top: 20px;
31 background-color: #990066;
32 height: 200px;
33 width: 300px;
34 overflow-x: scroll;
35 }
36 </style>
37
38 <script>
39 var debugMode = false;
40
41 if (window.testRunner)
42 testRunner.dumpAsText();
43
44 function write(str)
45 {
46 var pre = document.getElementById('console');
47 var text = document.createTextNode(str + '\n');
48 pre.appendChild(text);
49 }
50
51 function getStackingOrder()
52 {
53 var divElements = [];
54 // Force a style recalc.
55 document.body.offsetTop;
56
57 var stackingOrder = window.internals.nodesFromRect(document, 100, 75, 200, 200, 200, 200, false, false, false);
58
59 for (var i = 0; i < stackingOrder.length; ++i)
60 if (stackingOrder[i].nodeName === "DIV")
61 divElements.push(stackingOrder[i]);
62
63 return divElements;
64 }
65
66 function getPaintOrder()
67 {
68 var divElementsBeforePromote = [];
69 var divElementsAfterPromote = [];
70 // Force a style recalc.
71 document.body.offsetTop;
72
73 var paintOrderListBeforePromote = window.internals.paintOrderListBeforePro mote(document.getElementById('childscrollinglayer'));
74 var paintOrderListAfterPromote = window.internals.paintOrderListAfterPromo te(document.getElementById('childscrollinglayer'));
75
76 for (var i = 0; i < paintOrderListBeforePromote.length; ++i)
77 if (paintOrderListBeforePromote[i].nodeName === "DIV")
78 divElementsBeforePromote.push(paintOrderListBeforePromote[i]);
79
80 for (var i = 0; i < paintOrderListAfterPromote.length; ++i)
81 if (paintOrderListAfterPromote[i].nodeName === "DIV")
82 divElementsAfterPromote.push(paintOrderListAfterPromote[i]);
83
84 return {"beforePromote": divElementsBeforePromote,
85 "afterPromote": divElementsAfterPromote};
86 }
87
88 function comparePaintOrderLists(oldPaintOrder, newPaintOrder)
89 {
90 if (oldPaintOrder.length !== newPaintOrder.length)
91 return false;
92
93 for (var i = 0; i < oldPaintOrder.length; i++)
94 if (oldPaintOrder[i] !== newPaintOrder[i])
95 return false;
96
97 return true;
98 }
99
100 function compareStackingOrderWithPaintOrder(stackingOrder, paintOrder)
101 {
102 if (debugMode) {
103 write("paint:")
104 for (var i = 0; i < paintOrder.length; i++)
105 write(paintOrder[i].id + " " + paintOrder[i].className + " " + paintOr der[i].tagName);
106
107 write("stacking:")
108 for (var i = 0; i < stackingOrder.length; i++)
109 write(stackingOrder[i].id + " " + stackingOrder[i].className + " " + s tackingOrder[i].tagName);
110 }
111
112 for (var i = 0, j = 0; i < stackingOrder.length && j < paintOrder.length; i++) {
113 // Ignore elements with class "filler negativechild". These elements are
114 // irrelevant to stacking order, since they do not overlap with the
115 // elements we care about. They exist in the paint order lists because
116 // they are still descendants of the same stacking context, but they
117 // will not affect visual layout.
118 while (j < paintOrder.length && paintOrder[paintOrder.length - j - 1].cl assName === "filler negativechild")
119 j++;
120
121 if (j >= paintOrder.length)
122 break;
123
124 if (stackingOrder[i] === paintOrder[paintOrder.length - j - 1])
125 j++;
126 }
127
128 if (debugMode)
129 write(stackingOrder.length + " " + i + " " + paintOrder.length + " " + j );
130
131 return j === paintOrder.length;
132 }
133
134 function countOccurrencesOfChildScrollingLayerInPaintOrderList(paintOrder) {
135 var childScrollingLayer = document.getElementById('childscrollinglayer');
136 var occurrenceCount = 0;
137 for (var i = 0; i < paintOrder.length; i++)
138 if (paintOrder[i] === childScrollingLayer)
139 occurrenceCount++;
140
141 return occurrenceCount;
142 }
143
144 function doTest()
145 {
146 var parentscrollinglayer = document.getElementById('parentscrollinglayer') ;
147 var childscrollinglayer = document.getElementById('childscrollinglayer');
148
149 if (window.internals) {
150 // Here we want to compare paint order lists before and after promotion
151 // to the actual stacking order as determined by hit-testing. So we
152 // first force the element not to promote, then compute its paint and
153 // stacking order lists. We then force the element to opt in, and
154 // generate the paint and stacking order lists after opt-in.
155 //
156 // The paint order lists should exactly match the stacking order lists
157 // (modulo children that fall outside of the hit-testing area
158 // on-screen), both before and after promotion.
159 parentscrollinglayer.style.webkitTransform = 'translateZ(0px)';
160 document.body.offsetTop;
161
162 window.internals.settings.setAcceleratedCompositingForOverflowScrollEnab led(false);
163 parentscrollinglayer.style.webkitTransform = '';
164
165 var oldStackingOrder = getStackingOrder();
166 var oldPaintOrder = getPaintOrder();
167
168 window.internals.settings.setAcceleratedCompositingForOverflowScrollEnab led(true);
169 parentscrollinglayer.style.webkitTransform = 'translateZ(0px)';
170
171 var newStackingOrder = getStackingOrder();
172 var newPaintOrder = getPaintOrder();
173
174 // The getPaintOrder() function should return a pair of paint orders.
175 // One before promotion and one after. This pair of lists should remain
176 // identical whether the element is actually currently promoted or not,
177 // its purpose is to generate hypothetical pre- and post-lists to
178 // determine if the element is promotable.
179 if (!comparePaintOrderLists(oldPaintOrder, newPaintOrder))
180 write("FAIL - paint order lists not identical before/after promotion") ;
181
182 if (!compareStackingOrderWithPaintOrder(oldStackingOrder, oldPaintOrder. beforePromote))
183 write("FAIL - paint order list before promote doesn't match stacking o rder");
184
185 if (!compareStackingOrderWithPaintOrder(newStackingOrder, oldPaintOrder. afterPromote))
186 write("FAIL - paint order list after promote doesn't match stacking or der");
187
188 var childScrollingLayerOccurrences = countOccurrencesOfChildScrollingLay erInPaintOrderList(oldPaintOrder.beforePromote);
189 if (childScrollingLayerOccurrences !== 1)
190 write("FAIL - paint order list before promote contains " + childScroll ingLayerOccurrences + " occurrences of child scrolling layer. Should be exactly 1.");
191
192 childScrollingLayerOccurrences = countOccurrencesOfChildScrollingLayerIn PaintOrderList(oldPaintOrder.afterPromote);
193 if (childScrollingLayerOccurrences !== 1)
194 write("FAIL - paint order list after promote contains " + childScrolli ngLayerOccurrences + " occurrences of child scrolling layer. Should be exactly 1 .");
195
196 write("PASS - did not crash.");
197 }
198 }
199
200 window.addEventListener('load', doTest, false);
201 </script>
202 </head>
203 <body>
204 <div class="filler"></div>
205 <div id="parentscrollinglayer">
206 <div id="childscrollinglayer">
207 <div class="filler"></div>
208 </div>
209 <div class="filler"></div>
210 <div class="filler"></div>
211 </div>
212 <div id="fillerchild1" class="filler negativechild"></div>
213 <div id="fillerchild2" class="filler negativechild"></div>
214 <div id="fillerchild3" class="filler negativechild"></div>
215 <div id="fillerchild4" class="filler negativechild"></div>
216 <pre id="console"></pre>
217 </body>
218 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698