|
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 #include "SpeechSynthesis.h" |
|
8 #include "nsSynthVoiceRegistry.h" |
|
9 #include "mozilla/dom/SpeechSynthesisVoiceBinding.h" |
|
10 |
|
11 namespace mozilla { |
|
12 namespace dom { |
|
13 |
|
14 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(SpeechSynthesisVoice, mParent) |
|
15 NS_IMPL_CYCLE_COLLECTING_ADDREF(SpeechSynthesisVoice) |
|
16 NS_IMPL_CYCLE_COLLECTING_RELEASE(SpeechSynthesisVoice) |
|
17 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SpeechSynthesisVoice) |
|
18 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY |
|
19 NS_INTERFACE_MAP_ENTRY(nsISupports) |
|
20 NS_INTERFACE_MAP_END |
|
21 |
|
22 SpeechSynthesisVoice::SpeechSynthesisVoice(nsISupports* aParent, |
|
23 const nsAString& aUri) |
|
24 : mParent(aParent) |
|
25 , mUri(aUri) |
|
26 { |
|
27 SetIsDOMBinding(); |
|
28 } |
|
29 |
|
30 SpeechSynthesisVoice::~SpeechSynthesisVoice() |
|
31 { |
|
32 } |
|
33 |
|
34 JSObject* |
|
35 SpeechSynthesisVoice::WrapObject(JSContext* aCx) |
|
36 { |
|
37 return SpeechSynthesisVoiceBinding::Wrap(aCx, this); |
|
38 } |
|
39 |
|
40 nsISupports* |
|
41 SpeechSynthesisVoice::GetParentObject() const |
|
42 { |
|
43 return mParent; |
|
44 } |
|
45 |
|
46 void |
|
47 SpeechSynthesisVoice::GetVoiceURI(nsString& aRetval) const |
|
48 { |
|
49 aRetval = mUri; |
|
50 } |
|
51 |
|
52 void |
|
53 SpeechSynthesisVoice::GetName(nsString& aRetval) const |
|
54 { |
|
55 DebugOnly<nsresult> rv = |
|
56 nsSynthVoiceRegistry::GetInstance()->GetVoiceName(mUri, aRetval); |
|
57 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed to get SpeechSynthesisVoice.name"); |
|
58 } |
|
59 |
|
60 void |
|
61 SpeechSynthesisVoice::GetLang(nsString& aRetval) const |
|
62 { |
|
63 DebugOnly<nsresult> rv = |
|
64 nsSynthVoiceRegistry::GetInstance()->GetVoiceLang(mUri, aRetval); |
|
65 NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed to get SpeechSynthesisVoice.lang"); |
|
66 } |
|
67 |
|
68 bool |
|
69 SpeechSynthesisVoice::LocalService() const |
|
70 { |
|
71 bool isLocal; |
|
72 DebugOnly<nsresult> rv = |
|
73 nsSynthVoiceRegistry::GetInstance()->IsLocalVoice(mUri, &isLocal); |
|
74 NS_WARN_IF_FALSE( |
|
75 NS_SUCCEEDED(rv), "Failed to get SpeechSynthesisVoice.localService"); |
|
76 |
|
77 return isLocal; |
|
78 } |
|
79 |
|
80 bool |
|
81 SpeechSynthesisVoice::Default() const |
|
82 { |
|
83 bool isDefault; |
|
84 DebugOnly<nsresult> rv = |
|
85 nsSynthVoiceRegistry::GetInstance()->IsDefaultVoice(mUri, &isDefault); |
|
86 NS_WARN_IF_FALSE( |
|
87 NS_SUCCEEDED(rv), "Failed to get SpeechSynthesisVoice.default"); |
|
88 |
|
89 return isDefault; |
|
90 } |
|
91 |
|
92 } // namespace dom |
|
93 } // namespace mozilla |