| 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_H_ | 5 #ifndef CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_H_ |
| 6 #define CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_H_ | 6 #define CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/string16.h" |
| 10 |
| 9 namespace gfx { | 11 namespace gfx { |
| 10 class Rect; | 12 class Rect; |
| 11 } | 13 } |
| 12 class TabContents; | 14 class TabContents; |
| 13 | 15 |
| 14 // SpeechInputBubble displays a popup info bubble during speech recognition, | 16 // SpeechInputBubble displays a popup info bubble during speech recognition, |
| 15 // points to the html element which requested speech input and shows recognition | 17 // points to the html element which requested speech input and shows recognition |
| 16 // progress events. The popup is closed by the user clicking anywhere outside | 18 // progress events. The popup is closed by the user clicking anywhere outside |
| 17 // the popup window, or by the caller destroying this object. | 19 // the popup window, or by the caller destroying this object. |
| 18 class SpeechInputBubble { | 20 class SpeechInputBubble { |
| 19 public: | 21 public: |
| 22 // The various buttons which may be part of the bubble. |
| 23 enum Button { |
| 24 BUTTON_TRY_AGAIN, |
| 25 BUTTON_CANCEL |
| 26 }; |
| 27 |
| 20 // Informs listeners of user actions in the bubble. | 28 // Informs listeners of user actions in the bubble. |
| 21 class Delegate { | 29 class Delegate { |
| 22 public: | 30 public: |
| 23 // Invoked when the user cancels speech recognition by clicking on the | 31 // Invoked when the user selects a button in the info bubble. The InfoBubble |
| 24 // cancel button. The InfoBubble is still active and the caller should close | 32 // is still active and the caller should close it if necessary. |
| 25 // it if necessary. | 33 virtual void InfoBubbleButtonClicked(Button button) = 0; |
| 26 virtual void RecognitionCancelled() = 0; | |
| 27 | 34 |
| 28 // Invoked when the user clicks outside the InfoBubble causing it to close. | 35 // Invoked when the user clicks outside the InfoBubble causing it to close. |
| 29 // The InfoBubble window is no longer visible on screen and the caller can | 36 // The InfoBubble window is no longer visible on screen and the caller can |
| 30 // free the InfoBubble instance. This callback is not issued if the bubble | 37 // free the InfoBubble instance. This callback is not issued if the bubble |
| 31 // got closed because the object was destroyed by the caller. | 38 // got closed because the object was destroyed by the caller. |
| 32 virtual void InfoBubbleClosed() = 0; | 39 virtual void InfoBubbleFocusChanged() = 0; |
| 33 | 40 |
| 34 protected: | 41 protected: |
| 35 virtual ~Delegate() { | 42 virtual ~Delegate() { |
| 36 } | 43 } |
| 37 }; | 44 }; |
| 38 | 45 |
| 39 // Factory method to create new instances. | 46 // Factory method to create new instances. |
| 40 // Creates and displays the bubble. | 47 // Creates the bubble, call |Show| to display it on screen. |
| 41 // |tab_contents| is the TabContents hosting the page. | 48 // |tab_contents| is the TabContents hosting the page. |
| 42 // |element_rect| is the display bounds of the html element requesting speech | 49 // |element_rect| is the display bounds of the html element requesting speech |
| 43 // input (in page coordinates). | 50 // input (in page coordinates). |
| 44 static SpeechInputBubble* Create(TabContents* tab_contents, | 51 static SpeechInputBubble* Create(TabContents* tab_contents, |
| 45 Delegate* delegate, | 52 Delegate* delegate, |
| 46 const gfx::Rect& element_rect); | 53 const gfx::Rect& element_rect); |
| 47 | 54 |
| 48 // This is implemented by platform specific code to create the underlying | 55 // This is implemented by platform specific code to create the underlying |
| 49 // bubble window. Not to be called directly by users of this class. | 56 // bubble window. Not to be called directly by users of this class. |
| 50 static SpeechInputBubble* CreateNativeBubble(TabContents* tab_contents, | 57 static SpeechInputBubble* CreateNativeBubble(TabContents* tab_contents, |
| 51 Delegate* delegate, | 58 Delegate* delegate, |
| 52 const gfx::Rect& element_rect); | 59 const gfx::Rect& element_rect); |
| 53 | 60 |
| 54 // |Create| uses the currently registered FactoryMethod to create the | 61 // |Create| uses the currently registered FactoryMethod to create the |
| 55 // SpeechInputBubble instances. FactoryMethod is intended for testing. | 62 // SpeechInputBubble instances. FactoryMethod is intended for testing. |
| 56 typedef SpeechInputBubble* (*FactoryMethod)(TabContents*, | 63 typedef SpeechInputBubble* (*FactoryMethod)(TabContents*, |
| 57 Delegate*, | 64 Delegate*, |
| 58 const gfx::Rect&); | 65 const gfx::Rect&); |
| 59 // Sets the factory used by the static method Create. SpeechInputBubble does | 66 // Sets the factory used by the static method Create. SpeechInputBubble does |
| 60 // not take ownership of |factory|. A value of NULL results in a | 67 // not take ownership of |factory|. A value of NULL results in a |
| 61 // SpeechInputBubble being created directly. | 68 // SpeechInputBubble being created directly. |
| 62 #if defined(UNIT_TEST) | 69 #if defined(UNIT_TEST) |
| 63 static void set_factory(FactoryMethod factory) { factory_ = factory; } | 70 static void set_factory(FactoryMethod factory) { factory_ = factory; } |
| 64 #endif | 71 #endif |
| 65 | 72 |
| 66 virtual ~SpeechInputBubble() {} | 73 virtual ~SpeechInputBubble() {} |
| 67 | 74 |
| 68 // Indicates to the user that recognition is in progress. | 75 // Indicates to the user that audio recording is in progress. If the bubble is |
| 76 // hidden, |Show| must be called to make it appear on screen. |
| 77 virtual void SetRecordingMode() = 0; |
| 78 |
| 79 // Indicates to the user that recognition is in progress. If the bubble is |
| 80 // hidden, |Show| must be called to make it appear on screen. |
| 69 virtual void SetRecognizingMode() = 0; | 81 virtual void SetRecognizingMode() = 0; |
| 70 | 82 |
| 83 // Displays the given string with the 'Try again' and 'Cancel' buttons. If the |
| 84 // bubble is hidden, |Show| must be called to make it appear on screen. |
| 85 virtual void SetMessage(const string16& text) = 0; |
| 86 |
| 87 // Brings up the bubble on screen. |
| 88 virtual void Show() = 0; |
| 89 |
| 90 // Hides the info bubble, resulting in a call to |
| 91 // |Delegate::InfoBubbleFocusChanged| as well. |
| 92 virtual void Hide() = 0; |
| 93 |
| 71 // The horizontal distance between the start of the html widget and the speech | 94 // The horizontal distance between the start of the html widget and the speech |
| 72 // bubble's arrow. | 95 // bubble's arrow. |
| 73 static const int kBubbleTargetOffsetX; | 96 static const int kBubbleTargetOffsetX; |
| 74 | 97 |
| 75 private: | 98 private: |
| 76 static FactoryMethod factory_; | 99 static FactoryMethod factory_; |
| 77 }; | 100 }; |
| 78 | 101 |
| 102 // Base class for the platform specific bubble implementations, this contains |
| 103 // the platform independent code for SpeechInputBubble. |
| 104 class SpeechInputBubbleBase : public SpeechInputBubble { |
| 105 public: |
| 106 // The current display mode of the bubble, useful only for the platform |
| 107 // specific implementation. |
| 108 enum DisplayMode { |
| 109 DISPLAY_MODE_RECORDING, |
| 110 DISPLAY_MODE_RECOGNIZING, |
| 111 DISPLAY_MODE_MESSAGE |
| 112 }; |
| 113 |
| 114 SpeechInputBubbleBase(); |
| 115 |
| 116 // SpeechInputBubble methods |
| 117 virtual void SetRecordingMode(); |
| 118 virtual void SetRecognizingMode(); |
| 119 virtual void SetMessage(const string16& text); |
| 120 |
| 121 protected: |
| 122 // Updates the platform specific UI layout for the current display mode. |
| 123 virtual void UpdateLayout() = 0; |
| 124 |
| 125 DisplayMode display_mode() { |
| 126 return display_mode_; |
| 127 } |
| 128 |
| 129 string16 message_text() { |
| 130 return message_text_; |
| 131 } |
| 132 |
| 133 private: |
| 134 DisplayMode display_mode_; |
| 135 string16 message_text_; // Text displayed in DISPLAY_MODE_MESSAGE |
| 136 }; |
| 137 |
| 79 // This typedef is to workaround the issue with certain versions of | 138 // This typedef is to workaround the issue with certain versions of |
| 80 // Visual Studio where it gets confused between multiple Delegate | 139 // Visual Studio where it gets confused between multiple Delegate |
| 81 // classes and gives a C2500 error. (I saw this error on the try bots - | 140 // classes and gives a C2500 error. (I saw this error on the try bots - |
| 82 // the workaround was not needed for my machine). | 141 // the workaround was not needed for my machine). |
| 83 typedef SpeechInputBubble::Delegate SpeechInputBubbleDelegate; | 142 typedef SpeechInputBubble::Delegate SpeechInputBubbleDelegate; |
| 84 | 143 |
| 85 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_H_ | 144 #endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_H_ |
| OLD | NEW |