Bug 1457114 - Throttle the inspector window resize handler with requestIdleCallback. r=bgrins
authorGabriel Luong <gabriel.luong@gmail.com>
Thu, 05 Apr 2018 18:29:35 -0400
changeset 418793 b0682001d1f7
parent 418792 7d3ae4f78bd1
child 418794 015c85f88d0f
push id34013
push userdluca@mozilla.com
push date2018-05-18 09:56 +0000
treeherdermozilla-central@11ee70f24ea5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbgrins
bugs1457114
milestone62.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 1457114 - Throttle the inspector window resize handler with requestIdleCallback. r=bgrins MozReview-Commit-ID: 7UwTDAR0JDs
devtools/client/inspector/inspector.js
devtools/client/inspector/test/browser_inspector_breadcrumbs_visibility.js
--- a/devtools/client/inspector/inspector.js
+++ b/devtools/client/inspector/inspector.js
@@ -481,16 +481,20 @@ Inspector.prototype = {
   },
 
   /**
    * Check if the inspector should use the landscape mode.
    *
    * @return {Boolean} true if the inspector should be in landscape mode.
    */
   useLandscapeMode: function() {
+    if (!this.panelDoc) {
+      return true;
+    }
+
     let { clientWidth } = this.panelDoc.getElementById("inspector-splitter-box");
     return this.is3PaneModeEnabled && this.toolbox.hostType == Toolbox.HostType.SIDE ?
       clientWidth > SIDE_PORTAIT_MODE_WIDTH_THRESHOLD :
       clientWidth > PORTRAIT_MODE_WIDTH_THRESHOLD;
   },
 
   /**
    * Build Splitter located between the main and side area of
@@ -547,18 +551,22 @@ Inspector.prototype = {
     this.sidebar.off("destroy", this.onSidebarHidden);
   },
 
   /**
    * If Toolbox width is less than 600 px, the splitter changes its mode
    * to `horizontal` to support portrait view.
    */
   onPanelWindowResize: function() {
-    this.splitBox.setState({
-      vert: this.useLandscapeMode(),
+    window.cancelIdleCallback(this._resizeTimerId);
+    this._resizeTimerId = window.requestIdleCallback(() => {
+      this.splitBox.setState({
+        vert: this.useLandscapeMode(),
+      });
+      this.emit("inspector-resize");
     });
   },
 
   getSidebarSize: function() {
     let width;
     let height;
     let splitSidebarWidth;
 
--- a/devtools/client/inspector/test/browser_inspector_breadcrumbs_visibility.js
+++ b/devtools/client/inspector/test/browser_inspector_breadcrumbs_visibility.js
@@ -42,17 +42,19 @@ add_task(async function() {
   // No way to wait for scrolling to end (Bug 1172171)
   // Rather than wait a max time; limit test to instant scroll behavior
   inspector.breadcrumbs.arrowScrollBox.scrollBehavior = "instant";
 
   await toolbox.switchHost(Toolbox.HostType.WINDOW);
   let hostWindow = toolbox.win.parent;
   let originalWidth = hostWindow.outerWidth;
   let originalHeight = hostWindow.outerHeight;
+  let inspectorResized = inspector.once("inspector-resize");
   hostWindow.resizeTo(640, 300);
+  await inspectorResized;
 
   info("Testing transitions ltr");
   await pushPref("intl.uidirection", 0);
   await testBreadcrumbTransitions(hostWindow, inspector);
 
   info("Testing transitions rtl");
   await pushPref("intl.uidirection", 1);
   await testBreadcrumbTransitions(hostWindow, inspector);