Bug 1425964 - Compute locale direction only once in the toolbox code. r=jdescottes
authorAlexandre Poirot <poirot.alex@gmail.com>
Thu, 11 Jan 2018 08:09:33 -0800
changeset 453754 a0b830122fd309280eabd7122c86e820ae24963b
parent 453753 28801573d161104f58ddd8c44c77f4c8eca11cf8
child 453755 ee28a6041e99b959c04011a99342d36337f96b75
push id1648
push usermtabara@mozilla.com
push dateThu, 01 Mar 2018 12:45:47 +0000
treeherdermozilla-release@cbb9688c2eeb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdescottes
bugs1425964
milestone59.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 1425964 - Compute locale direction only once in the toolbox code. r=jdescottes MozReview-Commit-ID: 1owwWecAe0g
devtools/client/framework/toolbox.js
--- a/devtools/client/framework/toolbox.js
+++ b/devtools/client/framework/toolbox.js
@@ -174,16 +174,30 @@ function Toolbox(target, selectedTool, h
 
   this.on("ready", this._showDevEditionPromo);
 
   gDevTools.on("tool-registered", this._toolRegistered);
   gDevTools.on("tool-unregistered", this._toolUnregistered);
 
   this.on("picker-started", this._onPickerStarted);
   this.on("picker-stopped", this._onPickerStopped);
+
+  /**
+   * Get text direction for the current locale direction.
+   *
+   * `getComputedStyle` forces a synchronous reflow, so use a lazy getter in order to
+   * call it only once.
+   */
+  loader.lazyGetter(this, "direction", () => {
+    // Get the direction from browser.xul document
+    let top = this.win.top;
+    let topDocEl = top.document.documentElement;
+    let isRtl = top.getComputedStyle(topDocEl).direction === "rtl";
+    return isRtl ? "rtl" : "ltr";
+  });
 }
 exports.Toolbox = Toolbox;
 
 /**
  * The toolbox can be 'hosted' either embedded in a browser window
  * or in a separate window.
  */
 Toolbox.HostType = {
@@ -1735,20 +1749,17 @@ Toolbox.prototype = {
     if (!docEl || docEl.namespaceURI !== HTML_NS) {
       // Bail out if the content window or document is not ready or if the document is not
       // HTML.
       return;
     }
 
     if (docEl.hasAttribute("dir")) {
       // Set the dir attribute value only if dir is already present on the document.
-      let top = this.win.top;
-      let topDocEl = top.document.documentElement;
-      let isRtl = top.getComputedStyle(topDocEl).direction === "rtl";
-      docEl.setAttribute("dir", isRtl ? "rtl" : "ltr");
+      docEl.setAttribute("dir", this.direction);
     }
   },
 
   /**
    * Mark all in collection as unselected; and id as selected
    * @param {string} collection
    *        DOM collection of items
    * @param {string} id