summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authordmazzoni@chromium.org <dmazzoni@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-02 23:33:38 +0000
committerdmazzoni@chromium.org <dmazzoni@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-02 23:33:38 +0000
commitafcb435647a0ce2be73ff6102fe00d9338dfc985 (patch)
treeaa6b97369149df04a58e387c8e5d0fcd15a78d8d /content
parent321fb2dd2ab53714d2b827e5365b20ab3c911d0d (diff)
downloadchromium_src-afcb435647a0ce2be73ff6102fe00d9338dfc985.zip
chromium_src-afcb435647a0ce2be73ff6102fe00d9338dfc985.tar.gz
chromium_src-afcb435647a0ce2be73ff6102fe00d9338dfc985.tar.bz2
Adds a global keyboard shortcut to trigger speech input in the currently
focused speech-enabled text input box, if any. Depends on WebKit patch: https://bugs.webkit.org/show_bug.cgi?id=60170 BUG=94426 TEST=manual testing Review URL: http://codereview.chromium.org/7046021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@99471 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/renderer_host/render_view_host.cc6
-rw-r--r--content/browser/renderer_host/render_view_host.h2
-rw-r--r--content/common/speech_input_messages.h4
-rw-r--r--content/renderer/speech_input_dispatcher.cc43
-rw-r--r--content/renderer/speech_input_dispatcher.h1
5 files changed, 55 insertions, 1 deletions
diff --git a/content/browser/renderer_host/render_view_host.cc b/content/browser/renderer_host/render_view_host.cc
index f88940e..59cc504 100644
--- a/content/browser/renderer_host/render_view_host.cc
+++ b/content/browser/renderer_host/render_view_host.cc
@@ -38,6 +38,7 @@
#include "content/common/notification_details.h"
#include "content/common/notification_service.h"
#include "content/common/result_codes.h"
+#include "content/common/speech_input_messages.h"
#include "content/common/swapped_out_messages.h"
#include "content/common/url_constants.h"
#include "content/common/view_messages.h"
@@ -1237,6 +1238,10 @@ void RenderViewHost::DidCancelPopupMenu() {
}
#endif
+void RenderViewHost::ToggleSpeechInput() {
+ Send(new SpeechInputMsg_ToggleSpeechInput(routing_id()));
+}
+
void RenderViewHost::FilterURL(ChildProcessSecurityPolicy* policy,
int renderer_id,
GURL* url) {
@@ -1366,4 +1371,3 @@ void RenderViewHost::OnRunFileChooser(
const ViewHostMsg_RunFileChooser_Params& params) {
delegate_->RunFileChooser(this, params);
}
-
diff --git a/content/browser/renderer_host/render_view_host.h b/content/browser/renderer_host/render_view_host.h
index f403243..0e773ff 100644
--- a/content/browser/renderer_host/render_view_host.h
+++ b/content/browser/renderer_host/render_view_host.h
@@ -361,6 +361,8 @@ class RenderViewHost : public RenderWidgetHost {
void DidCancelPopupMenu();
#endif
+ void ToggleSpeechInput();
+
#if defined(UNIT_TEST)
// These functions shouldn't be necessary outside of testing.
diff --git a/content/common/speech_input_messages.h b/content/common/speech_input_messages.h
index df7f90f..2e2e27e 100644
--- a/content/common/speech_input_messages.h
+++ b/content/common/speech_input_messages.h
@@ -74,3 +74,7 @@ IPC_MESSAGE_ROUTED1(SpeechInputMsg_RecordingComplete,
IPC_MESSAGE_ROUTED1(SpeechInputMsg_RecognitionComplete,
int /* request_id */)
+// Toggle speech input on or off on the speech input control for the
+// current focused element. Has no effect if the current element doesn't
+// support speech input.
+IPC_MESSAGE_ROUTED0(SpeechInputMsg_ToggleSpeechInput)
diff --git a/content/renderer/speech_input_dispatcher.cc b/content/renderer/speech_input_dispatcher.cc
index b7a95a8..af798e4 100644
--- a/content/renderer/speech_input_dispatcher.cc
+++ b/content/renderer/speech_input_dispatcher.cc
@@ -7,14 +7,23 @@
#include "base/utf_string_conversions.h"
#include "content/common/speech_input_messages.h"
#include "content/renderer/render_view.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputElement.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSize.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebSpeechInputListener.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
+using WebKit::WebDocument;
+using WebKit::WebElement;
using WebKit::WebFrame;
+using WebKit::WebInputElement;
+using WebKit::WebNode;
+using WebKit::WebView;
SpeechInputDispatcher::SpeechInputDispatcher(
RenderView* render_view,
@@ -32,6 +41,8 @@ bool SpeechInputDispatcher::OnMessageReceived(const IPC::Message& message) {
OnSpeechRecordingComplete)
IPC_MESSAGE_HANDLER(SpeechInputMsg_RecognitionComplete,
OnSpeechRecognitionComplete)
+ IPC_MESSAGE_HANDLER(SpeechInputMsg_ToggleSpeechInput,
+ OnSpeechRecognitionToggleSpeechInput)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
@@ -93,3 +104,35 @@ void SpeechInputDispatcher::OnSpeechRecognitionComplete(int request_id) {
listener_->didCompleteRecognition(request_id);
VLOG(1) << "SpeechInputDispatcher::OnSpeechRecognitionComplete exit";
}
+
+void SpeechInputDispatcher::OnSpeechRecognitionToggleSpeechInput() {
+ VLOG(1) << "SpeechInputDispatcher::OnSpeechRecognitionToggleSpeechInput";
+
+ WebView* web_view = render_view()->webview();
+
+ WebFrame* frame = web_view->mainFrame();
+ if (!frame)
+ return;
+
+ WebDocument document = frame->document();
+ if (document.isNull())
+ return;
+
+ WebNode focusedNode = document.focusedNode();
+ if (focusedNode.isNull() || !focusedNode.isElementNode())
+ return;
+
+ WebKit::WebElement element = focusedNode.to<WebKit::WebElement>();
+ if (!element.isTextFormControlElement())
+ return;
+
+ WebKit::WebInputElement inputElement = element.to<WebKit::WebInputElement>();
+ if (!inputElement.isSpeechInputEnabled())
+ return;
+
+ if (inputElement.getSpeechInputState() == WebInputElement::Idle) {
+ inputElement.startSpeechInput();
+ } else {
+ inputElement.stopSpeechInput();
+ }
+}
diff --git a/content/renderer/speech_input_dispatcher.h b/content/renderer/speech_input_dispatcher.h
index b235886..6d44c3a 100644
--- a/content/renderer/speech_input_dispatcher.h
+++ b/content/renderer/speech_input_dispatcher.h
@@ -42,6 +42,7 @@ class SpeechInputDispatcher : public RenderViewObserver,
int request_id, const speech_input::SpeechInputResultArray& result);
void OnSpeechRecordingComplete(int request_id);
void OnSpeechRecognitionComplete(int request_id);
+ void OnSpeechRecognitionToggleSpeechInput();
WebKit::WebSpeechInputListener* listener_;