Bug 392418 - Sluggish response on rapid clicking of several checkboxes in the calendar list. r=philipp
authorAnant Kumar Singh <anantkumarsingh@gmail.com>
Tue, 18 Mar 2014 07:55:54 -0400
changeset 19730 9de1aac7e0311957a878cb05af72550ffe33a989
parent 19729 e7be96ffcbbee1c56370af30e807f813614a6a03
child 19731 297a405a9c853df52aa62464bcfde68d9b70c478
push id1151
push usermbanner@mozilla.com
push dateMon, 09 Jun 2014 22:14:36 +0000
treeherdercomm-beta@ce127428ad7d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilipp
bugs392418
Bug 392418 - Sluggish response on rapid clicking of several checkboxes in the calendar list. r=philipp
calendar/base/content/widgets/calendar-list-tree.xml
--- a/calendar/base/content/widgets/calendar-list-tree.xml
+++ b/calendar/base/content/widgets/calendar-list-tree.xml
@@ -222,16 +222,18 @@
 
       <field name="mCalendarList">[]</field>
       <field name="mCompositeCalendar">null</field>
       <field name="tree">null</field>
       <field name="treebox">null</field>
       <field name="ruleCache">new Object()</field>
       <field name="mCachedSheet">null</field>
 
+      <field name="mCycleCalendarFlag">new Object()</field>
+      <field name="mCycleTimer">null</field>
 
       <constructor><![CDATA[
         Components.utils.import("resource://calendar/modules/calUtils.jsm");
         Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
         this.tree.view = this;
       ]]></constructor>
       <destructor><![CDATA[
         // Clean up the calendar manager observers. Do not use removeCalendar
@@ -935,33 +937,46 @@
         ]]></body>
       </method>
 
       <method name="cycleCell">
         <parameter name="aRow"/>
         <parameter name="aCol"/>
         <body><![CDATA[
           let calendar = this.getCalendar(aRow);
-          let composite = this.compositeCalendar;
+          if (this.mCycleCalendarFlag[calendar.id]) {
+              delete this.mCycleCalendarFlag[calendar.id];
+          } else {
+              this.mCycleCalendarFlag[calendar.id]=calendar;
+          }
 
-          switch (aCol.element.getAttribute("anonid")) {
-              case "checkbox-treecol":
-                try {
-                    composite.startBatch();
-                    if (composite.getCalendarById(calendar.id)) {
-                        composite.removeCalendar(calendar);
-                    } else {
-                        composite.addCalendar(calendar);
-                    }
-                } finally {
-                    composite.endBatch();
-                }
-                break;
+          if (this.mCycleTimer) {
+              clearTimeout(this.mCycleTimer);
           }
           this.treebox.invalidateRow(aRow);
+          this.mCycleTimer = setTimeout(this.cycleCellCommit.bind(this), 200);
+        ]]></body>
+      </method>
+
+      <method name="cycleCellCommit">
+        <body><![CDATA[
+          let composite = this.compositeCalendar;
+              try {
+                  composite.startBatch();
+                  for (let id in this.mCycleCalendarFlag) {
+                      if (composite.getCalendarById(id)) {
+                          composite.removeCalendar(this.mCycleCalendarFlag[id]);
+                      } else {
+                          composite.addCalendar(this.mCycleCalendarFlag[id]);
+                      }
+                      delete this.mCycleCalendarFlag[id];
+                  }
+              } finally {
+                  composite.endBatch();
+              }
         ]]></body>
       </method>
 
       <method name="isEditable">
         <parameter name="aRow"/>
         <parameter name="aCol"/>
         <body><![CDATA[
           return false;