| OLD | NEW |
| (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 synchronous style recalc and layout. |
| 16 document.body.offsetTop; |
| 17 |
| 18 var nonFastScrollableRects = window.internals.nonFastScrollableRects(document)
; |
| 19 var elementBoundingBox = window.internals.boundingBox(element); |
| 20 |
| 21 for (var i = 0; i < nonFastScrollableRects.length; ++i) { |
| 22 var rect = nonFastScrollableRects[i]; |
| 23 |
| 24 if (rect.top === elementBoundingBox.top && rect.left === elementBoundingBox.
left && |
| 25 rect.bottom === elementBoundingBox.bottom && rect.right === elementBound
ingBox.right) |
| 26 return false; |
| 27 } |
| 28 |
| 29 return true; |
| 30 } |
| 31 |
| 32 function getStackingOrder(element) |
| 33 { |
| 34 var divElements = []; |
| 35 // Force a synchronous style recalc and layout. |
| 36 document.body.offsetTop; |
| 37 |
| 38 var stackingOrder = window.internals.nodesFromRect(document, 100, 75, 200, 200
, 200, 200, false, false, false); |
| 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(testPermutation, siblingIndex, containerIndex,
firstChildIndex, 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 testPermutation(permutationIteration, ordering, hasPositionedAncestor, c
ontainerIsPositioned); |
| 161 permutationIteration++; |
| 162 } |
| 163 } |
| 164 } |
| 165 } |
| 166 |
| 167 function permute(testPermutation) |
| 168 { |
| 169 var ancestor = document.getElementById('ancestor'); |
| 170 var predecessor = document.getElementById('predecessor'); |
| 171 var successor = document.getElementById('successor'); |
| 172 var container = document.getElementById('container'); |
| 173 var firstChild = document.getElementById('firstChild'); |
| 174 var secondChild = document.getElementById('secondChild'); |
| 175 |
| 176 var indices = [ 0, 1, 2, 3 ]; |
| 177 for (var siblingIndex = 0; siblingIndex < indices.length; ++siblingIndex) { |
| 178 var siblingIndices = indices.slice(0); |
| 179 siblingIndices.splice(siblingIndex, 1); |
| 180 for (var containerSubindex = 0; containerSubindex < siblingIndices.length; +
+containerSubindex) { |
| 181 var containerIndices = siblingIndices.slice(0); |
| 182 var containerIndex = containerIndices[containerSubindex]; |
| 183 containerIndices.splice(containerSubindex, 1); |
| 184 var firstChildIndex = containerIndices[0]; |
| 185 var secondChildIndex = containerIndices[1]; |
| 186 |
| 187 permuteWithFixedOrdering(testPermutation, siblingIndex, containerIndex, fi
rstChildIndex, secondChildIndex, 1); |
| 188 permuteWithFixedOrdering(testPermutation, siblingIndex, containerIndex, fi
rstChildIndex, secondChildIndex, 2); |
| 189 permuteWithFixedOrdering(testPermutation, siblingIndex, containerIndex, fi
rstChildIndex, secondChildIndex, 3); |
| 190 } |
| 191 } |
| 192 } // function doTest |
| OLD | NEW |