content/media/webspeech/synth/SpeechSynthesisUtterance.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/webspeech/synth/SpeechSynthesisUtterance.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,171 @@
     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 "nsCOMPtr.h"
    1.11 +#include "nsCycleCollectionParticipant.h"
    1.12 +#include "nsGkAtoms.h"
    1.13 +
    1.14 +#include "GeneratedEvents.h"
    1.15 +#include "nsIDOMSpeechSynthesisEvent.h"
    1.16 +
    1.17 +#include "mozilla/dom/SpeechSynthesisUtteranceBinding.h"
    1.18 +#include "SpeechSynthesisUtterance.h"
    1.19 +#include "SpeechSynthesisVoice.h"
    1.20 +
    1.21 +namespace mozilla {
    1.22 +namespace dom {
    1.23 +
    1.24 +NS_IMPL_CYCLE_COLLECTION_INHERITED(SpeechSynthesisUtterance,
    1.25 +                                   DOMEventTargetHelper, mVoice);
    1.26 +
    1.27 +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(SpeechSynthesisUtterance)
    1.28 +  NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
    1.29 +NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
    1.30 +
    1.31 +NS_IMPL_ADDREF_INHERITED(SpeechSynthesisUtterance, DOMEventTargetHelper)
    1.32 +NS_IMPL_RELEASE_INHERITED(SpeechSynthesisUtterance, DOMEventTargetHelper)
    1.33 +
    1.34 +SpeechSynthesisUtterance::SpeechSynthesisUtterance(nsPIDOMWindow* aOwnerWindow,
    1.35 +                                                   const nsAString& text)
    1.36 +  : DOMEventTargetHelper(aOwnerWindow)
    1.37 +  , mText(text)
    1.38 +  , mVolume(1)
    1.39 +  , mRate(1)
    1.40 +  , mPitch(1)
    1.41 +  , mState(STATE_NONE)
    1.42 +  , mPaused(false)
    1.43 +{
    1.44 +  SetIsDOMBinding();
    1.45 +}
    1.46 +
    1.47 +SpeechSynthesisUtterance::~SpeechSynthesisUtterance() {}
    1.48 +
    1.49 +JSObject*
    1.50 +SpeechSynthesisUtterance::WrapObject(JSContext* aCx)
    1.51 +{
    1.52 +  return SpeechSynthesisUtteranceBinding::Wrap(aCx, this);
    1.53 +}
    1.54 +
    1.55 +nsISupports*
    1.56 +SpeechSynthesisUtterance::GetParentObject() const
    1.57 +{
    1.58 +  return GetOwner();
    1.59 +}
    1.60 +
    1.61 +already_AddRefed<SpeechSynthesisUtterance>
    1.62 +SpeechSynthesisUtterance::Constructor(GlobalObject& aGlobal,
    1.63 +                                      ErrorResult& aRv)
    1.64 +{
    1.65 +  return Constructor(aGlobal, NS_LITERAL_STRING(""), aRv);
    1.66 +}
    1.67 +
    1.68 +already_AddRefed<SpeechSynthesisUtterance>
    1.69 +SpeechSynthesisUtterance::Constructor(GlobalObject& aGlobal,
    1.70 +                                      const nsAString& aText,
    1.71 +                                      ErrorResult& aRv)
    1.72 +{
    1.73 +  nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(aGlobal.GetAsSupports());
    1.74 +
    1.75 +  if (!win) {
    1.76 +    aRv.Throw(NS_ERROR_FAILURE);
    1.77 +  }
    1.78 +
    1.79 +  MOZ_ASSERT(win->IsInnerWindow());
    1.80 +  nsRefPtr<SpeechSynthesisUtterance> object =
    1.81 +    new SpeechSynthesisUtterance(win, aText);
    1.82 +  return object.forget();
    1.83 +}
    1.84 +
    1.85 +void
    1.86 +SpeechSynthesisUtterance::GetText(nsString& aResult) const
    1.87 +{
    1.88 +  aResult = mText;
    1.89 +}
    1.90 +
    1.91 +void
    1.92 +SpeechSynthesisUtterance::SetText(const nsAString& aText)
    1.93 +{
    1.94 +  mText = aText;
    1.95 +}
    1.96 +
    1.97 +void
    1.98 +SpeechSynthesisUtterance::GetLang(nsString& aResult) const
    1.99 +{
   1.100 +  aResult = mLang;
   1.101 +}
   1.102 +
   1.103 +void
   1.104 +SpeechSynthesisUtterance::SetLang(const nsAString& aLang)
   1.105 +{
   1.106 +  mLang = aLang;
   1.107 +}
   1.108 +
   1.109 +SpeechSynthesisVoice*
   1.110 +SpeechSynthesisUtterance::GetVoice() const
   1.111 +{
   1.112 +  return mVoice;
   1.113 +}
   1.114 +
   1.115 +void
   1.116 +SpeechSynthesisUtterance::SetVoice(SpeechSynthesisVoice* aVoice)
   1.117 +{
   1.118 +  mVoice = aVoice;
   1.119 +}
   1.120 +
   1.121 +float
   1.122 +SpeechSynthesisUtterance::Volume() const
   1.123 +{
   1.124 +  return mVolume;
   1.125 +}
   1.126 +
   1.127 +void
   1.128 +SpeechSynthesisUtterance::SetVolume(float aVolume)
   1.129 +{
   1.130 +  mVolume = aVolume;
   1.131 +}
   1.132 +
   1.133 +float
   1.134 +SpeechSynthesisUtterance::Rate() const
   1.135 +{
   1.136 +  return mRate;
   1.137 +}
   1.138 +
   1.139 +void
   1.140 +SpeechSynthesisUtterance::SetRate(float aRate)
   1.141 +{
   1.142 +  mRate = aRate;
   1.143 +}
   1.144 +
   1.145 +float
   1.146 +SpeechSynthesisUtterance::Pitch() const
   1.147 +{
   1.148 +  return mPitch;
   1.149 +}
   1.150 +
   1.151 +void
   1.152 +SpeechSynthesisUtterance::SetPitch(float aPitch)
   1.153 +{
   1.154 +  mPitch = aPitch;
   1.155 +}
   1.156 +
   1.157 +void
   1.158 +SpeechSynthesisUtterance::DispatchSpeechSynthesisEvent(const nsAString& aEventType,
   1.159 +                                                       uint32_t aCharIndex,
   1.160 +                                                       float aElapsedTime,
   1.161 +                                                       const nsAString& aName)
   1.162 +{
   1.163 +  nsCOMPtr<nsIDOMEvent> domEvent;
   1.164 +  NS_NewDOMSpeechSynthesisEvent(getter_AddRefs(domEvent), nullptr, nullptr, nullptr);
   1.165 +
   1.166 +  nsCOMPtr<nsIDOMSpeechSynthesisEvent> ssEvent = do_QueryInterface(domEvent);
   1.167 +  ssEvent->InitSpeechSynthesisEvent(aEventType, false, false,
   1.168 +                                    aCharIndex, aElapsedTime, aName);
   1.169 +
   1.170 +  DispatchTrustedEvent(domEvent);
   1.171 +}
   1.172 +
   1.173 +} // namespace dom
   1.174 +} // namespace mozilla

mercurial