Bug 562981 - Mouse click event in iframe has wrong coordinates [r=mfinkle]

This commit is contained in:
Vivien Nicolas 2010-05-03 11:42:56 -04:00
Родитель f8c918fdf3
Коммит 7700eca9a3
3 изменённых файлов: 33 добавлений и 11 удалений

Просмотреть файл

@ -1271,7 +1271,8 @@ var Browser = {
*/
elementFromPoint: function elementFromPoint(x, y) {
let browser = this._browserView.getBrowser();
if (!browser) return null;
if (!browser)
return null;
// browser's elementFromPoint expect browser-relative client coordinates.
// subtract browser's scroll values to adjust
@ -1775,9 +1776,10 @@ ContentCustomClicker.prototype = {
cwu.getScrollXY(false, scrollX, scrollY);
// the element can be out of the cX/cY point because of the touch radius
// ignore the redirection if the element is a HTMLHtmlElement (bug 562981)
let rect = Browser.getBoundingContentRect(element);
if (!rect.isEmpty() && ((x < rect.left || (x > rect.left + rect.width)) ||
(y < rect.top || (y > rect.top + rect.height)))) {
if (!rect.isEmpty() && !(element instanceof HTMLHtmlElement) &&
((x < rect.left || (x > rect.left + rect.width)) || (y < rect.top || (y > rect.top + rect.height)))) {
let point = rect.center();
x = point.x;
@ -1943,7 +1945,7 @@ const ElementTouchHelper = {
false); /* don't flush layout */
// return early if the click is just over a clickable element
if (!aWindowUtils.nodesFromRect || this._isElementClickable(target))
if (this._isElementClickable(target))
return target;
let nodes = aWindowUtils.nodesFromRect(aX, aY, this.radius.bottom,

Просмотреть файл

@ -1,4 +1,4 @@
<html>
<html style="border: 1px solid red">
<title>Browser Click Page 01</title>
<body>
<iframe src="data:,test test" width="100" height="100"><iframe>

Просмотреть файл

@ -3,6 +3,7 @@ let testURL_click = "chrome://mochikit/content/browser/mobile/chrome/browser_cli
let newTab;
let element;
let isClickFired = false;
let clickPosition = { x: null, y: null};
//------------------------------------------------------------------------------
// Entry point (must be named "test")
@ -15,14 +16,17 @@ function test() {
ok(newTab, "Tab Opened");
// Wait for tab load (need to check the tab "loading", not the document "loading")
waitFor(testClick, function() { return newTab.isLoading() == false; });
waitFor(testClickAndPosition, function() { return newTab.isLoading() == false; });
}
function clickFired() {
function clickFired(aEvent) {
isClickFired = true;
let [x, y] = Browser.browserViewToClient(aEvent.clientX, aEvent.clientY);
clickPosition.x = x;
clickPosition.y = y;
}
function testClick() {
function testClickAndPosition() {
// Do sanity tests
let uri = newTab.browser.currentURI.spec;
is(uri, testURL_click, "URL Matches newly created Tab");
@ -30,12 +34,31 @@ function testClick() {
// Check click
element = newTab.browser.contentDocument.querySelector("iframe");
element.addEventListener("click", clickFired, true);
EventUtils.synthesizeMouseForContent(element, 1, 1, {}, window);
waitFor(checkClick, function() { return isClickFired });
}
function checkClick() {
ok(isClickFired, "Click handler fired");
element.removeEventListener("click", clickFired, true);
// Check position
isClickFired = false;
element = newTab.browser.contentDocument.documentElement;
element.addEventListener("click", clickFired, true);
let rect = Browser.getBoundingContentRect(element);
EventUtils.synthesizeMouse(element, 1, rect.height + 10, {}, window);
waitFor(checkPosition, function() { return isClickFired });
}
function checkPosition() {
element.removeEventListener("click", clickFired, true);
let rect = Browser.getBoundingContentRect(element);
is(clickPosition.x, 1, "X position is correct");
is(clickPosition.y, rect.height + 10, "Y position is correct");
close();
}
@ -43,9 +66,6 @@ function close() {
// Close the tab
Browser.closeTab(newTab);
// Remove the listener
element.removeEventListener("click", clickFired, true);
// We must finialize the tests
finish();
}