nsContentUtils::GetButtonsFlagForButton() returns incorrect value in some cases and adds assertions
Categories
(Core :: DOM: Core & HTML, defect)
Tracking
()
Tracking | Status | |
---|---|---|
firefox86 | --- | fixed |
People
(Reporter: andrew, Assigned: saschanaz)
Details
Attachments
(1 file)
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36
Steps to reproduce:
According to https://w3c.github.io/uievents/#dom-mouseevent-button the values of the button attribute of a mouse event are as follows:
The value of the button attribute MUST be as follows:
- 0 MUST indicate the primary button of the device (in general, the left button or the only button on single-button devices, used to activate a user interface control or select text) or the un-initialized value.
- 1 MUST indicate the auxiliary button (in general, the middle button, often combined with a mouse wheel).
- 2 MUST indicate the secondary button (in general, the right button, often used to display a context menu).
- 3 MUST indicate the X1 (back) button.
- 4 MUST indicate the X2 (forward) button.
In the Mozilla docs buttons 3, and 4 are named as the "Fourth" and "Fifth" button respectively:
3: Fourth button, typically the Browser Back button
4: Fifth button, typically the Browser Forward button
https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/button
However when using these two buttons (from mochitest or marionette in this case) the incorrect flag is returned because the case statement in GetButtonsFlagForButton incorrectly assigns the "Fourth button" to button value 4 (instead of 3), and the "Fifth button" to button value 5 (instead of 4):
https://searchfox.org/mozilla-central/source/dom/base/nsContentUtils.cpp#8043-8061
This means that when the Fifth button is pressed, the flag for button 4 will be returned, and when the Fourth button is pressed, an NS_Error will be included, and the return value will be 0
(no button is currently active).
GetButtonsFlagForButton(4);
GetButtonsFlagForButton(3);
Actual results:
GetButtonsFlagForButton(4); // Returns 8
GetButtonsFlagForButton(3); // Returns 0 and includes an NS_ERROR:
0:12.86 GECKO(25894) [Child 25896, Main Thread] ###!!! ASSERTION: Button not known.: 'Error', file /builds/worker/checkouts/gecko/dom/base/nsContentUtils.cpp:8058
Expected results:
GetButtonsFlagForButton(4); // Returns 16
GetButtonsFlagForButton(3); // Returns 4
Reporter | ||
Comment 1•3 years ago
|
||
Apologies, the expected result is wrong, it should be:
GetButtonsFlagForButton(4); // Returns 16
GetButtonsFlagForButton(3); // Returns 8
Comment 2•3 years ago
|
||
The button flags can be found here: https://searchfox.org/mozilla-central/rev/07342ce09126c513540c1c343476e026cfa907bf/widget/EventForwards.h#448-459
And indeed there is a discrepancy between the MDN docs and how it is implemented.
Moving the bug to the correct component.
Updated•3 years ago
|
Assignee | ||
Comment 3•3 years ago
|
||
Updated•3 years ago
|
Assignee | ||
Updated•3 years ago
|
Pushed by krosylight@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/efeeb05fbe0b Use proper numbers for mouse 4th/5th buttons r=masayuki
Comment 5•3 years ago
|
||
bugherder |
Description
•