Line data Source code
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 "nsCOMPtr.h"
11 : #include "nsIObserver.h"
12 : #include "nsRefPtrHashtable.h"
13 : #include "nsString.h"
14 : #include "nsWeakReference.h"
15 : #include "nsWrapperCache.h"
16 : #include "js/TypeDecls.h"
17 :
18 : #include "SpeechSynthesisUtterance.h"
19 : #include "SpeechSynthesisVoice.h"
20 :
21 : class nsIDOMWindow;
22 :
23 : namespace mozilla {
24 : namespace dom {
25 :
26 : class nsSpeechTask;
27 :
28 : class SpeechSynthesis final : public DOMEventTargetHelper
29 : , public nsIObserver
30 : , public nsSupportsWeakReference
31 : {
32 : public:
33 : explicit SpeechSynthesis(nsPIDOMWindowInner* aParent);
34 :
35 : NS_DECL_ISUPPORTS_INHERITED
36 0 : NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(SpeechSynthesis, DOMEventTargetHelper)
37 : NS_DECL_NSIOBSERVER
38 :
39 : JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
40 :
41 : bool Pending() const;
42 :
43 : bool Speaking() const;
44 :
45 : bool Paused() const;
46 :
47 : bool HasEmptyQueue() const;
48 :
49 : void Speak(SpeechSynthesisUtterance& aUtterance);
50 :
51 : void Cancel();
52 :
53 : void Pause();
54 :
55 : void Resume();
56 :
57 : void OnEnd(const nsSpeechTask* aTask);
58 :
59 : void GetVoices(nsTArray< RefPtr<SpeechSynthesisVoice> >& aResult);
60 :
61 : void ForceEnd();
62 :
63 0 : IMPL_EVENT_HANDLER(voiceschanged)
64 :
65 : private:
66 : virtual ~SpeechSynthesis();
67 :
68 : void AdvanceQueue();
69 :
70 : bool HasVoices() const;
71 :
72 : nsTArray<RefPtr<SpeechSynthesisUtterance> > mSpeechQueue;
73 :
74 : RefPtr<nsSpeechTask> mCurrentTask;
75 :
76 : nsRefPtrHashtable<nsStringHashKey, SpeechSynthesisVoice> mVoiceCache;
77 :
78 : bool mHoldQueue;
79 :
80 : uint64_t mInnerID;
81 : };
82 :
83 : } // namespace dom
84 : } // namespace mozilla
85 : #endif
|