Bug 1460334 - Migrate XUL deck from a XBL binding to a Custom Element; draft
authorBrian Grinstead <bgrinstead@mozilla.com>
Wed, 04 Apr 2018 21:29:06 -0700
changeset 793164 4377181434dd27fe0c5645adb56c1d13982a4ac4
parent 792871 0cd106a2eb78aa04fd481785257e6f4f9b94707b
push id109304
push userbgrinstead@mozilla.com
push dateWed, 09 May 2018 16:26:55 +0000
bugs1460334
milestone62.0a1
Bug 1460334 - Migrate XUL deck from a XBL binding to a Custom Element; MozReview-Commit-ID: F95i9H9FvYv
toolkit/components/processsingleton/MainProcessSingleton.js
toolkit/content/jar.mn
toolkit/content/widgets/general.js
toolkit/content/widgets/general.xml
toolkit/content/xul.css
--- a/toolkit/components/processsingleton/MainProcessSingleton.js
+++ b/toolkit/components/processsingleton/MainProcessSingleton.js
@@ -81,16 +81,17 @@ MainProcessSingleton.prototype = {
       // in the document. Anything loaded here should be considered part of
       // core XUL functionality. Any window-specific elements can be registered
       // via <script> tags at the top of individual documents.
       const doc = subject;
       if (doc.nodePrincipal.isSystemPrincipal &&
           doc.contentType == "application/vnd.mozilla.xul+xml") {
         for (let script of [
           "chrome://global/content/elements/stringbundle.js",
+          "chrome://global/content/elements/general.js",
         ]) {
           Services.scriptloader.loadSubScript(script, doc.ownerGlobal);
         }
       }
       break;
 
     case "xpcom-shutdown":
       Services.mm.removeMessageListener("Search:AddEngine", this.addSearchEngine);
--- a/toolkit/content/jar.mn
+++ b/toolkit/content/jar.mn
@@ -95,14 +95,15 @@ toolkit.jar:
 *  content/global/bindings/textbox.xml         (widgets/textbox.xml)
    content/global/bindings/timekeeper.js       (widgets/timekeeper.js)
    content/global/bindings/timepicker.js       (widgets/timepicker.js)
    content/global/bindings/toolbar.xml         (widgets/toolbar.xml)
    content/global/bindings/toolbarbutton.xml   (widgets/toolbarbutton.xml)
 *  content/global/bindings/tree.xml            (widgets/tree.xml)
    content/global/bindings/videocontrols.xml   (widgets/videocontrols.xml)
 *  content/global/bindings/wizard.xml          (widgets/wizard.xml)
+   content/global/elements/general.js           (widgets/general.js)
    content/global/elements/stringbundle.js     (widgets/stringbundle.js)
 #ifdef XP_MACOSX
    content/global/macWindowMenu.js
 #endif
    content/global/gmp-sources/openh264.json    (gmp-sources/openh264.json)
    content/global/gmp-sources/widevinecdm.json (gmp-sources/widevinecdm.json)
new file mode 100644
--- /dev/null
+++ b/toolkit/content/widgets/general.js
@@ -0,0 +1,38 @@
+/* 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/. */
+
+"use strict";
+
+{
+
+class MozDeck extends XULElement {
+  set selectedIndex(val) {
+    if (this.selectedIndex == val) return val;
+    this.setAttribute("selectedIndex", val);
+    var event = document.createEvent("Events");
+    event.initEvent("select", true, true);
+    this.dispatchEvent(event);
+    return val;
+  }
+
+  get selectedIndex() {
+    return this.getAttribute("selectedIndex") || "0";
+  }
+
+  set selectedPanel(val) {
+    var selectedIndex = -1;
+    for (var panel = val; panel != null; panel = panel.previousSibling)
+      ++selectedIndex;
+    this.selectedIndex = selectedIndex;
+    return val;
+  }
+
+  get selectedPanel() {
+    return this.childNodes[this.selectedIndex];
+  }
+}
+
+customElements.define("deck", MozDeck);
+
+}
--- a/toolkit/content/widgets/general.xml
+++ b/toolkit/content/widgets/general.xml
@@ -75,53 +75,16 @@
       <property name="webNavigation"
                 onget="return this.docShell.QueryInterface(Components.interfaces.nsIWebNavigation);"
                 readonly="true"/>
       <property name="contentDocument" readonly="true"
                 onget="return this.webNavigation.document;"/>
     </implementation>
   </binding>
 
-  <binding id="deck">
-    <implementation>
-      <property name="selectedIndex"
-                onget="return this.getAttribute('selectedIndex') || '0'">
-        <setter>
-        <![CDATA[
-          if (this.selectedIndex == val)
-            return val;
-          this.setAttribute("selectedIndex", val);
-          var event = document.createEvent("Events");
-          event.initEvent("select", true, true);
-          this.dispatchEvent(event);
-          return val;
-        ]]>
-        </setter>
-      </property>
-
-      <property name="selectedPanel">
-        <getter>
-          <![CDATA[
-            return this.childNodes[this.selectedIndex];
-          ]]>
-        </getter>
-
-        <setter>
-          <![CDATA[
-            var selectedIndex = -1;
-            for (var panel = val; panel != null; panel = panel.previousSibling)
-              ++selectedIndex;
-            this.selectedIndex = selectedIndex;
-            return val;
-          ]]>
-        </setter>
-      </property>
-    </implementation>
-  </binding>
-
   <binding id="dropmarker" extends="xul:button">
     <resources>
       <stylesheet src="chrome://global/skin/dropmarker.css"/>
     </resources>
 
     <content>
       <xul:image class="dropmarker-icon"/>
     </content>
--- a/toolkit/content/xul.css
+++ b/toolkit/content/xul.css
@@ -653,17 +653,16 @@ tree:not([treelines="true"]) > treechild
 treechildren::-moz-tree-cell(ltr) {
   direction: ltr !important;
 }
 
 /********** deck & stack *********/
 
 deck {
   display: -moz-deck;
-  -moz-binding: url("chrome://global/content/bindings/general.xml#deck");
 }
 
 stack {
   display: -moz-stack;
 }
 
 /********** tabbox *********/