From d3af9638365bc79ee670d9de4e96490c8b372a08 Mon Sep 17 00:00:00 2001 From: "leandrogracia@chromium.org" Date: Thu, 22 Sep 2011 16:18:50 +0000 Subject: [PATCH] Source/WebCore: 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): 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 | 11 +++++ .../speech/input-ontextinput-event-expected.txt | 12 ++++++ .../fast/speech/input-ontextinput-event.html | 47 ++++++++++++++++++++++ .../fast/speech/input-text-speechstart.html | 4 +- Source/WebCore/ChangeLog | 17 ++++++++ Source/WebCore/dom/TextEventInputType.h | 1 + .../html/shadow/TextControlInnerElements.cpp | 8 +++- 7 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 LayoutTests/fast/speech/input-ontextinput-event-expected.txt create mode 100644 LayoutTests/fast/speech/input-ontextinput-event.html diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog index 770eebe..c670337 100644 --- a/LayoutTests/ChangeLog +++ b/LayoutTests/ChangeLog @@ -1,3 +1,14 @@ +2011-09-22 Leandro Gracia Gil + + 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 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 index 0000000..da53d4a --- /dev/null +++ b/LayoutTests/fast/speech/input-ontextinput-event-expected.txt @@ -0,0 +1,12 @@ +Tests for the ontextInput event with . + +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 index 0000000..dc04abb --- /dev/null +++ b/LayoutTests/fast/speech/input-ontextinput-event.html @@ -0,0 +1,47 @@ + + + + + + + +

+
+ + + + + diff --git a/LayoutTests/fast/speech/input-text-speechstart.html b/LayoutTests/fast/speech/input-text-speechstart.html index eb8ebc9..2df5660 100644 --- a/LayoutTests/fast/speech/input-text-speechstart.html +++ b/LayoutTests/fast/speech/input-text-speechstart.html @@ -13,8 +13,10 @@ description('Tests for triggering speech directly in a <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); } diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index 0822062..58c0fea 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,20 @@ +2011-09-22 Leandro Gracia Gil + + 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 Reviewed by Simon Fraser. diff --git a/Source/WebCore/dom/TextEventInputType.h b/Source/WebCore/dom/TextEventInputType.h index f5a05eb..98bf343 100644 --- a/Source/WebCore/dom/TextEventInputType.h +++ b/Source/WebCore/dom/TextEventInputType.h @@ -35,6 +35,7 @@ enum TextEventInputType { TextEventInputBackTab, TextEventInputPaste, TextEventInputDrop, + TextEventInputOther, }; } // namespace WebCore diff --git a/Source/WebCore/html/shadow/TextControlInnerElements.cpp b/Source/WebCore/html/shadow/TextControlInnerElements.cpp index c48d5f9..bf185cf 100644 --- a/Source/WebCore/html/shadow/TextControlInnerElements.cpp +++ b/Source/WebCore/html/shadow/TextControlInnerElements.cpp @@ -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 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 -- 2.7.4