SpeechRecognitionError.cpp (1745B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 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 "SpeechRecognitionError.h" 8 9 namespace mozilla::dom { 10 11 SpeechRecognitionError::SpeechRecognitionError( 12 mozilla::dom::EventTarget* aOwner, nsPresContext* aPresContext, 13 WidgetEvent* aEvent) 14 : Event(aOwner, aPresContext, aEvent), mError() {} 15 16 SpeechRecognitionError::~SpeechRecognitionError() = default; 17 18 already_AddRefed<SpeechRecognitionError> SpeechRecognitionError::Constructor( 19 const GlobalObject& aGlobal, const nsAString& aType, 20 const SpeechRecognitionErrorInit& aParam) { 21 nsCOMPtr<mozilla::dom::EventTarget> t = 22 do_QueryInterface(aGlobal.GetAsSupports()); 23 RefPtr<SpeechRecognitionError> e = 24 new SpeechRecognitionError(t, nullptr, nullptr); 25 bool trusted = e->Init(t); 26 e->InitSpeechRecognitionError(aType, aParam.mBubbles, aParam.mCancelable, 27 aParam.mError, 28 NS_ConvertUTF16toUTF8(aParam.mMessage)); 29 e->SetTrusted(trusted); 30 e->SetComposed(aParam.mComposed); 31 return e.forget(); 32 } 33 34 void SpeechRecognitionError::GetMessage(nsAString& aString) { 35 CopyUTF8toUTF16(mMessage, aString); 36 } 37 38 void SpeechRecognitionError::InitSpeechRecognitionError( 39 const nsAString& aType, bool aCanBubble, bool aCancelable, 40 SpeechRecognitionErrorCode aError, const nsACString& aMessage) { 41 Event::InitEvent(aType, aCanBubble, aCancelable); 42 mError = aError; 43 mMessage = aMessage; 44 } 45 46 } // namespace mozilla::dom