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> | 8 #include <map> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
13 #include "chrome/browser/speech/speech_input_bubble.h" | 13 #include "chrome/browser/speech/speech_input_bubble.h" |
| 14 #include "chrome/common/notification_observer.h" |
14 | 15 |
15 namespace gfx { | 16 namespace gfx { |
16 class Rect; | 17 class Rect; |
17 } | 18 } |
| 19 class NotificationRegistrar; |
18 | 20 |
19 namespace speech_input { | 21 namespace speech_input { |
20 | 22 |
21 // This class handles the speech input popup UI on behalf of SpeechInputManager. | 23 // This class handles the speech input popup UI on behalf of SpeechInputManager. |
22 // SpeechInputManager invokes methods in the IO thread and this class processes | 24 // SpeechInputManager invokes methods in the IO thread and this class processes |
23 // those requests in the UI thread. There could be multiple bubble objects alive | 25 // those requests in the UI thread. There could be multiple bubble objects alive |
24 // at the same time but only one of them is visible to the user. User actions on | 26 // 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. | 27 // that bubble are reported to the delegate. |
26 class SpeechInputBubbleController | 28 class SpeechInputBubbleController |
27 : public base::RefCountedThreadSafe<SpeechInputBubbleController>, | 29 : public base::RefCountedThreadSafe<SpeechInputBubbleController>, |
28 public SpeechInputBubbleDelegate { | 30 public SpeechInputBubbleDelegate, |
| 31 public NotificationObserver { |
29 public: | 32 public: |
30 // All methods of this delegate are called in the IO thread. | 33 // All methods of this delegate are called in the IO thread. |
31 class Delegate { | 34 class Delegate { |
32 public: | 35 public: |
33 // Invoked when the user clicks on a button in the speech input UI. | 36 // Invoked when the user clicks on a button in the speech input UI. |
34 virtual void InfoBubbleButtonClicked(int caller_id, | 37 virtual void InfoBubbleButtonClicked(int caller_id, |
35 SpeechInputBubble::Button button) = 0; | 38 SpeechInputBubble::Button button) = 0; |
36 | 39 |
37 // Invoked when the user clicks outside the speech input info bubble causing | 40 // Invoked when the user clicks outside the speech input info bubble causing |
38 // it to close and input focus to change. | 41 // it to close and input focus to change. |
(...skipping 27 matching lines...) Expand all Loading... |
66 | 69 |
67 // Updates the current captured audio volume displayed on screen. | 70 // Updates the current captured audio volume displayed on screen. |
68 void SetBubbleInputVolume(int caller_id, float volume); | 71 void SetBubbleInputVolume(int caller_id, float volume); |
69 | 72 |
70 void CloseBubble(int caller_id); | 73 void CloseBubble(int caller_id); |
71 | 74 |
72 // SpeechInputBubble::Delegate methods. | 75 // SpeechInputBubble::Delegate methods. |
73 virtual void InfoBubbleButtonClicked(SpeechInputBubble::Button button); | 76 virtual void InfoBubbleButtonClicked(SpeechInputBubble::Button button); |
74 virtual void InfoBubbleFocusChanged(); | 77 virtual void InfoBubbleFocusChanged(); |
75 | 78 |
| 79 // NotificationObserver implementation. |
| 80 virtual void Observe(NotificationType type, |
| 81 const NotificationSource& source, |
| 82 const NotificationDetails& details); |
| 83 |
76 private: | 84 private: |
77 // The various calls received by this object and handled in the UI thread. | 85 // The various calls received by this object and handled in the UI thread. |
78 enum RequestType { | 86 enum RequestType { |
79 REQUEST_SET_RECORDING_MODE, | 87 REQUEST_SET_RECORDING_MODE, |
80 REQUEST_SET_RECOGNIZING_MODE, | 88 REQUEST_SET_RECOGNIZING_MODE, |
81 REQUEST_SET_MESSAGE, | 89 REQUEST_SET_MESSAGE, |
82 REQUEST_SET_INPUT_VOLUME, | 90 REQUEST_SET_INPUT_VOLUME, |
83 REQUEST_CLOSE, | 91 REQUEST_CLOSE, |
84 }; | 92 }; |
85 | 93 |
| 94 enum ManageSubscriptionAction { |
| 95 BUBBLE_ADDED, |
| 96 BUBBLE_REMOVED |
| 97 }; |
| 98 |
86 void InvokeDelegateButtonClicked(int caller_id, | 99 void InvokeDelegateButtonClicked(int caller_id, |
87 SpeechInputBubble::Button button); | 100 SpeechInputBubble::Button button); |
88 void InvokeDelegateFocusChanged(int caller_id); | 101 void InvokeDelegateFocusChanged(int caller_id); |
89 void ProcessRequestInUiThread(int caller_id, | 102 void ProcessRequestInUiThread(int caller_id, |
90 RequestType type, | 103 RequestType type, |
91 const string16& text, | 104 const string16& text, |
92 float volume); | 105 float volume); |
93 | 106 |
| 107 // Called whenever a bubble was added to or removed from the list. If the |
| 108 // bubble was being added, this method registers for close notifications with |
| 109 // the TabContents if this was the first bubble for the tab. Similarly if the |
| 110 // bubble was being removed, this method unregisters from TabContents if this |
| 111 // was the last bubble associated with that tab. |
| 112 void UpdateTabContentsSubscription(int caller_id, |
| 113 ManageSubscriptionAction action); |
| 114 |
94 // Only accessed in the IO thread. | 115 // Only accessed in the IO thread. |
95 Delegate* delegate_; | 116 Delegate* delegate_; |
96 | 117 |
97 //*** The following are accessed only in the UI thread. | 118 //*** The following are accessed only in the UI thread. |
98 | 119 |
99 // The caller id for currently visible bubble (since only one bubble is | 120 // The caller id for currently visible bubble (since only one bubble is |
100 // visible at any time). | 121 // visible at any time). |
101 int current_bubble_caller_id_; | 122 int current_bubble_caller_id_; |
102 | 123 |
103 // Map of caller-ids to bubble objects. The bubbles are weak pointers owned by | 124 // Map of caller-ids to bubble objects. The bubbles are weak pointers owned by |
104 // this object and get destroyed by |CloseBubble|. | 125 // this object and get destroyed by |CloseBubble|. |
105 std::map<int, SpeechInputBubble*> bubbles_; | 126 typedef std::map<int, SpeechInputBubble*> BubbleCallerIdMap; |
| 127 BubbleCallerIdMap bubbles_; |
| 128 |
| 129 scoped_ptr<NotificationRegistrar> registrar_; |
106 }; | 130 }; |
107 | 131 |
108 // This typedef is to workaround the issue with certain versions of | 132 // This typedef is to workaround the issue with certain versions of |
109 // Visual Studio where it gets confused between multiple Delegate | 133 // Visual Studio where it gets confused between multiple Delegate |
110 // classes and gives a C2500 error. (I saw this error on the try bots - | 134 // classes and gives a C2500 error. (I saw this error on the try bots - |
111 // the workaround was not needed for my machine). | 135 // the workaround was not needed for my machine). |
112 typedef SpeechInputBubbleController::Delegate | 136 typedef SpeechInputBubbleController::Delegate |
113 SpeechInputBubbleControllerDelegate; | 137 SpeechInputBubbleControllerDelegate; |
114 | 138 |
115 } // namespace speech_input | 139 } // namespace speech_input |
116 | 140 |
117 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_CONTROLLER_H_ | 141 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_CONTROLLER_H_ |
OLD | NEW |