From 3bf0611bcbf149a2bbaa39fcbb91e7d689f8dc08 Mon Sep 17 00:00:00 2001 From: Bill McCloskey Date: Tue, 18 Mar 2014 08:00:33 -0700 Subject: [PATCH] Bug 984037 - Make sure we respect the general.autoScroll pref (r=felipe) --- toolkit/content/browser-content.js | 12 ++- toolkit/content/tests/browser/browser.ini | 1 + .../browser/browser_autoscroll_disabled.js | 77 +++++++++++++++++++ toolkit/content/widgets/browser.xml | 5 +- 4 files changed, 91 insertions(+), 4 deletions(-) create mode 100644 toolkit/content/tests/browser/browser_autoscroll_disabled.js diff --git a/toolkit/content/browser-content.js b/toolkit/content/browser-content.js index 69342691af8..00d8adcf16f 100644 --- a/toolkit/content/browser-content.js +++ b/toolkit/content/browser-content.js @@ -107,14 +107,20 @@ let ClickEventHandler = { } } + let [enabled] = sendSyncMessage("Autoscroll:Start", + {scrolldir: this._scrolldir, + screenX: event.screenX, + screenY: event.screenY}); + if (!enabled) { + this._scrollable = null; + return; + } + Cc["@mozilla.org/eventlistenerservice;1"] .getService(Ci.nsIEventListenerService) .addSystemEventListener(global, "mousemove", this, true); addEventListener("pagehide", this, true); - sendAsyncMessage("Autoscroll:Start", {scrolldir: this._scrolldir, - screenX: event.screenX, - screenY: event.screenY}); this._ignoreMouseEvents = true; this._startX = event.screenX; this._startY = event.screenY; diff --git a/toolkit/content/tests/browser/browser.ini b/toolkit/content/tests/browser/browser.ini index 4470af9eb1a..967cb99d9ae 100644 --- a/toolkit/content/tests/browser/browser.ini +++ b/toolkit/content/tests/browser/browser.ini @@ -1,5 +1,6 @@ [DEFAULT] +[browser_autoscroll_disabled.js] [browser_browserDrop.js] [browser_bug295977_autoscroll_overflow.js] [browser_bug594509.js] diff --git a/toolkit/content/tests/browser/browser_autoscroll_disabled.js b/toolkit/content/tests/browser/browser_autoscroll_disabled.js new file mode 100644 index 00000000000..3f6fffe9a8c --- /dev/null +++ b/toolkit/content/tests/browser/browser_autoscroll_disabled.js @@ -0,0 +1,77 @@ +function test() +{ + const kPrefName_AutoScroll = "general.autoScroll"; + Services.prefs.setBoolPref(kPrefName_AutoScroll, false); + + var doc; + + function startLoad(dataUri) { + gBrowser.selectedBrowser.addEventListener("pageshow", onLoad, false); + gBrowser.loadURI(dataUri); + } + + function onLoad() { + gBrowser.selectedBrowser.removeEventListener("pageshow", onLoad, false); + waitForFocus(onFocus, content); + } + + function onFocus() { + doc = gBrowser.contentDocument; + runChecks(); + } + + function endTest() { + // restore the changed prefs + if (Services.prefs.prefHasUserValue(kPrefName_AutoScroll)) + Services.prefs.clearUserPref(kPrefName_AutoScroll); + + // cleaning-up + gBrowser.addTab("about:blank"); + gBrowser.removeCurrentTab(); + + // waitForFocus() fixes a failure in the next test if the latter runs too soon. + waitForFocus(finish); + } + + waitForExplicitFinish(); + + let dataUri = 'data:text/html,
\ + \ +'; + startLoad(dataUri); + + function runChecks() { + var elem = doc.getElementById('i'); + // Skip the first callback as it's the same callback that the browser + // uses to kick off the scrolling. + var skipFrames = 1; + var checkScroll = function () { + if (skipFrames--) { + window.mozRequestAnimationFrame(checkScroll); + return; + } + ok(elem.scrollTop == 0, "element should not have scrolled vertically"); + ok(elem.scrollLeft == 0, "element should not have scrolled horizontally"); + + endTest(); + }; + EventUtils.synthesizeMouse(elem, 50, 50, { button: 1 }, + gBrowser.contentWindow); + + var iframe = gBrowser.contentDocument.getElementById("iframe"); + var e = iframe.contentDocument.createEvent("pagetransition"); + e.initPageTransitionEvent("pagehide", true, true, false); + iframe.contentDocument.dispatchEvent(e); + iframe.contentDocument.documentElement.dispatchEvent(e); + + EventUtils.synthesizeMouse(elem, 100, 100, + { type: "mousemove", clickCount: "0" }, + gBrowser.contentWindow); + /* + * if scrolling didn’t work, we wouldn’t do any redraws and thus time out. + * so request and force redraws to get the chance to check for scrolling at + * all. + */ + window.mozRequestAnimationFrame(checkScroll); + } +} diff --git a/toolkit/content/widgets/browser.xml b/toolkit/content/widgets/browser.xml index dde26a99eb3..57e70afc048 100644 --- a/toolkit/content/widgets/browser.xml +++ b/toolkit/content/widgets/browser.xml @@ -851,9 +851,12 @@ let data = aMessage.data; switch (aMessage.name) { case "Autoscroll:Start": { + if (!this.autoscrollEnabled) { + return false; + } let pos = this.mapScreenCoordinatesFromContent(data.screenX, data.screenY); this.startScroll(data.scrolldir, pos.x, pos.y); - break; + return true; } case "Autoscroll:Cancel": this._autoScrollPopup.hidePopup();