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

Side by Side Diff: LayoutTests/compositing/overflow/automatically-opt-into-composited-scrolling.js

Issue 13722015: Update automatically-opt-into-composited-scrolling.html (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: 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 var debugMode = false;
2
3 if (window.testRunner)
4 testRunner.dumpAsText();
5
6 function write(str)
7 {
8 var pre = document.getElementById('console');
9 var text = document.createTextNode(str + '\n');
10 pre.appendChild(text);
11 }
12
13 function didOptIn(element)
14 {
15 // Force a style recalc.
16 document.body.offsetTop;
17
18 // Force a layout.
19 window.internals.boundingBox(element);
20 var layerTree = window.internals.layerTreeAsText(document);
Julien - ping for review 2013/04/09 17:41:59 This is really magical unless you start to pull th
hartmanng 2013/04/09 20:40:09 Good point, although in this case there is only 1
21
22 if (debugMode)
23 write(layerTree);
24
25 return !!layerTree;
26 }
27
28 function getStackingOrder(element)
29 {
30 var divElements = [];
31 // Force a style recalc.
32 document.body.offsetTop;
33
34 // Force a layout.
35 window.internals.boundingBox(element);
Julien - ping for review 2013/04/09 17:41:59 I don't understand why you need this line as docum
hartmanng 2013/04/09 20:40:09 Ah, didn't realize that. Removed.
36
37 var errorCode = 0;
Julien - ping for review 2013/04/09 17:41:59 errorCode is useless and should be removed: the fu
hartmanng 2013/04/09 20:40:09 Done.
38 var stackingOrder = window.internals.nodesFromRect(document, 100, 75, 200, 200 , 200, 200, false, false, errorCode);
39
40 for (var i = 0; i < stackingOrder.length; ++i)
41 if (stackingOrder[i].nodeName === "DIV")
42 divElements.push(stackingOrder[i]);
43
44 return divElements;
45 }
46
47 function addDomElement(elementType, className, id, parent)
48 {
49 var element = document.createElement(elementType);
50 element.setAttribute("class", className);
51 element.setAttribute("id", id);
52 if (parent === "body")
53 document.body.appendChild(element);
54 else
55 document.getElementById(parent).appendChild(element);
56 }
57
58 function buildDom()
59 {
60 addDomElement("div", "", "ancestor", "body");
61 addDomElement("div", "positioned", "predecessor", "ancestor");
62 addDomElement("div", "container", "container", "ancestor");
63 addDomElement("div", "scrolled", "firstChild", "container");
64 addDomElement("div", "scrolled", "secondChild", "container");
65 addDomElement("div", "", "normalFlow", "container");
66 addDomElement("div", "positioned", "successor", "ancestor");
67 addDomElement("pre", "", "console", "body");
68 }
69
70 var permutationIteration = 0;
71
72 // We've already decided on the ordering of the elements, now we need to do the
73 // rest of the permutations.
74 function permuteWithFixedOrdering(didPass, siblingIndex, containerIndex, firstCh ildIndex, secondChildIndex, numElementsWithZIndexZero)
75 {
76 if (firstChildIndex > secondChildIndex)
77 return;
78 // One of the two children must be immediately to the right of us.
79 if (numElementsWithZIndexZero === 3 && containerIndex !== firstChildIndex - 1 && containerIndex !== secondChildIndex - 1)
80 return;
81 // If we have 2 elements with z-index:0, they will be the container and the
82 // sibling (we don't care about the case when the container and a child are
83 // both z-index:0 because the tree order would ensure that ordering anyway).
84 // The two elements with z-index:0 need to be adjacent in the ordering.
85 if (numElementsWithZIndexZero === 2 && containerIndex !== siblingIndex - 1 && containerIndex !== siblingIndex + 1)
86 return;
87
88 for (var containerIsPositioned = 0; containerIsPositioned <= 1; ++containerIsP ositioned) {
89 for (var hasPositionedAncestor = 0; hasPositionedAncestor <= 1; ++hasPositio nedAncestor) {
90 if (containerIsPositioned === 1 && hasPositionedAncestor === 1)
91 continue;
92 for (var siblingPrecedesContainer = 0; siblingPrecedesContainer <= 1; ++si blingPrecedesContainer) {
93 // If the sibling and the container both have z-index: 0, we only have
94 // one choice for who gets to be the sibling. For example, if the
95 // sibling is supposed to precede us in paint order, but we both have
96 // z-index: 0, the order will depend entirely on tree order, so we have
97 // to choose the predecessor as the sibling. If all elements have unique
98 // z-indices, either the predecessor or the successor could be our
99 // sibling; the z-indices will ensure that the paint order is correct.
100 if (numElementsWithZIndexZero >= 2 && siblingPrecedesContainer === 1)
101 continue;
102
103 var sibling = predecessor;
104 var toHide = successor;
105 if ((numElementsWithZIndexZero === 1 && siblingPrecedesContainer === 0) ||
106 (numElementsWithZIndexZero >= 2 && siblingIndex > containerIndex)) {
107 sibling = successor;
108 toHide = predecessor;
109 }
110
111 var ordering = [ null, null, null, null ];
112 ordering[siblingIndex] = sibling;
113 ordering[containerIndex] = hasPositionedAncestor === 1 ? ancestor : cont ainer;
114 ordering[firstChildIndex] = firstChild;
115 ordering[secondChildIndex] = secondChild;
116
117 toHide.style.display = 'none';
118 sibling.style.display = '';
119
120 var positioned = null;
121 if (containerIsPositioned === 1) {
122 container.style.position = 'relative';
123 positioned = container;
124 } else
125 container.style.position = '';
126
127 if (hasPositionedAncestor === 1) {
128 ancestor.style.position = 'relative';
129 positioned = ancestor;
130 } else
131 ancestor.style.position = '';
132
133 var currentZIndex = siblingPrecedesContainer === 1 ? 0 : -1;
134 for (var currentIndex = containerIndex - 1; currentIndex >= 0; --current Index) {
135 ordering[currentIndex].style.zIndex = currentZIndex.toString();
136 currentZIndex--;
137 }
138
139 currentZIndex = 1;
140 for (var currentIndex = containerIndex + 1; currentIndex < 4; ++currentI ndex) {
141 ordering[currentIndex].style.zIndex = currentZIndex.toString();
142 currentZIndex++;
143 }
144
145 if (numElementsWithZIndexZero >= 1)
146 ordering[containerIndex].style.zIndex = '0';
147
148 if (numElementsWithZIndexZero >= 2)
149 ordering[siblingIndex].style.zIndex = '0';
150
151 // We want the first descendant succeeding us in the ordering to get
152 // z-index: 0.
153 if (numElementsWithZIndexZero === 3) {
154 if (firstChildIndex > containerIndex)
155 ordering[firstChildIndex].style.zIndex = '0';
156 else
157 ordering[secondChildIndex].style.zIndex = '0';
158 }
159
160 if (window.internals) {
Julien - ping for review 2013/04/09 17:41:59 I don't see why you check window.internals here
hartmanng 2013/04/09 20:40:09 The particular didPass() function in this case req
Julien - ping for review 2013/04/09 22:05:06 Ah, it makes sense indeed. You could also require
161 didPass(permutationIteration, ordering, hasPositionedAncestor, contain erIsPositioned);
162 permutationIteration++;
163 }
164 }
165 }
166 }
167 }
168
169 function permute(didPass)
170 {
171 var ancestor = document.getElementById('ancestor');
172 var predecessor = document.getElementById('predecessor');
173 var successor = document.getElementById('successor');
174 var container = document.getElementById('container');
175 var firstChild = document.getElementById('firstChild');
176 var secondChild = document.getElementById('secondChild');
177
178 var indices = [ 0, 1, 2, 3 ];
179 for (var siblingIndex = 0; siblingIndex < 4; ++siblingIndex) {
Julien - ping for review 2013/04/09 17:41:59 4 is a magic constant here, indices.length is way
hartmanng 2013/04/09 20:40:09 Done.
180 var siblingIndices = indices.slice(0);
181 siblingIndices.splice(siblingIndex, 1);
182 for (var containerSubindex = 0; containerSubindex < 3; ++containerSubindex) {
Julien - ping for review 2013/04/09 17:41:59 Again, 3 is a magic constant, you should use sibli
hartmanng 2013/04/09 20:40:09 Done.
183 var containerIndices = siblingIndices.slice(0);
184 var containerIndex = containerIndices[containerSubindex];
185 containerIndices.splice(containerSubindex, 1);
186 var firstChildIndex = containerIndices[0];
187 var secondChildIndex = containerIndices[1];
188
189 permuteWithFixedOrdering(didPass, siblingIndex, containerIndex, firstChild Index, secondChildIndex, 1);
190 permuteWithFixedOrdering(didPass, siblingIndex, containerIndex, firstChild Index, secondChildIndex, 2);
191 permuteWithFixedOrdering(didPass, siblingIndex, containerIndex, firstChild Index, secondChildIndex, 3);
192 }
193 }
194 } // function doTest
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698