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