[Phoenix-commits] rev 19813 - public/yulup/src/trunk/yulup/prototypes/prototype1/src/chrome/content

andi at wyona.com andi at wyona.com
Fri Nov 3 18:01:45 CET 2006


Author: andi
Date: 2006-11-03 18:01:44 +0100 (Fri, 03 Nov 2006)
New Revision: 19813

Modified:
   public/yulup/src/trunk/yulup/prototypes/prototype1/src/chrome/content/view.js
Log:
Use a selection listener instead of mouseevents to trigger current location path computation.


Modified: public/yulup/src/trunk/yulup/prototypes/prototype1/src/chrome/content/view.js
===================================================================
--- public/yulup/src/trunk/yulup/prototypes/prototype1/src/chrome/content/view.js	2006-11-03 16:02:30 UTC (rev 19812)
+++ public/yulup/src/trunk/yulup/prototypes/prototype1/src/chrome/content/view.js	2006-11-03 17:01:44 UTC (rev 19813)
@@ -1216,8 +1216,11 @@
                                                              }, true);
 
             /** No selection events fired onSelectionChanged so we have to use a mouse listener for keeping track of selection changes **/
-            wysiwygXSLTEditor.contentWindow.addEventListener("mousedown", new WYSIWYGXSLTMouseListener(this), true);
+            //wysiwygXSLTEditor.contentWindow.addEventListener("mousedown", new WYSIWYGXSLTMouseListener(this), true);
 
+            // hook up selection listener
+            wysiwygXSLTEditor.contentWindow.getSelection().QueryInterface(Components.interfaces.nsISelectionPrivate).addSelectionListener(new WYSIWYGXSLTSelectionListener(this));
+
             //wysiwygXSLTEditor.contentWindow.addEventListener("mousedown", new WYSIWYGXSLTMouseListener(this), true);
             var nsCheckbox = document.getElementById("uiYulupXPathToolBarNSAwareCheckbox");
             nsCheckbox.addEventListener('CheckboxStateChange', new NSCheckboxStateChangeListener(this), true);
@@ -1927,6 +1930,47 @@
 };
 
 
+function WYSIWYGXSLTSelectionListener(aView) {
+    /* DEBUG */ YulupDebug.ASSERT(aView != null);
+
+    this.__view = aView;
+}
+
+WYSIWYGXSLTSelectionListener.prototype = {
+    __view: null,
+
+    notifySelectionChanged: function (aDocument, aSelection, aReason) {
+        var node        = null;
+        var domDocument = null;
+        var xpath       = null;
+        var sourceNode  = null;
+
+        node        = aSelection.focusNode;
+        domDocument = this.__view.domDocument;
+
+        this.__view.currentXHTMLNode = node;
+
+        xpath = this.__view.getSourceXPathForXHTMLNode(node, this.__view.isNamespaceAware);
+
+        if (xpath != null && xpath != this.__view.currentSourceSelectionPath) {
+            /* DEBUG */ dump("Yulup:view.js:WYSIWYGXSLTSelectionListener.notifySelectionChanged: XPath of selected node is: \"" + xpath + "\"\n");
+
+            sourceNode = domDocument.evaluate(xpath, domDocument, domDocument.createNSResolver(domDocument.documentElement), XPathResult.ANY_TYPE, null).iterateNext();
+
+            if (sourceNode != null) {
+                /* DEBUG */ dump("Yulup:view.js:WYSIWYGXSLTSelectionListener.notifySelectionChanged: setting source node \"" + sourceNode + "\" with XPath \"" + xpath + "\" as new current node\n");
+                this.__view.currentSourceSelectionPath = xpath;
+                this.__view.currentSourceNode = sourceNode;
+
+            } else {
+                this.__view.currentSourceSelectionPath = null;
+                this.__view.currentSourceNode = null;
+            }
+        }
+    }
+};
+
+
 function NSCheckboxStateChangeListener(aView) {
     /* DEBUG */ YulupDebug.ASSERT(aView != null);
 




More information about the Phoenix-commits mailing list