| 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 |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "modules/speech/SpeechSynthesis.h" | 27 #include "modules/speech/SpeechSynthesis.h" |
| 28 | 28 |
| 29 #include "bindings/v8/ExceptionState.h" | 29 #include "bindings/v8/ExceptionState.h" |
| 30 #include "core/dom/ExecutionContext.h" |
| 30 #include "core/platform/PlatformSpeechSynthesisVoice.h" | 31 #include "core/platform/PlatformSpeechSynthesisVoice.h" |
| 31 #include "core/platform/PlatformSpeechSynthesizer.h" | 32 #include "core/platform/PlatformSpeechSynthesizer.h" |
| 32 #include "modules/speech/SpeechSynthesisEvent.h" | 33 #include "modules/speech/SpeechSynthesisEvent.h" |
| 33 #include "modules/speech/SpeechSynthesisUtterance.h" | 34 #include "modules/speech/SpeechSynthesisUtterance.h" |
| 34 #include "wtf/CurrentTime.h" | 35 #include "wtf/CurrentTime.h" |
| 35 | 36 |
| 36 namespace WebCore { | 37 namespace WebCore { |
| 37 | 38 |
| 38 PassRefPtr<SpeechSynthesis> SpeechSynthesis::create() | 39 PassRefPtr<SpeechSynthesis> SpeechSynthesis::create(ExecutionContext* context) |
| 39 { | 40 { |
| 40 return adoptRef(new SpeechSynthesis()); | 41 return adoptRef(new SpeechSynthesis(context)); |
| 41 } | 42 } |
| 42 | 43 |
| 43 SpeechSynthesis::SpeechSynthesis() | 44 SpeechSynthesis::SpeechSynthesis(ExecutionContext* context) |
| 44 : m_platformSpeechSynthesizer(PlatformSpeechSynthesizer::create(this)) | 45 : ContextLifecycleObserver(context) |
| 46 , m_platformSpeechSynthesizer(PlatformSpeechSynthesizer::create(this)) |
| 45 , m_currentSpeechUtterance(0) | 47 , m_currentSpeechUtterance(0) |
| 46 , m_isPaused(false) | 48 , m_isPaused(false) |
| 47 { | 49 { |
| 48 ScriptWrappable::init(this); | 50 ScriptWrappable::init(this); |
| 49 } | 51 } |
| 50 | 52 |
| 51 void SpeechSynthesis::setPlatformSynthesizer(PassOwnPtr<PlatformSpeechSynthesize
r> synthesizer) | 53 void SpeechSynthesis::setPlatformSynthesizer(PassOwnPtr<PlatformSpeechSynthesize
r> synthesizer) |
| 52 { | 54 { |
| 53 m_platformSpeechSynthesizer = synthesizer; | 55 m_platformSpeechSynthesizer = synthesizer; |
| 54 } | 56 } |
| 55 | 57 |
| 58 ExecutionContext* SpeechSynthesis::executionContext() const |
| 59 { |
| 60 return ContextLifecycleObserver::executionContext(); |
| 61 } |
| 62 |
| 56 void SpeechSynthesis::voicesDidChange() | 63 void SpeechSynthesis::voicesDidChange() |
| 57 { | 64 { |
| 58 m_voiceList.clear(); | 65 m_voiceList.clear(); |
| 66 if (!executionContext()->activeDOMObjectsAreStopped()) |
| 67 dispatchEvent(Event::create(EventTypeNames::voiceschanged)); |
| 59 } | 68 } |
| 60 | 69 |
| 61 const Vector<RefPtr<SpeechSynthesisVoice> >& SpeechSynthesis::getVoices() | 70 const Vector<RefPtr<SpeechSynthesisVoice> >& SpeechSynthesis::getVoices() |
| 62 { | 71 { |
| 63 if (m_voiceList.size()) | 72 if (m_voiceList.size()) |
| 64 return m_voiceList; | 73 return m_voiceList; |
| 65 | 74 |
| 66 // If the voiceList is empty, that's the cue to get the voices from the plat
form again. | 75 // If the voiceList is empty, that's the cue to get the voices from the plat
form again. |
| 67 const Vector<RefPtr<PlatformSpeechSynthesisVoice> >& platformVoices = m_plat
formSpeechSynthesizer->voiceList(); | 76 const Vector<RefPtr<PlatformSpeechSynthesisVoice> >& platformVoices = m_plat
formSpeechSynthesizer->voiceList(); |
| 68 size_t voiceCount = platformVoices.size(); | 77 size_t voiceCount = platformVoices.size(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 | 144 |
| 136 void SpeechSynthesis::resume() | 145 void SpeechSynthesis::resume() |
| 137 { | 146 { |
| 138 if (!m_currentSpeechUtterance) | 147 if (!m_currentSpeechUtterance) |
| 139 return; | 148 return; |
| 140 m_platformSpeechSynthesizer->resume(); | 149 m_platformSpeechSynthesizer->resume(); |
| 141 } | 150 } |
| 142 | 151 |
| 143 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) |
| 144 { | 153 { |
| 145 utterance->dispatchEvent(SpeechSynthesisEvent::create(type, charIndex, (curr
entTime() - utterance->startTime()), name)); | 154 if (!executionContext()->activeDOMObjectsAreStopped()) |
| 155 utterance->dispatchEvent(SpeechSynthesisEvent::create(type, charIndex, (
currentTime() - utterance->startTime()), name)); |
| 146 } | 156 } |
| 147 | 157 |
| 148 void SpeechSynthesis::handleSpeakingCompleted(SpeechSynthesisUtterance* utteranc
e, bool errorOccurred) | 158 void SpeechSynthesis::handleSpeakingCompleted(SpeechSynthesisUtterance* utteranc
e, bool errorOccurred) |
| 149 { | 159 { |
| 150 ASSERT(utterance); | 160 ASSERT(utterance); |
| 151 ASSERT(m_currentSpeechUtterance); | 161 ASSERT(m_currentSpeechUtterance); |
| 152 m_currentSpeechUtterance = 0; | 162 m_currentSpeechUtterance = 0; |
| 153 | 163 |
| 154 fireEvent(errorOccurred ? EventTypeNames::error : EventTypeNames::end, utter
ance, 0, String()); | 164 fireEvent(errorOccurred ? EventTypeNames::error : EventTypeNames::end, utter
ance, 0, String()); |
| 155 | 165 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 if (utterance->client()) | 217 if (utterance->client()) |
| 208 handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance*>(utterance
->client()), false); | 218 handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance*>(utterance
->client()), false); |
| 209 } | 219 } |
| 210 | 220 |
| 211 void SpeechSynthesis::speakingErrorOccurred(PassRefPtr<PlatformSpeechSynthesisUt
terance> utterance) | 221 void SpeechSynthesis::speakingErrorOccurred(PassRefPtr<PlatformSpeechSynthesisUt
terance> utterance) |
| 212 { | 222 { |
| 213 if (utterance->client()) | 223 if (utterance->client()) |
| 214 handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance*>(utterance
->client()), true); | 224 handleSpeakingCompleted(static_cast<SpeechSynthesisUtterance*>(utterance
->client()), true); |
| 215 } | 225 } |
| 216 | 226 |
| 227 const AtomicString& SpeechSynthesis::interfaceName() const |
| 228 { |
| 229 return EventTargetNames::SpeechSynthesisUtterance; |
| 230 } |
| 231 |
| 217 } // namespace WebCore | 232 } // namespace WebCore |
| OLD | NEW |