Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_CONTROLLER_H_ | 6 #define CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include <map> | |
| 9 | |
| 8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 9 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
| 10 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 11 #include "chrome/browser/speech/speech_input_bubble.h" | 13 #include "chrome/browser/speech/speech_input_bubble.h" |
| 12 | 14 |
| 13 namespace gfx { | 15 namespace gfx { |
| 14 class Rect; | 16 class Rect; |
| 15 } | 17 } |
| 16 | 18 |
| 17 namespace speech_input { | 19 namespace speech_input { |
| 18 | 20 |
| 19 // This class handles the speech input popup UI on behalf of SpeechInputManager. | 21 // This class handles the speech input popup UI on behalf of SpeechInputManager. |
| 20 // SpeechInputManager invokes methods in the IO thread and this class processes | 22 // SpeechInputManager invokes methods in the IO thread and this class processes |
| 21 // those requests in the UI thread. There is only 1 speech input bubble shown to | 23 // those requests in the UI thread. There could be multiple bubble objects alive |
| 22 // the user at a time. User actions on that bubble are reported to the delegate. | 24 // at the same time but only one of them is visible to the user. User actions on |
| 25 // that bubble are reported to the delegate. | |
| 23 class SpeechInputBubbleController | 26 class SpeechInputBubbleController |
| 24 : public base::RefCountedThreadSafe<SpeechInputBubbleController>, | 27 : public base::RefCountedThreadSafe<SpeechInputBubbleController>, |
| 25 public SpeechInputBubbleDelegate { | 28 public SpeechInputBubbleDelegate { |
| 26 public: | 29 public: |
| 27 // All methods of this delegate are called in the IO thread. | 30 // All methods of this delegate are called in the IO thread. |
| 28 class Delegate { | 31 class Delegate { |
| 29 public: | 32 public: |
| 30 // Invoked when the user cancels speech recognition by clicking on the | 33 // Invoked when the user clicks on a button in the speech input UI. |
| 31 // cancel button or related action in the speech input UI. | 34 virtual void InfoBubbleButtonClicked(int caller_id, |
| 32 virtual void RecognitionCancelled(int caller_id) = 0; | 35 SpeechInputBubble::Button button) = 0; |
| 33 | 36 |
| 34 // Invoked when the user clicks outside the speech input info bubble causing | 37 // Invoked when the user clicks outside the speech input info bubble causing |
| 35 // it to close and input focus to change. | 38 // it to close and input focus to change. |
| 36 virtual void SpeechInputFocusChanged(int caller_id) = 0; | 39 virtual void InfoBubbleFocusChanged(int caller_id) = 0; |
| 37 | 40 |
| 38 protected: | 41 protected: |
| 39 virtual ~Delegate() {} | 42 virtual ~Delegate() {} |
| 40 }; | 43 }; |
| 41 | 44 |
| 42 explicit SpeechInputBubbleController(Delegate* delegate); | 45 explicit SpeechInputBubbleController(Delegate* delegate); |
| 46 virtual ~SpeechInputBubbleController(); | |
| 43 | 47 |
| 44 // Creates a new speech input bubble and displays it in the UI. | 48 // Creates a new speech input UI bubble. One of the SetXxxx methods below need |
| 49 // to be called to specify what to display. | |
| 45 void CreateBubble(int caller_id, | 50 void CreateBubble(int caller_id, |
| 46 int render_process_id, | 51 int render_process_id, |
| 47 int render_view_id, | 52 int render_view_id, |
| 48 const gfx::Rect& element_rect); | 53 const gfx::Rect& element_rect); |
| 49 | 54 |
| 50 // Sets the bubble to show that recording completed and recognition is in | 55 // Indicates to the user that audio recording is in progress. This also makes |
| 51 // progress. | 56 // the bubble visible if not already visible. |
| 52 void SetBubbleToRecognizingMode(int caller_id); | 57 void SetBubbleRecordingMode(int caller_id); |
| 58 | |
| 59 // Indicates to the user that recognition is in progress. If the bubble is | |
| 60 // hidden, |Show| must be called to make it appear on screen. | |
| 61 void SetBubbleRecognizingMode(int caller_id); | |
| 62 | |
| 63 // Displays the given string with the 'Try again' and 'Cancel' buttons. If the | |
| 64 // bubble is hidden, |Show| must be called to make it appear on screen. | |
| 65 void SetBubbleMessage(int caller_id, const string16& text); | |
| 53 | 66 |
| 54 void CloseBubble(int caller_id); | 67 void CloseBubble(int caller_id); |
| 55 | 68 |
| 56 // SpeechInputBubble::Delegate methods. | 69 // SpeechInputBubble::Delegate methods. |
| 57 virtual void RecognitionCancelled(); | 70 virtual void InfoBubbleButtonClicked(SpeechInputBubble::Button button); |
| 58 virtual void InfoBubbleClosed(); | 71 virtual void InfoBubbleFocusChanged(); |
| 59 | 72 |
| 60 private: | 73 private: |
| 61 void InvokeDelegateRecognitionCancelled(int caller_id); | 74 void InvokeDelegateButtonClicked(int caller_id, |
| 75 SpeechInputBubble::Button button); | |
| 62 void InvokeDelegateFocusChanged(int caller_id); | 76 void InvokeDelegateFocusChanged(int caller_id); |
| 77 void SetBubbleRecordingModeOrMessage(int caller_id, const string16& text); | |
| 63 | 78 |
| 64 // Only accessed in the IO thread. | 79 // Only accessed in the IO thread. |
| 65 Delegate* delegate_; | 80 Delegate* delegate_; |
| 66 | 81 |
| 67 // Only accessed in the UI thread. | 82 //*** The following are accessed only in the UI thread. |
| 83 | |
| 84 // The caller id for currently visible bubble (since only one bubble is | |
| 85 // visible at any time). | |
| 68 int current_bubble_caller_id_; | 86 int current_bubble_caller_id_; |
| 69 scoped_ptr<SpeechInputBubble> bubble_; | 87 |
| 88 // Map of caller-ids to bubble objects. The bubbles are weak pointers owned by | |
|
joth
2010/09/10 17:08:40
s/weak pointer/raw pointer/ (or just say "The bubb
| |
| 89 // this object and get destroyed by |CloseBubble|. | |
| 90 std::map<int, SpeechInputBubble*> bubbles_; | |
| 70 }; | 91 }; |
| 71 | 92 |
| 72 // This typedef is to workaround the issue with certain versions of | 93 // This typedef is to workaround the issue with certain versions of |
| 73 // Visual Studio where it gets confused between multiple Delegate | 94 // Visual Studio where it gets confused between multiple Delegate |
| 74 // classes and gives a C2500 error. (I saw this error on the try bots - | 95 // classes and gives a C2500 error. (I saw this error on the try bots - |
| 75 // the workaround was not needed for my machine). | 96 // the workaround was not needed for my machine). |
| 76 typedef SpeechInputBubbleController::Delegate | 97 typedef SpeechInputBubbleController::Delegate |
| 77 SpeechInputBubbleControllerDelegate; | 98 SpeechInputBubbleControllerDelegate; |
| 78 | 99 |
| 79 } // namespace speech_input | 100 } // namespace speech_input |
| 80 | 101 |
| 81 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_CONTROLLER_H_ | 102 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_CONTROLLER_H_ |
| OLD | NEW |