| 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 19 matching lines...) Expand all Loading... |
| 30 #include "platform/speech/PlatformSpeechSynthesisVoice.h" | 30 #include "platform/speech/PlatformSpeechSynthesisVoice.h" |
| 31 #include "wtf/CurrentTime.h" | 31 #include "wtf/CurrentTime.h" |
| 32 | 32 |
| 33 namespace blink { | 33 namespace blink { |
| 34 | 34 |
| 35 SpeechSynthesis* SpeechSynthesis::create(ExecutionContext* context) { | 35 SpeechSynthesis* SpeechSynthesis::create(ExecutionContext* context) { |
| 36 return new SpeechSynthesis(context); | 36 return new SpeechSynthesis(context); |
| 37 } | 37 } |
| 38 | 38 |
| 39 SpeechSynthesis::SpeechSynthesis(ExecutionContext* context) | 39 SpeechSynthesis::SpeechSynthesis(ExecutionContext* context) |
| 40 : ContextLifecycleObserver(context), | 40 : m_executionContext(context), |
| 41 m_platformSpeechSynthesizer(PlatformSpeechSynthesizer::create(this)), | 41 m_platformSpeechSynthesizer(PlatformSpeechSynthesizer::create(this)), |
| 42 m_isPaused(false) {} | 42 m_isPaused(false) {} |
| 43 | 43 |
| 44 void SpeechSynthesis::setPlatformSynthesizer( | 44 void SpeechSynthesis::setPlatformSynthesizer( |
| 45 PlatformSpeechSynthesizer* synthesizer) { | 45 PlatformSpeechSynthesizer* synthesizer) { |
| 46 m_platformSpeechSynthesizer = synthesizer; | 46 m_platformSpeechSynthesizer = synthesizer; |
| 47 } | 47 } |
| 48 | 48 |
| 49 ExecutionContext* SpeechSynthesis::getExecutionContext() const { | |
| 50 return ContextLifecycleObserver::getExecutionContext(); | |
| 51 } | |
| 52 | |
| 53 void SpeechSynthesis::voicesDidChange() { | 49 void SpeechSynthesis::voicesDidChange() { |
| 54 m_voiceList.clear(); | 50 m_voiceList.clear(); |
| 55 if (getExecutionContext() && !getExecutionContext()->isContextDestroyed()) | 51 if (!m_executionContext->isContextDestroyed()) |
| 56 dispatchEvent(Event::create(EventTypeNames::voiceschanged)); | 52 dispatchEvent(Event::create(EventTypeNames::voiceschanged)); |
| 57 } | 53 } |
| 58 | 54 |
| 59 const HeapVector<Member<SpeechSynthesisVoice>>& SpeechSynthesis::getVoices() { | 55 const HeapVector<Member<SpeechSynthesisVoice>>& SpeechSynthesis::getVoices() { |
| 60 if (m_voiceList.size()) | 56 if (m_voiceList.size()) |
| 61 return m_voiceList; | 57 return m_voiceList; |
| 62 | 58 |
| 63 // If the voiceList is empty, that's the cue to get the voices from the | 59 // If the voiceList is empty, that's the cue to get the voices from the |
| 64 // platform again. | 60 // platform again. |
| 65 const Vector<RefPtr<PlatformSpeechSynthesisVoice>>& platformVoices = | 61 const Vector<RefPtr<PlatformSpeechSynthesisVoice>>& platformVoices = |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 void SpeechSynthesis::resume() { | 119 void SpeechSynthesis::resume() { |
| 124 if (!currentSpeechUtterance()) | 120 if (!currentSpeechUtterance()) |
| 125 return; | 121 return; |
| 126 m_platformSpeechSynthesizer->resume(); | 122 m_platformSpeechSynthesizer->resume(); |
| 127 } | 123 } |
| 128 | 124 |
| 129 void SpeechSynthesis::fireEvent(const AtomicString& type, | 125 void SpeechSynthesis::fireEvent(const AtomicString& type, |
| 130 SpeechSynthesisUtterance* utterance, | 126 SpeechSynthesisUtterance* utterance, |
| 131 unsigned long charIndex, | 127 unsigned long charIndex, |
| 132 const String& name) { | 128 const String& name) { |
| 133 if (getExecutionContext() && !getExecutionContext()->isContextDestroyed()) { | 129 if (!m_executionContext->isContextDestroyed()) { |
| 134 double elapsedTimeMillis = | 130 double elapsedTimeMillis = |
| 135 (monotonicallyIncreasingTime() - utterance->startTime()) * 1000.0; | 131 (monotonicallyIncreasingTime() - utterance->startTime()) * 1000.0; |
| 136 utterance->dispatchEvent(SpeechSynthesisEvent::create( | 132 utterance->dispatchEvent(SpeechSynthesisEvent::create( |
| 137 type, utterance, charIndex, elapsedTimeMillis, name)); | 133 type, utterance, charIndex, elapsedTimeMillis, name)); |
| 138 } | 134 } |
| 139 } | 135 } |
| 140 | 136 |
| 141 void SpeechSynthesis::handleSpeakingCompleted( | 137 void SpeechSynthesis::handleSpeakingCompleted( |
| 142 SpeechSynthesisUtterance* utterance, | 138 SpeechSynthesisUtterance* utterance, |
| 143 bool errorOccurred) { | 139 bool errorOccurred) { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 return nullptr; | 227 return nullptr; |
| 232 | 228 |
| 233 return m_utteranceQueue.first(); | 229 return m_utteranceQueue.first(); |
| 234 } | 230 } |
| 235 | 231 |
| 236 const AtomicString& SpeechSynthesis::interfaceName() const { | 232 const AtomicString& SpeechSynthesis::interfaceName() const { |
| 237 return EventTargetNames::SpeechSynthesis; | 233 return EventTargetNames::SpeechSynthesis; |
| 238 } | 234 } |
| 239 | 235 |
| 240 DEFINE_TRACE(SpeechSynthesis) { | 236 DEFINE_TRACE(SpeechSynthesis) { |
| 237 visitor->trace(m_executionContext); |
| 241 visitor->trace(m_platformSpeechSynthesizer); | 238 visitor->trace(m_platformSpeechSynthesizer); |
| 242 visitor->trace(m_voiceList); | 239 visitor->trace(m_voiceList); |
| 243 visitor->trace(m_utteranceQueue); | 240 visitor->trace(m_utteranceQueue); |
| 244 PlatformSpeechSynthesizerClient::trace(visitor); | 241 PlatformSpeechSynthesizerClient::trace(visitor); |
| 245 EventTargetWithInlineData::trace(visitor); | 242 EventTargetWithInlineData::trace(visitor); |
| 246 ContextLifecycleObserver::trace(visitor); | |
| 247 } | 243 } |
| 248 | 244 |
| 249 } // namespace blink | 245 } // namespace blink |
| OLD | NEW |