OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 15 matching lines...) Expand all Loading... | |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "core/speech/SpeechInput.h" | 32 #include "core/speech/SpeechInput.h" |
33 | 33 |
34 #if ENABLE(INPUT_SPEECH) | 34 #if ENABLE(INPUT_SPEECH) |
35 | 35 |
36 #include "core/html/shadow/TextControlInnerElements.h" | |
36 #include "core/speech/SpeechInputClient.h" | 37 #include "core/speech/SpeechInputClient.h" |
37 #include "wtf/PassOwnPtr.h" | 38 #include "wtf/PassOwnPtr.h" |
38 | 39 |
39 namespace WebCore { | 40 namespace WebCore { |
40 | 41 |
41 SpeechInput::SpeechInput(PassOwnPtr<SpeechInputClient> client) | 42 SpeechInput::SpeechInput(PassOwnPtr<SpeechInputClient> client) |
42 : m_client(client) | 43 : m_client(client) |
43 , m_nextListenerId(1) | 44 , m_nextListenerId(1) |
44 { | 45 { |
45 m_client->setListener(this); | 46 m_client->setListener(this); |
46 } | 47 } |
47 | 48 |
48 SpeechInput::~SpeechInput() | 49 SpeechInput::~SpeechInput() |
49 { | 50 { |
50 m_client->setListener(0); | 51 m_client->setListener(0); |
51 } | 52 } |
52 | 53 |
53 PassOwnPtr<SpeechInput> SpeechInput::create(PassOwnPtr<SpeechInputClient> client ) | 54 PassOwnPtr<SpeechInput> SpeechInput::create(PassOwnPtr<SpeechInputClient> client ) |
54 { | 55 { |
55 return adoptPtr(new SpeechInput(client)); | 56 return adoptPtr(new SpeechInput(client)); |
56 } | 57 } |
57 | 58 |
58 int SpeechInput::registerListener(SpeechInputListener* listener) | 59 int SpeechInput::registerListener(InputFieldSpeechButtonElement* listener) |
59 { | 60 { |
60 #if defined(DEBUG) | 61 #if defined(DEBUG) |
61 // Check if already present. | 62 // Check if already present. |
62 for (HashMap<int, SpeechInputListener*>::iterator it = m_listeners.begin(); it != m_listeners.end(); ++it) | 63 for (HashMap<int, InputFieldSpeechButtonElement*>::iterator it = m_listeners .begin(); it != m_listeners.end(); ++it) |
63 ASSERT(it->value != listener); | 64 ASSERT(it->value != listener); |
64 #endif | 65 #endif |
65 | 66 |
66 m_listeners.add(m_nextListenerId, listener); | 67 m_listeners.add(m_nextListenerId, listener); |
67 return m_nextListenerId++; | 68 return m_nextListenerId++; |
68 } | 69 } |
69 | 70 |
70 void SpeechInput::unregisterListener(int listenerId) | 71 void SpeechInput::unregisterListener(int listenerId) |
71 { | 72 { |
72 if (m_listeners.contains(listenerId)) | 73 if (m_listeners.contains(listenerId)) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 const char* SpeechInput::supplementName() | 119 const char* SpeechInput::supplementName() |
119 { | 120 { |
120 return "SpeechInput"; | 121 return "SpeechInput"; |
121 } | 122 } |
122 | 123 |
123 void provideSpeechInputTo(Page& page, PassOwnPtr<SpeechInputClient> client) | 124 void provideSpeechInputTo(Page& page, PassOwnPtr<SpeechInputClient> client) |
124 { | 125 { |
125 SpeechInput::provideTo(page, SpeechInput::supplementName(), SpeechInput::cre ate(client)); | 126 SpeechInput::provideTo(page, SpeechInput::supplementName(), SpeechInput::cre ate(client)); |
126 } | 127 } |
127 | 128 |
129 void SpeechInput::clearWeakMembers(Visitor* visitor) | |
130 { | |
131 Vector<int> deadListenerIds; | |
132 HashMap<int, InputFieldSpeechButtonElement*>::const_iterator end = m_listene rs.end(); | |
133 for (HashMap<int, InputFieldSpeechButtonElement*>::const_iterator it = m_lis teners.begin(); it != end; ++it) { | |
134 if (!visitor->isAlive(it->value)) { | |
135 deadListenerIds.append(it->key); | |
136 m_client->cancelRecognition(it->key); | |
haraken
2014/04/24 04:18:43
Don't you need to check if(m_state != Idle) before
Mads Ager (chromium)
2014/04/24 10:57:36
I don't see anything in the code that requires tha
| |
137 } | |
138 } | |
139 for (unsigned i = 0; i < deadListenerIds.size(); ++i) | |
140 m_listeners.remove(deadListenerIds[i]); | |
141 } | |
142 | |
128 } // namespace WebCore | 143 } // namespace WebCore |
129 | 144 |
130 #endif // ENABLE(INPUT_SPEECH) | 145 #endif // ENABLE(INPUT_SPEECH) |
OLD | NEW |