SpeechSynthesisUtterance.h (2908B)
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_SpeechSynthesisUtterance_h 8 #define mozilla_dom_SpeechSynthesisUtterance_h 9 10 #include "js/TypeDecls.h" 11 #include "mozilla/DOMEventTargetHelper.h" 12 #include "nsCOMPtr.h" 13 #include "nsSpeechTask.h" 14 #include "nsString.h" 15 16 namespace mozilla::dom { 17 18 class SpeechSynthesisVoice; 19 class SpeechSynthesis; 20 class nsSynthVoiceRegistry; 21 22 class SpeechSynthesisUtterance final : public DOMEventTargetHelper { 23 friend class SpeechSynthesis; 24 friend class nsSpeechTask; 25 friend class nsSynthVoiceRegistry; 26 27 public: 28 SpeechSynthesisUtterance(nsPIDOMWindowInner* aOwnerWindow, 29 const nsAString& aText); 30 31 NS_DECL_ISUPPORTS_INHERITED 32 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SpeechSynthesisUtterance, 33 DOMEventTargetHelper) 34 35 nsISupports* GetParentObject() const; 36 37 JSObject* WrapObject(JSContext* aCx, 38 JS::Handle<JSObject*> aGivenProto) override; 39 40 static already_AddRefed<SpeechSynthesisUtterance> Constructor( 41 GlobalObject& aGlobal, ErrorResult& aRv); 42 static already_AddRefed<SpeechSynthesisUtterance> Constructor( 43 GlobalObject& aGlobal, const nsAString& aText, ErrorResult& aRv); 44 45 void GetText(nsString& aResult) const; 46 47 void SetText(const nsAString& aText); 48 49 void GetLang(nsString& aResult) const; 50 51 void SetLang(const nsAString& aLang); 52 53 SpeechSynthesisVoice* GetVoice() const; 54 55 void SetVoice(SpeechSynthesisVoice* aVoice); 56 57 float Volume() const; 58 59 void SetVolume(float aVolume); 60 61 float Rate() const; 62 63 void SetRate(float aRate); 64 65 float Pitch() const; 66 67 void SetPitch(float aPitch); 68 69 void GetChosenVoiceURI(nsString& aResult) const; 70 71 bool IsPaused() { return mPaused; } 72 73 bool ShouldResistFingerprinting() const { 74 return mShouldResistFingerprinting; 75 } 76 77 IMPL_EVENT_HANDLER(start) 78 IMPL_EVENT_HANDLER(end) 79 IMPL_EVENT_HANDLER(error) 80 IMPL_EVENT_HANDLER(pause) 81 IMPL_EVENT_HANDLER(resume) 82 IMPL_EVENT_HANDLER(mark) 83 IMPL_EVENT_HANDLER(boundary) 84 85 private: 86 virtual ~SpeechSynthesisUtterance(); 87 88 void DispatchSpeechSynthesisEvent(const nsAString& aEventType, 89 uint32_t aCharIndex, 90 const Nullable<uint32_t>& aCharLength, 91 float aElapsedTime, const nsAString& aName); 92 93 nsString mText; 94 95 nsString mLang; 96 97 float mVolume; 98 99 float mRate; 100 101 float mPitch; 102 103 nsString mChosenVoiceURI; 104 105 bool mPaused; 106 107 RefPtr<SpeechSynthesisVoice> mVoice; 108 109 bool mShouldResistFingerprinting; 110 }; 111 112 } // namespace mozilla::dom 113 114 #endif