[Phoenix-commits] rev 14979 - public/phoenix/trunk/phoenix/prototypes/prototype1/test/testpackage/chrome/content

andi at wyona.com andi at wyona.com
Tue Jul 4 23:15:02 CEST 2006


Author: andi
Date: 2006-07-04 23:15:00 +0200 (Tue, 04 Jul 2006)
New Revision: 14979

Added:
   public/phoenix/trunk/phoenix/prototypes/prototype1/test/testpackage/chrome/content/processingloop-test.xul
Log:
Basic processing loop prototyping harness.

Added: public/phoenix/trunk/phoenix/prototypes/prototype1/test/testpackage/chrome/content/processingloop-test.xul
===================================================================
--- public/phoenix/trunk/phoenix/prototypes/prototype1/test/testpackage/chrome/content/processingloop-test.xul	2006-07-04 16:34:09 UTC (rev 14978)
+++ public/phoenix/trunk/phoenix/prototypes/prototype1/test/testpackage/chrome/content/processingloop-test.xul	2006-07-04 21:15:00 UTC (rev 14979)
@@ -0,0 +1,136 @@
+<?xml version="1.0"?>
+
+<window id="uiEditorWindow"
+        orient="vertical"
+        align="stretch"
+        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+
+  <script type="application/x-javascript">
+<![CDATA[
+function onLoadHandler() {
+    var iframe1      = null;
+
+    /* DEBUG */ dump("######## PhoenixTEST:processingloop-test.js:onLoadHandler() invoked\n");
+
+    iframe1 = document.getElementById("iframe1");
+
+    dumpTree(iframe1);
+}
+
+function dumpTree(aIframe) {
+    dump("\######## PhoenixTEST:processingloop-test.js:dumpTree: innerHTML:\n" + aIframe.contentDocument.childNodes[1].innerHTML + "\n");
+
+    dump("\######## PhoenixTEST:processingloop-test.js:dumpTree: serialised:\n");
+    dump((new WYSIWYGDOMSerialiser(aIframe.contentDocument)).serialise());
+    dump("\n\n");
+};
+
+
+function WYSIWYGDOMSerialiser(aRootNode) {
+    /* DEBUG */ dump("######## PhoenixTEST:processingloop-test.js:WYSIWYGDOMSerialiser(\"" + aRootNode + "\") invoked\n");
+
+    this.rootNode = aRootNode;
+}
+
+WYSIWYGDOMSerialiser.prototype = {
+    rootNode:     null,
+    outputString: null,
+
+    serialise: function () {
+        /* DEBUG */ dump("######## PhoenixTEST:processingloop-test.js:WYSIWYGDOMSerialiser.serialise() invoked\n");
+
+        this.serialiseDOMTree(this.rootNode, 0);
+
+        return this.outputString;
+    },
+
+    serialiseDOMTree: function (aNode, aNestingLevel) {
+        var child = null;
+
+        // if emitNodeStart() returns false, don't inspect its children
+        if (this.emitNodeStart(aNode, aNestingLevel)) {
+            for (child = aNode.firstChild; child != null; child = child.nextSibling) {
+                this.serialiseDOMTree(child, aNestingLevel + 1);
+            }
+
+            this.emitNodeEnd(aNode, aNestingLevel);
+        }
+    },
+
+    createNestingPrefix: function (aNestingLevel) {
+        var nestingPrefix = "";
+
+        for (var i = 0; i < aNestingLevel; i++)
+            nestingPrefix += "  ";
+
+        return nestingPrefix;
+    },
+
+    emitNodeStart: function (aNode, aNestingLevel) {
+        var retVal = true;
+        var nestingPrefix = this.createNestingPrefix(aNestingLevel);
+
+        switch (aNode.nodeType) {
+            case Components.interfaces.nsIDOMNode.ELEMENT_NODE:
+                this.outputString += nestingPrefix + "<" + aNode.nodeName.toLowerCase();
+
+                if (aNode.hasAttributes()) {
+                    // emit the attributes
+                    for (var i = 0; i < aNode.attributes.length; i++) {
+                        if (aNode.attributes.item(i).nodeName != "_moz_dirty")
+                            this.outputString += " " + aNode.attributes.item(i).nodeName + "=\"" + aNode.attributes.item(i).nodeValue + "\"";
+                    }
+                }
+
+                if (aNode.hasChildNodes()) {
+                    this.outputString += ">\n";
+                } else {
+                    this.outputString += "/>\n";
+                }
+                break;
+            case Components.interfaces.nsIDOMNode.TEXT_NODE:
+                this.outputString += aNode.nodeValue + "\n";
+                break;
+            case Components.interfaces.nsIDOMNode.PROCESSING_INSTRUCTION_NODE:
+                this.outputString += nestingPrefix + "<?" + aNode.target + " " + aNode.data + "?>";
+                break;
+            case Components.interfaces.nsIDOMNode.COMMENT_NODE:
+                this.outputString += nestingPrefix + "<!--" + aNode.nodeValue + "-->";
+                break;
+            case Components.interfaces.nsIDOMNode.DOCUMENT_NODE:
+                // the document itself; nothing to emit here
+                break;
+            case Components.interfaces.nsIDOMNode.DOCUMENT_TYPE_NODE:
+                // TODO: emit notations (see http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-412266927)
+                this.outputString += nestingPrefix + "<!DOCTYPE " + aNode.name + (aNode.publicId ? " PUBLIC \"" + aNode.publicId + "\" " : " ")  + "\"" + aNode.systemId + "\">\n";
+                break;
+            default:
+               /* DEBUG */ dump("######## PhoenixTEST:processingloop-test.js:WYSIWYGDOMSerialiser.emitNodeStart: unknown node \"" + aNode.nodeName + "\" of node type \"" + aNode.nodeType + "\" encountered\n");
+               throw new PhoenixEditorException("Phoenix:processingloop-test.js:WYSIWYGDOMSerialiser.emitNodeStart: unknown node \"" + aNode.nodeName + "\" of node type \"" + aNode.nodeType + "\" encountered.");
+        }
+
+        return retVal;
+    },
+
+    emitNodeEnd: function (aNode, aNestingLevel) {
+        var nestingPrefix = this.createNestingPrefix(aNestingLevel);
+
+        switch (aNode.nodeType) {
+            case Components.interfaces.nsIDOMNode.ELEMENT_NODE:
+                if (aNode.hasChildNodes()) {
+                    this.outputString += nestingPrefix + "</" + aNode.nodeName.toLowerCase() + ">\n";
+                }
+                break;
+            default:
+                // nothing to do here
+        }
+    }
+};
+
+]]>
+  </script>
+
+  <iframe id="iframe1" src="file:///Users/awuest-devel/Documents/devel/src/wyona/lenya-1.4_svn/public/phoenix/trunk/phoenix/prototypes/prototype1/test/testdocs/product_sketch.xml" flex="1" style="border: 1px solid black" onload="onLoadHandler()"/>
+  <iframe id="iframe2" flex="1" style="border: 1px solid black"/>
+
+</window>




More information about the Phoenix-commits mailing list