Bug 686417 - Cache the width of the sidebar in ViewableAreaObserver [r=mfinkle]
authorMatt Brubeck <mbrubeck@mozilla.com>
Thu, 22 Sep 2011 19:17:46 -0700
changeset 77369 99280262eba3dd39a4ff405a35b8afd7c8bc6d19
parent 77368 4990427104e13beeb3aa0193f39773345066468a
child 77370 8547992229cc1d3efdcc9be67ddd9c8256cb7aef
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersmfinkle
bugs686417
milestone9.0a1
Bug 686417 - Cache the width of the sidebar in ViewableAreaObserver [r=mfinkle]
mobile/chrome/content/browser.js
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -3155,30 +3155,35 @@ function rendererFactory(aBrowser, aCanv
 /* ViewableAreaObserver is an helper object where width/height represents the
  * size of the currently viewable area in pixels. This is use instead of
  * window.innerHeight/innerWidth because some keyboards does not resize the
  * window but floats over it.
  */
 var ViewableAreaObserver = {
   get width() {
     let width = this._width || window.innerWidth;
-    if (Util.isTablet()) {
-      let sidebarWidth = Math.round(Elements.tabs.getBoundingClientRect().width);
-      width -= sidebarWidth;
-    }
+    if (Util.isTablet())
+      width -= this.sidebarWidth;
     return width;
   },
 
   get height() {
     let height = (this._height || window.innerHeight);
     if (Util.isTablet())
       height -= BrowserUI.toolbarH;
     return height;
   },
 
+  _sidebarWidth: null,
+  get sidebarWidth() {
+    if (!this._sidebarWidth)
+      this._sidebarWidth = Math.round(Elements.tabs.getBoundingClientRect().width);
+    return this._sidebarWidth;
+  },
+
   _isKeyboardOpened: true,
   get isKeyboardOpened() {
     return this._isKeyboardOpened;
   },
 
   set isKeyboardOpened(aValue) {
     if (!this.hasVirtualKeyboard())
       return this._isKeyboardOpened;
@@ -3222,16 +3227,18 @@ var ViewableAreaObserver = {
 #endif
   },
 
   receiveMessage: function receiveMessage(aMessage) {
     return this.isKeyboardOpened;
   },
 
   update: function va_update() {
+    this._sidebarWidth = null;
+
     let oldHeight = parseInt(Browser.styles["viewable-height"].height);
     let oldWidth = parseInt(Browser.styles["viewable-width"].width);
 
     let newWidth = this.width;
     let newHeight = this.height;
     if (newHeight == oldHeight && newWidth == oldWidth)
       return;