Bug 1325464 - Use ES6 method syntax for subdialogs.js. r=mattn draft
authorJared Wein <jwein@mozilla.com>
Thu, 22 Dec 2016 15:57:24 -0500
changeset 454591 217439d9312810a398ba11b4a69c8331cdc2fb72
parent 454590 8b6cf583fb17b5f73a3669df96c441b589163da0
child 454592 7585d3ef8773045438813497be74479e0ca0cb61
push id39985
push userbmo:jaws@mozilla.com
push dateThu, 29 Dec 2016 19:31:36 +0000
reviewersmattn
bugs1325464
milestone53.0a1
Bug 1325464 - Use ES6 method syntax for subdialogs.js. r=mattn MozReview-Commit-ID: 2bQW97yWhrg
browser/components/preferences/in-content/subdialogs.js
--- a/browser/components/preferences/in-content/subdialogs.js
+++ b/browser/components/preferences/in-content/subdialogs.js
@@ -14,39 +14,39 @@ var gSubDialog = {
   _injectedStyleSheets: [
     "chrome://browser/skin/preferences/preferences.css",
     "chrome://global/skin/in-content/common.css",
     "chrome://browser/skin/preferences/in-content/preferences.css",
     "chrome://browser/skin/preferences/in-content/dialog.css",
   ],
   _resizeObserver: null,
 
-  init: function() {
+  init() {
     this._frame = document.getElementById("dialogFrame");
     this._overlay = document.getElementById("dialogOverlay");
     this._box = document.getElementById("dialogBox");
     this._closeButton = document.getElementById("dialogClose");
   },
 
-  updateTitle: function(aEvent) {
+  updateTitle(aEvent) {
     if (aEvent.target != gSubDialog._frame.contentDocument)
       return;
     document.getElementById("dialogTitle").textContent = gSubDialog._frame.contentDocument.title;
   },
 
-  injectXMLStylesheet: function(aStylesheetURL) {
+  injectXMLStylesheet(aStylesheetURL) {
     let contentStylesheet = this._frame.contentDocument.createProcessingInstruction(
       'xml-stylesheet',
       'href="' + aStylesheetURL + '" type="text/css"'
     );
     this._frame.contentDocument.insertBefore(contentStylesheet,
                                              this._frame.contentDocument.documentElement);
   },
 
-  open: function(aURL, aFeatures = null, aParams = null, aClosingCallback = null) {
+  open(aURL, aFeatures = null, aParams = null, aClosingCallback = null) {
     // If we're already open/opening on this URL, do nothing.
     if (this._openedURL == aURL && !this._isClosing) {
       return;
     }
     // If we're open on some (other) URL or we're closing, open when closing has finished.
     if (this._openedURL || this._isClosing) {
       if (!this._isClosing) {
         this.close();
@@ -71,17 +71,17 @@ var gSubDialog = {
 
     features = features.replace(/,/g, "&");
     let featureParams = new URLSearchParams(features.toLowerCase());
     this._box.setAttribute("resizable", featureParams.has("resizable") &&
                                         featureParams.get("resizable") != "no" &&
                                         featureParams.get("resizable") != "0");
   },
 
-  close: function(aEvent = null) {
+  close(aEvent = null) {
     if (this._isClosing) {
       return;
     }
     this._isClosing = true;
     this._closingPromise = new Promise(resolve => {
       this._resolveClosePromise = resolve;
     });
 
@@ -117,17 +117,17 @@ var gSubDialog = {
           this._resolveClosePromise();
         }
       };
       this._frame.addEventListener("load", onBlankLoad);
       this._frame.loadURI("about:blank");
     }, 0);
   },
 
-  handleEvent: function(aEvent) {
+  handleEvent(aEvent) {
     switch (aEvent.type) {
       case "command":
         this._frame.contentWindow.close();
         break;
       case "dialogclosing":
         this._onDialogClosing(aEvent);
         break;
       case "DOMTitleChanged":
@@ -148,23 +148,23 @@ var gSubDialog = {
       case "focus":
         this._onParentWinFocus(aEvent);
         break;
     }
   },
 
   /* Private methods */
 
-  _onUnload: function(aEvent) {
+  _onUnload(aEvent) {
     if (aEvent.target.location.href == this._openedURL) {
       this._frame.contentWindow.close();
     }
   },
 
-  _onContentLoaded: function(aEvent) {
+  _onContentLoaded(aEvent) {
     if (aEvent.target != this._frame || aEvent.target.contentWindow.location == "about:blank") {
       return;
     }
 
     for (let styleSheetURL of this._injectedStyleSheets) {
       this.injectXMLStylesheet(styleSheetURL);
     }
 
@@ -204,17 +204,17 @@ var gSubDialog = {
 
     // XXX: Hack to make focus during the dialog's load functions work. Make the element visible
     // sooner in DOMContentLoaded but mostly invisible instead of changing visibility just before
     // the dialog's load event.
     this._overlay.style.visibility = "visible";
     this._overlay.style.opacity = "0.01";
   },
 
-  _onLoad: function(aEvent) {
+  _onLoad(aEvent) {
     if (aEvent.target.contentWindow.location == "about:blank") {
       return;
     }
 
     // Do this on load to wait for the CSS to load and apply before calculating the size.
     let docEl = this._frame.contentDocument.documentElement;
 
     let groupBoxTitle = document.getAnonymousElementByAttribute(this._box, "class", "groupbox-title");
@@ -288,17 +288,17 @@ var gSubDialog = {
     if (this._box.getAttribute("resizable") == "true") {
       this._resizeObserver = new MutationObserver(this._onResize);
       this._resizeObserver.observe(this._box, {attributes: true});
     }
 
     this._trapFocus();
   },
 
-  _onResize: function(mutations) {
+  _onResize(mutations) {
     let frame = gSubDialog._frame;
     // The width and height styles are needed for the initial
     // layout of the frame, but afterward they need to be removed
     // or their presence will restrict the contents of the <browser>
     // from resizing to a smaller size.
     frame.style.removeProperty("width");
     frame.style.removeProperty("height");
 
@@ -314,22 +314,22 @@ var gSubDialog = {
       if (mutation.attributeName == "width") {
         docEl.setAttribute("width", docEl.scrollWidth);
       } else if (mutation.attributeName == "height") {
         docEl.setAttribute("height", docEl.scrollHeight);
       }
     }
   },
 
-  _onDialogClosing: function(aEvent) {
+  _onDialogClosing(aEvent) {
     this._frame.contentWindow.removeEventListener("dialogclosing", this);
     this._closingEvent = aEvent;
   },
 
-  _onKeyDown: function(aEvent) {
+  _onKeyDown(aEvent) {
     if (aEvent.currentTarget == window && aEvent.keyCode == aEvent.DOM_VK_ESCAPE &&
         !aEvent.defaultPrevented) {
       this.close(aEvent);
       return;
     }
     if (aEvent.keyCode != aEvent.DOM_VK_TAB ||
         aEvent.ctrlKey || aEvent.altKey || aEvent.metaKey) {
       return;
@@ -357,25 +357,25 @@ var gSubDialog = {
       } else {
         // Somehow, moving back 'past' the opening doc is not trivial. Cheat by doing it in 2 steps:
         fm.moveFocus(window, null, fm.MOVEFOCUS_ROOT, fm.FLAG_BYKEY);
         fm.moveFocus(parentWin, null, fm.MOVEFOCUS_BACKWARD, fm.FLAG_BYKEY);
       }
     }
   },
 
-  _onParentWinFocus: function(aEvent) {
+  _onParentWinFocus(aEvent) {
     // Explicitly check for the focus target of |window| to avoid triggering this when the window
     // is refocused
     if (aEvent.target != this._closeButton && aEvent.target != window) {
       this._closeButton.focus();
     }
   },
 
-  _addDialogEventListeners: function() {
+  _addDialogEventListeners() {
     // Make the close button work.
     this._closeButton.addEventListener("command", this);
 
     // DOMTitleChanged isn't fired on the frame, only on the chromeEventHandler
     let chromeBrowser = this._getBrowser();
     chromeBrowser.addEventListener("DOMTitleChanged", this, true);
 
     // Similarly DOMFrameContentLoaded only fires on the top window
@@ -387,17 +387,17 @@ var gSubDialog = {
 
     chromeBrowser.addEventListener("unload", this, true);
     // Ensure we get <esc> keypresses even if nothing in the subdialog is focusable
     // (happens on OS X when only text inputs and lists are focusable, and
     //  the subdialog only has checkboxes/radiobuttons/buttons)
     window.addEventListener("keydown", this, true);
   },
 
-  _removeDialogEventListeners: function() {
+  _removeDialogEventListeners() {
     let chromeBrowser = this._getBrowser();
     chromeBrowser.removeEventListener("DOMTitleChanged", this, true);
     chromeBrowser.removeEventListener("unload", this, true);
 
     this._closeButton.removeEventListener("command", this);
 
     window.removeEventListener("DOMFrameContentLoaded", this, true);
     this._frame.removeEventListener("load", this);
@@ -405,30 +405,30 @@ var gSubDialog = {
     window.removeEventListener("keydown", this, true);
     if (this._resizeObserver) {
       this._resizeObserver.disconnect();
       this._resizeObserver = null;
     }
     this._untrapFocus();
   },
 
-  _trapFocus: function() {
+  _trapFocus() {
     let fm = Services.focus;
     fm.moveFocus(this._frame.contentWindow, null, fm.MOVEFOCUS_FIRST, 0);
     this._frame.contentDocument.addEventListener("keydown", this, true);
     this._closeButton.addEventListener("keydown", this);
 
     window.addEventListener("focus", this, true);
   },
 
-  _untrapFocus: function() {
+  _untrapFocus() {
     this._frame.contentDocument.removeEventListener("keydown", this, true);
     this._closeButton.removeEventListener("keydown", this);
     window.removeEventListener("focus", this);
   },
 
-  _getBrowser: function() {
+  _getBrowser() {
     return window.QueryInterface(Ci.nsIInterfaceRequestor)
                  .getInterface(Ci.nsIWebNavigation)
                  .QueryInterface(Ci.nsIDocShell)
                  .chromeEventHandler;
   },
 };