[Pkg-mozext-commits] [firebug] 41/68: Manual port of: Wait for load when updating a CSS panel (style, stylesheet, css), related also to issue 4893

David Prévot taffit at moszumanska.debian.org
Mon Mar 31 22:45:53 UTC 2014


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

taffit pushed a commit to tag fbtest-1.11.4
in repository firebug.

commit cf4d0604874fc8585c8a8858c93f1c1ab888e4a4
Author: Jan Odvarko <odvarko at gmail.com>
Date:   Fri Apr 12 16:00:18 2013 +0200

    Manual port of: Wait for load when updating a CSS panel (style, stylesheet, css), related also to issue 4893
---
 extension/content/firebug/css/computedPanel.js | 26 +++--------
 extension/content/firebug/css/cssPanel.js      | 18 +++++---
 extension/content/firebug/css/loadHandler.js   | 61 ++++++++++++++++++++++++++
 extension/content/firebug/css/stylePanel.js    | 22 +++++-----
 4 files changed, 88 insertions(+), 39 deletions(-)

diff --git a/extension/content/firebug/css/computedPanel.js b/extension/content/firebug/css/computedPanel.js
index c7cc75a..c30cae0 100644
--- a/extension/content/firebug/css/computedPanel.js
+++ b/extension/content/firebug/css/computedPanel.js
@@ -17,10 +17,11 @@ define([
     "firebug/lib/string",
     "firebug/lib/persist",
     "firebug/css/cssModule",
-    "firebug/css/cssReps"
+    "firebug/css/cssReps",
+    "firebug/css/loadHandler",
 ],
 function(Obj, Firebug, Domplate, Locale, Events, Css, Dom, Xml, Url, Arr, SourceLink, Menu,
-    Options, Str, Persist, CSSModule, CSSInfoTip) {
+    Options, Str, Persist, CSSModule, CSSInfoTip, LoadHandler) {
 
 with (Domplate) {
 
@@ -159,26 +160,9 @@ CSSComputedPanel.prototype = Obj.extend(Firebug.Panel,
         if (!element)
             return;
 
-        var doc = element.ownerDocument;
-        var win = doc.defaultView;
-
         // Update now if the document is loaded, otherwise wait for "load" event.
-        if (doc.readyState == "complete")
-            return this.doUpdateComputedView(element);
-
-        if (this.updateInProgress)
-            return;
-
-        var self = this;
-        var onWindowLoadHandler = function()
-        {
-            self.context.removeEventListener(win, "load", onWindowLoadHandler, true);
-            self.updateInProgress = false;
-            self.doUpdateComputedView(element);
-        }
-
-        this.context.addEventListener(win, "load", onWindowLoadHandler, true);
-        this.updateInProgress = true;
+        var loadHandler = new LoadHandler();
+        loadHandler.handle(this.context, Obj.bindFixed(this.doUpdateComputedView, this, element));
     },
 
     doUpdateComputedView: function(element)
diff --git a/extension/content/firebug/css/cssPanel.js b/extension/content/firebug/css/cssPanel.js
index 3479b5a..daed786 100644
--- a/extension/content/firebug/css/cssPanel.js
+++ b/extension/content/firebug/css/cssPanel.js
@@ -25,13 +25,14 @@ define([
     "firebug/css/cssReps",
     "firebug/css/selectorEditor",
     "firebug/lib/trace",
+    "firebug/css/loadHandler",
     "firebug/editor/editor",
     "firebug/editor/editorSelector",
     "firebug/chrome/searchBox"
 ],
 function(Obj, Firebug, Domplate, FirebugReps, Locale, Events, Url, SourceLink, Css, Dom, Win,
     Search, Str, Arr, Fonts, Xml, Persist, System, Menu, Options, CSSModule, CSSInfoTip,
-    SelectorEditor, FBTrace) {
+    SelectorEditor, FBTrace, LoadHandler) {
 
 with (Domplate) {
 
@@ -990,12 +991,17 @@ Firebug.CSSStyleSheetPanel.prototype = Obj.extend(Firebug.Panel,
                 "no stylesheet"));
         }
 
-        // We can properly update the view only if the page is fully loaded (see issue 4893).
-        var doc = this.context.window.document;
-        if (doc.readyState != "complete")
+        // Update as soon as the document is fully loaded (see 4893).
+        var loadHandler = new LoadHandler();
+        loadHandler.handle(this.context, Obj.bindFixed(this.doUpdateLocation, this, styleSheet));
+    },
+
+    doUpdateLocation: function(styleSheet)
+    {
+        if (FBTrace.DBG_CSS)
         {
-            this.context.setTimeout(Obj.bindFixed(this.updateLocation, this, styleSheet), 200);
-            return;
+            FBTrace.sysout("css.doUpdateLocation; " + (styleSheet ? styleSheet.href :
+                "no stylesheet"));
         }
 
         var rules = [];
diff --git a/extension/content/firebug/css/loadHandler.js b/extension/content/firebug/css/loadHandler.js
new file mode 100644
index 0000000..33385b2
--- /dev/null
+++ b/extension/content/firebug/css/loadHandler.js
@@ -0,0 +1,61 @@
+/* See license.txt for terms of usage */
+
+define([
+    "firebug/lib/trace",
+],
+function(FBTrace) {
+
+// ********************************************************************************************* //
+// Constants
+
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+
+// ********************************************************************************************* //
+// CSS Module
+
+/**
+ * @object LoadHandler is a helpe objects that automates registerind and unregistering
+ * 'load' listener and executes passed callback. This object is used by CSS panels that
+ * need to populat theirs content after document (window) is fully loaded.
+ */
+function LoadHandler()
+{
+    this.inProgress = false;
+}
+
+LoadHandler.prototype =
+/** @lends Firebug.TabWatcher */
+{
+    handle: function(context, handler)
+    {
+        var win = context.window;
+        var doc = win.document;
+
+        // Execute the handler now if the document is loaded, otherwise wait for "load" event.
+        if (doc.readyState == "complete")
+            return handler();
+
+        if (this.inProgress)
+            return;
+
+        var self = this;
+        var onLoadHandler = function()
+        {
+            context.removeEventListener(win, "load", onLoadHandler, true);
+            self.inProgress = false;
+            handler();
+        };
+
+        context.addEventListener(win, "load", onLoadHandler, true);
+        this.inProgress = true;
+    }
+}
+
+// ********************************************************************************************* //
+// Registration
+
+return LoadHandler;
+
+// ********************************************************************************************* //
+});
diff --git a/extension/content/firebug/css/stylePanel.js b/extension/content/firebug/css/stylePanel.js
index 78896ca..883423b 100644
--- a/extension/content/firebug/css/stylePanel.js
+++ b/extension/content/firebug/css/stylePanel.js
@@ -20,10 +20,12 @@ define([
     "firebug/lib/options",
     "firebug/css/cssModule",
     "firebug/css/cssPanel",
-    "firebug/chrome/menu"
+    "firebug/chrome/menu",
+    "firebug/css/loadHandler",
 ],
 function(Obj, Firebug, Firefox, Domplate, FirebugReps, Xpcom, Locale, Events, Url, Arr,
-    SourceLink, Dom, Css, Xpath, Str, Fonts, Options, CSSModule, CSSStyleSheetPanel, Menu) {
+    SourceLink, Dom, Css, Xpath, Str, Fonts, Options, CSSModule, CSSStyleSheetPanel, Menu,
+    LoadHandler) {
 
 with (Domplate) {
 
@@ -516,17 +518,13 @@ CSSStylePanel.prototype = Obj.extend(CSSStyleSheetPanel.prototype,
 
     updateView: function(element)
     {
-        var result = CSSModule.cleanupSheets(element.ownerDocument, Firebug.currentContext);
-
-        // If cleanupSheets returns false there was an exception thrown when accessing
-        // a styleshet (probably since it isn't fully loaded yet). So, delay the panel
-        // update and try it again a bit later (issue 5654).
-        if (!result)
-        {
-            this.context.setTimeout(Obj.bindFixed(this.updateView, this, element), 200);
-            return;
-        }
+        // We can properly update the view only if the page is fully loaded (see issue 5654).
+        var loadHandler = new LoadHandler();
+        loadHandler.handle(this.context, Obj.bindFixed(this.doUpdateView, this, element));
+    },
 
+    doUpdateView: function(element)
+    {
         // All stylesheets should be ready now, update the view.
         this.updateCascadeView(element);
 

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



More information about the Pkg-mozext-commits mailing list