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-09-10 22:46:52 +0000
committersatish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-10 22:46:52 +0000
commit210399f6f7eddbe934e8eaef79277d96fccb2e51 (patch)
treede6b320bc1008bafe6b489582fa32232582c52fc /chrome/browser/speech/speech_input_bubble_controller.h
parent15d9c0c8432dc9b0bd700ebfdb5542534e7b2e00 (diff)
downloadchromium_src-210399f6f7eddbe934e8eaef79277d96fccb2e51.zip
chromium_src-210399f6f7eddbe934e8eaef79277d96fccb2e51.tar.gz
chromium_src-210399f6f7eddbe934e8eaef79277d96fccb2e51.tar.bz2
We used to show error messages as info bars earlier. Based on UX feedback, we now show the messages within the speech input UI bubble. We also let the user retry recognition without returning the error to the web page unless the user clicked the cancel button or closed the bubble.
For this to work, we now keep the request alive in the SpeechInputManager map until it completes successfully or user explicitly cancelled it. We also keep the SpeechInputBubble object alive, even when the actual bubble window is not visible on screen, and construct the window if required whenever we want to show the recording status or error message on screen. BUG=53598 TEST=unit_tests --gtest_filter=SpeechInputBubbleControllerTest.* Review URL: http://codereview.chromium.org/3352018 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59166 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.h51
1 files changed, 36 insertions, 15 deletions
diff --git a/chrome/browser/speech/speech_input_bubble_controller.h b/chrome/browser/speech/speech_input_bubble_controller.h
index 6bd3d6a..2117b24 100644
--- a/chrome/browser/speech/speech_input_bubble_controller.h
+++ b/chrome/browser/speech/speech_input_bubble_controller.h
@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_CONTROLLER_H_
#define CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_CONTROLLER_H_
+#include <map>
+
#include "base/basictypes.h"
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
@@ -18,8 +20,9 @@ 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.
+// those requests in the UI thread. There could be multiple bubble objects alive
+// at the same time but only one of them is visible to the user. User actions on
+// that bubble are reported to the delegate.
class SpeechInputBubbleController
: public base::RefCountedThreadSafe<SpeechInputBubbleController>,
public SpeechInputBubbleDelegate {
@@ -27,46 +30,64 @@ class SpeechInputBubbleController
// 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 on a button in the speech input UI.
+ virtual void InfoBubbleButtonClicked(int caller_id,
+ SpeechInputBubble::Button button) = 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;
+ virtual void InfoBubbleFocusChanged(int caller_id) = 0;
protected:
virtual ~Delegate() {}
};
explicit SpeechInputBubbleController(Delegate* delegate);
+ virtual ~SpeechInputBubbleController();
- // Creates a new speech input bubble and displays it in the UI.
+ // Creates a new speech input UI bubble. One of the SetXxxx methods below need
+ // to be called to specify what to display.
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);
+ // Indicates to the user that audio recording is in progress. This also makes
+ // the bubble visible if not already visible.
+ void SetBubbleRecordingMode(int caller_id);
+
+ // Indicates to the user that recognition is in progress. If the bubble is
+ // hidden, |Show| must be called to make it appear on screen.
+ void SetBubbleRecognizingMode(int caller_id);
+
+ // Displays the given string with the 'Try again' and 'Cancel' buttons. If the
+ // bubble is hidden, |Show| must be called to make it appear on screen.
+ void SetBubbleMessage(int caller_id, const string16& text);
void CloseBubble(int caller_id);
// SpeechInputBubble::Delegate methods.
- virtual void RecognitionCancelled();
- virtual void InfoBubbleClosed();
+ virtual void InfoBubbleButtonClicked(SpeechInputBubble::Button button);
+ virtual void InfoBubbleFocusChanged();
private:
- void InvokeDelegateRecognitionCancelled(int caller_id);
+ void InvokeDelegateButtonClicked(int caller_id,
+ SpeechInputBubble::Button button);
void InvokeDelegateFocusChanged(int caller_id);
+ void SetBubbleRecordingModeOrMessage(int caller_id, const string16& text);
// Only accessed in the IO thread.
Delegate* delegate_;
- // Only accessed in the UI thread.
+ //*** The following are accessed only in the UI thread.
+
+ // The caller id for currently visible bubble (since only one bubble is
+ // visible at any time).
int current_bubble_caller_id_;
- scoped_ptr<SpeechInputBubble> bubble_;
+
+ // Map of caller-ids to bubble objects. The bubbles are weak pointers owned by
+ // this object and get destroyed by |CloseBubble|.
+ std::map<int, SpeechInputBubble*> bubbles_;
};
// This typedef is to workaround the issue with certain versions of