Bug 485901: use new flush-less scrollX/Y getter to avoid unnecessary layout flushes, r=mfinkle
authorGavin Sharp <gavin@mozilla.com>
Sun, 05 Apr 2009 03:20:57 -0400
changeset 65153 84d970d8d3cbdb7be7f3570f2125c5d36a17206a
parent 65152 292578d16bfa06df07ff21104912ffa83411d280
child 65154 35edef680c52863702744fa5df1603967e968cc2
push idunknown
push userunknown
push dateunknown
reviewersmfinkle
bugs485901
Bug 485901: use new flush-less scrollX/Y getter to avoid unnecessary layout flushes, r=mfinkle
mobile/app/application.ini
mobile/chrome/content/CanvasBrowser.js
--- a/mobile/app/application.ini
+++ b/mobile/app/application.ini
@@ -9,13 +9,13 @@ SourceRepository=@MOZ_SOURCE_REPO@
 #endif
 #ifdef MOZ_SOURCE_STAMP
 SourceStamp=@MOZ_SOURCE_STAMP@
 #endif
 Copyright=Copyright (c) 2008 Mozilla.org
 ID={a23983c0-fd0e-11dc-95ff-0800200c9a66}
 
 [Gecko]
-MinVersion=1.9.1b2pre
+MinVersion=1.9.2a1pre
 MaxVersion=@GRE_MILESTONE@
 
 [XRE]
 EnableExtensionManager=1
--- a/mobile/chrome/content/CanvasBrowser.js
+++ b/mobile/chrome/content/CanvasBrowser.js
@@ -355,28 +355,25 @@ CanvasBrowser.prototype = {
                                   this._pageBounds.y + this._screenToPage(rects[i+1]),
                                   this._screenToPage(rects[i+2]),
                                   this._screenToPage(rects[i+3])));
     }
     this._redrawRects(rectsToDraw);
   },
 
   _handleMozAfterPaint: function(aEvent) {
-    let cwin = this._browser.contentWindow;
-
-    let csx = cwin.scrollX;
-    let csy = cwin.scrollY;
+    let [scrollX, scrollY] = this.contentScrollValues;
     let clientRects = aEvent.clientRects;
 
     let rects = [];
     // loop backwards to avoid xpconnect penalty for .length
     for (let i = clientRects.length - 1; i >= 0; --i) {
       let e = clientRects.item(i);
-      let r = new wsRect(e.left + csx,
-                         e.top + csy,
+      let r = new wsRect(e.left + scrollX,
+                         e.top + scrollY,
                          e.width, e.height);
       rects.push(r);
     }
 
     this._redrawRects(rects);
   },
 
   _redrawRects: function(rects) {
@@ -584,44 +581,51 @@ CanvasBrowser.prototype = {
                                 false); /* don't flush layout */
   },
 
   /**
    * Retrieve the page position for a given element
    * (relative to the document origin).
    */
   _getPagePosition: function(aElement) {
+    let [scrollX, scrollY] = this.contentScrollValues;
     let r = aElement.getBoundingClientRect();
-    let cwin = this._browser.contentWindow;
-    let retVal = {
+
+    return {
       width: r.width,
       height: r.height,
-      x: r.left + cwin.scrollX,
-      y: r.top + cwin.scrollY
+      x: r.left + scrollX,
+      y: r.top + scrollY
     };
-
-    return retVal;
   },
 
   /* Given a set of client coordinates (relative to the app window),
    * returns the content coordinates relative to the viewport.
    */
   _clientToContentCoords: function(aClientX, aClientY) {
     // Determine position relative to the document origin
     // Need to adjust for the deckbrowser not being at 0,0
     // (e.g. due to other browser UI)
 
     let canvasRect = this._canvas.getBoundingClientRect();
     let clickOffsetX = this._screenToPage(aClientX - canvasRect.left) + this._pageBounds.x;
     let clickOffsetY = this._screenToPage(aClientY - canvasRect.top) + this._pageBounds.y;
 
     // Take scroll offset into account to return coordinates relative to the viewport
-    let cwin = this._browser.contentWindow;
-    return [clickOffsetX - cwin.scrollX,
-            clickOffsetY - cwin.scrollY];
+    let [scrollX, scrollY] = this.contentScrollValues;
+    return [clickOffsetX - scrollX,
+            clickOffsetY - scrollY];
+  },
+  
+  get contentScrollValues() {
+    let cwu = this.contentDOMWindowUtils;
+    let scrollX = {}, scrollY = {};
+    cwu.getScrollXY(false, scrollX, scrollY);
+
+    return [scrollX.value, scrollY.value];
   },
 
   get _effectiveContentAreaDimensions() {
     return this._contentAreaDimensions.map(this._pageToScreen, this);
   },
 
   get _contentAreaDimensions() {
     var cdoc = this._browser.contentDocument;