Bug 1516640 - Scriptify facets binding. r=mkmelin
authorArshad Khan <arshdkhn1@gmail.com>
Fri, 28 Dec 2018 20:03:14 +0530
changeset 34159 10ad26e5d74d555404b4ad902e898681d6afd756
parent 34158 67c263d7544b2b52ddcdeb9ed35d35737b6fd758
child 34160 0a09c6d031d8375f02964bfc217eaf1abeb8b75c
push id389
push userclokep@gmail.com
push dateMon, 18 Mar 2019 19:01:53 +0000
reviewersmkmelin
bugs1516640
Bug 1516640 - Scriptify facets binding. r=mkmelin
mail/base/content/glodaFacetBindings.css
mail/base/content/glodaFacetBindings.xml
mail/base/content/glodaFacetView.js
--- a/mail/base/content/glodaFacetBindings.css
+++ b/mail/base/content/glodaFacetBindings.css
@@ -1,16 +1,12 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-.facets {
-  -moz-binding: url('chrome://messenger/content/glodaFacetBindings.xml#facets');
-}
-
 .facetious[type="discrete"] {
   -moz-binding: url('chrome://messenger/content/glodaFacetBindings.xml#facet-discrete');
 }
 
 .facetious[type="boolean"] {
   -moz-binding: url('chrome://messenger/content/glodaFacetBindings.xml#facet-boolean');
 }
 
--- a/mail/base/content/glodaFacetBindings.xml
+++ b/mail/base/content/glodaFacetBindings.xml
@@ -7,52 +7,16 @@
 
 <bindings id="glodaFacetBindings"
           xmlns="http://www.mozilla.org/xbl"
           xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
           xmlns:html="http://www.w3.org/1999/xhtml"
           xmlns:xbl="http://www.mozilla.org/xbl"
           xmlns:svg="http://www.w3.org/2000/svg">
 
-<!-- ===== Facets ===== -->
-
-<binding id="facets">
-  <content>
-  </content>
-  <implementation>
-    <method name="clearFacets">
-      <body><![CDATA[
-        while (this.hasChildNodes())
-          this.lastChild.remove();
-      ]]></body>
-    </method>
-    <method name="addFacet">
-      <parameter name="aType" />
-      <parameter name="aAttrDef" />
-      <parameter name="aArgs" />
-      <body><![CDATA[
-        let facets = this;
-
-        let facet = document.createElement("div");
-        facet.attrDef = aAttrDef;
-        facet.nounDef = aAttrDef.objectNounDef;
-        for (let key in aArgs) {
-          facet[key] = aArgs[key];
-        }
-        facet.setAttribute("class", "facetious");
-        facet.setAttribute("type", aType);
-        facet.setAttribute("name", aAttrDef.attributeName);
-        facets.appendChild(facet);
-
-        return facet;
-      ]]></body>
-    </method>
-  </implementation>
-</binding>
-
 <binding id="facet-base">
   <implementation>
     <method name="brushItems">
       <body><![CDATA[
       ]]></body>
     </method>
     <method name="clearBrushedItems">
       <body><![CDATA[
--- a/mail/base/content/glodaFacetView.js
+++ b/mail/base/content/glodaFacetView.js
@@ -106,16 +106,44 @@ const QueryExplanation = {
       label = label + constraintStrings.join(", "); // XXX l10n?
     } catch (e) {
       logException(e);
     }
   },
 };
 
 /**
+ * Object containing facets binding methods.
+ */
+const UIFacets = {
+  get node() {
+    return document.getElementById("facets");
+  },
+  clearFacets() {
+    while (this.node.hasChildNodes()) {
+      this.node.lastChild.remove();
+    }
+  },
+  addFacet(type, attrDef, args) {
+    let facet = document.createElement("div");
+    facet.attrDef = attrDef;
+    facet.nounDef = attrDef.objectNounDef;
+    for (let key in args) {
+      facet[key] = args[key];
+    }
+    facet.setAttribute("class", "facetious");
+    facet.setAttribute("type", type);
+    facet.setAttribute("name", attrDef.attributeName);
+    this.node.appendChild(facet);
+
+    return facet;
+  },
+};
+
+/**
  * Represents the active constraints on a singular facet.  Singular facets can
  *  only have an inclusive set or an exclusive set, but not both.  Non-singular
  *  facets can have both.  Because they are different worlds, non-singular gets
  *  its own class, |ActiveNonSingularConstraint|.
  */
 function ActiveSingularConstraint(aFaceter, aRanged) {
   this.faceter = aFaceter;
   this.attrDef = aFaceter.attrDef;
@@ -518,18 +546,16 @@ var FacetContext = {
   },
   /**
    * Tells the UI about all the facets when notified by the |facetDriver| when
    *  it is done faceting everything.
    */
   facetingCompleted() {
     this.planLayout();
 
-    let uiFacets = document.getElementById("facets");
-
     if (!this.everFaceted) {
       this.everFaceted = true;
       this.faceters.sort(this._groupCountComparator);
       for (let faceter of this.faceters) {
         let attrName = faceter.attrDef.attributeName;
         let explicitBinding = document.getElementById("facet-" + attrName);
 
         if (explicitBinding) {
@@ -555,17 +581,17 @@ var FacetContext = {
         }
 
         // ignore facets that do not vary!
         if (faceter.groupCount <= 1) {
           faceter.xblNode = null;
           continue;
         }
 
-        faceter.xblNode = uiFacets.addFacet(faceter.type, faceter.attrDef, {
+        faceter.xblNode = UIFacets.addFacet(faceter.type, faceter.attrDef, {
           faceter,
           facetDef: faceter.facetDef,
           orderedGroups: faceter.orderedGroups,
           maxDisplayRows: this.maxDisplayRows,
           explicit: false,
         });
       }
     } else {