Bug 1943761 - Add class alignment to the mozsearch analysis file. r=asuth
[gecko.git] / dom / media / webspeech / synth / nsSpeechTask.h
blobfc121cf8f1d62ec2431293587909f36784a8e169
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/. */
7 #ifndef mozilla_dom_nsSpeechTask_h
8 #define mozilla_dom_nsSpeechTask_h
10 #include "SpeechSynthesisUtterance.h"
11 #include "AudioChannelAgent.h"
12 #include "nsISpeechService.h"
13 #include "nsWeakReference.h"
15 namespace mozilla {
17 class SharedBuffer;
19 namespace dom {
21 class SpeechSynthesisUtterance;
22 class SpeechSynthesis;
24 class nsSpeechTask : public nsISpeechTask,
25 public nsIAudioChannelAgentCallback,
26 public nsSupportsWeakReference {
27 public:
28 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
29 NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsSpeechTask, nsISpeechTask)
31 NS_DECL_NSISPEECHTASK
32 NS_DECL_NSIAUDIOCHANNELAGENTCALLBACK
34 explicit nsSpeechTask(SpeechSynthesisUtterance* aUtterance,
35 bool aShouldResistFingerprinting);
36 nsSpeechTask(float aVolume, const nsAString& aText,
37 bool aShouldResistFingerprinting);
39 virtual void Pause();
41 virtual void Resume();
43 virtual void Cancel();
45 virtual void ForceEnd();
47 void SetSpeechSynthesis(SpeechSynthesis* aSpeechSynthesis);
49 void Init();
51 void SetChosenVoiceURI(const nsAString& aUri);
53 virtual void SetAudioOutputVolume(float aVolume);
55 void ForceError(float aElapsedTime, uint32_t aCharIndex);
57 bool IsPreCanceled() { return mPreCanceled; };
59 bool IsPrePaused() { return mPrePaused; }
61 bool ShouldResistFingerprinting() { return mShouldResistFingerprinting; }
63 enum { STATE_PENDING, STATE_SPEAKING, STATE_ENDED };
65 uint32_t GetState() const { return mState; }
67 bool IsSpeaking() const { return mState == STATE_SPEAKING; }
69 bool IsPending() const { return mState == STATE_PENDING; }
71 protected:
72 virtual ~nsSpeechTask();
74 nsresult DispatchStartImpl();
76 virtual nsresult DispatchStartImpl(const nsAString& aUri);
78 virtual nsresult DispatchEndImpl(float aElapsedTime, uint32_t aCharIndex);
80 virtual nsresult DispatchPauseImpl(float aElapsedTime, uint32_t aCharIndex);
82 virtual nsresult DispatchResumeImpl(float aElapsedTime, uint32_t aCharIndex);
84 virtual nsresult DispatchErrorImpl(float aElapsedTime, uint32_t aCharIndex);
86 virtual nsresult DispatchBoundaryImpl(const nsAString& aName,
87 float aElapsedTime, uint32_t aCharIndex,
88 uint32_t aCharLength, uint8_t argc);
90 virtual nsresult DispatchMarkImpl(const nsAString& aName, float aElapsedTime,
91 uint32_t aCharIndex);
93 RefPtr<SpeechSynthesisUtterance> mUtterance;
95 float mVolume;
97 nsString mText;
99 bool mInited;
101 bool mPrePaused;
103 bool mPreCanceled;
105 private:
106 void End();
108 void CreateAudioChannelAgent();
110 void DestroyAudioChannelAgent();
112 nsCOMPtr<nsISpeechTaskCallback> mCallback;
114 RefPtr<mozilla::dom::AudioChannelAgent> mAudioChannelAgent;
116 RefPtr<SpeechSynthesis> mSpeechSynthesis;
118 nsString mChosenVoiceURI;
120 bool mShouldResistFingerprinting;
122 uint32_t mState;
125 } // namespace dom
126 } // namespace mozilla
128 #endif