SpeechRecognitionResult.cpp (1932B)
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 "SpeechRecognitionResult.h" 8 9 #include "SpeechRecognition.h" 10 #include "mozilla/dom/SpeechRecognitionResultBinding.h" 11 12 namespace mozilla::dom { 13 14 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(SpeechRecognitionResult, mParent) 15 NS_IMPL_CYCLE_COLLECTING_ADDREF(SpeechRecognitionResult) 16 NS_IMPL_CYCLE_COLLECTING_RELEASE(SpeechRecognitionResult) 17 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SpeechRecognitionResult) 18 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY 19 NS_INTERFACE_MAP_ENTRY(nsISupports) 20 NS_INTERFACE_MAP_END 21 22 SpeechRecognitionResult::SpeechRecognitionResult(SpeechRecognition* aParent) 23 : mParent(aParent) {} 24 25 SpeechRecognitionResult::~SpeechRecognitionResult() = default; 26 27 JSObject* SpeechRecognitionResult::WrapObject( 28 JSContext* aCx, JS::Handle<JSObject*> aGivenProto) { 29 return SpeechRecognitionResult_Binding::Wrap(aCx, this, aGivenProto); 30 } 31 32 nsISupports* SpeechRecognitionResult::GetParentObject() const { 33 return static_cast<EventTarget*>(mParent.get()); 34 } 35 36 already_AddRefed<SpeechRecognitionAlternative> 37 SpeechRecognitionResult::IndexedGetter(uint32_t aIndex, bool& aPresent) { 38 if (aIndex >= Length()) { 39 aPresent = false; 40 return nullptr; 41 } 42 43 aPresent = true; 44 return Item(aIndex); 45 } 46 47 uint32_t SpeechRecognitionResult::Length() const { return mItems.Length(); } 48 49 already_AddRefed<SpeechRecognitionAlternative> SpeechRecognitionResult::Item( 50 uint32_t aIndex) { 51 RefPtr<SpeechRecognitionAlternative> alternative = mItems.ElementAt(aIndex); 52 return alternative.forget(); 53 } 54 55 bool SpeechRecognitionResult::IsFinal() const { 56 return true; // TODO 57 } 58 59 } // namespace mozilla::dom