kocienda | 96caded | 2004-05-04 23:31:42 +0000 | [diff] [blame] | 1 | //------------------------------------------------------------------------------------------------------- |
| 2 | // Java script library to run traversal layout tests |
| 3 | |
| 4 | function dumpNodeIterator(it, expectedResult) { |
| 5 | var string = '<p><b>Expect ' + expectedResult + '</b>: '; |
| 6 | var checkIt = document.createNodeIterator(root, NodeFilter.SHOW_ELEMENT, testNodeFiter, false); |
| 7 | var printedPointer = false; |
| 8 | while (1) { |
| 9 | var node = checkIt.nextNode(); |
| 10 | if (!node) |
| 11 | break; |
| 12 | if (!printedPointer && (it.referenceNode == node || it.referenceNode == undefined)) { |
| 13 | printedPointer = true; |
| 14 | var s = it.referenceNode == undefined ? node.id + ' ' : '[' + node.id + '] '; |
| 15 | if (it.pointerBeforeReferenceNode) |
| 16 | string += "* " + s; |
| 17 | else |
| 18 | string += s + "* "; |
| 19 | } |
| 20 | else { |
| 21 | string += node.id + " "; |
| 22 | } |
| 23 | } |
| 24 | return string; |
| 25 | } |
| 26 | |
| 27 | //------------------------------------------------------------------------------------------------------- |
| 28 | |
| 29 | function nodeDepth(node) { |
| 30 | var depth = 0; |
| 31 | while ((node = node.parentNode)) |
| 32 | depth++; |
| 33 | return depth; |
| 34 | } |
| 35 | |
| 36 | //------------------------------------------------------------------------------------------------------- |
| 37 | |
| 38 | function dumpTreeWalker(tw, root, start, backwards) { |
| 39 | var string = '<p><b>Tree Walker: </b><br>'; |
| 40 | if (root == undefined) |
| 41 | root = tw.currentNode; |
| 42 | var rootDepth = nodeDepth(root); |
| 43 | if (start == undefined) |
| 44 | start = root; |
| 45 | tw.currentNode = start; |
| 46 | string += start.id + '<br>'; |
| 47 | while (1) { |
| 48 | var current = tw.currentNode; |
| 49 | if (backwards == undefined) |
| 50 | tw.nextNode(); |
| 51 | else |
| 52 | backwards ? tw.previousNode() : tw.nextNode(); |
| 53 | var n = tw.currentNode; |
| 54 | if (current == n) |
| 55 | break; |
| 56 | var depth = nodeDepth(n) - rootDepth; |
| 57 | for (i = 0; i < depth; i++) |
| 58 | string += ' '; |
| 59 | string += n.id + '<br>'; |
| 60 | } |
| 61 | return string; |
| 62 | } |
| 63 | |
| 64 | //------------------------------------------------------------------------------------------------------- |
| 65 | |