Bug 654122 - window.scrollTo on pageload does not always hide Fennec urlbar [r=stechz]

This commit is contained in:
Matt Brubeck 2011-05-03 10:12:02 -07:00
parent e89cd9d39e
commit 166c9c12a1
4 changed files with 47 additions and 5 deletions

View File

@ -1174,12 +1174,10 @@ var Browser = {
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;
@ -1532,7 +1530,8 @@ Browser.WebProgress.prototype = {
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();

View File

@ -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>

View File

@ -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.");
});
});
}

View File

@ -34,6 +34,14 @@ function waitForAndContinue(callback, test, timeout) {
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);
};