Bug 1285128 - Should not generate pointer events for those synthesized events that are not dispatched to DOM. r=smaug

This commit is contained in:
Stone Shih 2016-07-07 15:28:11 +08:00
Родитель be60817f4b
Коммит f8f5ef1c1a
10 изменённых файлов: 104 добавлений и 24 удалений

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

@ -8089,7 +8089,8 @@ nsContentUtils::SendMouseEvent(nsCOMPtr<nsIPresShell> aPresShell,
unsigned short aInputSourceArg,
bool aToWindow,
bool *aPreventDefault,
bool aIsSynthesized)
bool aIsDOMEventSynthesized,
bool aIsWidgetEventSynthesized)
{
nsPoint offset;
nsCOMPtr<nsIWidget> widget = GetWidget(aPresShell, &offset);
@ -8123,7 +8124,10 @@ nsContentUtils::SendMouseEvent(nsCOMPtr<nsIPresShell> aPresShell,
aInputSourceArg = nsIDOMMouseEvent::MOZ_SOURCE_MOUSE;
}
WidgetMouseEvent event(true, msg, widget, WidgetMouseEvent::eReal,
WidgetMouseEvent event(true, msg, widget,
aIsWidgetEventSynthesized ?
WidgetMouseEvent::eSynthesized :
WidgetMouseEvent::eReal,
contextMenuKey ? WidgetMouseEvent::eContextMenuKey :
WidgetMouseEvent::eNormal);
event.mModifiers = GetWidgetModifiers(aModifiers);
@ -8133,7 +8137,7 @@ nsContentUtils::SendMouseEvent(nsCOMPtr<nsIPresShell> aPresShell,
event.inputSource = aInputSourceArg;
event.mClickCount = aClickCount;
event.mTime = PR_IntervalNow();
event.mFlags.mIsSynthesizedForTests = aIsSynthesized;
event.mFlags.mIsSynthesizedForTests = aIsDOMEventSynthesized;
nsPresContext* presContext = aPresShell->GetPresContext();
if (!presContext)

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

@ -2552,7 +2552,8 @@ public:
unsigned short aInputSourceArg,
bool aToWindow,
bool *aPreventDefault,
bool aIsSynthesized);
bool aIsDOMEventSynthesized,
bool aIsWidgetEventSynthesized);
static void FirePageShowEvent(nsIDocShellTreeItem* aItem,
mozilla::dom::EventTarget* aChromeEventHandler,

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

@ -648,14 +648,18 @@ nsDOMWindowUtils::SendMouseEvent(const nsAString& aType,
bool aIgnoreRootScrollFrame,
float aPressure,
unsigned short aInputSourceArg,
bool aIsSynthesized,
bool aIsDOMEventSynthesized,
bool aIsWidgetEventSynthesized,
uint8_t aOptionalArgCount,
bool *aPreventDefault)
{
return SendMouseEventCommon(aType, aX, aY, aButton, aClickCount, aModifiers,
aIgnoreRootScrollFrame, aPressure,
aInputSourceArg, false, aPreventDefault,
aOptionalArgCount >= 4 ? aIsSynthesized : true);
aOptionalArgCount >= 4 ?
aIsDOMEventSynthesized : true,
aOptionalArgCount >= 5 ?
aIsWidgetEventSynthesized : false);
}
NS_IMETHODIMP
@ -668,7 +672,8 @@ nsDOMWindowUtils::SendMouseEventToWindow(const nsAString& aType,
bool aIgnoreRootScrollFrame,
float aPressure,
unsigned short aInputSourceArg,
bool aIsSynthesized,
bool aIsDOMEventSynthesized,
bool aIsWidgetEventSynthesized,
uint8_t aOptionalArgCount)
{
PROFILER_LABEL("nsDOMWindowUtils", "SendMouseEventToWindow",
@ -677,7 +682,10 @@ nsDOMWindowUtils::SendMouseEventToWindow(const nsAString& aType,
return SendMouseEventCommon(aType, aX, aY, aButton, aClickCount, aModifiers,
aIgnoreRootScrollFrame, aPressure,
aInputSourceArg, true, nullptr,
aOptionalArgCount >= 4 ? aIsSynthesized : true);
aOptionalArgCount >= 4 ?
aIsDOMEventSynthesized : true,
aOptionalArgCount >= 5 ?
aIsWidgetEventSynthesized : false);
}
NS_IMETHODIMP
@ -692,12 +700,14 @@ nsDOMWindowUtils::SendMouseEventCommon(const nsAString& aType,
unsigned short aInputSourceArg,
bool aToWindow,
bool *aPreventDefault,
bool aIsSynthesized)
bool aIsDOMEventSynthesized,
bool aIsWidgetEventSynthesized)
{
nsCOMPtr<nsIPresShell> presShell = GetPresShell();
return nsContentUtils::SendMouseEvent(presShell, aType, aX, aY, aButton,
aClickCount, aModifiers, aIgnoreRootScrollFrame, aPressure,
aInputSourceArg, aToWindow, aPreventDefault, aIsSynthesized);
aInputSourceArg, aToWindow, aPreventDefault, aIsDOMEventSynthesized,
aIsWidgetEventSynthesized);
}
NS_IMETHODIMP

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

@ -93,7 +93,8 @@ protected:
unsigned short aInputSourceArg,
bool aToWindow,
bool *aPreventDefault,
bool aIsSynthesized);
bool aIsDOMEventSynthesized,
bool aIsWidgetEventSynthesized);
NS_IMETHOD SendPointerEventCommon(const nsAString& aType,
float aX,

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

@ -124,6 +124,6 @@ support-files =
pointerevent_touch-action-span-test_touch-manual.html
pointerevent_touch-action-svg-test_touch-manual.html
pointerevent_touch-action-table-test_touch-manual.html
[test_bug1285128.html]
[test_empty_file.html]
disabled = disabled # Bug 1150091 - Issue with support-files

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

@ -0,0 +1,48 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1285128
-->
<head>
<meta charset="utf-8">
<title>Test for Bug 1285128</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1285128">Mozilla Bug 1285128</a>
<p id="display"></p>
<div id="target0" style="width: 200px; height: 200px; background: green"></div>
<script type="text/javascript">
/** Test for Bug 1285128 **/
SimpleTest.waitForExplicitFinish();
function runTests() {
let target0 = window.document.getElementById("target0");
let pointerEventsList = ["pointerover", "pointerenter", "pointerdown",
"pointerup", "pointerleave", "pointerout"];
let receivedPointerEvents = false;
pointerEventsList.forEach((elem, index, arr) => {
target0.addEventListener(elem, (event) => {
ok(false, "receiving event " + event.type);
receivedPointerEvents = true;
}, false);
});
target0.addEventListener("mouseenter", () => {
ok(!receivedPointerEvents, "synthesized mousemove should not trigger any pointer events");
SimpleTest.finish();
});
synthesizeMouseAtCenter(target0, { type: "mousemove",
inputSource: SpecialPowers.Ci.nsIDOMMouseEvent.MOZ_SOURCE_MOUSE,
isWidgetEventSynthesized: true });
}
SpecialPowers.pushPrefEnv({"set": [["dom.w3c_pointer_events.enabled", true]]}, runTests);
</script>
</body>
</html>

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

@ -312,9 +312,11 @@ interface nsIDOMWindowUtils : nsISupports {
* @param aPressure touch input pressure: 0.0 -> 1.0
* @param aInputSourceArg input source, see nsIDOMMouseEvent for values,
* defaults to mouse input.
* @param aIsSynthesized controls nsIDOMEvent.isSynthesized value
* that helps identifying test related events,
* defaults to true
* @param aIsDOMEventSynthesized controls nsIDOMEvent.isSynthesized value
* that helps identifying test related events,
* defaults to true
* @param aIsWidgetEventSynthesized controls WidgetMouseEvent.mReason value
* defaults to false (WidgetMouseEvent::eReal)
*
* returns true if the page called prevent default on this event
*/
@ -328,7 +330,8 @@ interface nsIDOMWindowUtils : nsISupports {
[optional] in boolean aIgnoreRootScrollFrame,
[optional] in float aPressure,
[optional] in unsigned short aInputSourceArg,
[optional] in boolean aIsSynthesized);
[optional] in boolean aIsDOMEventSynthesized,
[optional] in boolean aIsWidgetEventSynthesized);
/** Synthesize a pointer event. The event types supported are:
@ -447,7 +450,8 @@ interface nsIDOMWindowUtils : nsISupports {
[optional] in boolean aIgnoreRootScrollFrame,
[optional] in float aPressure,
[optional] in unsigned short aInputSourceArg,
[optional] in boolean aIsSynthesized);
[optional] in boolean aIsDOMEventSynthesized,
[optional] in boolean aIsWidgetEventSynthesized);
/** The same as sendPointerEvent but ensures that the event
* is dispatched to this DOM window or one of its children.

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

@ -499,7 +499,8 @@ APZCCallbackHelper::DispatchMouseEvent(const nsCOMPtr<nsIPresShell>& aPresShell,
bool defaultPrevented = false;
nsContentUtils::SendMouseEvent(aPresShell, aType, aPoint.x, aPoint.y,
aButton, aClickCount, aModifiers, aIgnoreRootScrollFrame, 0,
aInputSourceArg, false, &defaultPrevented, false);
aInputSourceArg, false, &defaultPrevented, false,
/* aIsWidgetEventSynthesized = */ false);
return defaultPrevented;
}

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

@ -7134,8 +7134,11 @@ DispatchPointerFromMouseOrTouch(PresShell* aShell,
EventMessage pointerMessage = eVoidEvent;
if (aEvent->mClass == eMouseEventClass) {
WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
// if it is not mouse then it is likely will come as touch event
if (!mouseEvent->convertToPointer) {
// 1. If it is not mouse then it is likely will come as touch event
// 2. We don't synthesize pointer events for those events that are not
// dispatched to DOM.
if (!mouseEvent->convertToPointer ||
!aEvent->IsAllowedToDispatchDOMEvent()) {
return NS_OK;
}
int16_t button = mouseEvent->button;

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

@ -361,17 +361,25 @@ function synthesizeMouseAtPoint(left, top, aEvent, aWindow = window)
var modifiers = _parseModifiers(aEvent, aWindow);
var pressure = ("pressure" in aEvent) ? aEvent.pressure : 0;
var inputSource = ("inputSource" in aEvent) ? aEvent.inputSource : 0;
var synthesized = ("isSynthesized" in aEvent) ? aEvent.isSynthesized : true;
var isDOMEventSynthesized =
("isSynthesized" in aEvent) ? aEvent.isSynthesized : true;
var isWidgetEventSynthesized =
("isWidgetEventSynthesized" in aEvent) ? aEvent.isWidgetEventSynthesized : false;
if (("type" in aEvent) && aEvent.type) {
defaultPrevented = utils.sendMouseEvent(aEvent.type, left, top, button,
clickCount, modifiers, false,
pressure, inputSource,
synthesized);
isDOMEventSynthesized,
isWidgetEventSynthesized);
}
else {
utils.sendMouseEvent("mousedown", left, top, button, clickCount, modifiers, false, pressure, inputSource);
utils.sendMouseEvent("mouseup", left, top, button, clickCount, modifiers, false, pressure, inputSource);
utils.sendMouseEvent("mousedown", left, top, button, clickCount, modifiers,
false, pressure, inputSource, isDOMEventSynthesized,
isWidgetEventSynthesized);
utils.sendMouseEvent("mouseup", left, top, button, clickCount, modifiers,
false, pressure, inputSource, isDOMEventSynthesized,
isWidgetEventSynthesized);
}
}