[Pkg-mozext-commits] [itsalltext] 292/459: checkpoint in monitor migration. pageStart seems broken again. :-( Basically, the monitor will just check files. We'll use a DOM event to track changes to the pagase (new styles, etc.)

David Prévot taffit at moszumanska.debian.org
Tue Feb 24 23:26:31 UTC 2015


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository itsalltext.

commit 2bb75eba1d8e341a2e15c6abeef102ecb928b2db
Author: Christian Höltje <docwhat at gerf.org>
Date:   Wed Nov 7 00:36:53 2007 -0500

    checkpoint in monitor migration. pageStart seems broken again. :-(  Basically, the monitor will just check files.  We'll use a DOM event to track changes to the pagase (new styles, etc.)
---
 notes.txt                        |  17 ++++
 src/chrome/content/API.js        |   2 +-
 src/chrome/content/itsalltext.js | 164 ++++++++++++++-----------------------
 src/chrome/content/monitor.js    | 171 +++++++++++++++++++++++++++++++++++++++
 tests/hidden.html                |  71 +++++++++++-----
 5 files changed, 300 insertions(+), 125 deletions(-)

diff --git a/notes.txt b/notes.txt
index c181cb0..75652bb 100644
--- a/notes.txt
+++ b/notes.txt
@@ -6,3 +6,20 @@ http://en.wikipedia.org/wiki/DOM_Events
 
 I'm going to assume that keeping references to DOMElements are
 bad. :-(
+
+* javascript.options.showInConsole = true. Logs errors in chrome files
+  to the Error Console.
+* nglayout.debug.disable_xul_cache = true. Disables the XUL cache so
+  that changes to windows and dialogs do not require a restart. This
+  assumes you're using directories rather than JARs. Changes to XUL
+  overlays will still require reloading of the document overlaid.
+* browser.dom.window.dump.enabled = true. Enables the use of the
+  dump() statement to print to the standard console. See window.dump
+  for more info. You can also use nsIConsoleService from privileged
+  script.
+* javascript.options.strict = true. Enables strict JavaScript warnings
+  in the Error Console. Note that since many people have this setting
+  turned off when developing, you will see lots of warnings for
+  problems with their code in addition to warnings for your own
+  extension. You can filter those with Console2.
+
diff --git a/src/chrome/content/API.js b/src/chrome/content/API.js
index 66d5dc4..e508d28 100644
--- a/src/chrome/content/API.js
+++ b/src/chrome/content/API.js
@@ -50,7 +50,7 @@
 
     var onload = function (event) {
         /* Start watching the document, but force it. */
-        ItsAllText.monitor.watch(document, true);
+        ItsAllText.monitor.startPage(document, true);
 
         /* Turn on all the hidden CSS */
         var nodes = [], i;
diff --git a/src/chrome/content/itsalltext.js b/src/chrome/content/itsalltext.js
index c96a7c9..2948970 100644
--- a/src/chrome/content/itsalltext.js
+++ b/src/chrome/content/itsalltext.js
@@ -191,7 +191,9 @@ var ItsAllText = function() {
         /* Load the various bits needed to make this work. */
         var loader = Components.classes["@mozilla.org/moz/jssubscript-loader;1"].getService(Components.interfaces.mozIJSSubScriptLoader);
         loader.loadSubScript('chrome://itsalltext/content/Color.js', that);
+        loader.loadSubScript('chrome://itsalltext/content/monitor.js', that);
         loader.loadSubScript('chrome://itsalltext/content/cacheobj.js', that);
+        that.new_monitor = new that.new_monitor(that);
     };
     loadthings();
 
@@ -291,7 +293,7 @@ var ItsAllText = function() {
             if (that.preferences) {
                 that.preferences[aData] = that.preferences.private_get(aData);
                 if (aData == 'refresh') {
-                    that.monitor.restart();
+                    that.new_monitor.restart();
                 }
             }
         }
@@ -313,7 +315,7 @@ var ItsAllText = function() {
     that.getRefresh = function() {
         var refresh = that.preferences.refresh;
         if (!refresh || refresh < 1) {
-            that.debug('Invalid refresh gotten:',refresh);
+            that.debug('Invalid refresh:',refresh);
             refresh = 1;
         }
         var retval = 1000*refresh;
@@ -455,15 +457,29 @@ var ItsAllText = function() {
     that.getCacheObj = function(node) {
         var cobj = null;
         var str = that.MYSTRING+"_UID";
-        if (typeof(node) == 'string') {
-            cobj = that.tracker[node];
+        var id = null;
+        if (typeof(node) === 'string') {
+            id = node;
+        } else if (node && node.hasAttribute(str)) {
+            id = node.getAttribute(str);
+        }
+        if (id && that.tracker.hasOwnProperty(id)) {
+            return that.tracker[id];
         } else {
-            if (node && node.hasAttribute(str)) {
-                cobj = that.tracker[node.getAttribute(str)];
-            }
-            if (!cobj) {
-                cobj = new ItsAllText.CacheObj(node);
-            }
+            return null;
+        }
+    };
+
+    /**
+     * Creates a cache object, unless one exists already.
+     * Note: These UIDs are only unique for Its All Text.
+     * @param {DOMElement} node A dom object node or id to one.
+     * @returns {String} the UID or null.
+     */
+    that.makeCacheObj = function(node) {
+        var cobj = that.getCacheObj(node);
+        if (!cobj) {
+            cobj = new ItsAllText.CacheObj(node);
         }
         return cobj;
     };
@@ -633,20 +649,20 @@ var ItsAllText = function() {
     /**
      * This function is called regularly to watch changes to web documents.
      */
-    that.monitor = {
+    that.old_monitor = {
         id: null,
         last_now:0,
         documents: [],
         /**
-         * Starts or restarts the document monitor.
+         * Starts or restarts the document old_monitor.
          */
         restart: function() {
             var rate = that.getRefresh();
-            var id   = that.monitor.id;
+            var id   = that.old_monitor.id;
             if (id) {
                 clearInterval(id);
             }
-            that.monitor.id = setInterval(that.monitor.watcher, rate);
+            that.old_monitor.id = setInterval(that.old_monitor.watcher, rate);
         },
         /**
          * watches the document 'doc'.
@@ -683,7 +699,7 @@ Line 0
                 }
             }
 
-            var documents = that.monitor.documents;
+            var documents = that.old_monitor.documents;
             var i;
             for(i in documents) {
                 if (documents[i] === doc) {
@@ -694,25 +710,25 @@ Line 0
             }
             that.debug('watch()ing: ', doc && doc.location);
             that.refreshDocument(doc);
-            that.monitor.documents.push(doc);
+            that.old_monitor.documents.push(doc);
         },
         /**
          * Callback to be used by restart()
          * @private
          */
         watcher: function(offset) {
-            var monitor = that.monitor;
+            var old_monitor = that.old_monitor;
             var rate = that.getRefresh();
 
             var now = Date.now();
-            if (now - monitor.last_now < Math.round(rate * 0.9)) {
-                that.debug('monitor.watcher(',offset,') -- skipping catchup refresh');
+            if (now - old_monitor.last_now < Math.round(rate * 0.9)) {
+                that.debug('old_monitor.watcher(',offset,') -- skipping catchup refresh');
                 return;
             }
-            monitor.last_now = now;
+            old_monitor.last_now = now;
 
             /* Walk the documents looking for changes */
-            var documents = monitor.documents;
+            var documents = old_monitor.documents;
             var i, doc;
             for(i in documents) {
                 if (documents.hasOwnProperty(i)) {
@@ -728,7 +744,7 @@ Line 0
          * @param {Object} doc The document to watch.
          */
         unwatch: function(doc) {
-            var documents = that.monitor.documents;
+            var documents = that.old_monitor.documents;
             var i;
             for(i in documents) {
                 if (documents[i] === doc) {
@@ -802,17 +818,31 @@ Line 0
 
 
     // Do the startup when things are loaded.
-    that.listen(window, 'load', that.hitch(that, 'pageload'));
-    that.listen(window, 'unload', that.hitch(that, 'pageunload'));
+    that.listen(window, 'load', function () {
+        // Add a callback to be run every time a document loads.
+        // note that this includes frames/iframes within the document
+        that.listen(gBrowser, "load",
+                    that.hitch(that.new_monitor, 'registerPage'), true);
+        that.listen(gBrowser, "unload",
+                    that.hitch(that.new_monitor, 'unregisterPage'), true);
+
+        // Start watching the preferences.
+        that.preference_observer.register();
+
+        // Setup the context menu whenever it is shown.
+        var contentAreaContextMenu = document.getElementById("contentAreaContextMenu");
+        if (contentAreaContextMenu) {
+            that.listen(contentAreaContextMenu, 'popupshowing', that.hitch(that, 'onContextMenu'), false);
+        }
+    }, false);
 
+    that.listen(window, 'unload', function () {
+        var doc = event.originalTarget;
+        that.debug("pageunload(): A page has been unloaded", doc && doc.location);
+        that.preference_observer.unregister();
+        that.cleanCacheObjs();
+    }, false);
 
-    /* This helps debug the monitor and page and memory usage. */
-    if (1) { //narf
-        var f = function () {
-            that.debug(' -- MARK -- '+ that.monitor.documents.length);
-        }
-        setInterval(f, 1000 * 7);
-    }
 };
 
 /**
@@ -971,7 +1001,7 @@ ItsAllText.prototype.menuExtEdit = function(ext, clobber, event) {
     }
     this.debug('menuExtEdit:',uid, ext, clobber);
     var cobj = this.getCacheObj(uid);
-    this.monitor.watch(cobj.node.ownerDocument);
+    //narf this.monitor.watch(cobj.node.ownerDocument);
     cobj.edit(ext, clobber);
 };
 
@@ -1051,75 +1081,5 @@ ItsAllText.prototype.getLocale = function() {
     return obj.createBundle("chrome://itsalltext/locale/itsalltext.properties");
 };
 
-/**
- * An event to watch a document.
- * This must be a stand-alone constant function so that it will replace previous versions if they exist.
- * @method contentLoad
- */
-ItsAllText.prototype.contentLoad = function (event) {
-    var doc = event.target;
-    var unsafeWin = doc.defaultView.wrappedJSObject;
-    this.debug('contentLoad() ', doc && doc.location);
-    this.monitor.watch(doc);
-    this.listen(unsafeWin, 'pagehide', this.hitch(this, 'contentUnload'));
-};
-/**
- * An event to watch a document.
- * This must be a stand-alone constant function so that it will replace previous versions if they exist.
- * @method contentUnload
- */
-ItsAllText.prototype.contentUnload = function (event) {
-    var doc = event.target;
-    this.debug('contentUnload() ', doc && doc.location);
-    this.monitor.unwatch(doc);
-};
-
-/**
- * Initialize the module.  Should be called once, when a window is loaded.
- * @private
- */
-ItsAllText.prototype.pageload = function(event) {
-    var doc = event.originalTarget;
-    if (!doc || doc.nodeName != "#document") {
-        return;
-    }
-    this.debug("pageload(): A page has been loaded:",doc && doc.location);
-
-    // Start watching the preferences.
-    this.preference_observer.register();
-
-    // Start the monitor
-    this.monitor.restart();
-
-    // Schedule a watch when the content is loaded.
-    var appContent = document.getElementById("appcontent"); // The Browser
-    this.appContent = appContent;
-    if (appContent) {
-        this.listen(appContent, 'DOMContentLoaded', this.hitch(this, 'contentLoad'), true);
-    }
-
-    // Attach the context menu, if we can.
-    var contentAreaContextMenu = doc.getElementById("contentAreaContextMenu");
-    if (contentAreaContextMenu) {
-        this.listen(contentAreaContextMenu, 'popupshowing', this.hitch(this, 'onContextMenu'), false);
-    }
-};
-
-/**
- * Uninitialize the module.  Should be called once, when a window is unloaded.
- * @private
- */
-ItsAllText.prototype.pageunload = function(event) {
-    var doc = event.originalTarget;
-    /* We don't check for the doc type because we want to
-     * be sure everything is unloaded.
-     */
-    this.debug("pageunload(): A page has been unloaded", doc && doc.location);
-    this.monitor.unwatch(doc);
-    this.preference_observer.unregister();
-    this.cleanCacheObjs();
-};
-
-
 ItsAllText = new ItsAllText();
 
diff --git a/src/chrome/content/monitor.js b/src/chrome/content/monitor.js
new file mode 100644
index 0000000..68ed8f2
--- /dev/null
+++ b/src/chrome/content/monitor.js
@@ -0,0 +1,171 @@
+/*
+ *  It's All Text! - Easy external editing of web forms.
+ *
+ *  Copyright (C) 2006-2007 Christian Höltje
+ *
+ *  This program is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/*jslint nomen: true, evil: false, browser: true */
+
+function new_monitor(iat) {
+    this.iat = iat;
+    this.iat.debug('new_monitor');
+
+    var hitch_re = /^hitched_/;
+    for (method in this) {
+        if (hitch_re.test(method)) {
+
+            this.iat.debug('hitching ', method ,' -> ', method.replace(hitch_re, ''));
+            this[method.replace(hitch_re, '')] = this.iat.hitch(this, method);
+        }
+    }
+
+}
+
+new_monitor.prototype.hitched_restart = function () {
+    var rate = this.iat.getRefresh();
+    var id   = this.id;
+    if (id) {
+        clearInterval(id);
+    }
+    this.id = setInterval(this.watcher, rate);
+};
+
+new_monitor.prototype.registerPage = function (event) {
+    if (event.originalTarget instanceof HTMLDocument) {
+        var doc = event.originalTarget;
+        if (event.originalTarget.defaultView.frameElement) {
+            // Frame within a tab was loaded. doc should be the root document of
+            // the frameset. If you don't want do anything when frames/iframes
+            // are loaded in this web page, uncomment the following line:
+            // return;
+            // Find the root document:
+            while (doc.defaultView.frameElement) {
+                doc=doc.defaultView.frameElement.ownerDocument;
+            }
+        }
+
+        this.iat.debug('registerPage: ', doc && doc.location);
+
+        /* appContent is the browser chrome. */
+        var appContent = document.getElementById("appcontent");
+        this.iat.listen(appContent, 'DOMContentLoaded', this.startPage, true);
+    }
+};
+
+new_monitor.prototype.unregisterPage = function (event) {
+    var doc = event.originalTarget;
+    this.iat.debug('unregisterPage', doc && doc.location);
+
+    // Stop any monitoring.
+    this.stopPage(event);
+
+    // Remove any other handlers.
+    var appContent = document.getElementById("appcontent");
+    this.iat.unlisten(appContent, 'DOMContentLoaded', this.startPage, true);
+};
+
+new_monitor.prototype.hitched_watcher = function (init) {
+    var doc = gBrowser.selectedBrowser.contentDocument;
+    this.iat.debug('watcher: ', init, doc);
+    var nodes = [];
+    var i, cobj;
+    var is_html = this.isHTML(doc);
+    var is_xul  = this.isXUL(doc);
+    if (is_html) {
+        /* HTML */
+        nodes = doc.getElementsByTagName('textarea');
+    } else if (is_xul) {
+        /* XUL */
+        nodes = doc.getElementsByTagName('textbox');
+    } else {
+        this.unregisterPage(doc);
+    }
+    for(i=0; i < nodes.length; i++) {
+        if (init) {
+            cobj = ItsAllText.makeCacheObj(node);
+        } else {
+            cobj = ItsAllText.getCacheObj(node);
+        }
+        if (cobj) {
+            cobj.update();
+            if (init && is_html) {
+                cobj.addGumDrop();
+            }
+        }
+    }
+};
+
+new_monitor.prototype.hitched_startPage = function (event, force) {
+    this.iat.debug('narf');
+    
+    var doc = event.originalTarget;
+    this.iat.debug('startPage', doc && doc.location, force);
+    if (!(force || this.isHTML(doc))) {
+        this.unregisterPage(event);
+        return;
+    }
+
+    var unsafeWin = doc.defaultView.wrappedJSObject;
+    this.iat.listen(unsafeWin, 'pagehide', this.iat.hitch(this, 'stopPage'));
+
+    // Kick off a watcher now...
+    this.watcher();
+    // Set up the future ones
+    this.restart();
+};
+
+new_monitor.prototype.hitched_stopPage = function (event) {
+    var doc = event.originalTarget;
+    this.iat.debug('stopPage', doc && doc.location);
+};
+
+new_monitor.prototype.isXUL = function (doc) {
+    var is_xul=(contentType=='application/vnd.mozilla.xul+xml');
+    var is_my_readme;
+    try {
+        is_my_readme = location && location.href == this.iat.README;
+    } catch(e) {
+        is_my_readme = false;
+    }
+    return is_xul && !is_my_readme;
+};
+
+new_monitor.prototype.isHTML = function (doc) {
+    var contentType, location, is_html, is_usable, is_my_readme;
+    /* Check that this is a document we want to play with. */
+    contentType = doc.contentType;
+    location = doc.location;
+    is_html = (contentType=='text/html' ||
+               contentType=='text/xhtml' ||
+               contentType=='application/xhtml+xml');
+    is_usable = is_html &&
+                location &&
+                location.protocol !== 'about:' &&
+                location.protocol !== 'chrome:';
+    try {
+        is_my_readme = location && location.href == this.iat.README;
+        /*
+         * Avoiding this error.... I hope.
+         * uncaught exception: [Exception... "Component returned failure code: 0x80004003 (NS_ERROR_INVALID_POINTER) [nsIDOMLocation.href]"  nsresult: "0x80004003 (NS_ERROR_INVALID_POINTER)"  location: "JS frame :: chrome://itsalltext/chrome/itsalltext.js :: anonymous :: line 634"  data: no]
+         * Line 0
+         */
+    } catch(e) {
+        is_my_readme = false;
+        is_usable = false;
+    }
+    return is_usable && !is_my_readme;
+};
+
+
diff --git a/tests/hidden.html b/tests/hidden.html
index 1ece1cb..b2d7119 100644
--- a/tests/hidden.html
+++ b/tests/hidden.html
@@ -12,26 +12,41 @@
        var dis2 = document.getElementById('dis2');
        var vis2 = document.getElementById('vis2');
 
+       var dis3 = document.getElementById('dis3');
+       var vis3 = document.getElementById('vis3');
+
        if(dis.style.display == 'none') {
          dis.style.display = '';
-       } else { 
+       } else {
          dis.style.display = 'none';
        }
        if(vis.style.visibility == 'hidden') {
          vis.style.visibility = '';
-       } else { 
+       } else {
          vis.style.visibility = 'hidden';
        }
+
        if(dis2.className == 'nodis') {
            dis2.className = '';
-       } else { 
+       } else {
            dis2.className = 'nodis';
        }
        if(vis2.className == 'novis') {
            vis2.className = '';
-       } else { 
+       } else {
            vis2.className = 'novis';
        }
+
+       if(dis3.className == 'nodis') {
+           dis3.className = '';
+       } else {
+           dis3.className = 'nodis';
+       }
+       if(vis3.className == 'novis') {
+           vis3.className = '';
+       } else {
+           vis3.className = 'novis';
+       }
        return false;
      }
     </script>
@@ -55,33 +70,45 @@
     <form action="" method="get">
       <ol>
         <li>
-          In the boxed area below, there should <em>not</em> be a button or a textarea visible.
-          <br>
-            <div class="boxed">
-               <textarea id="dis" style="display: none;">display: none</textarea>
-            </div>
+          <div class="boxed">
+             <textarea id="dis" style="display: none;">display: none</textarea>
+          </div>
         </li>
         <li>
-          In the boxed area below, there should <em>not</em> be a button or a textarea visible.
-          <br>
-            <div class="boxed">
-               <textarea id="dis2" class="nodis">display: none</textarea>
-            </div>
+          <div class="boxed">
+             <textarea id="dis2" class="nodis">display: none</textarea>
+          </div>
         </li>
         <li>
-          In the boxed area below, there should <em>not</em> be a button or a textarea visible.
-          <br>
-            <div class="boxed">
-              <textarea id="vis" style="visibility: hidden;">visibility: hidden</textarea>
+          <div class="boxed">
+            <textarea id="vis" style="visibility: hidden;">visibility: hidden</textarea>
+          </div>
+        </li>
+        <li>
+          <div class="boxed">
+            <textarea id="vis2" class="novis">visibility: hidden</textarea>
+          </div>
+        </li>
+
+        <li>
+          <div class="boxed">
+            <div id="dis3" class="nodis">
+              <div>
+                <textarea>nested display: none</textarea>
+              </div>
             </div>
+          </div>
         </li>
         <li>
-          In the boxed area below, there should <em>not</em> be a button or a textarea visible.
-          <br>
-            <div class="boxed">
-              <textarea id="vis2" class="novis">visibility: hidden</textarea>
+          <div class="boxed">
+            <div id="vis3" class="novis">
+              <div>
+                <textarea>nested visibility: hidden</textarea>
+              </div>
             </div>
+          </div>
         </li>
+
         <li>
           Click on the button to toggle the hiddeness/visibility of
           the textareas.  The edit button should appear within a few

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/itsalltext.git



More information about the Pkg-mozext-commits mailing list