| 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 #ifndef SpeechSynthesis_h | 26 #ifndef SpeechSynthesis_h |
| 27 #define SpeechSynthesis_h | 27 #define SpeechSynthesis_h |
| 28 | 28 |
| 29 #include "core/dom/ContextLifecycleObserver.h" | |
| 30 #include "modules/EventTargetModules.h" | 29 #include "modules/EventTargetModules.h" |
| 31 #include "modules/ModulesExport.h" | 30 #include "modules/ModulesExport.h" |
| 32 #include "modules/speech/SpeechSynthesisUtterance.h" | 31 #include "modules/speech/SpeechSynthesisUtterance.h" |
| 33 #include "modules/speech/SpeechSynthesisVoice.h" | 32 #include "modules/speech/SpeechSynthesisVoice.h" |
| 34 #include "platform/heap/Handle.h" | 33 #include "platform/heap/Handle.h" |
| 35 #include "platform/speech/PlatformSpeechSynthesisUtterance.h" | 34 #include "platform/speech/PlatformSpeechSynthesisUtterance.h" |
| 36 #include "platform/speech/PlatformSpeechSynthesizer.h" | 35 #include "platform/speech/PlatformSpeechSynthesizer.h" |
| 37 | 36 |
| 38 namespace blink { | 37 namespace blink { |
| 39 | 38 |
| 40 class PlatformSpeechSynthesizerClient; | 39 class PlatformSpeechSynthesizerClient; |
| 41 | 40 |
| 42 class MODULES_EXPORT SpeechSynthesis final | 41 class MODULES_EXPORT SpeechSynthesis final |
| 43 : public EventTargetWithInlineData, | 42 : public EventTargetWithInlineData, |
| 44 public PlatformSpeechSynthesizerClient, | 43 public PlatformSpeechSynthesizerClient { |
| 45 public ContextLifecycleObserver { | |
| 46 DEFINE_WRAPPERTYPEINFO(); | 44 DEFINE_WRAPPERTYPEINFO(); |
| 47 USING_GARBAGE_COLLECTED_MIXIN(SpeechSynthesis); | 45 USING_GARBAGE_COLLECTED_MIXIN(SpeechSynthesis); |
| 48 | 46 |
| 49 public: | 47 public: |
| 50 static SpeechSynthesis* create(ExecutionContext*); | 48 static SpeechSynthesis* create(ExecutionContext*); |
| 51 | 49 |
| 52 bool pending() const; | 50 bool pending() const; |
| 53 bool speaking() const; | 51 bool speaking() const; |
| 54 bool paused() const; | 52 bool paused() const; |
| 55 | 53 |
| 56 void speak(SpeechSynthesisUtterance*); | 54 void speak(SpeechSynthesisUtterance*); |
| 57 void cancel(); | 55 void cancel(); |
| 58 void pause(); | 56 void pause(); |
| 59 void resume(); | 57 void resume(); |
| 60 | 58 |
| 61 const HeapVector<Member<SpeechSynthesisVoice>>& getVoices(); | 59 const HeapVector<Member<SpeechSynthesisVoice>>& getVoices(); |
| 62 | 60 |
| 63 // Used in testing to use a mock platform synthesizer | 61 // Used in testing to use a mock platform synthesizer |
| 64 void setPlatformSynthesizer(PlatformSpeechSynthesizer*); | 62 void setPlatformSynthesizer(PlatformSpeechSynthesizer*); |
| 65 | 63 |
| 66 DEFINE_ATTRIBUTE_EVENT_LISTENER(voiceschanged); | 64 DEFINE_ATTRIBUTE_EVENT_LISTENER(voiceschanged); |
| 67 | 65 |
| 68 ExecutionContext* getExecutionContext() const override; | 66 ExecutionContext* getExecutionContext() const override { |
| 67 return m_executionContext; |
| 68 } |
| 69 | 69 |
| 70 DECLARE_VIRTUAL_TRACE(); | 70 DECLARE_VIRTUAL_TRACE(); |
| 71 | 71 |
| 72 private: | 72 private: |
| 73 explicit SpeechSynthesis(ExecutionContext*); | 73 explicit SpeechSynthesis(ExecutionContext*); |
| 74 | 74 |
| 75 // PlatformSpeechSynthesizerClient override methods. | 75 // PlatformSpeechSynthesizerClient override methods. |
| 76 void voicesDidChange() override; | 76 void voicesDidChange() override; |
| 77 void didStartSpeaking(PlatformSpeechSynthesisUtterance*) override; | 77 void didStartSpeaking(PlatformSpeechSynthesisUtterance*) override; |
| 78 void didPauseSpeaking(PlatformSpeechSynthesisUtterance*) override; | 78 void didPauseSpeaking(PlatformSpeechSynthesisUtterance*) override; |
| 79 void didResumeSpeaking(PlatformSpeechSynthesisUtterance*) override; | 79 void didResumeSpeaking(PlatformSpeechSynthesisUtterance*) override; |
| 80 void didFinishSpeaking(PlatformSpeechSynthesisUtterance*) override; | 80 void didFinishSpeaking(PlatformSpeechSynthesisUtterance*) override; |
| 81 void speakingErrorOccurred(PlatformSpeechSynthesisUtterance*) override; | 81 void speakingErrorOccurred(PlatformSpeechSynthesisUtterance*) override; |
| 82 void boundaryEventOccurred(PlatformSpeechSynthesisUtterance*, | 82 void boundaryEventOccurred(PlatformSpeechSynthesisUtterance*, |
| 83 SpeechBoundary, | 83 SpeechBoundary, |
| 84 unsigned charIndex) override; | 84 unsigned charIndex) override; |
| 85 | 85 |
| 86 void startSpeakingImmediately(); | 86 void startSpeakingImmediately(); |
| 87 void handleSpeakingCompleted(SpeechSynthesisUtterance*, bool errorOccurred); | 87 void handleSpeakingCompleted(SpeechSynthesisUtterance*, bool errorOccurred); |
| 88 void fireEvent(const AtomicString& type, | 88 void fireEvent(const AtomicString& type, |
| 89 SpeechSynthesisUtterance*, | 89 SpeechSynthesisUtterance*, |
| 90 unsigned long charIndex, | 90 unsigned long charIndex, |
| 91 const String& name); | 91 const String& name); |
| 92 | 92 |
| 93 // Returns the utterance at the front of the queue. | 93 // Returns the utterance at the front of the queue. |
| 94 SpeechSynthesisUtterance* currentSpeechUtterance() const; | 94 SpeechSynthesisUtterance* currentSpeechUtterance() const; |
| 95 | 95 |
| 96 Member<ExecutionContext> m_executionContext; |
| 96 Member<PlatformSpeechSynthesizer> m_platformSpeechSynthesizer; | 97 Member<PlatformSpeechSynthesizer> m_platformSpeechSynthesizer; |
| 97 HeapVector<Member<SpeechSynthesisVoice>> m_voiceList; | 98 HeapVector<Member<SpeechSynthesisVoice>> m_voiceList; |
| 98 HeapDeque<Member<SpeechSynthesisUtterance>> m_utteranceQueue; | 99 HeapDeque<Member<SpeechSynthesisUtterance>> m_utteranceQueue; |
| 99 bool m_isPaused; | 100 bool m_isPaused; |
| 100 | 101 |
| 101 // EventTarget | 102 // EventTarget |
| 102 const AtomicString& interfaceName() const override; | 103 const AtomicString& interfaceName() const override; |
| 103 }; | 104 }; |
| 104 | 105 |
| 105 } // namespace blink | 106 } // namespace blink |
| 106 | 107 |
| 107 #endif // SpeechSynthesisEvent_h | 108 #endif // SpeechSynthesisEvent_h |
| OLD | NEW |