1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/webspeech/recognition/SpeechRecognitionResult.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 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 "SpeechRecognitionResult.h" 1.11 +#include "mozilla/dom/SpeechRecognitionResultBinding.h" 1.12 + 1.13 +#include "SpeechRecognition.h" 1.14 + 1.15 +namespace mozilla { 1.16 +namespace dom { 1.17 + 1.18 +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(SpeechRecognitionResult, mParent) 1.19 +NS_IMPL_CYCLE_COLLECTING_ADDREF(SpeechRecognitionResult) 1.20 +NS_IMPL_CYCLE_COLLECTING_RELEASE(SpeechRecognitionResult) 1.21 +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SpeechRecognitionResult) 1.22 + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY 1.23 + NS_INTERFACE_MAP_ENTRY(nsISupports) 1.24 +NS_INTERFACE_MAP_END 1.25 + 1.26 +SpeechRecognitionResult::SpeechRecognitionResult(SpeechRecognition* aParent) 1.27 + : mParent(aParent) 1.28 +{ 1.29 + SetIsDOMBinding(); 1.30 +} 1.31 + 1.32 +SpeechRecognitionResult::~SpeechRecognitionResult() 1.33 +{ 1.34 +} 1.35 + 1.36 +JSObject* 1.37 +SpeechRecognitionResult::WrapObject(JSContext* aCx) 1.38 +{ 1.39 + return SpeechRecognitionResultBinding::Wrap(aCx, this); 1.40 +} 1.41 + 1.42 +nsISupports* 1.43 +SpeechRecognitionResult::GetParentObject() const 1.44 +{ 1.45 + return static_cast<DOMEventTargetHelper*>(mParent.get()); 1.46 +} 1.47 + 1.48 +already_AddRefed<SpeechRecognitionAlternative> 1.49 +SpeechRecognitionResult::IndexedGetter(uint32_t aIndex, bool& aPresent) 1.50 +{ 1.51 + if (aIndex >= Length()) { 1.52 + aPresent = false; 1.53 + return nullptr; 1.54 + } 1.55 + 1.56 + aPresent = true; 1.57 + return Item(aIndex); 1.58 +} 1.59 + 1.60 +uint32_t 1.61 +SpeechRecognitionResult::Length() const 1.62 +{ 1.63 + return mItems.Length(); 1.64 +} 1.65 + 1.66 +already_AddRefed<SpeechRecognitionAlternative> 1.67 +SpeechRecognitionResult::Item(uint32_t aIndex) 1.68 +{ 1.69 + nsRefPtr<SpeechRecognitionAlternative> alternative = mItems.ElementAt(aIndex); 1.70 + return alternative.forget(); 1.71 +} 1.72 + 1.73 +bool 1.74 +SpeechRecognitionResult::Final() const 1.75 +{ 1.76 + return true; // TODO 1.77 +} 1.78 +} // namespace dom 1.79 +} // namespace mozilla