1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/webspeech/synth/SpeechSynthesisVoice.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,93 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "SpeechSynthesis.h" 1.11 +#include "nsSynthVoiceRegistry.h" 1.12 +#include "mozilla/dom/SpeechSynthesisVoiceBinding.h" 1.13 + 1.14 +namespace mozilla { 1.15 +namespace dom { 1.16 + 1.17 +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(SpeechSynthesisVoice, mParent) 1.18 +NS_IMPL_CYCLE_COLLECTING_ADDREF(SpeechSynthesisVoice) 1.19 +NS_IMPL_CYCLE_COLLECTING_RELEASE(SpeechSynthesisVoice) 1.20 +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SpeechSynthesisVoice) 1.21 + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY 1.22 + NS_INTERFACE_MAP_ENTRY(nsISupports) 1.23 +NS_INTERFACE_MAP_END 1.24 + 1.25 +SpeechSynthesisVoice::SpeechSynthesisVoice(nsISupports* aParent, 1.26 + const nsAString& aUri) 1.27 + : mParent(aParent) 1.28 + , mUri(aUri) 1.29 +{ 1.30 + SetIsDOMBinding(); 1.31 +} 1.32 + 1.33 +SpeechSynthesisVoice::~SpeechSynthesisVoice() 1.34 +{ 1.35 +} 1.36 + 1.37 +JSObject* 1.38 +SpeechSynthesisVoice::WrapObject(JSContext* aCx) 1.39 +{ 1.40 + return SpeechSynthesisVoiceBinding::Wrap(aCx, this); 1.41 +} 1.42 + 1.43 +nsISupports* 1.44 +SpeechSynthesisVoice::GetParentObject() const 1.45 +{ 1.46 + return mParent; 1.47 +} 1.48 + 1.49 +void 1.50 +SpeechSynthesisVoice::GetVoiceURI(nsString& aRetval) const 1.51 +{ 1.52 + aRetval = mUri; 1.53 +} 1.54 + 1.55 +void 1.56 +SpeechSynthesisVoice::GetName(nsString& aRetval) const 1.57 +{ 1.58 + DebugOnly<nsresult> rv = 1.59 + nsSynthVoiceRegistry::GetInstance()->GetVoiceName(mUri, aRetval); 1.60 + NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed to get SpeechSynthesisVoice.name"); 1.61 +} 1.62 + 1.63 +void 1.64 +SpeechSynthesisVoice::GetLang(nsString& aRetval) const 1.65 +{ 1.66 + DebugOnly<nsresult> rv = 1.67 + nsSynthVoiceRegistry::GetInstance()->GetVoiceLang(mUri, aRetval); 1.68 + NS_WARN_IF_FALSE(NS_SUCCEEDED(rv), "Failed to get SpeechSynthesisVoice.lang"); 1.69 +} 1.70 + 1.71 +bool 1.72 +SpeechSynthesisVoice::LocalService() const 1.73 +{ 1.74 + bool isLocal; 1.75 + DebugOnly<nsresult> rv = 1.76 + nsSynthVoiceRegistry::GetInstance()->IsLocalVoice(mUri, &isLocal); 1.77 + NS_WARN_IF_FALSE( 1.78 + NS_SUCCEEDED(rv), "Failed to get SpeechSynthesisVoice.localService"); 1.79 + 1.80 + return isLocal; 1.81 +} 1.82 + 1.83 +bool 1.84 +SpeechSynthesisVoice::Default() const 1.85 +{ 1.86 + bool isDefault; 1.87 + DebugOnly<nsresult> rv = 1.88 + nsSynthVoiceRegistry::GetInstance()->IsDefaultVoice(mUri, &isDefault); 1.89 + NS_WARN_IF_FALSE( 1.90 + NS_SUCCEEDED(rv), "Failed to get SpeechSynthesisVoice.default"); 1.91 + 1.92 + return isDefault; 1.93 +} 1.94 + 1.95 +} // namespace dom 1.96 +} // namespace mozilla