summaryrefslogtreecommitdiffstats
path: root/chrome/browser/speech/speech_input_bubble_controller.h
diff options
context:
space:
mode:
authorsatish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-27 11:59:03 +0000
committersatish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-27 11:59:03 +0000
commit6a7746dbcef8cfcef182887a337eb297d476f98e (patch)
tree2ef8870775cd910bc965bbd98b3a01c5627d67ec /chrome/browser/speech/speech_input_bubble_controller.h
parent32a99f81432bcc1a8ee515b34e6dfdf81c3fa090 (diff)
downloadchromium_src-6a7746dbcef8cfcef182887a337eb297d476f98e.zip
chromium_src-6a7746dbcef8cfcef182887a337eb297d476f98e.tar.gz
chromium_src-6a7746dbcef8cfcef182887a337eb297d476f98e.tar.bz2
Displays a speech input UI bubble during speech recognition.
The webkit code passes in display rect of the input element requesting speech input and we create a UI bubble pointing at this element when starting speech input. The user can click outside the bubble to close it, which aborts recognition if we were still recording audio. The user can also click the cancel link in the bubble which aborts recognition irrespective of what state it is in now. Added a SpeechInputBubbleController class to take care of marshalling the requests between the speech input code in IO thread and the UI bubble in the UI thread. Also added a unit test for this class. BUG=none TEST=unit_tests --gtest_filter=SpeechInputBubbleControllerTest.* Review URL: http://codereview.chromium.org/3156048 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57666 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/speech/speech_input_bubble_controller.h')
-rw-r--r--chrome/browser/speech/speech_input_bubble_controller.h81
1 files changed, 81 insertions, 0 deletions
diff --git a/chrome/browser/speech/speech_input_bubble_controller.h b/chrome/browser/speech/speech_input_bubble_controller.h
new file mode 100644
index 0000000..6bd3d6a
--- /dev/null
+++ b/chrome/browser/speech/speech_input_bubble_controller.h
@@ -0,0 +1,81 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_CONTROLLER_H_
+#define CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_CONTROLLER_H_
+
+#include "base/basictypes.h"
+#include "base/ref_counted.h"
+#include "base/scoped_ptr.h"
+#include "chrome/browser/speech/speech_input_bubble.h"
+
+namespace gfx {
+class Rect;
+}
+
+namespace speech_input {
+
+// This class handles the speech input popup UI on behalf of SpeechInputManager.
+// SpeechInputManager invokes methods in the IO thread and this class processes
+// those requests in the UI thread. There is only 1 speech input bubble shown to
+// the user at a time. User actions on that bubble are reported to the delegate.
+class SpeechInputBubbleController
+ : public base::RefCountedThreadSafe<SpeechInputBubbleController>,
+ public SpeechInputBubbleDelegate {
+ public:
+ // All methods of this delegate are called in the IO thread.
+ class Delegate {
+ public:
+ // Invoked when the user cancels speech recognition by clicking on the
+ // cancel button or related action in the speech input UI.
+ virtual void RecognitionCancelled(int caller_id) = 0;
+
+ // Invoked when the user clicks outside the speech input info bubble causing
+ // it to close and input focus to change.
+ virtual void SpeechInputFocusChanged(int caller_id) = 0;
+
+ protected:
+ virtual ~Delegate() {}
+ };
+
+ explicit SpeechInputBubbleController(Delegate* delegate);
+
+ // Creates a new speech input bubble and displays it in the UI.
+ void CreateBubble(int caller_id,
+ int render_process_id,
+ int render_view_id,
+ const gfx::Rect& element_rect);
+
+ // Sets the bubble to show that recording completed and recognition is in
+ // progress.
+ void SetBubbleToRecognizingMode(int caller_id);
+
+ void CloseBubble(int caller_id);
+
+ // SpeechInputBubble::Delegate methods.
+ virtual void RecognitionCancelled();
+ virtual void InfoBubbleClosed();
+
+ private:
+ void InvokeDelegateRecognitionCancelled(int caller_id);
+ void InvokeDelegateFocusChanged(int caller_id);
+
+ // Only accessed in the IO thread.
+ Delegate* delegate_;
+
+ // Only accessed in the UI thread.
+ int current_bubble_caller_id_;
+ scoped_ptr<SpeechInputBubble> bubble_;
+};
+
+// This typedef is to workaround the issue with certain versions of
+// Visual Studio where it gets confused between multiple Delegate
+// classes and gives a C2500 error. (I saw this error on the try bots -
+// the workaround was not needed for my machine).
+typedef SpeechInputBubbleController::Delegate
+ SpeechInputBubbleControllerDelegate;
+
+} // namespace speech_input
+
+#endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_CONTROLLER_H_