Bug 1340987 - (Part 1) Use arrow functions in gSubDialog. r=MattN draft
authorScott Wu <scottcwwu@gmail.com>
Mon, 10 Apr 2017 15:45:47 +0800
changeset 588995 90623590a69caa54fde1d4df03a05922b8cf82be
parent 588783 8a3aa1701537ea6b8334f432cd030d260d492fa3
child 588996 9c5da231133291449ffd1869056a18c32e3a89a2
push id62215
push userbmo:scwwu@mozilla.com
push dateMon, 05 Jun 2017 11:59:07 +0000
reviewersMattN
bugs1340987
milestone55.0a1
Bug 1340987 - (Part 1) Use arrow functions in gSubDialog. r=MattN MozReview-Commit-ID: 4k5dsviCJ4d
browser/components/preferences/in-content-new/subdialogs.js
--- a/browser/components/preferences/in-content-new/subdialogs.js
+++ b/browser/components/preferences/in-content-new/subdialogs.js
@@ -26,19 +26,19 @@ var gSubDialog = {
   init() {
     this._frame = document.getElementById("dialogFrame");
     this._overlay = document.getElementById("dialogOverlay");
     this._box = document.getElementById("dialogBox");
     this._closeButton = document.getElementById("dialogClose");
   },
 
   updateTitle(aEvent) {
-    if (aEvent.target != gSubDialog._frame.contentDocument)
+    if (aEvent.target != this._frame.contentDocument)
       return;
-    document.getElementById("dialogTitle").textContent = gSubDialog._frame.contentDocument.title;
+    document.getElementById("dialogTitle").textContent = this._frame.contentDocument.title;
   },
 
   injectXMLStylesheet(aStylesheetURL) {
     let contentStylesheet = this._frame.contentDocument.createProcessingInstruction(
       "xml-stylesheet",
       'href="' + aStylesheetURL + '" type="text/css"'
     );
     this._frame.contentDocument.insertBefore(contentStylesheet,
@@ -180,42 +180,42 @@ var gSubDialog = {
     }
 
     // Provide the ability for the dialog to know that it is being loaded "in-content".
     this._frame.contentDocument.documentElement.setAttribute("subdialog", "true");
 
     this._frame.contentWindow.addEventListener("dialogclosing", this);
 
     let oldResizeBy = this._frame.contentWindow.resizeBy;
-    this._frame.contentWindow.resizeBy = function(resizeByWidth, resizeByHeight) {
+    this._frame.contentWindow.resizeBy = (resizeByWidth, resizeByHeight) => {
       // Only handle resizeByHeight currently.
-      let frameHeight = gSubDialog._frame.clientHeight;
-      let boxMinHeight = parseFloat(getComputedStyle(gSubDialog._box).minHeight, 10);
+      let frameHeight = this._frame.clientHeight;
+      let boxMinHeight = parseFloat(getComputedStyle(this._box).minHeight, 10);
 
-      gSubDialog._frame.style.height = (frameHeight + resizeByHeight) + "px";
-      gSubDialog._box.style.minHeight = (boxMinHeight + resizeByHeight) + "px";
+      this._frame.style.height = (frameHeight + resizeByHeight) + "px";
+      this._box.style.minHeight = (boxMinHeight + resizeByHeight) + "px";
 
-      oldResizeBy.call(gSubDialog._frame.contentWindow, resizeByWidth, resizeByHeight);
+      oldResizeBy.call(this._frame.contentWindow, resizeByWidth, resizeByHeight);
     };
 
     // Make window.close calls work like dialog closing.
     let oldClose = this._frame.contentWindow.close;
-    this._frame.contentWindow.close = function() {
-      var closingEvent = gSubDialog._closingEvent;
+    this._frame.contentWindow.close = () => {
+      var closingEvent = this._closingEvent;
       if (!closingEvent) {
         closingEvent = new CustomEvent("dialogclosing", {
           bubbles: true,
           detail: { button: null },
         });
 
-        gSubDialog._frame.contentWindow.dispatchEvent(closingEvent);
+        this._frame.contentWindow.dispatchEvent(closingEvent);
       }
 
-      gSubDialog.close(closingEvent);
-      oldClose.call(gSubDialog._frame.contentWindow);
+      this.close(closingEvent);
+      oldClose.call(this._frame.contentWindow);
     };
 
     // 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";
   },
@@ -300,17 +300,17 @@ var gSubDialog = {
       this._resizeObserver = new MutationObserver(this._onResize);
       this._resizeObserver.observe(this._box, {attributes: true});
     }
 
     this._trapFocus();
   },
 
   _onResize(mutations) {
-    let frame = gSubDialog._frame;
+    let frame = this._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");
 
     let docEl = frame.contentDocument.documentElement;
@@ -343,23 +343,23 @@ var gSubDialog = {
     }
     if (aEvent.keyCode != aEvent.DOM_VK_TAB ||
         aEvent.ctrlKey || aEvent.altKey || aEvent.metaKey) {
       return;
     }
 
     let fm = Services.focus;
 
-    function isLastFocusableElement(el) {
+    let isLastFocusableElement = el => {
       // XXXgijs unfortunately there is no way to get the last focusable element without asking
       // the focus manager to move focus to it.
-      let rv = el == fm.moveFocus(gSubDialog._frame.contentWindow, null, fm.MOVEFOCUS_LAST, 0);
+      let rv = el == fm.moveFocus(this._frame.contentWindow, null, fm.MOVEFOCUS_LAST, 0);
       fm.setFocus(el, 0);
       return rv;
-    }
+    };
 
     let forward = !aEvent.shiftKey;
     // check if focus is leaving the frame (incl. the close button):
     if ((aEvent.target == this._closeButton && !forward) ||
         (isLastFocusableElement(aEvent.originalTarget) && forward)) {
       aEvent.preventDefault();
       aEvent.stopImmediatePropagation();
       let parentWin = this._getBrowser().ownerGlobal;