Bug 876033 - Add arranged event to richgrid, event cleanup. r=mbrubeck
authorSam Foster <sfoster@mozilla.com>
Wed, 17 Jul 2013 11:18:09 -0700
changeset 152275 92a4fbaff6c4089ef0fa5c34d118270db8b1777a
parent 152274 523e2724bbe6288437774183df0864c3c090d664
child 152276 d46e861a4203c404030d22cae06a1c69deee12f0
push id382
push userakeybl@mozilla.com
push dateMon, 21 Oct 2013 21:47:13 +0000
treeherdermozilla-release@5f1868ee45cb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmbrubeck
bugs876033
milestone25.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 876033 - Add arranged event to richgrid, event cleanup. r=mbrubeck
browser/metro/base/content/bindings/grid.xml
--- a/browser/metro/base/content/bindings/grid.xml
+++ b/browser/metro/base/content/bindings/grid.xml
@@ -50,40 +50,43 @@
         <parameter name="anItem"/>
         <body>
           <![CDATA[
             let wasSelected = anItem.selected;
             if ("single" == this.getAttribute("seltype")) {
               this.clearSelection();
             }
             this._selectedItem = wasSelected ? null : anItem;
-            anItem.selected = !wasSelected;
-
-            this._fireOnSelectionChange();
+            if (wasSelected)
+              anItem.removeAttribute("selected");
+            else
+              anItem.setAttribute("selected", true);
+            this._fireEvent("selectionchange");
           ]]>
         </body>
       </method>
 
       <method name="selectItem">
         <parameter name="anItem"/>
         <body>
           <![CDATA[
             let wasSelected = anItem.selected,
                 isSingleMode = ("single" == this.getAttribute("seltype"));
             if (isSingleMode) {
               this.clearSelection();
             }
             this._selectedItem = anItem;
-            anItem.selected = true;
+            if (wasSelected) {
+              return;
+            }
+            anItem.setAttribute("selected", true);
             if (isSingleMode) {
-              if (!wasSelected) {
-                this._fireOnSelect();
-              }
+              this._fireEvent("select");
             } else {
-              this._fireOnSelectionChange();
+              this._fireEvent("selectionchange");
             }
           ]]>
         </body>
       </method>
 
       <method name="handleItemClick">
         <parameter name="aItem"/>
         <parameter name="aEvent"/>
@@ -165,17 +168,17 @@
           ]]>
         </setter>
       </property>
 
       <!-- partial implementation of multiple selection interface -->
       <property name="selectedItems">
         <getter>
           <![CDATA[
-            return this.querySelectorAll("richgriditem[selected='true']");
+            return this.querySelectorAll("richgriditem[selected]");
           ]]>
         </getter>
       </property>
 
       <property name="selectedIndex">
         <getter>
           <![CDATA[
             return this.getIndexOfItem(this._selectedItem);
@@ -481,16 +484,17 @@
                   ) : this.getAttribute("columns") || 0;
 
             // width is typically auto, cap max columns by truncating items collection
             // or, setting max-width style property with overflow hidden
             // '0' is an invalid value, just leave the property unset when 0 columns
             if (this._columnCount) {
               gridStyle.MozColumnCount = this._columnCount;
             }
+            this._fireEvent("arranged");
           ]]>
         </body>
       </method>
       <method name="arrangeItemsNow">
         <body>
           <![CDATA[
             this.removeAttribute("deferlayout");
             // cancel any scheduled arrangeItems and reset flags
@@ -627,38 +631,32 @@
             if(this.hasAttribute("tiletype")) {
               item.setAttribute("tiletype", this.getAttribute("tiletype"));
             }
             return item;
           ]]>
         </body>
       </method>
 
-      <method name="_fireOnSelect">
+      <method name="_fireEvent">
+        <parameter name="aType"/>
         <body>
           <![CDATA[
-            if (this.suppressOnSelect || this._suppressOnSelect)
-              return;
+            switch (aType) {
+              case "select" :
+              case "selectionchange" :
+                if (this.suppressOnSelect || this._suppressOnSelect)
+                  return;
+                break;
+              case "arranged" :
+                break;
+            }
 
             let event = document.createEvent("Events");
-            event.initEvent("select", true, true);
-            this.dispatchEvent(event);
-          ]]>
-        </body>
-      </method>
-      <method name="_fireOnSelectionChange">
-        <body>
-          <![CDATA[
-            // flush out selection-related cached properties so they get recalc'd next time
-            // fire an event?
-            if (this.suppressOnSelect || this._suppressOnSelect)
-              return;
-
-            let event = document.createEvent("Events");
-            event.initEvent("selectionchange", true, true);
+            event.initEvent(aType, true, true);
             this.dispatchEvent(event);
           ]]>
         </body>
       </method>
 
       <method name="bendItem">
         <parameter name="aItem"/>
         <parameter name="aEvent"/>
@@ -942,15 +940,18 @@
           event.stopPropagation();
         ]]>
       </handler>
 
       <handler event="contextmenu">
         <![CDATA[
           // fires for right-click, long-click and (keyboard) contextmenu input
           // toggle the selected state of tiles in a grid
-          this.control.handleItemContextMenu(this, event);
+          let gridParent = this.control;
+          if(!this.isBound || !gridParent)
+            return;
+          gridParent.handleItemContextMenu(this, event);
         ]]>
       </handler>
     </handlers>
   </binding>
 
 </bindings>