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
+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.
--- /dev/null
+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
+
--- /dev/null
+<!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 <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>
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);
}
+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.
TextEventInputBackTab,
TextEventInputPaste,
TextEventInputDrop,
+ TextEventInputOther,
};
} // namespace WebCore
#include "ScrollbarTheme.h"
#include "SpeechInput.h"
#include "SpeechInputEvent.h"
+#include "TextEvent.h"
+#include "TextEventInputType.h"
namespace WebCore {
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