OLD | NEW |
1 // Copyright (c) 2012 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_H_ | 5 #ifndef CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_BUBBLE_H_ |
6 #define CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_H_ | 6 #define CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_BUBBLE_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/string16.h" | 13 #include "base/string16.h" |
14 | 14 |
15 class SkBitmap; | 15 class SkBitmap; |
16 class SkCanvas; | 16 class SkCanvas; |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 class WebContents; | 19 class WebContents; |
20 } | 20 } |
21 | 21 |
22 namespace gfx { | 22 namespace gfx { |
23 class Canvas; | 23 class Canvas; |
24 class Rect; | 24 class Rect; |
25 } | 25 } |
26 | 26 |
27 // SpeechInputBubble displays a popup info bubble during speech recognition, | 27 // SpeechRecognitionBubble displays a popup info bubble during speech |
28 // points to the html element which requested speech input and shows recognition | 28 // recognition, points to the html element which requested speech recognition |
29 // progress events. The popup is closed by the user clicking anywhere outside | 29 // and shows progress events. The popup is closed by the user clicking anywhere |
30 // the popup window, or by the caller destroying this object. | 30 // outside the popup window, or by the caller destroying this object. |
31 class SpeechInputBubble { | 31 class SpeechRecognitionBubble { |
32 public: | 32 public: |
33 // The various buttons which may be part of the bubble. | 33 // The various buttons which may be part of the bubble. |
34 enum Button { | 34 enum Button { |
35 BUTTON_TRY_AGAIN, | 35 BUTTON_TRY_AGAIN, |
36 BUTTON_CANCEL | 36 BUTTON_CANCEL |
37 }; | 37 }; |
38 | 38 |
39 // Informs listeners of user actions in the bubble. | 39 // Informs listeners of user actions in the bubble. |
40 class Delegate { | 40 class Delegate { |
41 public: | 41 public: |
42 // Invoked when the user selects a button in the info bubble. The InfoBubble | 42 // Invoked when the user selects a button in the info bubble. The InfoBubble |
43 // is still active and the caller should close it if necessary. | 43 // is still active and the caller should close it if necessary. |
44 virtual void InfoBubbleButtonClicked(Button button) = 0; | 44 virtual void InfoBubbleButtonClicked(Button button) = 0; |
45 | 45 |
46 // Invoked when the user clicks outside the InfoBubble causing it to close. | 46 // Invoked when the user clicks outside the InfoBubble causing it to close. |
47 // The InfoBubble window is no longer visible on screen and the caller can | 47 // The InfoBubble window is no longer visible on screen and the caller can |
48 // free the InfoBubble instance. This callback is not issued if the bubble | 48 // free the InfoBubble instance. This callback is not issued if the bubble |
49 // got closed because the object was destroyed by the caller. | 49 // got closed because the object was destroyed by the caller. |
50 virtual void InfoBubbleFocusChanged() = 0; | 50 virtual void InfoBubbleFocusChanged() = 0; |
51 | 51 |
52 protected: | 52 protected: |
53 virtual ~Delegate() { | 53 virtual ~Delegate() { |
54 } | 54 } |
55 }; | 55 }; |
56 | 56 |
57 // Factory method to create new instances. | 57 // Factory method to create new instances. |
58 // Creates the bubble, call |Show| to display it on screen. | 58 // Creates the bubble, call |Show| to display it on screen. |
59 // |web_contents| is the WebContents hosting the page. | 59 // |web_contents| is the WebContents hosting the page. |
60 // |element_rect| is the display bounds of the html element requesting speech | 60 // |element_rect| is the display bounds of the html element requesting speech |
61 // input (in page coordinates). | 61 // recognition (in page coordinates). |
62 static SpeechInputBubble* Create(content::WebContents* web_contents, | 62 static SpeechRecognitionBubble* Create(content::WebContents* web_contents, |
63 Delegate* delegate, | 63 Delegate* delegate, |
64 const gfx::Rect& element_rect); | 64 const gfx::Rect& element_rect); |
65 | 65 |
66 // This is implemented by platform specific code to create the underlying | 66 // This is implemented by platform specific code to create the underlying |
67 // bubble window. Not to be called directly by users of this class. | 67 // bubble window. Not to be called directly by users of this class. |
68 static SpeechInputBubble* CreateNativeBubble( | 68 static SpeechRecognitionBubble* CreateNativeBubble( |
69 content::WebContents* web_contents, | 69 content::WebContents* web_contents, |
70 Delegate* delegate, | 70 Delegate* delegate, |
71 const gfx::Rect& element_rect); | 71 const gfx::Rect& element_rect); |
72 | 72 |
73 // |Create| uses the currently registered FactoryMethod to create the | 73 // |Create| uses the currently registered FactoryMethod to create the |
74 // SpeechInputBubble instances. FactoryMethod is intended for testing. | 74 // SpeechRecognitionBubble instances. FactoryMethod is intended for testing. |
75 typedef SpeechInputBubble* (*FactoryMethod)(content::WebContents*, | 75 typedef SpeechRecognitionBubble* (*FactoryMethod)(content::WebContents*, |
76 Delegate*, | 76 Delegate*, |
77 const gfx::Rect&); | 77 const gfx::Rect&); |
78 // Sets the factory used by the static method Create. SpeechInputBubble does | 78 // Sets the factory used by the static method Create. SpeechRecognitionBubble |
79 // not take ownership of |factory|. A value of NULL results in a | 79 // does not take ownership of |factory|. A value of NULL results in a |
80 // SpeechInputBubble being created directly. | 80 // SpeechRecognitionBubble being created directly. |
81 #if defined(UNIT_TEST) | 81 #if defined(UNIT_TEST) |
82 static void set_factory(FactoryMethod factory) { factory_ = factory; } | 82 static void set_factory(FactoryMethod factory) { factory_ = factory; } |
83 #endif | 83 #endif |
84 | 84 |
85 virtual ~SpeechInputBubble() {} | 85 virtual ~SpeechRecognitionBubble() {} |
86 | 86 |
87 // Indicates to the user that audio hardware is initializing. If the bubble is | 87 // Indicates to the user that audio hardware is initializing. If the bubble is |
88 // hidden, |Show| must be called to make it appear on screen. | 88 // hidden, |Show| must be called to make it appear on screen. |
89 virtual void SetWarmUpMode() = 0; | 89 virtual void SetWarmUpMode() = 0; |
90 | 90 |
91 // Indicates to the user that audio recording is in progress. If the bubble is | 91 // Indicates to the user that audio recording is in progress. If the bubble is |
92 // hidden, |Show| must be called to make it appear on screen. | 92 // hidden, |Show| must be called to make it appear on screen. |
93 virtual void SetRecordingMode() = 0; | 93 virtual void SetRecordingMode() = 0; |
94 | 94 |
95 // Indicates to the user that recognition is in progress. If the bubble is | 95 // Indicates to the user that recognition is in progress. If the bubble is |
(...skipping 19 matching lines...) Expand all Loading... |
115 | 115 |
116 // The horizontal distance between the start of the html widget and the speech | 116 // The horizontal distance between the start of the html widget and the speech |
117 // bubble's arrow. | 117 // bubble's arrow. |
118 static const int kBubbleTargetOffsetX; | 118 static const int kBubbleTargetOffsetX; |
119 | 119 |
120 private: | 120 private: |
121 static FactoryMethod factory_; | 121 static FactoryMethod factory_; |
122 }; | 122 }; |
123 | 123 |
124 // Base class for the platform specific bubble implementations, this contains | 124 // Base class for the platform specific bubble implementations, this contains |
125 // the platform independent code for SpeechInputBubble. | 125 // the platform independent code for SpeechRecognitionBubble. |
126 class SpeechInputBubbleBase : public SpeechInputBubble { | 126 class SpeechRecognitionBubbleBase : public SpeechRecognitionBubble { |
127 public: | 127 public: |
128 // The current display mode of the bubble, useful only for the platform | 128 // The current display mode of the bubble, useful only for the platform |
129 // specific implementation. | 129 // specific implementation. |
130 enum DisplayMode { | 130 enum DisplayMode { |
131 DISPLAY_MODE_WARM_UP, | 131 DISPLAY_MODE_WARM_UP, |
132 DISPLAY_MODE_RECORDING, | 132 DISPLAY_MODE_RECORDING, |
133 DISPLAY_MODE_RECOGNIZING, | 133 DISPLAY_MODE_RECOGNIZING, |
134 DISPLAY_MODE_MESSAGE | 134 DISPLAY_MODE_MESSAGE |
135 }; | 135 }; |
136 | 136 |
137 explicit SpeechInputBubbleBase(content::WebContents* web_contents); | 137 explicit SpeechRecognitionBubbleBase(content::WebContents* web_contents); |
138 virtual ~SpeechInputBubbleBase(); | 138 virtual ~SpeechRecognitionBubbleBase(); |
139 | 139 |
140 // SpeechInputBubble methods | 140 // SpeechRecognitionBubble methods |
141 virtual void SetWarmUpMode() OVERRIDE; | 141 virtual void SetWarmUpMode() OVERRIDE; |
142 virtual void SetRecordingMode() OVERRIDE; | 142 virtual void SetRecordingMode() OVERRIDE; |
143 virtual void SetRecognizingMode() OVERRIDE; | 143 virtual void SetRecognizingMode() OVERRIDE; |
144 virtual void SetMessage(const string16& text) OVERRIDE; | 144 virtual void SetMessage(const string16& text) OVERRIDE; |
145 virtual void SetInputVolume(float volume, float noise_volume) OVERRIDE; | 145 virtual void SetInputVolume(float volume, float noise_volume) OVERRIDE; |
146 virtual content::WebContents* web_contents() OVERRIDE; | 146 virtual content::WebContents* web_contents() OVERRIDE; |
147 | 147 |
148 protected: | 148 protected: |
149 // Updates the platform specific UI layout for the current display mode. | 149 // Updates the platform specific UI layout for the current display mode. |
150 virtual void UpdateLayout() = 0; | 150 virtual void UpdateLayout() = 0; |
(...skipping 10 matching lines...) Expand all Loading... |
161 private: | 161 private: |
162 void DoRecognizingAnimationStep(); | 162 void DoRecognizingAnimationStep(); |
163 void DoWarmingUpAnimationStep(); | 163 void DoWarmingUpAnimationStep(); |
164 void SetImage(const SkBitmap& image); | 164 void SetImage(const SkBitmap& image); |
165 | 165 |
166 void DrawVolumeOverlay(SkCanvas* canvas, | 166 void DrawVolumeOverlay(SkCanvas* canvas, |
167 const SkBitmap& bitmap, | 167 const SkBitmap& bitmap, |
168 float volume); | 168 float volume); |
169 | 169 |
170 // Task factory used for animation timer. | 170 // Task factory used for animation timer. |
171 base::WeakPtrFactory<SpeechInputBubbleBase> weak_factory_; | 171 base::WeakPtrFactory<SpeechRecognitionBubbleBase> weak_factory_; |
172 int animation_step_; // Current index/step of the animation. | 172 int animation_step_; // Current index/step of the animation. |
173 std::vector<SkBitmap> animation_frames_; | 173 std::vector<SkBitmap> animation_frames_; |
174 std::vector<SkBitmap> warming_up_frames_; | 174 std::vector<SkBitmap> warming_up_frames_; |
175 | 175 |
176 DisplayMode display_mode_; | 176 DisplayMode display_mode_; |
177 string16 message_text_; // Text displayed in DISPLAY_MODE_MESSAGE | 177 string16 message_text_; // Text displayed in DISPLAY_MODE_MESSAGE |
178 // The current microphone image with volume level indication. | 178 // The current microphone image with volume level indication. |
179 scoped_ptr<SkBitmap> mic_image_; | 179 scoped_ptr<SkBitmap> mic_image_; |
180 // A temporary buffer image used in creating the above mic image. | 180 // A temporary buffer image used in creating the above mic image. |
181 scoped_ptr<SkBitmap> buffer_image_; | 181 scoped_ptr<SkBitmap> buffer_image_; |
182 // WebContents in which this this bubble gets displayed. | 182 // WebContents in which this this bubble gets displayed. |
183 content::WebContents* web_contents_; | 183 content::WebContents* web_contents_; |
184 // The current image displayed in the bubble's icon widget. | 184 // The current image displayed in the bubble's icon widget. |
185 scoped_ptr<SkBitmap> icon_image_; | 185 scoped_ptr<SkBitmap> icon_image_; |
186 }; | 186 }; |
187 | 187 |
188 // This typedef is to workaround the issue with certain versions of | 188 // This typedef is to workaround the issue with certain versions of |
189 // Visual Studio where it gets confused between multiple Delegate | 189 // Visual Studio where it gets confused between multiple Delegate |
190 // classes and gives a C2500 error. (I saw this error on the try bots - | 190 // classes and gives a C2500 error. (I saw this error on the try bots - |
191 // the workaround was not needed for my machine). | 191 // the workaround was not needed for my machine). |
192 typedef SpeechInputBubble::Delegate SpeechInputBubbleDelegate; | 192 typedef SpeechRecognitionBubble::Delegate SpeechRecognitionBubbleDelegate; |
193 | 193 |
194 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_H_ | 194 #endif // CHROME_BROWSER_SPEECH_SPEECH_RECOGNITION_BUBBLE_H_ |
OLD | NEW |