Bug 251903 - autoscroll does not function as expected when in an iframe. r=neil

This commit is contained in:
Martijn Wargers 2014-07-23 13:57:54 +02:00
parent d439cd381c
commit a2fe4d6f7e
2 changed files with 54 additions and 17 deletions

View File

@ -53,13 +53,13 @@ let ClickEventHandler = {
return false;
},
startScroll: function(event) {
findNearestScrollableElement: function(aNode) {
// this is a list of overflow property values that allow scrolling
const scrollingAllowed = ['scroll', 'auto'];
// go upward in the DOM and find any parent element that has a overflow
// area and can therefore be scrolled
for (this._scrollable = event.originalTarget; this._scrollable;
for (this._scrollable = aNode; this._scrollable;
this._scrollable = this._scrollable.parentNode) {
// do not use overflow based autoscroll for <html> and <body>
// Elements or non-html elements such as svg or Document nodes
@ -96,16 +96,25 @@ let ClickEventHandler = {
}
if (!this._scrollable) {
this._scrollable = event.originalTarget.ownerDocument.defaultView;
this._scrollable = aNode.ownerDocument.defaultView;
if (this._scrollable.scrollMaxX > 0) {
this._scrolldir = this._scrollable.scrollMaxY > 0 ? "NSEW" : "EW";
} else if (this._scrollable.scrollMaxY > 0) {
this._scrolldir = "NS";
} else if (this._scrollable.frameElement) {
this.findNearestScrollableElement(this._scrollable.frameElement);
} else {
this._scrollable = null; // abort scrolling
return;
}
}
},
startScroll: function(event) {
this.findNearestScrollableElement(event.originalTarget);
if (!this._scrollable)
return;
let [enabled] = sendSyncMessage("Autoscroll:Start",
{scrolldir: this._scrolldir,

View File

@ -40,7 +40,21 @@ function test()
<body id="j"><div style="height: 2000px"></div>\
<iframe id="iframe" style="display: none;"></iframe>\
</body></html>'},
{elem: 'j', expected: expectScrollVert} // bug 914251
{elem: 'j', expected: expectScrollVert}, // bug 914251
{dataUri: 'data:text/html,<html><head></head><body>\
<div id="k" style="height: 150px; width: 200px; overflow: scroll; border: 1px solid black;">\
<iframe style="height: 200px; width: 300px;"></iframe>\
</div>\
<div id="l" style="height: 150px; width: 300px; overflow: scroll; border: 1px dashed black;">\
<iframe style="height: 200px; width: 200px;" src="data:text/html,<div style=\'border: 5px solid blue; height: 200%; width: 200%;\'></div>"></iframe>\
</div>\
<iframe id="m"></iframe>\
<div style="height: 200%; border: 5px dashed black;">filler to make document overflow: scroll;</div>\
</body></html>'},
{elem: 'k', expected: expectScrollBoth},
{elem: 'k', expected: expectScrollNone, testwindow: true},
{elem: 'l', expected: expectScrollNone},
{elem: 'm', expected: expectScrollVert, testwindow: true}
];
var doc;
@ -89,13 +103,24 @@ function test()
// Close the autoscroll popup by synthesizing Esc.
EventUtils.synthesizeKey("VK_ESCAPE", {}, gBrowser.contentWindow);
var scrollVert = test.expected & expectScrollVert;
ok((scrollVert && elem.scrollTop > 0) ||
(!scrollVert && elem.scrollTop == 0),
test.elem+' should'+(scrollVert ? '' : ' not')+' have scrolled vertically');
var scrollHori = test.expected & expectScrollHori;
ok((scrollHori && elem.scrollLeft > 0) ||
(!scrollHori && elem.scrollLeft == 0),
test.elem+' should'+(scrollHori ? '' : ' not')+' have scrolled horizontally');
if (test.testwindow) {
ok((scrollVert && gBrowser.contentWindow.scrollY > 0) ||
(!scrollVert && gBrowser.contentWindow.scrollY == 0),
'Window for '+test.elem+' should'+(scrollVert ? '' : ' not')+' have scrolled vertically');
ok((scrollHori && gBrowser.contentWindow.scrollX > 0) ||
(!scrollHori && gBrowser.contentWindow.scrollX == 0),
'Window for '+test.elem+' should'+(scrollHori ? '' : ' not')+' have scrolled horizontally');
gBrowser.contentWindow.scroll(0, 0);
} else {
ok((scrollVert && elem.scrollTop > 0) ||
(!scrollVert && elem.scrollTop == 0),
test.elem+' should'+(scrollVert ? '' : ' not')+' have scrolled vertically');
ok((scrollHori && elem.scrollLeft > 0) ||
(!scrollHori && elem.scrollLeft == 0),
test.elem+' should'+(scrollHori ? '' : ' not')+' have scrolled horizontally');
}
// Before continuing the test, we need to ensure that the IPC
// message that stops autoscrolling has had time to arrive.
@ -107,12 +132,15 @@ function test()
// This ensures bug 605127 is fixed: pagehide in an unrelated document
// should not cancel the autoscroll.
var iframe = gBrowser.contentDocument.getElementById("iframe");
var e = new iframe.contentWindow.PageTransitionEvent("pagehide",
{ bubbles: true,
cancelable: true,
persisted: false });
iframe.contentDocument.dispatchEvent(e);
iframe.contentDocument.documentElement.dispatchEvent(e);
if (iframe) {
var e = new iframe.contentWindow.PageTransitionEvent("pagehide",
{ bubbles: true,
cancelable: true,
persisted: false });
iframe.contentDocument.dispatchEvent(e);
iframe.contentDocument.documentElement.dispatchEvent(e);
}
EventUtils.synthesizeMouse(elem, 100, 100,
{ type: "mousemove", clickCount: "0" },