Add support for KeyboardEvent.isComposing attribute
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Oct 2016 00:02:48 +0000 (00:02 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 5 Oct 2016 00:02:48 +0000 (00:02 +0000)
https://bugs.webkit.org/show_bug.cgi?id=162921

Reviewed by Darin Adler.

Source/WebCore:

Add support for KeyboardEvent.isComposing attribute:
- https://www.w3.org/TR/uievents/#dom-keyboardevent-iscomposing
- https://www.w3.org/TR/uievents/#ref-for-dom-keyboardevent-iscomposing-3

Manual test: https://jsfiddle.net/ay92sr08/9/

No new tests, extended existing tests.

* dom/KeyboardEvent.cpp:
(WebCore::KeyboardEvent::KeyboardEvent):
* dom/KeyboardEvent.h:
* dom/KeyboardEvent.idl:

LayoutTests:

Extend layout test coverage to test KeyboardEvent.isComposing.

* editing/mac/input/kotoeri-enter-to-confirm-and-newline-expected.txt:
* editing/mac/input/kotoeri-enter-to-confirm-and-newline.html:
* fast/events/constructors/keyboard-event-constructor-expected.txt:
* fast/events/constructors/keyboard-event-constructor.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@206796 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/editing/mac/input/kotoeri-enter-to-confirm-and-newline-expected.txt
LayoutTests/editing/mac/input/kotoeri-enter-to-confirm-and-newline.html
LayoutTests/fast/events/constructors/keyboard-event-constructor-expected.txt
LayoutTests/fast/events/constructors/keyboard-event-constructor.html
Source/WebCore/ChangeLog
Source/WebCore/dom/KeyboardEvent.cpp
Source/WebCore/dom/KeyboardEvent.h
Source/WebCore/dom/KeyboardEvent.idl

index 646c57f..f857bd4 100644 (file)
@@ -1,3 +1,17 @@
+2016-10-04  Chris Dumez  <cdumez@apple.com>
+
+        Add support for KeyboardEvent.isComposing attribute
+        https://bugs.webkit.org/show_bug.cgi?id=162921
+
+        Reviewed by Darin Adler.
+
+        Extend layout test coverage to test KeyboardEvent.isComposing.
+
+        * editing/mac/input/kotoeri-enter-to-confirm-and-newline-expected.txt:
+        * editing/mac/input/kotoeri-enter-to-confirm-and-newline.html:
+        * fast/events/constructors/keyboard-event-constructor-expected.txt:
+        * fast/events/constructors/keyboard-event-constructor.html:
+
 2016-10-03  Ryosuke Niwa  <rniwa@webkit.org>
 
         ShadowRoot interface should have elementFromPoint
index 714595c..591a577 100644 (file)
@@ -4,14 +4,41 @@ During composition all keydown events should have keyCode 229, this is necessary
 To test this manually switch to the Kotoeri/Hiragana input method, and type 'toukyou'<enter><enter>.
 You should see only a single keypress event, as the very last reported event.
 
+compositionstart
+compositionupdate
+keydown : keyCode == 229, key: t, isComposing: true
 Received valid keydown event
+keyup : keyCode == 84, key: t, isComposing: true
+compositionupdate
+keydown : keyCode == 229, key: o, isComposing: true
 Received valid keydown event
+keyup : keyCode == 79, key: o, isComposing: true
+compositionupdate
+keydown : keyCode == 229, key: u, isComposing: true
 Received valid keydown event
+keyup : keyCode == 85, key: u, isComposing: true
+compositionupdate
+keydown : keyCode == 229, key: k, isComposing: true
 Received valid keydown event
+keyup : keyCode == 75, key: k, isComposing: true
+compositionupdate
+keydown : keyCode == 229, key: y, isComposing: true
 Received valid keydown event
+keyup : keyCode == 89, key: y, isComposing: true
+compositionupdate
+keydown : keyCode == 229, key: o, isComposing: true
 Received valid keydown event
+keyup : keyCode == 79, key: o, isComposing: true
+compositionupdate
+keydown : keyCode == 229, key: u, isComposing: true
 Received valid keydown event
+keyup : keyCode == 85, key: u, isComposing: true
+compositionend
+keydown : keyCode == 229, key: Enter, isComposing: false
 Received valid keydown event
+keyup : keyCode == 13, key: Enter, isComposing: false
+keydown : keyCode == 13, key: Enter, isComposing: false
 Received valid keydown event
 Received valid keypress event
+keyup : keyCode == 13, key: Enter, isComposing: false
 PASSED: Successfully typed 'toukyou'
index 7e915b7..4e1961e 100644 (file)
@@ -7,7 +7,7 @@
     To test this manually switch to the Kotoeri/Hiragana input method, and type 'toukyou'&lt;enter&gt;&lt;enter&gt;.<br />
     You should see only a single keypress event, as the very last reported event.
 </div>
-<input id="targetInput" onkeydown="keyDown()" onkeypress="keyPress()">
+<input id="targetInput" onkeydown="keyDown()" onkeyup="keyUp()" onkeypress="keyPress()">
 <ul id="console"></console>
 
 <script src="resources/logger.js"></script>
 <script>
     var shouldBeCompositionEvent = false;
     function keyDown() {
-        if (!window.testRunner) {
-            log("keydown : keyCode == " + event.keyCode);
+        log("keydown : keyCode == " + event.keyCode + ", key: " + event.key + ", isComposing: " + event.isComposing);
+        if (!window.testRunner)
             return;
-        }
+
         if (shouldBeCompositionEvent && event.keyCode != 229)
             log("FAILURE: received keyCode " + event.keyCode + " in a keydown when VK_PROCESSKEY is expected");
         else if (!shouldBeCompositionEvent && event.keyCode == 229)
         else
             log("Received valid keydown event");
     }
+
+    function keyUp() {
+        log("keyup : keyCode == " + event.keyCode + ", key: " + event.key + ", isComposing: " + event.isComposing);
+    }
     
     function keyPress() {
         if (!window.testRunner) {
@@ -39,6 +43,9 @@
     }
     
     var targetInput = document.getElementById('targetInput');
+    targetInput.addEventListener("compositionstart", function() { log("compositionstart"); });
+    targetInput.addEventListener("compositionupdate", function() { log("compositionupdate"); });
+    targetInput.addEventListener("compositionend", function() { log("compositionend"); });
     targetInput.focus();
     if (window.testRunner) {
         testRunner.dumpAsText();
index d8d22a0..a206275 100644 (file)
@@ -22,6 +22,9 @@ PASS new KeyboardEvent('eventType', { view: this }).view is this
 PASS new KeyboardEvent('eventType', { }).repeat is false
 PASS new KeyboardEvent('eventType', { repeat: false }).repeat is false
 PASS new KeyboardEvent('eventType', { repeat: true }).repeat is true
+PASS new KeyboardEvent('eventType', { }).isComposing is false
+PASS new KeyboardEvent('eventType', { isComposing: false }).isComposing is false
+PASS new KeyboardEvent('eventType', { isComposing: true }).isComposing is true
 PASS new KeyboardEvent('eventType', { view: testObject }).view threw exception TypeError: Dictionary member is not of type Window.
 PASS new KeyboardEvent('eventType', { view: document }).view threw exception TypeError: Dictionary member is not of type Window.
 PASS new KeyboardEvent('eventType', { view: undefined }).view is null
index c2b2dd7..b774857 100644 (file)
@@ -40,6 +40,11 @@ shouldBe("new KeyboardEvent('eventType', { }).repeat", "false");
 shouldBe("new KeyboardEvent('eventType', { repeat: false }).repeat", "false");
 shouldBe("new KeyboardEvent('eventType', { repeat: true }).repeat", "true");
 
+// isCompositing is passed.
+shouldBe("new KeyboardEvent('eventType', { }).isComposing", "false");
+shouldBe("new KeyboardEvent('eventType', { isComposing: false }).isComposing", "false");
+shouldBe("new KeyboardEvent('eventType', { isComposing: true }).isComposing", "true");
+
 // Non-window objects.
 shouldThrowErrorName("new KeyboardEvent('eventType', { view: testObject }).view", "TypeError");
 shouldThrowErrorName("new KeyboardEvent('eventType', { view: document }).view", "TypeError");
index f3fb44f..d2d1ad7 100644 (file)
@@ -1,3 +1,23 @@
+2016-10-04  Chris Dumez  <cdumez@apple.com>
+
+        Add support for KeyboardEvent.isComposing attribute
+        https://bugs.webkit.org/show_bug.cgi?id=162921
+
+        Reviewed by Darin Adler.
+
+        Add support for KeyboardEvent.isComposing attribute:
+        - https://www.w3.org/TR/uievents/#dom-keyboardevent-iscomposing
+        - https://www.w3.org/TR/uievents/#ref-for-dom-keyboardevent-iscomposing-3
+
+        Manual test: https://jsfiddle.net/ay92sr08/9/
+
+        No new tests, extended existing tests.
+
+        * dom/KeyboardEvent.cpp:
+        (WebCore::KeyboardEvent::KeyboardEvent):
+        * dom/KeyboardEvent.h:
+        * dom/KeyboardEvent.idl:
+
 2016-10-03  Ryosuke Niwa  <rniwa@webkit.org>
 
         ShadowRoot interface should have elementFromPoint
index 2d5b6b0..d49a6fa 100644 (file)
@@ -24,6 +24,7 @@
 #include "KeyboardEvent.h"
 
 #include "Document.h"
+#include "Editor.h"
 #include "EventDispatcher.h"
 #include "EventHandler.h"
 #include "EventNames.h"
@@ -91,14 +92,7 @@ static inline KeyboardEvent::KeyLocationCode keyLocationCode(const PlatformKeybo
     }
 }
 
-KeyboardEvent::KeyboardEvent()
-    : m_location(DOM_KEY_LOCATION_STANDARD)
-    , m_altGraphKey(false)
-#if PLATFORM(COCOA)
-    , m_handledByInputMethod(false)
-#endif
-{
-}
+KeyboardEvent::KeyboardEvent() = default;
 
 KeyboardEvent::KeyboardEvent(const PlatformKeyboardEvent& key, DOMWindow* view)
     : UIEventWithKeyState(eventTypeForKeyboardEventType(key.type()),
@@ -111,6 +105,7 @@ KeyboardEvent::KeyboardEvent(const PlatformKeyboardEvent& key, DOMWindow* view)
     , m_location(keyLocationCode(key))
     , m_repeat(key.isAutoRepeat())
     , m_altGraphKey(false)
+    , m_isComposing(view && view->frame() && view->frame()->editor().hasComposition())
 #if PLATFORM(COCOA)
 #if USE(APPKIT)
     , m_handledByInputMethod(key.handledByInputMethod())
@@ -137,6 +132,7 @@ KeyboardEvent::KeyboardEvent(const AtomicString& eventType, const KeyboardEventI
     , m_location(initializer.location)
     , m_repeat(initializer.repeat)
     , m_altGraphKey(false)
+    , m_isComposing(initializer.isComposing)
 #if PLATFORM(COCOA)
     , m_handledByInputMethod(false)
 #endif
index 7109199..b26cf9c 100644 (file)
@@ -40,6 +40,7 @@ struct KeyboardEventInit : public UIEventWithKeyStateInit {
     String keyIdentifier;
     unsigned location { 0 };
     bool repeat { false };
+    bool isComposing { false };
 };
 
 class KeyboardEvent final : public UIEventWithKeyState {
@@ -100,6 +101,8 @@ public:
     bool isKeyboardEvent() const final;
     int which() const final;
 
+    bool isComposing() const { return m_isComposing; }
+
 #if PLATFORM(COCOA)
     bool handledByInputMethod() const { return m_handledByInputMethod; }
     const Vector<KeypressCommand>& keypressCommands() const { return m_keypressCommands; }
@@ -121,13 +124,14 @@ private:
     String m_key;
 #endif
     String m_keyIdentifier;
-    unsigned m_location;
-    bool m_repeat : 1;
-    bool m_altGraphKey : 1;
+    unsigned m_location { DOM_KEY_LOCATION_STANDARD };
+    bool m_repeat { false };
+    bool m_altGraphKey { false };
+    bool m_isComposing { false };
 
 #if PLATFORM(COCOA)
     // Commands that were sent by AppKit when interpreting the event. Doesn't include input method commands.
-    bool m_handledByInputMethod;
+    bool m_handledByInputMethod { false };
     Vector<KeypressCommand> m_keypressCommands;
 #endif
 };
index 1ea236c..b12ef2b 100644 (file)
@@ -41,8 +41,7 @@
     [InitializedByEventConstructor] readonly attribute boolean metaKey;
     [InitializedByEventConstructor] readonly attribute boolean repeat;
 
-    // FIXME: We should support this.
-    // readonly attribute boolean isComposing;
+    [InitializedByEventConstructor] readonly attribute boolean isComposing;
 
     boolean getModifierState(DOMString keyArg);