OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_RECOGNITION_BUBBLE_CONTROLLER_H_ |
6 #define CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_CONTROLLER_H_ | 6 #define CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_BUBBLE_CONTROLLER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "chrome/browser/speech/speech_input_bubble.h" | 13 #include "chrome/browser/speech/speech_recognition_bubble.h" |
14 #include "content/public/browser/notification_observer.h" | 14 #include "content/public/browser/notification_observer.h" |
15 | 15 |
16 namespace gfx { | 16 namespace gfx { |
17 class Rect; | 17 class Rect; |
18 } | 18 } |
19 | 19 |
20 namespace content { | 20 namespace content { |
21 class NotificationRegistrar; | 21 class NotificationRegistrar; |
22 } | 22 } |
23 | 23 |
24 namespace speech_input { | 24 namespace speech { |
25 | 25 |
26 // This class handles the speech input popup UI on behalf of SpeechInputManager. | 26 // This class handles the speech recognition popup UI on behalf of |
27 // SpeechInputManager invokes methods in the IO thread and this class processes | 27 // SpeechRecognitionManager, which invokes methods in the IO thread, processing |
28 // those requests in the UI thread. There could be multiple bubble objects alive | 28 // those requests in the UI thread. There could be multiple bubble objects alive |
29 // at the same time but only one of them is visible to the user. User actions on | 29 // at the same time but only one of them is visible to the user. User actions on |
30 // that bubble are reported to the delegate. | 30 // that bubble are reported to the delegate. |
31 class SpeechInputBubbleController | 31 class SpeechRecognitionBubbleController |
32 : public base::RefCountedThreadSafe<SpeechInputBubbleController>, | 32 : public base::RefCountedThreadSafe<SpeechRecognitionBubbleController>, |
33 public SpeechInputBubbleDelegate, | 33 public SpeechRecognitionBubbleDelegate, |
34 public content::NotificationObserver { | 34 public content::NotificationObserver { |
35 public: | 35 public: |
36 // All methods of this delegate are called in the IO thread. | 36 // All methods of this delegate are called in the IO thread. |
37 class Delegate { | 37 class Delegate { |
38 public: | 38 public: |
39 // Invoked when the user clicks on a button in the speech input UI. | 39 // Invoked when the user clicks on a button in the speech recognition UI. |
40 virtual void InfoBubbleButtonClicked(int caller_id, | 40 virtual void InfoBubbleButtonClicked( |
41 SpeechInputBubble::Button button) = 0; | 41 int caller_id, SpeechRecognitionBubble::Button button) = 0; |
42 | 42 |
43 // Invoked when the user clicks outside the speech input info bubble causing | 43 // Invoked when the user clicks outside the speech recognition info bubble |
44 // it to close and input focus to change. | 44 // causing it to close and input focus to change. |
45 virtual void InfoBubbleFocusChanged(int caller_id) = 0; | 45 virtual void InfoBubbleFocusChanged(int caller_id) = 0; |
46 | 46 |
47 protected: | 47 protected: |
48 virtual ~Delegate() {} | 48 virtual ~Delegate() {} |
49 }; | 49 }; |
50 | 50 |
51 explicit SpeechInputBubbleController(Delegate* delegate); | 51 explicit SpeechRecognitionBubbleController(Delegate* delegate); |
52 virtual ~SpeechInputBubbleController(); | 52 virtual ~SpeechRecognitionBubbleController(); |
53 | 53 |
54 // Creates a new speech input UI bubble. One of the SetXxxx methods below need | 54 // Creates a new speech recognition UI bubble. One of the SetXxxx methods |
55 // to be called to specify what to display. | 55 // below need to be called to specify what to display. |
56 void CreateBubble(int caller_id, | 56 void CreateBubble(int caller_id, |
57 int render_process_id, | 57 int render_process_id, |
58 int render_view_id, | 58 int render_view_id, |
59 const gfx::Rect& element_rect); | 59 const gfx::Rect& element_rect); |
60 | 60 |
61 // Indicates to the user that audio hardware is warming up. This also makes | 61 // Indicates to the user that audio hardware is warming up. This also makes |
62 // the bubble visible if not already visible. | 62 // the bubble visible if not already visible. |
63 void SetBubbleWarmUpMode(int caller_id); | 63 void SetBubbleWarmUpMode(int caller_id); |
64 | 64 |
65 // Indicates to the user that audio recording is in progress. This also makes | 65 // Indicates to the user that audio recording is in progress. This also makes |
66 // the bubble visible if not already visible. | 66 // the bubble visible if not already visible. |
67 void SetBubbleRecordingMode(int caller_id); | 67 void SetBubbleRecordingMode(int caller_id); |
68 | 68 |
69 // Indicates to the user that recognition is in progress. If the bubble is | 69 // Indicates to the user that recognition is in progress. If the bubble is |
70 // hidden, |Show| must be called to make it appear on screen. | 70 // hidden, |Show| must be called to make it appear on screen. |
71 void SetBubbleRecognizingMode(int caller_id); | 71 void SetBubbleRecognizingMode(int caller_id); |
72 | 72 |
73 // Displays the given string with the 'Try again' and 'Cancel' buttons. If the | 73 // Displays the given string with the 'Try again' and 'Cancel' buttons. If the |
74 // bubble is hidden, |Show| must be called to make it appear on screen. | 74 // bubble is hidden, |Show| must be called to make it appear on screen. |
75 void SetBubbleMessage(int caller_id, const string16& text); | 75 void SetBubbleMessage(int caller_id, const string16& text); |
76 | 76 |
77 // Updates the current captured audio volume displayed on screen. | 77 // Updates the current captured audio volume displayed on screen. |
78 void SetBubbleInputVolume(int caller_id, float volume, float noise_volume); | 78 void SetBubbleInputVolume(int caller_id, float volume, float noise_volume); |
79 | 79 |
80 void CloseBubble(int caller_id); | 80 void CloseBubble(int caller_id); |
81 | 81 |
82 // SpeechInputBubble::Delegate methods. | 82 // SpeechRecognitionBubble::Delegate methods. |
83 virtual void InfoBubbleButtonClicked( | 83 virtual void InfoBubbleButtonClicked( |
84 SpeechInputBubble::Button button) OVERRIDE; | 84 SpeechRecognitionBubble::Button button) OVERRIDE; |
85 virtual void InfoBubbleFocusChanged() OVERRIDE; | 85 virtual void InfoBubbleFocusChanged() OVERRIDE; |
86 | 86 |
87 // content::NotificationObserver implementation. | 87 // content::NotificationObserver implementation. |
88 virtual void Observe(int type, | 88 virtual void Observe(int type, |
89 const content::NotificationSource& source, | 89 const content::NotificationSource& source, |
90 const content::NotificationDetails& details) OVERRIDE; | 90 const content::NotificationDetails& details) OVERRIDE; |
91 | 91 |
92 private: | 92 private: |
93 // The various calls received by this object and handled in the UI thread. | 93 // The various calls received by this object and handled in the UI thread. |
94 enum RequestType { | 94 enum RequestType { |
95 REQUEST_SET_WARM_UP_MODE, | 95 REQUEST_SET_WARM_UP_MODE, |
96 REQUEST_SET_RECORDING_MODE, | 96 REQUEST_SET_RECORDING_MODE, |
97 REQUEST_SET_RECOGNIZING_MODE, | 97 REQUEST_SET_RECOGNIZING_MODE, |
98 REQUEST_SET_MESSAGE, | 98 REQUEST_SET_MESSAGE, |
99 REQUEST_SET_INPUT_VOLUME, | 99 REQUEST_SET_INPUT_VOLUME, |
100 REQUEST_CLOSE, | 100 REQUEST_CLOSE, |
101 }; | 101 }; |
102 | 102 |
103 enum ManageSubscriptionAction { | 103 enum ManageSubscriptionAction { |
104 BUBBLE_ADDED, | 104 BUBBLE_ADDED, |
105 BUBBLE_REMOVED | 105 BUBBLE_REMOVED |
106 }; | 106 }; |
107 | 107 |
108 void InvokeDelegateButtonClicked(int caller_id, | 108 void InvokeDelegateButtonClicked(int caller_id, |
109 SpeechInputBubble::Button button); | 109 SpeechRecognitionBubble::Button button); |
110 void InvokeDelegateFocusChanged(int caller_id); | 110 void InvokeDelegateFocusChanged(int caller_id); |
111 void ProcessRequestInUiThread(int caller_id, | 111 void ProcessRequestInUiThread(int caller_id, |
112 RequestType type, | 112 RequestType type, |
113 const string16& text, | 113 const string16& text, |
114 float volume, | 114 float volume, |
115 float noise_volume); | 115 float noise_volume); |
116 | 116 |
117 // Called whenever a bubble was added to or removed from the list. If the | 117 // Called whenever a bubble was added to or removed from the list. If the |
118 // bubble was being added, this method registers for close notifications with | 118 // bubble was being added, this method registers for close notifications with |
119 // the TabContents if this was the first bubble for the tab. Similarly if the | 119 // the TabContents if this was the first bubble for the tab. Similarly if the |
120 // bubble was being removed, this method unregisters from TabContents if this | 120 // bubble was being removed, this method unregisters from TabContents if this |
121 // was the last bubble associated with that tab. | 121 // was the last bubble associated with that tab. |
122 void UpdateTabContentsSubscription(int caller_id, | 122 void UpdateTabContentsSubscription(int caller_id, |
123 ManageSubscriptionAction action); | 123 ManageSubscriptionAction action); |
124 | 124 |
125 // Only accessed in the IO thread. | 125 // Only accessed in the IO thread. |
126 Delegate* delegate_; | 126 Delegate* delegate_; |
127 | 127 |
128 // *** The following are accessed only in the UI thread. | 128 // *** The following are accessed only in the UI thread. |
129 | 129 |
130 // The caller id for currently visible bubble (since only one bubble is | 130 // The caller id for currently visible bubble (since only one bubble is |
131 // visible at any time). | 131 // visible at any time). |
132 int current_bubble_caller_id_; | 132 int current_bubble_caller_id_; |
133 | 133 |
134 // Map of caller-ids to bubble objects. The bubbles are weak pointers owned by | 134 // Map of caller-ids to bubble objects. The bubbles are weak pointers owned by |
135 // this object and get destroyed by |CloseBubble|. | 135 // this object and get destroyed by |CloseBubble|. |
136 typedef std::map<int, SpeechInputBubble*> BubbleCallerIdMap; | 136 typedef std::map<int, SpeechRecognitionBubble*> BubbleCallerIdMap; |
137 BubbleCallerIdMap bubbles_; | 137 BubbleCallerIdMap bubbles_; |
138 | 138 |
139 scoped_ptr<content::NotificationRegistrar> registrar_; | 139 scoped_ptr<content::NotificationRegistrar> registrar_; |
140 }; | 140 }; |
141 | 141 |
142 // This typedef is to workaround the issue with certain versions of | 142 // This typedef is to workaround the issue with certain versions of |
143 // Visual Studio where it gets confused between multiple Delegate | 143 // Visual Studio where it gets confused between multiple Delegate |
144 // classes and gives a C2500 error. (I saw this error on the try bots - | 144 // classes and gives a C2500 error. (I saw this error on the try bots - |
145 // the workaround was not needed for my machine). | 145 // the workaround was not needed for my machine). |
146 typedef SpeechInputBubbleController::Delegate | 146 typedef SpeechRecognitionBubbleController::Delegate |
147 SpeechInputBubbleControllerDelegate; | 147 SpeechRecognitionBubbleControllerDelegate; |
148 | 148 |
149 } // namespace speech_input | 149 } // namespace speech |
150 | 150 |
151 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_CONTROLLER_H_ | 151 #endif // CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_BUBBLE_CONTROLLER_H_ |
OLD | NEW |