blob: d99289d78649be14ac512ae1d9f6f5191b3ef948 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_H_
#define CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_H_
#pragma once
namespace gfx {
class Rect;
}
class TabContents;
// SpeechInputBubble displays a popup info bubble during speech recognition,
// points to the html element which requested speech input and shows recognition
// progress events. The popup is closed by the user clicking anywhere outside
// the popup window, or by the caller destroying this object.
class SpeechInputBubble {
public:
// Informs listeners of user actions in the bubble.
class Delegate {
public:
// Invoked when the user cancels speech recognition by clicking on the
// cancel button. The InfoBubble is still active and the caller should close
// it if necessary.
virtual void RecognitionCancelled() = 0;
// Invoked when the user clicks outside the InfoBubble causing it to close.
// The InfoBubble window is no longer visible on screen and the caller can
// free the InfoBubble instance. This callback is not issued if the bubble
// got closed because the object was destroyed by the caller.
virtual void InfoBubbleClosed() = 0;
protected:
virtual ~Delegate() {
}
};
// Factory method to create new instances.
// Creates and displays the bubble.
// |tab_contents| is the TabContents hosting the page.
// |element_rect| is the display bounds of the html element requesting speech
// input (in page coordinates).
static SpeechInputBubble* Create(TabContents* tab_contents,
Delegate* delegate,
const gfx::Rect& element_rect);
// This is implemented by platform specific code to create the underlying
// bubble window. Not to be called directly by users of this class.
static SpeechInputBubble* CreateNativeBubble(TabContents* tab_contents,
Delegate* delegate,
const gfx::Rect& element_rect);
// |Create| uses the currently registered FactoryMethod to create the
// SpeechInputBubble instances. FactoryMethod is intended for testing.
typedef SpeechInputBubble* (*FactoryMethod)(TabContents*,
Delegate*,
const gfx::Rect&);
// Sets the factory used by the static method Create. SpeechInputBubble does
// not take ownership of |factory|. A value of NULL results in a
// SpeechInputBubble being created directly.
#if defined(UNIT_TEST)
static void set_factory(FactoryMethod factory) { factory_ = factory; }
#endif
virtual ~SpeechInputBubble() {}
// Indicates to the user that recognition is in progress.
virtual void SetRecognizingMode() = 0;
// The horizontal distance between the start of the html widget and the speech
// bubble's arrow.
static const int kBubbleTargetOffsetX;
private:
static FactoryMethod factory_;
};
// This typedef is to workaround the issue with certain versions of
// Visual Studio where it gets confused between multiple Delegate
// classes and gives a C2500 error. (I saw this error on the try bots -
// the workaround was not needed for my machine).
typedef SpeechInputBubble::Delegate SpeechInputBubbleDelegate;
#endif // CHROME_BROWSER_SPEECH_SPEECH_INPUT_BUBBLE_H_
|