Title: [235329] trunk
Revision
235329
Author
rn...@webkit.org
Date
2018-08-24 13:07:36 -0700 (Fri, 24 Aug 2018)

Log Message

Add getModifierState to MouseEvent
https://bugs.webkit.org/show_bug.cgi?id=188913
<rdar://problem/43668772>

Reviewed by Simon Fraser.

Source/WebCore:

Moved getModifierState from KeyboardEvent to UIEventWithKeyState and exposed it in MouseEvent.
See https://www.w3.org/TR/2016/WD-uievents-20160804/#mouseevent

This patch also fixes the bug that initMouseEvent was not clearing AltGraph and CapsLock states,
which was preserved in the refactoring done in r235158.

Tests: fast/events/constructors/mouse-event-getModifierState.html
       fast/events/dblclick-event-getModifierState.html

* dom/KeyboardEvent.cpp:
(WebCore::KeyboardEvent::getModifierState const): Moved to UIEventWithKeyState.
* dom/KeyboardEvent.h:
* dom/KeyboardEvent.idl: Insert a blank line to match the spec's IDL.
* dom/MouseEvent.idl: Added getModifierState. 
* dom/UIEventWithKeyState.cpp:
(WebCore::UIEventWithKeyState::modifiersFromInitializer): Moved from the header file.
(WebCore::UIEventWithKeyState::getModifierState const):
(WebCore::UIEventWithKeyState::setModifierKeys): Moved from the header file.
* dom/UIEventWithKeyState.h:
(WebCore::UIEventWithKeyState::modifierKeys const):
(WebCore::UIEventWithKeyState::setModifierKeys): Deleted the variant which didn't take altGraphKey
since that variant behaves same as the one which takes altGraphKey.

LayoutTests:

Added two tests for getModifierState: one manually setting modifier key states in MouseEvent's constructor,
and another one for dblclick inheriting modifier key states from the click event.

Also improved the test coverage for KeyboardEvent's getModifierState.

* fast/events/constructors/keyboard-event-getModifierState-expected.txt:
* fast/events/constructors/keyboard-event-getModifierState.html: Added more test cases.
* fast/events/constructors/mouse-event-getModifierState-expected.txt: Added.
* fast/events/constructors/mouse-event-getModifierState.html: Added.
* fast/events/dblclick-event-getModifierState-expected.txt: Added.
* fast/events/dblclick-event-getModifierState.html: Added.
* fast/events/init-event-clears-capslock-expected.txt:
* fast/events/init-event-clears-capslock.html: Added tests for MouseEvent. Note that initMouseEvent doesn't
take altGraphKey boolean unlike initKeyboardEvent.
* platform/ios/TestExpectations: Skip the dblclick test in iOS since click event isn't supported on iOS.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (235328 => 235329)


--- trunk/LayoutTests/ChangeLog	2018-08-24 19:43:20 UTC (rev 235328)
+++ trunk/LayoutTests/ChangeLog	2018-08-24 20:07:36 UTC (rev 235329)
@@ -1,3 +1,27 @@
+2018-08-24  Ryosuke Niwa  <rn...@webkit.org>
+
+        Add getModifierState to MouseEvent
+        https://bugs.webkit.org/show_bug.cgi?id=188913
+        <rdar://problem/43668772>
+
+        Reviewed by Simon Fraser.
+
+        Added two tests for getModifierState: one manually setting modifier key states in MouseEvent's constructor,
+        and another one for dblclick inheriting modifier key states from the click event.
+
+        Also improved the test coverage for KeyboardEvent's getModifierState.
+
+        * fast/events/constructors/keyboard-event-getModifierState-expected.txt:
+        * fast/events/constructors/keyboard-event-getModifierState.html: Added more test cases.
+        * fast/events/constructors/mouse-event-getModifierState-expected.txt: Added.
+        * fast/events/constructors/mouse-event-getModifierState.html: Added.
+        * fast/events/dblclick-event-getModifierState-expected.txt: Added.
+        * fast/events/dblclick-event-getModifierState.html: Added.
+        * fast/events/init-event-clears-capslock-expected.txt:
+        * fast/events/init-event-clears-capslock.html: Added tests for MouseEvent. Note that initMouseEvent doesn't
+        take altGraphKey boolean unlike initKeyboardEvent.
+        * platform/ios/TestExpectations: Skip the dblclick test in iOS since click event isn't supported on iOS.
+
 2018-08-24  Youenn Fablet  <you...@apple.com>
 
         libwebrtc PeerConnection::AddTrack sometimes fail

Modified: trunk/LayoutTests/fast/events/constructors/keyboard-event-getModifierState-expected.txt (235328 => 235329)


--- trunk/LayoutTests/fast/events/constructors/keyboard-event-getModifierState-expected.txt	2018-08-24 19:43:20 UTC (rev 235328)
+++ trunk/LayoutTests/fast/events/constructors/keyboard-event-getModifierState-expected.txt	2018-08-24 20:07:36 UTC (rev 235329)
@@ -7,26 +7,50 @@
 PASS event.getModifierState('Alt') is false
 PASS event.getModifierState('Shift') is false
 PASS event.getModifierState('Meta') is false
+PASS event.getModifierState('AltGraph') is false
+PASS event.getModifierState('CapsLock') is false
 PASS event.getModifierState('Control') is true
 PASS event.getModifierState('Alt') is false
 PASS event.getModifierState('Shift') is false
 PASS event.getModifierState('Meta') is false
+PASS event.getModifierState('AltGraph') is false
+PASS event.getModifierState('CapsLock') is false
 PASS event.getModifierState('Control') is false
 PASS event.getModifierState('Alt') is true
 PASS event.getModifierState('Shift') is false
 PASS event.getModifierState('Meta') is false
+PASS event.getModifierState('AltGraph') is false
+PASS event.getModifierState('CapsLock') is false
 PASS event.getModifierState('Control') is false
 PASS event.getModifierState('Alt') is false
 PASS event.getModifierState('Shift') is true
 PASS event.getModifierState('Meta') is false
+PASS event.getModifierState('AltGraph') is false
+PASS event.getModifierState('CapsLock') is false
 PASS event.getModifierState('Control') is false
 PASS event.getModifierState('Alt') is false
 PASS event.getModifierState('Shift') is false
 PASS event.getModifierState('Meta') is true
+PASS event.getModifierState('AltGraph') is false
+PASS event.getModifierState('CapsLock') is false
+PASS event.getModifierState('Control') is false
+PASS event.getModifierState('Alt') is false
+PASS event.getModifierState('Shift') is false
+PASS event.getModifierState('Meta') is false
+PASS event.getModifierState('AltGraph') is true
+PASS event.getModifierState('CapsLock') is false
+PASS event.getModifierState('Control') is false
+PASS event.getModifierState('Alt') is false
+PASS event.getModifierState('Shift') is false
+PASS event.getModifierState('Meta') is false
+PASS event.getModifierState('AltGraph') is false
+PASS event.getModifierState('CapsLock') is true
 PASS event.getModifierState('Control') is true
 PASS event.getModifierState('Alt') is true
 PASS event.getModifierState('Shift') is true
 PASS event.getModifierState('Meta') is true
+PASS event.getModifierState('AltGraph') is true
+PASS event.getModifierState('CapsLock') is true
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/fast/events/constructors/keyboard-event-getModifierState.html (235328 => 235329)


--- trunk/LayoutTests/fast/events/constructors/keyboard-event-getModifierState.html	2018-08-24 19:43:20 UTC (rev 235328)
+++ trunk/LayoutTests/fast/events/constructors/keyboard-event-getModifierState.html	2018-08-24 20:07:36 UTC (rev 235329)
@@ -13,6 +13,8 @@
 shouldBeFalse("event.getModifierState('Alt')");
 shouldBeFalse("event.getModifierState('Shift')");
 shouldBeFalse("event.getModifierState('Meta')");
+shouldBeFalse("event.getModifierState('AltGraph')");
+shouldBeFalse("event.getModifierState('CapsLock')");
 
 var event = new KeyboardEvent('keydown', { ctrlKey: true });
 shouldBeTrue("event.getModifierState('Control')");
@@ -19,6 +21,8 @@
 shouldBeFalse("event.getModifierState('Alt')");
 shouldBeFalse("event.getModifierState('Shift')");
 shouldBeFalse("event.getModifierState('Meta')");
+shouldBeFalse("event.getModifierState('AltGraph')");
+shouldBeFalse("event.getModifierState('CapsLock')");
 
 var event = new KeyboardEvent('keydown', { altKey: true });
 shouldBeFalse("event.getModifierState('Control')");
@@ -25,6 +29,8 @@
 shouldBeTrue("event.getModifierState('Alt')");
 shouldBeFalse("event.getModifierState('Shift')");
 shouldBeFalse("event.getModifierState('Meta')");
+shouldBeFalse("event.getModifierState('AltGraph')");
+shouldBeFalse("event.getModifierState('CapsLock')");
 
 var event = new KeyboardEvent('keydown', { shiftKey: true });
 shouldBeFalse("event.getModifierState('Control')");
@@ -31,6 +37,8 @@
 shouldBeFalse("event.getModifierState('Alt')");
 shouldBeTrue("event.getModifierState('Shift')");
 shouldBeFalse("event.getModifierState('Meta')");
+shouldBeFalse("event.getModifierState('AltGraph')");
+shouldBeFalse("event.getModifierState('CapsLock')");
 
 var event = new KeyboardEvent('keydown', { metaKey: true });
 shouldBeFalse("event.getModifierState('Control')");
@@ -37,12 +45,32 @@
 shouldBeFalse("event.getModifierState('Alt')");
 shouldBeFalse("event.getModifierState('Shift')");
 shouldBeTrue("event.getModifierState('Meta')");
+shouldBeFalse("event.getModifierState('AltGraph')");
+shouldBeFalse("event.getModifierState('CapsLock')");
 
-var event = new KeyboardEvent('keydown', { ctrlKey: true, altKey: true, shiftKey: true, metaKey: true });
+var event = new KeyboardEvent('keydown', { modifierAltGraph: true });
+shouldBeFalse("event.getModifierState('Control')");
+shouldBeFalse("event.getModifierState('Alt')");
+shouldBeFalse("event.getModifierState('Shift')");
+shouldBeFalse("event.getModifierState('Meta')");
+shouldBeTrue("event.getModifierState('AltGraph')");
+shouldBeFalse("event.getModifierState('CapsLock')");
+
+var event = new KeyboardEvent('keydown', { modifierCapsLock: true });
+shouldBeFalse("event.getModifierState('Control')");
+shouldBeFalse("event.getModifierState('Alt')");
+shouldBeFalse("event.getModifierState('Shift')");
+shouldBeFalse("event.getModifierState('Meta')");
+shouldBeFalse("event.getModifierState('AltGraph')");
+shouldBeTrue("event.getModifierState('CapsLock')");
+
+var event = new KeyboardEvent('keydown', { ctrlKey: true, altKey: true, shiftKey: true, metaKey: true, modifierAltGraph: true, modifierCapsLock: true });
 shouldBeTrue("event.getModifierState('Control')");
 shouldBeTrue("event.getModifierState('Alt')");
 shouldBeTrue("event.getModifierState('Shift')");
 shouldBeTrue("event.getModifierState('Meta')");
+shouldBeTrue("event.getModifierState('AltGraph')");
+shouldBeTrue("event.getModifierState('CapsLock')");
 </script>
 <script src=""
 </body>

Added: trunk/LayoutTests/fast/events/constructors/mouse-event-getModifierState-expected.txt (0 => 235329)


--- trunk/LayoutTests/fast/events/constructors/mouse-event-getModifierState-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/events/constructors/mouse-event-getModifierState-expected.txt	2018-08-24 20:07:36 UTC (rev 235329)
@@ -0,0 +1,57 @@
+This tests KeyboardEvent.getModifierState().
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS event.getModifierState('Control') is false
+PASS event.getModifierState('Alt') is false
+PASS event.getModifierState('Shift') is false
+PASS event.getModifierState('Meta') is false
+PASS event.getModifierState('AltGraph') is false
+PASS event.getModifierState('CapsLock') is false
+PASS event.getModifierState('Control') is true
+PASS event.getModifierState('Alt') is false
+PASS event.getModifierState('Shift') is false
+PASS event.getModifierState('Meta') is false
+PASS event.getModifierState('AltGraph') is false
+PASS event.getModifierState('CapsLock') is false
+PASS event.getModifierState('Control') is false
+PASS event.getModifierState('Alt') is true
+PASS event.getModifierState('Shift') is false
+PASS event.getModifierState('Meta') is false
+PASS event.getModifierState('AltGraph') is false
+PASS event.getModifierState('CapsLock') is false
+PASS event.getModifierState('Control') is false
+PASS event.getModifierState('Alt') is false
+PASS event.getModifierState('Shift') is true
+PASS event.getModifierState('Meta') is false
+PASS event.getModifierState('AltGraph') is false
+PASS event.getModifierState('CapsLock') is false
+PASS event.getModifierState('Control') is false
+PASS event.getModifierState('Alt') is false
+PASS event.getModifierState('Shift') is false
+PASS event.getModifierState('Meta') is true
+PASS event.getModifierState('AltGraph') is false
+PASS event.getModifierState('CapsLock') is false
+PASS event.getModifierState('Control') is false
+PASS event.getModifierState('Alt') is false
+PASS event.getModifierState('Shift') is false
+PASS event.getModifierState('Meta') is false
+PASS event.getModifierState('AltGraph') is true
+PASS event.getModifierState('CapsLock') is false
+PASS event.getModifierState('Control') is false
+PASS event.getModifierState('Alt') is false
+PASS event.getModifierState('Shift') is false
+PASS event.getModifierState('Meta') is false
+PASS event.getModifierState('AltGraph') is false
+PASS event.getModifierState('CapsLock') is true
+PASS event.getModifierState('Control') is true
+PASS event.getModifierState('Alt') is true
+PASS event.getModifierState('Shift') is true
+PASS event.getModifierState('Meta') is true
+PASS event.getModifierState('AltGraph') is true
+PASS event.getModifierState('CapsLock') is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Copied: trunk/LayoutTests/fast/events/constructors/mouse-event-getModifierState.html (from rev 235267, trunk/LayoutTests/fast/events/constructors/keyboard-event-getModifierState.html) (0 => 235329)


--- trunk/LayoutTests/fast/events/constructors/mouse-event-getModifierState.html	                        (rev 0)
+++ trunk/LayoutTests/fast/events/constructors/mouse-event-getModifierState.html	2018-08-24 20:07:36 UTC (rev 235329)
@@ -0,0 +1,77 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src=""
+</head>
+<body>
+<script>
+
+description("This tests KeyboardEvent.getModifierState().");
+
+var event = new MouseEvent('mousedown', { });
+shouldBeFalse("event.getModifierState('Control')");
+shouldBeFalse("event.getModifierState('Alt')");
+shouldBeFalse("event.getModifierState('Shift')");
+shouldBeFalse("event.getModifierState('Meta')");
+shouldBeFalse("event.getModifierState('AltGraph')");
+shouldBeFalse("event.getModifierState('CapsLock')");
+
+var event = new MouseEvent('mousedown', { ctrlKey: true });
+shouldBeTrue("event.getModifierState('Control')");
+shouldBeFalse("event.getModifierState('Alt')");
+shouldBeFalse("event.getModifierState('Shift')");
+shouldBeFalse("event.getModifierState('Meta')");
+shouldBeFalse("event.getModifierState('AltGraph')");
+shouldBeFalse("event.getModifierState('CapsLock')");
+
+var event = new MouseEvent('mousedown', { altKey: true });
+shouldBeFalse("event.getModifierState('Control')");
+shouldBeTrue("event.getModifierState('Alt')");
+shouldBeFalse("event.getModifierState('Shift')");
+shouldBeFalse("event.getModifierState('Meta')");
+shouldBeFalse("event.getModifierState('AltGraph')");
+shouldBeFalse("event.getModifierState('CapsLock')");
+
+var event = new MouseEvent('mousedown', { shiftKey: true });
+shouldBeFalse("event.getModifierState('Control')");
+shouldBeFalse("event.getModifierState('Alt')");
+shouldBeTrue("event.getModifierState('Shift')");
+shouldBeFalse("event.getModifierState('Meta')");
+shouldBeFalse("event.getModifierState('AltGraph')");
+shouldBeFalse("event.getModifierState('CapsLock')");
+
+var event = new MouseEvent('mousedown', { metaKey: true });
+shouldBeFalse("event.getModifierState('Control')");
+shouldBeFalse("event.getModifierState('Alt')");
+shouldBeFalse("event.getModifierState('Shift')");
+shouldBeTrue("event.getModifierState('Meta')");
+shouldBeFalse("event.getModifierState('AltGraph')");
+shouldBeFalse("event.getModifierState('CapsLock')");
+
+var event = new MouseEvent('mousedown', { modifierAltGraph: true });
+shouldBeFalse("event.getModifierState('Control')");
+shouldBeFalse("event.getModifierState('Alt')");
+shouldBeFalse("event.getModifierState('Shift')");
+shouldBeFalse("event.getModifierState('Meta')");
+shouldBeTrue("event.getModifierState('AltGraph')");
+shouldBeFalse("event.getModifierState('CapsLock')");
+
+var event = new MouseEvent('mousedown', { modifierCapsLock: true });
+shouldBeFalse("event.getModifierState('Control')");
+shouldBeFalse("event.getModifierState('Alt')");
+shouldBeFalse("event.getModifierState('Shift')");
+shouldBeFalse("event.getModifierState('Meta')");
+shouldBeFalse("event.getModifierState('AltGraph')");
+shouldBeTrue("event.getModifierState('CapsLock')");
+
+var event = new MouseEvent('mousedown', { ctrlKey: true, altKey: true, shiftKey: true, metaKey: true, modifierAltGraph: true, modifierCapsLock: true });
+shouldBeTrue("event.getModifierState('Control')");
+shouldBeTrue("event.getModifierState('Alt')");
+shouldBeTrue("event.getModifierState('Shift')");
+shouldBeTrue("event.getModifierState('Meta')");
+shouldBeTrue("event.getModifierState('AltGraph')");
+shouldBeTrue("event.getModifierState('CapsLock')");
+</script>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/events/dblclick-event-getModifierState-expected.txt (0 => 235329)


--- trunk/LayoutTests/fast/events/dblclick-event-getModifierState-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/events/dblclick-event-getModifierState-expected.txt	2018-08-24 20:07:36 UTC (rev 235329)
@@ -0,0 +1,59 @@
+This tests mouse events sets the correct modifier key states.
+To manually test, turn on CapsLock and press Alt key and move the mosue cursor to the red box below, and then double click it.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS currentEvent.type is "mousedown"
+PASS currentEvent.getModifierState("Control") is false
+PASS currentEvent.getModifierState("Alt") is true
+PASS currentEvent.getModifierState("Shift") is false
+PASS currentEvent.getModifierState("Meta") is false
+PASS currentEvent.getModifierState("AltGraph") is false
+PASS currentEvent.getModifierState("CapsLock") is true
+PASS currentEvent.type is "mouseup"
+PASS currentEvent.getModifierState("Control") is false
+PASS currentEvent.getModifierState("Alt") is true
+PASS currentEvent.getModifierState("Shift") is false
+PASS currentEvent.getModifierState("Meta") is false
+PASS currentEvent.getModifierState("AltGraph") is false
+PASS currentEvent.getModifierState("CapsLock") is true
+PASS currentEvent.type is "click"
+PASS currentEvent.getModifierState("Control") is false
+PASS currentEvent.getModifierState("Alt") is true
+PASS currentEvent.getModifierState("Shift") is false
+PASS currentEvent.getModifierState("Meta") is false
+PASS currentEvent.getModifierState("AltGraph") is false
+PASS currentEvent.getModifierState("CapsLock") is true
+PASS currentEvent.type is "mousedown"
+PASS currentEvent.getModifierState("Control") is false
+PASS currentEvent.getModifierState("Alt") is true
+PASS currentEvent.getModifierState("Shift") is false
+PASS currentEvent.getModifierState("Meta") is false
+PASS currentEvent.getModifierState("AltGraph") is false
+PASS currentEvent.getModifierState("CapsLock") is true
+PASS currentEvent.type is "mouseup"
+PASS currentEvent.getModifierState("Control") is false
+PASS currentEvent.getModifierState("Alt") is true
+PASS currentEvent.getModifierState("Shift") is false
+PASS currentEvent.getModifierState("Meta") is false
+PASS currentEvent.getModifierState("AltGraph") is false
+PASS currentEvent.getModifierState("CapsLock") is true
+PASS currentEvent.type is "click"
+PASS currentEvent.getModifierState("Control") is false
+PASS currentEvent.getModifierState("Alt") is true
+PASS currentEvent.getModifierState("Shift") is false
+PASS currentEvent.getModifierState("Meta") is false
+PASS currentEvent.getModifierState("AltGraph") is false
+PASS currentEvent.getModifierState("CapsLock") is true
+PASS currentEvent.type is "dblclick"
+PASS currentEvent.getModifierState("Control") is false
+PASS currentEvent.getModifierState("Alt") is true
+PASS currentEvent.getModifierState("Shift") is false
+PASS currentEvent.getModifierState("Meta") is false
+PASS currentEvent.getModifierState("AltGraph") is false
+PASS currentEvent.getModifierState("CapsLock") is true
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/events/dblclick-event-getModifierState.html (0 => 235329)


--- trunk/LayoutTests/fast/events/dblclick-event-getModifierState.html	                        (rev 0)
+++ trunk/LayoutTests/fast/events/dblclick-event-getModifierState.html	2018-08-24 20:07:36 UTC (rev 235329)
@@ -0,0 +1,60 @@
+<!DOCTYPE html>
+<html>
+<body>
+
+<div id="target" style="margin: 1rem; width: 100px; height: 100px; border: solid 5px red;"></div>
+<script src=""
+<script>
+
+description(`This tests mouse events sets the correct modifier key states.<br>
+To manually test, turn on CapsLock and press Alt key and move the mosue cursor to the red box below, and then double click it.`);
+
+jsTestIsAsync = true;
+
+const events = [];
+function addEvent(event) { events.push(event) };
+let firstMousemoveEvent = null;
+
+const target = document.getElementById('target');
+target.addEventListener('mousedown', addEvent);
+target.addEventListener('mouseup', addEvent);
+target.addEventListener('click', addEvent);
+target.addEventListener('dblclick', (event) => {
+    addEvent(event);
+    verify();
+});
+
+var currentEvent;
+function verify() {
+    const eventTypes = ['mousedown', 'mouseup', 'click', 'mousedown', 'mouseup', 'click', 'dblclick'];
+    for (let i = 0; i < events.length; i++) {
+        currentEvent = events[i];
+        shouldBeEqualToString('currentEvent.type', eventTypes[i]);
+        shouldBeFalse('currentEvent.getModifierState("Control")');
+        shouldBeTrue('currentEvent.getModifierState("Alt")');
+        shouldBeFalse('currentEvent.getModifierState("Shift")');
+        shouldBeFalse('currentEvent.getModifierState("Meta")');
+        shouldBeFalse('currentEvent.getModifierState("AltGraph")');
+        shouldBeTrue('currentEvent.getModifierState("CapsLock")');
+    }
+    finishJSTest();
+}
+
+if (window.eventSender) {
+    eventSender.leapForward(1000); // drain dblclick timer
+
+    eventSender.mouseMoveTo(1, 1);
+    eventSender.mouseMoveTo(target.offsetLeft + target.offsetWidth / 2, target.offsetTop + target.offsetHeight / 2);
+
+    eventSender.mouseDown(0, ['altKey', 'capsLockKey']);
+    eventSender.mouseUp(0, ['altKey', 'capsLockKey']);
+    eventSender.mouseDown(0, ['altKey', 'capsLockKey']);
+    eventSender.mouseUp(0, ['altKey', 'capsLockKey']);
+} else if (window.testRunner) {
+    testFailed('This test requires eventSender');
+    finishJSTest();
+}
+
+</script>
+</body>
+</html>

Modified: trunk/LayoutTests/fast/events/init-event-clears-capslock-expected.txt (235328 => 235329)


--- trunk/LayoutTests/fast/events/init-event-clears-capslock-expected.txt	2018-08-24 19:43:20 UTC (rev 235328)
+++ trunk/LayoutTests/fast/events/init-event-clears-capslock-expected.txt	2018-08-24 20:07:36 UTC (rev 235329)
@@ -37,6 +37,40 @@
 PASS keyEvent.getModifierState("Meta") is true
 PASS keyEvent.getModifierState("AltGraph") is true
 PASS keyEvent.getModifierState("CapsLock") is false
+mouseEvent = new MouseEvent('mousedown', { bubbles: true, cancelable: true, view: window, detail: 0, key: 'a', code: 'KeyA',
+    ctrlKey: true, altKey: true, shiftKey: true, metaKey: true, modifierAltGraph: true, modifierCapsLock: true });
+PASS mouseEvent.ctrlKey is true
+PASS mouseEvent.shiftKey is true
+PASS mouseEvent.altKey is true
+PASS mouseEvent.metaKey is true
+PASS mouseEvent.getModifierState("Control") is true
+PASS mouseEvent.getModifierState("Shift") is true
+PASS mouseEvent.getModifierState("Alt") is true
+PASS mouseEvent.getModifierState("Meta") is true
+PASS mouseEvent.getModifierState("AltGraph") is true
+PASS mouseEvent.getModifierState("CapsLock") is true
+mouseEvent.initMouseEvent('mousedown', false, false, window, 0, 0, 0, 0, 0, /* ctrl */ false, /* alt */ false, /* shift */ false, /* meta */ false)
+PASS mouseEvent.ctrlKey is false
+PASS mouseEvent.shiftKey is false
+PASS mouseEvent.altKey is false
+PASS mouseEvent.metaKey is false
+PASS mouseEvent.getModifierState("Control") is false
+PASS mouseEvent.getModifierState("Shift") is false
+PASS mouseEvent.getModifierState("Alt") is false
+PASS mouseEvent.getModifierState("Meta") is false
+PASS mouseEvent.getModifierState("AltGraph") is false
+PASS mouseEvent.getModifierState("CapsLock") is false
+mouseEvent.initMouseEvent('mousedown', false, false, window, 0, 0, 0, 0, 0, /* ctrl */ true, /* alt */ true, /* shift */ true, /* meta */ true)
+PASS mouseEvent.ctrlKey is true
+PASS mouseEvent.shiftKey is true
+PASS mouseEvent.altKey is true
+PASS mouseEvent.metaKey is true
+PASS mouseEvent.getModifierState("Control") is true
+PASS mouseEvent.getModifierState("Shift") is true
+PASS mouseEvent.getModifierState("Alt") is true
+PASS mouseEvent.getModifierState("Meta") is true
+PASS mouseEvent.getModifierState("AltGraph") is false
+PASS mouseEvent.getModifierState("CapsLock") is false
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/fast/events/init-event-clears-capslock.html (235328 => 235329)


--- trunk/LayoutTests/fast/events/init-event-clears-capslock.html	2018-08-24 19:43:20 UTC (rev 235328)
+++ trunk/LayoutTests/fast/events/init-event-clears-capslock.html	2018-08-24 20:07:36 UTC (rev 235329)
@@ -43,6 +43,43 @@
 shouldBeTrue('keyEvent.getModifierState("AltGraph")');
 shouldBeFalse('keyEvent.getModifierState("CapsLock")');
 
+evalAndLog(`mouseEvent = new MouseEvent('mousedown', { bubbles: true, cancelable: true, view: window, detail: 0, key: 'a', code: 'KeyA',
+    ctrlKey: true, altKey: true, shiftKey: true, metaKey: true, modifierAltGraph: true, modifierCapsLock: true });`);
+shouldBeTrue('mouseEvent.ctrlKey');
+shouldBeTrue('mouseEvent.shiftKey');
+shouldBeTrue('mouseEvent.altKey');
+shouldBeTrue('mouseEvent.metaKey');
+shouldBeTrue('mouseEvent.getModifierState("Control")');
+shouldBeTrue('mouseEvent.getModifierState("Shift")');
+shouldBeTrue('mouseEvent.getModifierState("Alt")');
+shouldBeTrue('mouseEvent.getModifierState("Meta")');
+shouldBeTrue('mouseEvent.getModifierState("AltGraph")');
+shouldBeTrue('mouseEvent.getModifierState("CapsLock")');
+
+evalAndLog(`mouseEvent.initMouseEvent('mousedown', false, false, window, 0, 0, 0, 0, 0, /* ctrl */ false, /* alt */ false, /* shift */ false, /* meta */ false)`);
+shouldBeFalse('mouseEvent.ctrlKey');
+shouldBeFalse('mouseEvent.shiftKey');
+shouldBeFalse('mouseEvent.altKey');
+shouldBeFalse('mouseEvent.metaKey');
+shouldBeFalse('mouseEvent.getModifierState("Control")');
+shouldBeFalse('mouseEvent.getModifierState("Shift")');
+shouldBeFalse('mouseEvent.getModifierState("Alt")');
+shouldBeFalse('mouseEvent.getModifierState("Meta")');
+shouldBeFalse('mouseEvent.getModifierState("AltGraph")');
+shouldBeFalse('mouseEvent.getModifierState("CapsLock")');
+
+evalAndLog(`mouseEvent.initMouseEvent('mousedown', false, false, window, 0, 0, 0, 0, 0, /* ctrl */ true, /* alt */ true, /* shift */ true, /* meta */ true)`);
+shouldBeTrue('mouseEvent.ctrlKey');
+shouldBeTrue('mouseEvent.shiftKey');
+shouldBeTrue('mouseEvent.altKey');
+shouldBeTrue('mouseEvent.metaKey');
+shouldBeTrue('mouseEvent.getModifierState("Control")');
+shouldBeTrue('mouseEvent.getModifierState("Shift")');
+shouldBeTrue('mouseEvent.getModifierState("Alt")');
+shouldBeTrue('mouseEvent.getModifierState("Meta")');
+shouldBeFalse('mouseEvent.getModifierState("AltGraph")');
+shouldBeFalse('mouseEvent.getModifierState("CapsLock")');
+
 </script>
 </body>
 </html>

Modified: trunk/LayoutTests/platform/ios/TestExpectations (235328 => 235329)


--- trunk/LayoutTests/platform/ios/TestExpectations	2018-08-24 19:43:20 UTC (rev 235328)
+++ trunk/LayoutTests/platform/ios/TestExpectations	2018-08-24 20:07:36 UTC (rev 235329)
@@ -448,6 +448,7 @@
 fast/events/contextmenu-scrolled-page-with-frame.html [ Skip ]
 fast/events/data-transfer-files-attribute-identity.html [ Skip ]
 fast/events/dblclick-addEventListener.html [ Skip ]
+fast/events/dblclick-event-getModifierState.html [ Skip ]
 fast/events/display-none-on-focus-crash.html [ Skip ]
 fast/events/dont-loose-last-event.html [ Skip ]
 fast/events/drag-select-when-zoomed-with-header.html [ Skip ]

Modified: trunk/Source/WebCore/ChangeLog (235328 => 235329)


--- trunk/Source/WebCore/ChangeLog	2018-08-24 19:43:20 UTC (rev 235328)
+++ trunk/Source/WebCore/ChangeLog	2018-08-24 20:07:36 UTC (rev 235329)
@@ -1,3 +1,34 @@
+2018-08-24  Ryosuke Niwa  <rn...@webkit.org>
+
+        Add getModifierState to MouseEvent
+        https://bugs.webkit.org/show_bug.cgi?id=188913
+        <rdar://problem/43668772>
+
+        Reviewed by Simon Fraser.
+
+        Moved getModifierState from KeyboardEvent to UIEventWithKeyState and exposed it in MouseEvent.
+        See https://www.w3.org/TR/2016/WD-uievents-20160804/#mouseevent
+
+        This patch also fixes the bug that initMouseEvent was not clearing AltGraph and CapsLock states,
+        which was preserved in the refactoring done in r235158.
+
+        Tests: fast/events/constructors/mouse-event-getModifierState.html
+               fast/events/dblclick-event-getModifierState.html
+
+        * dom/KeyboardEvent.cpp:
+        (WebCore::KeyboardEvent::getModifierState const): Moved to UIEventWithKeyState.
+        * dom/KeyboardEvent.h:
+        * dom/KeyboardEvent.idl: Insert a blank line to match the spec's IDL.
+        * dom/MouseEvent.idl: Added getModifierState. 
+        * dom/UIEventWithKeyState.cpp:
+        (WebCore::UIEventWithKeyState::modifiersFromInitializer): Moved from the header file.
+        (WebCore::UIEventWithKeyState::getModifierState const):
+        (WebCore::UIEventWithKeyState::setModifierKeys): Moved from the header file.
+        * dom/UIEventWithKeyState.h:
+        (WebCore::UIEventWithKeyState::modifierKeys const):
+        (WebCore::UIEventWithKeyState::setModifierKeys): Deleted the variant which didn't take altGraphKey
+        since that variant behaves same as the one which takes altGraphKey.
+
 2018-08-24  Youenn Fablet  <you...@apple.com>
 
         libwebrtc PeerConnection::AddTrack sometimes fail

Modified: trunk/Source/WebCore/dom/KeyboardEvent.cpp (235328 => 235329)


--- trunk/Source/WebCore/dom/KeyboardEvent.cpp	2018-08-24 19:43:20 UTC (rev 235328)
+++ trunk/Source/WebCore/dom/KeyboardEvent.cpp	2018-08-24 20:07:36 UTC (rev 235329)
@@ -183,24 +183,6 @@
 #endif
 }
 
-bool KeyboardEvent::getModifierState(const String& keyIdentifier) const
-{
-    if (keyIdentifier == "Control")
-        return ctrlKey();
-    if (keyIdentifier == "Shift")
-        return shiftKey();
-    if (keyIdentifier == "Alt")
-        return altKey();
-    if (keyIdentifier == "Meta")
-        return metaKey();
-    if (keyIdentifier == "AltGraph")
-        return altGraphKey();
-    if (keyIdentifier == "CapsLock")
-        return capsLockKey();
-    // FIXME: The specification also has Fn, FnLock, Hyper, NumLock, Super, ScrollLock, Symbol, SymbolLock.
-    return false;
-}
-
 int KeyboardEvent::keyCode() const
 {
     if (m_keyCode)

Modified: trunk/Source/WebCore/dom/KeyboardEvent.h (235328 => 235329)


--- trunk/Source/WebCore/dom/KeyboardEvent.h	2018-08-24 19:43:20 UTC (rev 235328)
+++ trunk/Source/WebCore/dom/KeyboardEvent.h	2018-08-24 20:07:36 UTC (rev 235329)
@@ -80,8 +80,6 @@
     unsigned location() const { return m_location; }
     bool repeat() const { return m_repeat; }
 
-    WEBCORE_EXPORT bool getModifierState(const String& keyIdentifier) const;
-    
     const PlatformKeyboardEvent* underlyingPlatformEvent() const { return m_underlyingPlatformEvent.get(); }
     PlatformKeyboardEvent* underlyingPlatformEvent() { return m_underlyingPlatformEvent.get(); }
 

Modified: trunk/Source/WebCore/dom/KeyboardEvent.idl (235328 => 235329)


--- trunk/Source/WebCore/dom/KeyboardEvent.idl	2018-08-24 19:43:20 UTC (rev 235328)
+++ trunk/Source/WebCore/dom/KeyboardEvent.idl	2018-08-24 20:07:36 UTC (rev 235329)
@@ -35,8 +35,8 @@
     readonly attribute boolean shiftKey;
     readonly attribute boolean altKey;
     readonly attribute boolean metaKey;
+
     readonly attribute boolean repeat;
-
     readonly attribute boolean isComposing;
 
     boolean getModifierState(DOMString keyArg);

Modified: trunk/Source/WebCore/dom/MouseEvent.idl (235328 => 235329)


--- trunk/Source/WebCore/dom/MouseEvent.idl	2018-08-24 19:43:20 UTC (rev 235328)
+++ trunk/Source/WebCore/dom/MouseEvent.idl	2018-08-24 20:07:36 UTC (rev 235329)
@@ -35,6 +35,9 @@
     readonly attribute unsigned short button;
     readonly attribute unsigned short buttons;
     readonly attribute EventTarget? relatedTarget;
+
+    boolean getModifierState(DOMString keyArg);
+
     [Conditional=POINTER_LOCK] readonly attribute long movementX;
     [Conditional=POINTER_LOCK] readonly attribute long movementY;
     [Conditional=MOUSE_FORCE_EVENTS, ImplementedAs=force]readonly attribute double webkitForce;

Modified: trunk/Source/WebCore/dom/UIEventWithKeyState.cpp (235328 => 235329)


--- trunk/Source/WebCore/dom/UIEventWithKeyState.cpp	2018-08-24 19:43:20 UTC (rev 235328)
+++ trunk/Source/WebCore/dom/UIEventWithKeyState.cpp	2018-08-24 20:07:36 UTC (rev 235329)
@@ -22,7 +22,59 @@
 #include "UIEventWithKeyState.h"
 
 namespace WebCore {
-    
+
+auto UIEventWithKeyState::modifiersFromInitializer(const EventModifierInit& initializer) -> OptionSet<Modifier>
+{
+    OptionSet<Modifier> result;
+    if (initializer.ctrlKey)
+        result |= Modifier::CtrlKey;
+    if (initializer.altKey)
+        result |= Modifier::AltKey;
+    if (initializer.shiftKey)
+        result |= Modifier::ShiftKey;
+    if (initializer.metaKey)
+        result |= Modifier::MetaKey;
+    if (initializer.modifierAltGraph)
+        result |= Modifier::AltGraphKey;
+    if (initializer.modifierCapsLock)
+        result |= Modifier::CapsLockKey;
+    return result;
+}
+
+bool UIEventWithKeyState::getModifierState(const String& keyIdentifier) const
+{
+    if (keyIdentifier == "Control")
+        return ctrlKey();
+    if (keyIdentifier == "Shift")
+        return shiftKey();
+    if (keyIdentifier == "Alt")
+        return altKey();
+    if (keyIdentifier == "Meta")
+        return metaKey();
+    if (keyIdentifier == "AltGraph")
+        return altGraphKey();
+    if (keyIdentifier == "CapsLock")
+        return capsLockKey();
+    // FIXME: The specification also has Fn, FnLock, Hyper, NumLock, Super, ScrollLock, Symbol, SymbolLock.
+    return false;
+}
+
+void UIEventWithKeyState::setModifierKeys(bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool altGraphKey)
+{
+    OptionSet<Modifier> result;
+    if (ctrlKey)
+        result |= Modifier::CtrlKey;
+    if (altKey)
+        result |= Modifier::AltKey;
+    if (shiftKey)
+        result |= Modifier::ShiftKey;
+    if (metaKey)
+        result |= Modifier::MetaKey;
+    if (altGraphKey)
+        result |= Modifier::AltGraphKey;
+    m_modifiers = result;
+}
+
 UIEventWithKeyState* findEventWithKeyState(Event* event)
 {
     for (Event* e = event; e; e = e->underlyingEvent())

Modified: trunk/Source/WebCore/dom/UIEventWithKeyState.h (235328 => 235329)


--- trunk/Source/WebCore/dom/UIEventWithKeyState.h	2018-08-24 19:43:20 UTC (rev 235328)
+++ trunk/Source/WebCore/dom/UIEventWithKeyState.h	2018-08-24 20:07:36 UTC (rev 235329)
@@ -40,8 +40,10 @@
     bool altGraphKey() const { return m_modifiers.contains(Modifier::AltGraphKey); }
     bool capsLockKey() const { return m_modifiers.contains(Modifier::CapsLockKey); }
 
-    OptionSet<Modifier> modifierKeys() { return m_modifiers; }
+    OptionSet<Modifier> modifierKeys() const { return m_modifiers; }
 
+    WEBCORE_EXPORT bool getModifierState(const String& keyIdentifier) const;
+
 protected:
     UIEventWithKeyState() = default;
 
@@ -63,62 +65,12 @@
     {
     }
 
-    void setModifierKeys(bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool altGraphKey)
-    {
-        OptionSet<Modifier> result;
-        if (ctrlKey)
-            result |= Modifier::CtrlKey;
-        if (altKey)
-            result |= Modifier::AltKey;
-        if (shiftKey)
-            result |= Modifier::ShiftKey;
-        if (metaKey)
-            result |= Modifier::MetaKey;
-        if (altGraphKey)
-            result |= Modifier::AltGraphKey;
-        m_modifiers = result;
-    }
+    void setModifierKeys(bool ctrlKey, bool altKey, bool shiftKey, bool metaKey, bool altGraphKey = false);
 
-    void setModifierKeys(bool ctrlKey, bool altKey, bool shiftKey, bool metaKey)
-    {
-        OptionSet<Modifier> result;
-        if (ctrlKey)
-            result |= Modifier::CtrlKey;
-        if (altKey)
-            result |= Modifier::AltKey;
-        if (shiftKey)
-            result |= Modifier::ShiftKey;
-        if (metaKey)
-            result |= Modifier::MetaKey;
-        //  FIXME: Chrome or Firefox don't preserve these states.
-        if (m_modifiers & Modifier::AltGraphKey)
-            result |= Modifier::AltGraphKey;
-        if (m_modifiers & Modifier::CapsLockKey)
-            result |= Modifier::CapsLockKey;
-        m_modifiers = result;
-    }
-
 private:
     OptionSet<Modifier> m_modifiers;
 
-    OptionSet<Modifier> modifiersFromInitializer(const EventModifierInit& initializer)
-    {
-        OptionSet<Modifier> result;
-        if (initializer.ctrlKey)
-            result |= Modifier::CtrlKey;
-        if (initializer.altKey)
-            result |= Modifier::AltKey;
-        if (initializer.shiftKey)
-            result |= Modifier::ShiftKey;
-        if (initializer.metaKey)
-            result |= Modifier::MetaKey;
-        if (initializer.modifierAltGraph)
-            result |= Modifier::AltGraphKey;
-        if (initializer.modifierCapsLock)
-            result |= Modifier::CapsLockKey;
-        return result;
-    }
-    
+    static OptionSet<Modifier> modifiersFromInitializer(const EventModifierInit& initializer);
 };
 
 UIEventWithKeyState* findEventWithKeyState(Event*);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to