michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et cindent: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsCOMPtr.h" michael@0: #include "nsCycleCollectionParticipant.h" michael@0: #include "nsGkAtoms.h" michael@0: michael@0: #include "GeneratedEvents.h" michael@0: #include "nsIDOMSpeechSynthesisEvent.h" michael@0: michael@0: #include "mozilla/dom/SpeechSynthesisUtteranceBinding.h" michael@0: #include "SpeechSynthesisUtterance.h" michael@0: #include "SpeechSynthesisVoice.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: NS_IMPL_CYCLE_COLLECTION_INHERITED(SpeechSynthesisUtterance, michael@0: DOMEventTargetHelper, mVoice); michael@0: michael@0: NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(SpeechSynthesisUtterance) michael@0: NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY michael@0: NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper) michael@0: michael@0: NS_IMPL_ADDREF_INHERITED(SpeechSynthesisUtterance, DOMEventTargetHelper) michael@0: NS_IMPL_RELEASE_INHERITED(SpeechSynthesisUtterance, DOMEventTargetHelper) michael@0: michael@0: SpeechSynthesisUtterance::SpeechSynthesisUtterance(nsPIDOMWindow* aOwnerWindow, michael@0: const nsAString& text) michael@0: : DOMEventTargetHelper(aOwnerWindow) michael@0: , mText(text) michael@0: , mVolume(1) michael@0: , mRate(1) michael@0: , mPitch(1) michael@0: , mState(STATE_NONE) michael@0: , mPaused(false) michael@0: { michael@0: SetIsDOMBinding(); michael@0: } michael@0: michael@0: SpeechSynthesisUtterance::~SpeechSynthesisUtterance() {} michael@0: michael@0: JSObject* michael@0: SpeechSynthesisUtterance::WrapObject(JSContext* aCx) michael@0: { michael@0: return SpeechSynthesisUtteranceBinding::Wrap(aCx, this); michael@0: } michael@0: michael@0: nsISupports* michael@0: SpeechSynthesisUtterance::GetParentObject() const michael@0: { michael@0: return GetOwner(); michael@0: } michael@0: michael@0: already_AddRefed michael@0: SpeechSynthesisUtterance::Constructor(GlobalObject& aGlobal, michael@0: ErrorResult& aRv) michael@0: { michael@0: return Constructor(aGlobal, NS_LITERAL_STRING(""), aRv); michael@0: } michael@0: michael@0: already_AddRefed michael@0: SpeechSynthesisUtterance::Constructor(GlobalObject& aGlobal, michael@0: const nsAString& aText, michael@0: ErrorResult& aRv) michael@0: { michael@0: nsCOMPtr win = do_QueryInterface(aGlobal.GetAsSupports()); michael@0: michael@0: if (!win) { michael@0: aRv.Throw(NS_ERROR_FAILURE); michael@0: } michael@0: michael@0: MOZ_ASSERT(win->IsInnerWindow()); michael@0: nsRefPtr object = michael@0: new SpeechSynthesisUtterance(win, aText); michael@0: return object.forget(); michael@0: } michael@0: michael@0: void michael@0: SpeechSynthesisUtterance::GetText(nsString& aResult) const michael@0: { michael@0: aResult = mText; michael@0: } michael@0: michael@0: void michael@0: SpeechSynthesisUtterance::SetText(const nsAString& aText) michael@0: { michael@0: mText = aText; michael@0: } michael@0: michael@0: void michael@0: SpeechSynthesisUtterance::GetLang(nsString& aResult) const michael@0: { michael@0: aResult = mLang; michael@0: } michael@0: michael@0: void michael@0: SpeechSynthesisUtterance::SetLang(const nsAString& aLang) michael@0: { michael@0: mLang = aLang; michael@0: } michael@0: michael@0: SpeechSynthesisVoice* michael@0: SpeechSynthesisUtterance::GetVoice() const michael@0: { michael@0: return mVoice; michael@0: } michael@0: michael@0: void michael@0: SpeechSynthesisUtterance::SetVoice(SpeechSynthesisVoice* aVoice) michael@0: { michael@0: mVoice = aVoice; michael@0: } michael@0: michael@0: float michael@0: SpeechSynthesisUtterance::Volume() const michael@0: { michael@0: return mVolume; michael@0: } michael@0: michael@0: void michael@0: SpeechSynthesisUtterance::SetVolume(float aVolume) michael@0: { michael@0: mVolume = aVolume; michael@0: } michael@0: michael@0: float michael@0: SpeechSynthesisUtterance::Rate() const michael@0: { michael@0: return mRate; michael@0: } michael@0: michael@0: void michael@0: SpeechSynthesisUtterance::SetRate(float aRate) michael@0: { michael@0: mRate = aRate; michael@0: } michael@0: michael@0: float michael@0: SpeechSynthesisUtterance::Pitch() const michael@0: { michael@0: return mPitch; michael@0: } michael@0: michael@0: void michael@0: SpeechSynthesisUtterance::SetPitch(float aPitch) michael@0: { michael@0: mPitch = aPitch; michael@0: } michael@0: michael@0: void michael@0: SpeechSynthesisUtterance::DispatchSpeechSynthesisEvent(const nsAString& aEventType, michael@0: uint32_t aCharIndex, michael@0: float aElapsedTime, michael@0: const nsAString& aName) michael@0: { michael@0: nsCOMPtr domEvent; michael@0: NS_NewDOMSpeechSynthesisEvent(getter_AddRefs(domEvent), nullptr, nullptr, nullptr); michael@0: michael@0: nsCOMPtr ssEvent = do_QueryInterface(domEvent); michael@0: ssEvent->InitSpeechSynthesisEvent(aEventType, false, false, michael@0: aCharIndex, aElapsedTime, aName); michael@0: michael@0: DispatchTrustedEvent(domEvent); michael@0: } michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla