Bug 598391 - Listen for scroll events from content [r=mbrubeck]
authorBenjamin Stover <bstover@mozilla.com>
Tue, 21 Sep 2010 12:26:54 -0700
changeset 66700 cd298ee49cc241c4edd1391c3ff2bece145b911a
parent 66699 7daae378d44cfca63f7c4242db2500ef3cef1f8f
child 66701 81f0d15aa9f65045ba837b04cd3a6a199053bb33
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmbrubeck
bugs598391
Bug 598391 - Listen for scroll events from content [r=mbrubeck]
mobile/chrome/content/bindings/browser.js
mobile/chrome/content/bindings/browser.xml
--- a/mobile/chrome/content/bindings/browser.js
+++ b/mobile/chrome/content/bindings/browser.js
@@ -361,34 +361,37 @@ let ContentScroll =  {
         content.scrollBy(json.dx, json.dy);
         break;
 
       case "Content:SetCacheViewport": {
         let displayport = new Rect(json.x, json.y, json.w, json.h);
         if (displayport.isEmpty())
           break;
 
+        let scrollOffset = Util.getScrollOffset(content);
         let cwu = Util.getWindowUtils(content);
         cwu.setResolution(json.scale, json.scale);
-        cwu.setDisplayPort(displayport.x, displayport.y, displayport.width, displayport.height);
+        cwu.setDisplayPort(displayport.x - scrollOffset.x, displayport.y - scrollOffset.y,
+                           displayport.width, displayport.height);
         break;
       }
 
       case "Content:SetWindowSize": {
         let cwu = Util.getWindowUtils(content);
         cwu.setCSSViewport(json.width, json.height);
         break;
       }
     }
   },
 
   handleEvent: function(aEvent) {
     switch (aEvent.type) {
       case "scroll":
-        Util.dumpLn("XXX stub");
+        let scrollOffset = Util.getScrollOffset(content);
+        sendAsyncMessage("scroll", scrollOffset);
         break;
 
       case "MozScrolledAreaChanged": {
         let doc = aEvent.originalTarget;
         if (content != doc.defaultView) // We are only interested in root scroll pane changes
           return;
 
         // XXX need to make some things in Util as its own module!
--- a/mobile/chrome/content/bindings/browser.xml
+++ b/mobile/chrome/content/bindings/browser.xml
@@ -89,16 +89,18 @@
 
       <field name="_ios">
          Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
       </field>
 
       <method name="receiveMessage">
         <parameter name="aMessage"/>
         <body><![CDATA[
+          let json = aMessage.json;
+
           switch (aMessage.name) {
             case "DOMPopupBlocked":
               this.onPopupBlocked(aMessage);
               break;
 
             case "pageshow":
               this.onPageShow(aMessage);
 
@@ -141,16 +143,26 @@
                   }
                   break;
                 case "search":
                   this._searchEngines.push({ title: link.title, href: link.href });
                   break;
               }
               break;
 
+            case "scroll":
+              // Cache viewport coordinates are specified relative to CSS viewport, so we
+              // have to be sure we send the message.
+              this._pendingPixelsX = Number.MAX_VALUE;
+              this._pendingPixelsY = Number.MAX_VALUE;
+
+              // Use floor so that we always guarantee top-left corner of content is visible.
+              this.scrollTo(Math.floor(json.x * this.scale), Math.floor(json.y * this.scale));
+              break;
+
             case "MozScrolledAreaChanged":
               this._contentDocumentWidth = aMessage.json.width;
               this._contentDocumentHeight = aMessage.json.height;
               // Recalculate whether the visible area is actually in bounds
               this.scrollBy(0, 0);
               this._updateCacheViewport();
               break;
          }
@@ -536,16 +548,17 @@
           this.messageManager.addMessageListener("DOMTitleChanged", this);
           this.messageManager.addMessageListener("DOMLinkAdded", this);
 
           // Listen for first load for lazy attachment to form fill controller
           this.messageManager.addMessageListener("pageshow", this);
           this.messageManager.addMessageListener("pagehide", this);
           this.messageManager.addMessageListener("DOMPopupBlocked", this);
 
+          this.messageManager.addMessageListener("scroll", this);
           this.messageManager.addMessageListener("MozScrolledAreaChanged", this);
 
           this._webProgress._init();
         ]]>
       </constructor>
 
     </implementation>