SpeechSynthesis.h (2072B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_dom_SpeechSynthesis_h 8 #define mozilla_dom_SpeechSynthesis_h 9 10 #include "SpeechSynthesisUtterance.h" 11 #include "SpeechSynthesisVoice.h" 12 #include "js/TypeDecls.h" 13 #include "nsCOMPtr.h" 14 #include "nsIObserver.h" 15 #include "nsRefPtrHashtable.h" 16 #include "nsString.h" 17 #include "nsWeakReference.h" 18 #include "nsWrapperCache.h" 19 20 class nsIDOMWindow; 21 22 namespace mozilla::dom { 23 24 class nsSpeechTask; 25 26 class SpeechSynthesis final : public DOMEventTargetHelper, 27 public nsIObserver, 28 public nsSupportsWeakReference { 29 public: 30 explicit SpeechSynthesis(nsPIDOMWindowInner* aParent); 31 32 NS_DECL_ISUPPORTS_INHERITED 33 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SpeechSynthesis, 34 DOMEventTargetHelper) 35 NS_DECL_NSIOBSERVER 36 37 JSObject* WrapObject(JSContext* aCx, 38 JS::Handle<JSObject*> aGivenProto) override; 39 40 bool Pending() const; 41 42 bool Speaking() const; 43 44 bool Paused() const; 45 46 bool HasEmptyQueue() const; 47 48 void Speak(SpeechSynthesisUtterance& aUtterance); 49 50 void Cancel(); 51 52 void Pause(); 53 54 void Resume(); 55 56 void OnEnd(const nsSpeechTask* aTask); 57 58 void GetVoices(nsTArray<RefPtr<SpeechSynthesisVoice> >& aResult); 59 60 void ForceEnd(); 61 62 IMPL_EVENT_HANDLER(voiceschanged) 63 64 private: 65 virtual ~SpeechSynthesis(); 66 67 void AdvanceQueue(); 68 69 bool HasVoices() const; 70 71 bool HasSpeakingTask() const { 72 return mCurrentTask && mCurrentTask->IsSpeaking(); 73 } 74 75 nsTArray<RefPtr<SpeechSynthesisUtterance> > mSpeechQueue; 76 77 RefPtr<nsSpeechTask> mCurrentTask; 78 79 nsRefPtrHashtable<nsStringHashKey, SpeechSynthesisVoice> mVoiceCache; 80 81 bool mHoldQueue; 82 83 uint64_t mInnerID; 84 }; 85 86 } // namespace mozilla::dom 87 #endif