Bug 654122 - window.scrollTo on pageload does not always hide Fennec urlbar [r=stechz]
authorMatt Brubeck <mbrubeck@mozilla.com>
Tue, 03 May 2011 10:12:02 -0700
changeset 68903 5d1e8ed138dba36942a6f23c8473aa2fdaf1833a
parent 68902 0a0081de66e32f5ae6e3fc9da5db16d58af1953c
child 68904 66cff9a9d5d2817bbc53c51acdb19621f5afd909
push id19794
push usermbrubeck@mozilla.com
push dateTue, 03 May 2011 17:13:26 +0000
treeherdermozilla-central@5d1e8ed138db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersstechz
bugs654122
milestone6.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 654122 - window.scrollTo on pageload does not always hide Fennec urlbar [r=stechz]
mobile/chrome/content/browser.js
mobile/chrome/tests/browser_scroll.html
mobile/chrome/tests/browser_scroll.js
mobile/chrome/tests/head.js
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -1169,22 +1169,20 @@ var Browser = {
           this.zoomToPoint(json.x, json.y, rect);
         } else {
           this.zoomFromPoint(json.x, json.y);
         }
         break;
 
       case "scroll":
         if (browser == this.selectedBrowser) {
-          let view = browser.getRootView();
-          let position = view.getPosition();
-          if (position.x != 0)
+          if (json.x != 0)
             this.hideSidebars();
 
-          if (position.y != 0)
+          if (json.y != 0)
             this.hideTitlebar();
         }
         break;
       case "Browser:CertException":
         this._handleCertException(aMessage);
         break;
       case "Browser:BlockedSite":
         this._handleBlockedSite(aMessage);
@@ -1527,17 +1525,18 @@ Browser.WebProgress.prototype = {
 
       // We're about to have new page content, so scroll the content area
       // so the new paints will draw correctly.
       // Background tabs are delayed scrolled to top in _documentStop
       if (getBrowser() == browser) {
         let json = aMessage.json;
         browser.getRootView().scrollTo(Math.floor(json.x * browser.scale),
                                        Math.floor(json.y * browser.scale));
-        Browser.pageScrollboxScroller.scrollTo(0, 0);
+        if (json.x == 0 && json.y == 0)
+          Browser.pageScrollboxScroller.scrollTo(0, 0);
       }
 
       aTab.scrolledAreaChanged();
       aTab.updateThumbnail();
 
       browser.messageManager.addMessageListener("MozScrolledAreaChanged", aTab.scrolledAreaChanged);
       ContentTouchHandler.updateContentCapture();
     });
new file mode 100644
--- /dev/null
+++ b/mobile/chrome/tests/browser_scroll.html
@@ -0,0 +1,16 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>scrollTo test</title>
+  <meta name="viewport" content="width=device-width">
+  <script>
+    function run() {
+      window.scrollTo(0,1);
+    }
+  </script>
+</head>
+<body onload="run()" style="height:2000px">
+  <h1>scrollTo test</h1>
+  <p>The urlbar should scroll out of view after this page loads.</p>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/mobile/chrome/tests/browser_scroll.js
@@ -0,0 +1,19 @@
+// Test behavior of window.scrollTo during page load (bug 654122).
+"use strict";
+
+var gTab;
+registerCleanupFunction(function() Browser.closeTab(gTab));
+
+const BASE_URL = "http://mochi.test:8888/browser/mobile/chrome/";
+const TEST_URL = BASE_URL + "browser_scroll.html";
+
+function test() {
+  waitForExplicitFinish();
+  gTab = Browser.addTab(TEST_URL, true);
+  onMessageOnce(gTab.browser.messageManager, "Browser:FirstPaint", function() {
+    executeSoon(function() {
+      let rect = Elements.browsers.getBoundingClientRect();
+      is(rect.top, 0, "Titlebar is hidden.");
+    });
+  });
+}
--- a/mobile/chrome/tests/head.js
+++ b/mobile/chrome/tests/head.js
@@ -29,16 +29,24 @@ function waitForAndContinue(callback, te
   timeout = timeout || Date.now();
   if (Date.now() - timeout > kDefaultWait) {
     callback();
     return;
   }
   setTimeout(waitForAndContinue, 50, callback, test, timeout);
 };
 
+// Listen for the specified message once, then remove the listener.
+function onMessageOnce(aMessageManager, aName, aCallback) {
+  aMessageManager.addMessageListener(aName, function onMessage(aMessage) {
+    aMessageManager.removeMessageListener(aName, onMessage);
+    aCallback(aMessage);
+  });
+}
+
 function makeURI(spec) {
   return Services.io.newURI(spec, null, null);
 };
 
 EventUtils.synthesizeString = function synthesizeString(aString, aWindow) {
   for (let i = 0; i < aString.length; i++) {
     EventUtils.synthesizeKey(aString.charAt(i), {}, aWindow);
   }