Bug 1471403 - Part 3 - Add a MozElements namespace for element classes. r=bgrins
authorPaolo Amadini <paolo.mozmail@amadzone.org>
Mon, 05 Nov 2018 13:56:01 +0000
changeset 445386 5fc40fe6b994e684f9db2c67b0c4d7e8be5540df
parent 445385 a2a92421b50f91f29ed416eafd8f86f62dfdab45
child 445387 b6676334369f8034686e9c50ceb941a27bfa6674
push id109739
push userpaolo.mozmail@amadzone.org
push dateFri, 09 Nov 2018 17:25:47 +0000
treeherdermozilla-inbound@b6676334369f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins
bugs1471403
milestone65.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 1471403 - Part 3 - Add a MozElements namespace for element classes. r=bgrins This provides a way to access specific element classes before any associated Custom Element is instantiated, without creating a new global for each class. This can be useful to access static methods, create derived classes in a page, or allow lazy custom constructors. Differential Revision: https://phabricator.services.mozilla.com/D10893
toolkit/content/customElements.js
toolkit/content/widgets/radio.js
toolkit/content/widgets/tree.js
--- a/toolkit/content/customElements.js
+++ b/toolkit/content/customElements.js
@@ -1,15 +1,15 @@
 /* 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/. */
 
  // This file defines these globals on the window object.
  // Define them here so that ESLint can find them:
-/* globals MozElementMixin, MozXULElement, MozBaseControl */
+/* globals MozElementMixin, MozXULElement, MozElements */
 
 "use strict";
 
 // This is loaded into chrome windows with the subscript loader. Wrap in
 // a block to prevent accidentally leaking globals onto `window`.
 (() => {
 
 // Handle customElements.js being loaded as a script in addition to the subscriptLoader
@@ -40,16 +40,18 @@ window.addEventListener("DOMContentLoade
     element.isRunningDelayedConnectedCallback = false;
   }
   gElementsPendingConnection.clear();
 }, { once: true, capture: true });
 
 const gXULDOMParser = new DOMParser();
 gXULDOMParser.forceEnableXULXBL();
 
+const MozElements = {};
+
 const MozElementMixin = Base => class MozElement extends Base {
 
   /*
    * Implements attribute inheritance by a child element. Uses XBL @inherit
    * syntax of |to=from|.
    *
    * @param {element} child
    *        A child element that inherits an attribute.
@@ -248,17 +250,17 @@ function getInterfaceProxy(obj) {
         return propOrMethod;
       },
     });
   }
 
   return obj._customInterfaceProxy;
 }
 
-class MozBaseControl extends MozXULElement {
+MozElements.BaseControl = class BaseControl extends MozXULElement {
   get disabled() {
     return this.getAttribute("disabled") == "true";
   }
 
   set disabled(val) {
     if (val) {
       this.setAttribute("disabled", "true");
     } else {
@@ -272,24 +274,25 @@ class MozBaseControl extends MozXULEleme
 
   set tabIndex(val) {
     if (val) {
       this.setAttribute("tabindex", val);
     } else {
       this.removeAttribute("tabindex");
     }
   }
-}
+};
 
-MozXULElement.implementCustomInterface(MozBaseControl, [Ci.nsIDOMXULControlElement]);
+MozXULElement.implementCustomInterface(MozElements.BaseControl,
+                                       [Ci.nsIDOMXULControlElement]);
 
 // Attach the base class to the window so other scripts can use it:
 window.MozElementMixin = MozElementMixin;
 window.MozXULElement = MozXULElement;
-window.MozBaseControl = MozBaseControl;
+window.MozElements = MozElements;
 
 // For now, don't load any elements in the extension dummy document.
 // We will want to load <browser> when that's migrated (bug 1441935).
 const isDummyDocument = document.documentURI == "chrome://extensions/content/dummy.xul";
 if (!isDummyDocument) {
   for (let script of [
     "chrome://global/content/elements/general.js",
     "chrome://global/content/elements/progressmeter.js",
--- a/toolkit/content/widgets/radio.js
+++ b/toolkit/content/widgets/radio.js
@@ -3,17 +3,17 @@
   * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 // This is loaded into all XUL windows. Wrap in a block to prevent
 // leaking to window scope.
 {
 
-class MozRadiogroup extends MozBaseControl {
+class MozRadiogroup extends MozElements.BaseControl {
   constructor() {
     super();
 
     this.addEventListener("mousedown", (event) => {
       if (this.disabled)
         event.preventDefault();
     });
 
--- a/toolkit/content/widgets/tree.js
+++ b/toolkit/content/widgets/tree.js
@@ -3,17 +3,17 @@
   * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
   "use strict";
 
   // This is loaded into all XUL windows. Wrap in a block to prevent
   // leaking to window scope.
   {
 
-  class MozTreecol extends MozBaseControl {
+  class MozTreecol extends MozElements.BaseControl {
     static get observedAttributes() {
       return [
         "label",
         "sortdirection",
         "hideheader",
         "crop",
       ];
     }