Bug 1265796 - defer element-style change notifications while populating draft
authorTom Tromey <tom@tromey.com>
Wed, 14 Sep 2016 11:28:40 -0600
changeset 414619 b133b76a82106cfc974b5582a42e204182db626c
parent 414618 d798f7d5d1f41e7fb7c9114962e950bca4a01c0c
child 414620 0514aa5341f153151d7b19520391f10d75305c4b
push id29724
push userbmo:ttromey@mozilla.com
push dateFri, 16 Sep 2016 21:16:12 +0000
bugs1265796
milestone51.0a1
Bug 1265796 - defer element-style change notifications while populating MozReview-Commit-ID: EpcEySG1MhE
devtools/client/inspector/rules/models/element-style.js
--- a/devtools/client/inspector/rules/models/element-style.js
+++ b/devtools/client/inspector/rules/models/element-style.js
@@ -40,16 +40,18 @@ function ElementStyle(element, ruleView,
   this.pageStyle = pageStyle;
   this.showUserAgentStyles = showUserAgentStyles;
   this.rules = [];
   this.cssProperties = getCssProperties(this.ruleView.inspector.toolbox);
 
   // Make sure that the populate calls wait in a queue so they are processed in the order
   // they were received.
   this.populate = queueAsyncCalls(this.populate, this);
+  this._populating = false;
+  this._changeSeen = false;
 
   // We don't want to overwrite this.store.userProperties so we only create it
   // if it doesn't already exist.
   if (!("userProperties" in this.store)) {
     this.store.userProperties = new UserProperties();
   }
 
   if (!("disabled" in this.store)) {
@@ -74,29 +76,35 @@ ElementStyle.prototype = {
     }
   },
 
   /**
    * Called by the Rule object when it has been changed through the
    * setProperty* methods.
    */
   _changed: function () {
-    if (this.onChanged) {
+    if (this._populating) {
+      this._changeSeen = true;
+    } else if (this.onChanged) {
+      this._changeSeen = false;
       this.onChanged();
     }
   },
 
   /**
    * Refresh the list of rules to be displayed for the active element.
    * Upon completion, this.rules[] will hold a list of Rule objects.
    *
    * Returns a promise that will be resolved when the elementStyle is
    * ready.
    */
   populate: Task.async(function* () {
+    this._populating = true;
+    this._changeSeen = false;
+
     let entries = yield this.pageStyle.getApplied(this.element, {
       inherited: true,
       matchedSelectors: true,
       filter: this.showUserAgentStyles ? "ua" : undefined,
     }).then(null, e => {
       // Don't warn if the element style is already destroyed as populate is often
       // called after a setTimeout and the connection may already be closed.
       if (!this.destroyed) {
@@ -130,17 +138,20 @@ ElementStyle.prototype = {
 
     // We're done with the previous list of rules.
     for (let r of existingRules) {
       if (r && r.editor) {
         r.editor.destroy();
       }
     }
 
-    return;
+    if (this._populating) {
+      this._populating = false;
+      this._changed();
+    }
   }),
 
   /**
    * Put pseudo elements in front of others.
    */
   _sortRulesForPseudoElement: function () {
     this.rules = this.rules.sort((a, b) => {
       return (a.pseudoElement || "z") > (b.pseudoElement || "z");