Source/WebCore: Fire TextInput events on speech input, but not set/add any inputMetho...
authorleandrogracia@chromium.org <leandrogracia@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Sep 2011 16:18:50 +0000 (16:18 +0000)
committerleandrogracia@chromium.org <leandrogracia@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 22 Sep 2011 16:18:50 +0000 (16:18 +0000)
https://bugs.webkit.org/show_bug.cgi?id=60451

Reviewed by Ryosuke Niwa.

Introduce code to dispatch TextInput events when text is introduced via
the speech input feature. Handle also the cases where speech input is
started programmatically from the LayoutTestController.

Test: fast/speech/input-ontextinput-event.html

* dom/TextEventInputType.h:
* html/shadow/TextControlInnerElements.cpp:
(WebCore::InputFieldSpeechButtonElement::setRecognitionResult):

LayoutTests: Testing text events triggered by speech input.
https://bugs.webkit.org/show_bug.cgi?id=60451

Reviewed by Ryosuke Niwa.

* fast/speech/input-ontextinput-event-expected.txt: Added.
* fast/speech/input-ontextinput-event.html: Added.
* fast/speech/input-text-speechstart.html:

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

LayoutTests/ChangeLog
LayoutTests/fast/speech/input-ontextinput-event-expected.txt [new file with mode: 0644]
LayoutTests/fast/speech/input-ontextinput-event.html [new file with mode: 0644]
LayoutTests/fast/speech/input-text-speechstart.html
Source/WebCore/ChangeLog
Source/WebCore/dom/TextEventInputType.h
Source/WebCore/html/shadow/TextControlInnerElements.cpp

index 770eebe..c670337 100644 (file)
@@ -1,3 +1,14 @@
+2011-09-22  Leandro Gracia Gil  <leandrogracia@chromium.org>
+
+        Testing text events triggered by speech input.
+        https://bugs.webkit.org/show_bug.cgi?id=60451
+
+        Reviewed by Ryosuke Niwa.
+
+        * fast/speech/input-ontextinput-event-expected.txt: Added.
+        * fast/speech/input-ontextinput-event.html: Added.
+        * fast/speech/input-text-speechstart.html:
+
 2011-09-20  Jason Liu  <jason.liu@torchmobile.com.cn>
 
         Reviewed by Simon Fraser.
diff --git a/LayoutTests/fast/speech/input-ontextinput-event-expected.txt b/LayoutTests/fast/speech/input-ontextinput-event-expected.txt
new file mode 100644 (file)
index 0000000..da53d4a
--- /dev/null
@@ -0,0 +1,12 @@
+Tests for the ontextInput event with <input type="text" speech>.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS document.getElementById("speechInput").value is ""
+PASS window.event.data is "Green eggs and ham"
+PASS window.event.inputMethod is undefined
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/speech/input-ontextinput-event.html b/LayoutTests/fast/speech/input-ontextinput-event.html
new file mode 100644 (file)
index 0000000..dc04abb
--- /dev/null
@@ -0,0 +1,47 @@
+<!DOCTYPE html>
+<html>
+<head>
+<link rel="stylesheet" href="../js/resources/js-test-style.css">
+<script src="../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+<script type="text/javascript">
+description('Tests for the ontextInput event with &lt;input type="text" speech>.');
+
+function onTextInput() {
+    shouldBeEqualToString('document.getElementById("speechInput").value', '');
+    shouldBeEqualToString('window.event.data', 'Green eggs and ham');
+
+    // Set to undefined to make this test fail if it's implemented, so it can be properly set to the correct value once it's available.
+    shouldBe('window.event.inputMethod', 'undefined');
+
+    finishJSTest();
+}
+
+function run() {
+    if (window.layoutTestController && window.eventSender) {
+        layoutTestController.addMockSpeechInputResult('Green eggs and ham', 0.8, '');
+        layoutTestController.addMockSpeechInputResult('Green x and ham', 0.5, '');
+
+        // Clicking the speech button should fill in mock speech-recognized text.
+        var input = document.getElementById('speechInput');
+        input.addEventListener("textInput", onTextInput, false);
+
+        var x = input.offsetLeft + input.offsetWidth - 4;
+        var y = input.offsetTop + input.offsetHeight / 2;
+        eventSender.mouseMoveTo(x, y);
+        eventSender.mouseDown();
+        eventSender.mouseUp();
+    }
+}
+
+window.onload = run;
+window.jsTestIsAsync = true;
+window.successfullyParsed = true;
+</script>
+<script src="../js/resources/js-test-post.js"></script>
+<input id='speechInput' x-webkit-speech>
+</body>
+</html>
index eb8ebc9..2df5660 100644 (file)
@@ -13,8 +13,10 @@ description('Tests for triggering speech directly in a &lt;input type="text" spe
 function startSpeechInput(id) {
     // Test that we can trigger speech with a method call to the input
     // element, so the user agent could toggle speech via a keypress,
-    // for example.
+    // for example. Select is required in order to ensure that the result
+    // will be set in input during the generated TextInput event.
     var input = document.getElementById(id);
+    input.select();
     layoutTestController.startSpeechInput(input);
 }
 
index 0822062..58c0fea 100644 (file)
@@ -1,3 +1,20 @@
+2011-09-22  Leandro Gracia Gil  <leandrogracia@chromium.org>
+
+        Fire TextInput events on speech input, but not set/add any inputMethod attribute.
+        https://bugs.webkit.org/show_bug.cgi?id=60451
+
+        Reviewed by Ryosuke Niwa.
+
+        Introduce code to dispatch TextInput events when text is introduced via
+        the speech input feature. Handle also the cases where speech input is
+        started programmatically from the LayoutTestController.
+
+        Test: fast/speech/input-ontextinput-event.html
+
+        * dom/TextEventInputType.h:
+        * html/shadow/TextControlInnerElements.cpp:
+        (WebCore::InputFieldSpeechButtonElement::setRecognitionResult):
+
 2011-09-20  Jason Liu  <jason.liu@torchmobile.com.cn>
 
         Reviewed by Simon Fraser.
index f5a05eb..98bf343 100644 (file)
@@ -35,6 +35,7 @@ enum TextEventInputType {
     TextEventInputBackTab,
     TextEventInputPaste,
     TextEventInputDrop,
+    TextEventInputOther,
 };
 
 } // namespace WebCore
index c48d5f9..bf185cf 100644 (file)
@@ -43,6 +43,8 @@
 #include "ScrollbarTheme.h"
 #include "SpeechInput.h"
 #include "SpeechInputEvent.h"
+#include "TextEvent.h"
+#include "TextEventInputType.h"
 
 namespace WebCore {
 
@@ -488,7 +490,11 @@ void InputFieldSpeechButtonElement::setRecognitionResult(int, const SpeechInputR
         return;
 
     RefPtr<InputFieldSpeechButtonElement> holdRefButton(this);
-    input->setValue(results.isEmpty() ? "" : results[0]->utterance());
+    if (document() && document()->domWindow())
+        input->dispatchEvent(TextEvent::create(document()->domWindow(), results.isEmpty() ? "" : results[0]->utterance(), TextEventInputOther));
+
+    // This event is sent after the text event so the website can perform actions using the input field content immediately.
+    // It provides alternative recognition hypotheses and notifies that the results come from speech input.
     input->dispatchEvent(SpeechInputEvent::create(eventNames().webkitspeechchangeEvent, results));
 
     // Check before accessing the renderer as the above event could have potentially turned off