Bug 1700241 - Mark click event as position-less event when accesskey of label element is pressed; r=masayuki

The click event dispatched for accesskey on other elements is marked as position-less event.
And other simulated click events are also marked as position-less, e.g. click() call, keydown Enter ...

label element should just behave the same on accesskey for consistency.

It is not clear on spec, see https://github.com/w3c/csswg-drafts/issues/1070,
but blink/webkit both returns 0 for offset{X|Y}.

Differential Revision: https://phabricator.services.mozilla.com/D109451
This commit is contained in:
Edgar Chen 2021-03-23 10:29:14 +00:00
Родитель 8560eb86e8
Коммит 130519b475
2 изменённых файлов: 15 добавлений и 10 удалений

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

@ -191,15 +191,9 @@ bool HTMLLabelElement::PerformAccesskey(bool aKeyCausesActivation,
}
// Click on it if the users prefs indicate to do so.
WidgetMouseEvent event(aIsTrustedEvent, eMouseClick, nullptr,
WidgetMouseEvent::eReal);
event.mInputSource = MouseEvent_Binding::MOZ_SOURCE_KEYBOARD;
AutoPopupStatePusher popupStatePusher(
aIsTrustedEvent ? PopupBlocker::openAllowed : PopupBlocker::openAbused);
EventDispatcher::Dispatch(static_cast<nsIContent*>(this), presContext,
&event);
DispatchSimulatedClick(this, aIsTrustedEvent, presContext);
}
return aKeyCausesActivation;

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

@ -7,12 +7,14 @@
<p>Tests that a keyboard access key to press a button will fire only the click event</p>
<button id="button" accesskey="g">Click Me with Shift+Alt+g or on Mac with Control+Option+g</button>
<input id="inputbutton" type="button" accesskey="b" value="Click me with Shift+Alt+b or on Mac with Control+Option+b">
<label id="label" accesskey="l">Click Me with Shift+Alt+l or on Mac with Control+Option+l</label>
<script>
let button = document.getElementById("button");
let inputbutton = document.getElementById("inputbutton");
let radiobutton = document.getElementById("radiobutton");
let elementList = [button, inputbutton];
let label = document.getElementById("label");
let elementList = [button, inputbutton, label];
let eventLog = [];
const eventList = ["pointerdown", "pointerup", "mousedown", "mouseup", "click"];
elementList.forEach((el)=>{eventList.forEach((ev)=>el.addEventListener(ev, (e)=>{
@ -24,12 +26,21 @@ elementList.forEach((el)=>{eventList.forEach((ev)=>el.addEventListener(ev, (e)=>
assert_equals(e.pointerId, 0, "Click's pointerId has default value");
assert_equals(e.pointerType, "", "Click's pointerType has default value");
}
assert_equals(e.screenX, 0, "Click's screenX has default value");
assert_equals(e.screenY, 0, "Click's screenY has default value");
assert_equals(e.clientX, 0, "Click's clientX has default value");
assert_equals(e.clientY, 0, "Click's clientY has default value");
assert_equals(e.pageX, 0, "Click's pageX has default value");
assert_equals(e.pageY, 0, "Click's pageY has default value");
// https://github.com/w3c/csswg-drafts/issues/1070
assert_equals(e.offsetX, 0, "Click's offsetX should have default value");
assert_equals(e.offsetY, 0, "Click's offsetY should have default value");
});
}
}));});
let currentTest;
let testElements = [button, inputbutton];
let accesskeyMap = new Map([[button, "g"], [inputbutton, "b"]]);
let testElements = [button, inputbutton, label];
let accesskeyMap = new Map([[button, "g"], [inputbutton, "b"], [label, "l"]]);
testElements.forEach((el)=>promise_test((test)=> new Promise(async (resolve,reject)=>{
currentTest = test;
eventLog = [];