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