OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Apple Inc. All rights reserved. | 2 * Copyright (C) 2013 Apple 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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 26 matching lines...) Expand all Loading... |
37 DEFINE_GC_INFO(SpeechSynthesis); | 37 DEFINE_GC_INFO(SpeechSynthesis); |
38 | 38 |
39 PassRefPtrWillBeRawPtr<SpeechSynthesis> SpeechSynthesis::create(ExecutionContext
* context) | 39 PassRefPtrWillBeRawPtr<SpeechSynthesis> SpeechSynthesis::create(ExecutionContext
* context) |
40 { | 40 { |
41 return adoptRefCountedWillBeRefCountedGarbageCollected(new SpeechSynthesis(c
ontext)); | 41 return adoptRefCountedWillBeRefCountedGarbageCollected(new SpeechSynthesis(c
ontext)); |
42 } | 42 } |
43 | 43 |
44 SpeechSynthesis::SpeechSynthesis(ExecutionContext* context) | 44 SpeechSynthesis::SpeechSynthesis(ExecutionContext* context) |
45 : ContextLifecycleObserver(context) | 45 : ContextLifecycleObserver(context) |
46 , m_platformSpeechSynthesizer(PlatformSpeechSynthesizer::create(this)) | 46 , m_platformSpeechSynthesizer(PlatformSpeechSynthesizer::create(this)) |
47 , m_currentSpeechUtterance(0) | 47 , m_currentSpeechUtterance(nullptr) |
48 , m_isPaused(false) | 48 , m_isPaused(false) |
49 { | 49 { |
50 ScriptWrappable::init(this); | 50 ScriptWrappable::init(this); |
51 } | 51 } |
52 | 52 |
53 void SpeechSynthesis::setPlatformSynthesizer(PassOwnPtr<PlatformSpeechSynthesize
r> synthesizer) | 53 void SpeechSynthesis::setPlatformSynthesizer(PassOwnPtr<PlatformSpeechSynthesize
r> synthesizer) |
54 { | 54 { |
55 m_platformSpeechSynthesizer = synthesizer; | 55 m_platformSpeechSynthesizer = synthesizer; |
56 } | 56 } |
57 | 57 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 startSpeakingImmediately(utterance); | 123 startSpeakingImmediately(utterance); |
124 } | 124 } |
125 | 125 |
126 void SpeechSynthesis::cancel() | 126 void SpeechSynthesis::cancel() |
127 { | 127 { |
128 // Remove all the items from the utterance queue. | 128 // Remove all the items from the utterance queue. |
129 // Hold on to the current utterance so the platform synthesizer can have a c
hance to clean up. | 129 // Hold on to the current utterance so the platform synthesizer can have a c
hance to clean up. |
130 RefPtrWillBeMember<SpeechSynthesisUtterance> current = m_currentSpeechUttera
nce; | 130 RefPtrWillBeMember<SpeechSynthesisUtterance> current = m_currentSpeechUttera
nce; |
131 m_utteranceQueue.clear(); | 131 m_utteranceQueue.clear(); |
132 m_platformSpeechSynthesizer->cancel(); | 132 m_platformSpeechSynthesizer->cancel(); |
133 current = 0; | 133 current = nullptr; |
134 | 134 |
135 // The platform should have called back immediately and cleared the current
utterance. | 135 // The platform should have called back immediately and cleared the current
utterance. |
136 ASSERT(!m_currentSpeechUtterance); | 136 ASSERT(!m_currentSpeechUtterance); |
137 } | 137 } |
138 | 138 |
139 void SpeechSynthesis::pause() | 139 void SpeechSynthesis::pause() |
140 { | 140 { |
141 if (!m_isPaused) | 141 if (!m_isPaused) |
142 m_platformSpeechSynthesizer->pause(); | 142 m_platformSpeechSynthesizer->pause(); |
143 } | 143 } |
144 | 144 |
145 void SpeechSynthesis::resume() | 145 void SpeechSynthesis::resume() |
146 { | 146 { |
147 if (!m_currentSpeechUtterance) | 147 if (!m_currentSpeechUtterance) |
148 return; | 148 return; |
149 m_platformSpeechSynthesizer->resume(); | 149 m_platformSpeechSynthesizer->resume(); |
150 } | 150 } |
151 | 151 |
152 void SpeechSynthesis::fireEvent(const AtomicString& type, SpeechSynthesisUtteran
ce* utterance, unsigned long charIndex, const String& name) | 152 void SpeechSynthesis::fireEvent(const AtomicString& type, SpeechSynthesisUtteran
ce* utterance, unsigned long charIndex, const String& name) |
153 { | 153 { |
154 if (!executionContext()->activeDOMObjectsAreStopped()) | 154 if (!executionContext()->activeDOMObjectsAreStopped()) |
155 utterance->dispatchEvent(SpeechSynthesisEvent::create(type, charIndex, (
currentTime() - utterance->startTime()), name)); | 155 utterance->dispatchEvent(SpeechSynthesisEvent::create(type, charIndex, (
currentTime() - utterance->startTime()), name)); |
156 } | 156 } |
157 | 157 |
158 void SpeechSynthesis::handleSpeakingCompleted(SpeechSynthesisUtterance* utteranc
e, bool errorOccurred) | 158 void SpeechSynthesis::handleSpeakingCompleted(SpeechSynthesisUtterance* utteranc
e, bool errorOccurred) |
159 { | 159 { |
160 ASSERT(utterance); | 160 ASSERT(utterance); |
161 ASSERT(m_currentSpeechUtterance); | 161 ASSERT(m_currentSpeechUtterance); |
162 m_currentSpeechUtterance = 0; | 162 m_currentSpeechUtterance = nullptr; |
163 | 163 |
164 fireEvent(errorOccurred ? EventTypeNames::error : EventTypeNames::end, utter
ance, 0, String()); | 164 fireEvent(errorOccurred ? EventTypeNames::error : EventTypeNames::end, utter
ance, 0, String()); |
165 | 165 |
166 if (m_utteranceQueue.size()) { | 166 if (m_utteranceQueue.size()) { |
167 RefPtrWillBeMember<SpeechSynthesisUtterance> firstUtterance = m_utteranc
eQueue.first(); | 167 RefPtrWillBeMember<SpeechSynthesisUtterance> firstUtterance = m_utteranc
eQueue.first(); |
168 ASSERT(firstUtterance == utterance); | 168 ASSERT(firstUtterance == utterance); |
169 if (firstUtterance == utterance) | 169 if (firstUtterance == utterance) |
170 m_utteranceQueue.removeFirst(); | 170 m_utteranceQueue.removeFirst(); |
171 | 171 |
172 // Start the next job if there is one pending. | 172 // Start the next job if there is one pending. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 } | 230 } |
231 | 231 |
232 void SpeechSynthesis::trace(Visitor* visitor) | 232 void SpeechSynthesis::trace(Visitor* visitor) |
233 { | 233 { |
234 visitor->trace(m_voiceList); | 234 visitor->trace(m_voiceList); |
235 visitor->trace(m_currentSpeechUtterance); | 235 visitor->trace(m_currentSpeechUtterance); |
236 visitor->trace(m_utteranceQueue); | 236 visitor->trace(m_utteranceQueue); |
237 } | 237 } |
238 | 238 |
239 } // namespace WebCore | 239 } // namespace WebCore |
OLD | NEW |