1926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)/* 2926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * Copyright (C) 2013 Apple Inc. All rights reserved. 3926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * 4926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * Redistribution and use in source and binary forms, with or without 5926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * modification, are permitted provided that the following conditions 6926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * are met: 7926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * 1. Redistributions of source code must retain the above copyright 8926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * notice, this list of conditions and the following disclaimer. 9926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright 10926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * notice, this list of conditions and the following disclaimer in the 11926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * documentation and/or other materials provided with the distribution. 12926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * 13926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) */ 25926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 26926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)#ifndef SpeechSynthesis_h 27926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)#define SpeechSynthesis_h 28926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 29bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)#include "core/dom/ContextLifecycleObserver.h" 30d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles)#include "modules/EventTargetModules.h" 3153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "modules/speech/SpeechSynthesisUtterance.h" 3253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "modules/speech/SpeechSynthesisVoice.h" 3310f88d5669dbd969c059d61ba09fa37dd72ac559Ben Murdoch#include "platform/heap/Handle.h" 34a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/speech/PlatformSpeechSynthesisUtterance.h" 35a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)#include "platform/speech/PlatformSpeechSynthesizer.h" 36926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 37c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink { 3802772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 39bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles)class ExceptionState; 40926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)class PlatformSpeechSynthesizerClient; 4102772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 42197021e6b966cfb06891637935ef33fff06433d1Ben Murdochclass SpeechSynthesis FINAL : public RefCountedGarbageCollectedWillBeGarbageCollectedFinalized<SpeechSynthesis>, public PlatformSpeechSynthesizerClient, public ContextLifecycleObserver, public EventTargetWithInlineData { 435d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) DEFINE_EVENT_TARGET_REFCOUNTING_WILL_BE_REMOVED(RefCountedGarbageCollected<SpeechSynthesis>); 447242dc3dbeb210b5e876a3c42d1ec1a667fc621aPrimiano Tucci DEFINE_WRAPPERTYPEINFO(); 455d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) USING_GARBAGE_COLLECTED_MIXIN(SpeechSynthesis); 46926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)public: 475d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) static SpeechSynthesis* create(ExecutionContext*); 4802772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 49926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) bool pending() const; 50926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) bool speaking() const; 51926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) bool paused() const; 5202772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 53bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) void speak(SpeechSynthesisUtterance*, ExceptionState&); 54926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) void cancel(); 55926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) void pause(); 56926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) void resume(); 5702772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 585d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) const HeapVector<Member<SpeechSynthesisVoice> >& getVoices(); 5902772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 60926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) // Used in testing to use a mock platform synthesizer 615d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) void setPlatformSynthesizer(PlatformSpeechSynthesizer*); 6202772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 63bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) DEFINE_ATTRIBUTE_EVENT_LISTENER(voiceschanged); 64bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 6509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) virtual ExecutionContext* executionContext() const OVERRIDE; 6609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles) 67d6cdb82654e8f3343a693ca752d5c4cee0324e17Torne (Richard Coles) virtual void trace(Visitor*) OVERRIDE; 68bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 69926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)private: 70bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) explicit SpeechSynthesis(ExecutionContext*); 7102772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 72926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) // PlatformSpeechSynthesizerClient override methods. 73926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) virtual void voicesDidChange() OVERRIDE; 745d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) virtual void didStartSpeaking(PlatformSpeechSynthesisUtterance*) OVERRIDE; 755d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) virtual void didPauseSpeaking(PlatformSpeechSynthesisUtterance*) OVERRIDE; 765d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) virtual void didResumeSpeaking(PlatformSpeechSynthesisUtterance*) OVERRIDE; 775d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) virtual void didFinishSpeaking(PlatformSpeechSynthesisUtterance*) OVERRIDE; 785d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) virtual void speakingErrorOccurred(PlatformSpeechSynthesisUtterance*) OVERRIDE; 795d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) virtual void boundaryEventOccurred(PlatformSpeechSynthesisUtterance*, SpeechBoundary, unsigned charIndex) OVERRIDE; 80926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 81d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) void startSpeakingImmediately(); 82926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) void handleSpeakingCompleted(SpeechSynthesisUtterance*, bool errorOccurred); 83926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) void fireEvent(const AtomicString& type, SpeechSynthesisUtterance*, unsigned long charIndex, const String& name); 8402772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 85d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) // Returns the utterance at the front of the queue. 86d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) SpeechSynthesisUtterance* currentSpeechUtterance() const; 87d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles) 885d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) Member<PlatformSpeechSynthesizer> m_platformSpeechSynthesizer; 895d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) HeapVector<Member<SpeechSynthesisVoice> > m_voiceList; 905d92fedcae5e801a8b224de090094f2d9df0b54aTorne (Richard Coles) HeapDeque<Member<SpeechSynthesisUtterance> > m_utteranceQueue; 91926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) bool m_isPaused; 92bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) 93bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) // EventTarget 94bfe3590b1806e3ff18f46ee3af5d4b83078f305aTorne (Richard Coles) virtual const AtomicString& interfaceName() const OVERRIDE; 95926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}; 9602772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch 97c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink 98926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles) 99926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)#endif // SpeechSynthesisEvent_h 100