|
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 #include "mozilla/dom/SpeechRecognitionResultBinding.h" |
|
9 |
|
10 #include "SpeechRecognition.h" |
|
11 |
|
12 namespace mozilla { |
|
13 namespace dom { |
|
14 |
|
15 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_1(SpeechRecognitionResult, mParent) |
|
16 NS_IMPL_CYCLE_COLLECTING_ADDREF(SpeechRecognitionResult) |
|
17 NS_IMPL_CYCLE_COLLECTING_RELEASE(SpeechRecognitionResult) |
|
18 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SpeechRecognitionResult) |
|
19 NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY |
|
20 NS_INTERFACE_MAP_ENTRY(nsISupports) |
|
21 NS_INTERFACE_MAP_END |
|
22 |
|
23 SpeechRecognitionResult::SpeechRecognitionResult(SpeechRecognition* aParent) |
|
24 : mParent(aParent) |
|
25 { |
|
26 SetIsDOMBinding(); |
|
27 } |
|
28 |
|
29 SpeechRecognitionResult::~SpeechRecognitionResult() |
|
30 { |
|
31 } |
|
32 |
|
33 JSObject* |
|
34 SpeechRecognitionResult::WrapObject(JSContext* aCx) |
|
35 { |
|
36 return SpeechRecognitionResultBinding::Wrap(aCx, this); |
|
37 } |
|
38 |
|
39 nsISupports* |
|
40 SpeechRecognitionResult::GetParentObject() const |
|
41 { |
|
42 return static_cast<DOMEventTargetHelper*>(mParent.get()); |
|
43 } |
|
44 |
|
45 already_AddRefed<SpeechRecognitionAlternative> |
|
46 SpeechRecognitionResult::IndexedGetter(uint32_t aIndex, bool& aPresent) |
|
47 { |
|
48 if (aIndex >= Length()) { |
|
49 aPresent = false; |
|
50 return nullptr; |
|
51 } |
|
52 |
|
53 aPresent = true; |
|
54 return Item(aIndex); |
|
55 } |
|
56 |
|
57 uint32_t |
|
58 SpeechRecognitionResult::Length() const |
|
59 { |
|
60 return mItems.Length(); |
|
61 } |
|
62 |
|
63 already_AddRefed<SpeechRecognitionAlternative> |
|
64 SpeechRecognitionResult::Item(uint32_t aIndex) |
|
65 { |
|
66 nsRefPtr<SpeechRecognitionAlternative> alternative = mItems.ElementAt(aIndex); |
|
67 return alternative.forget(); |
|
68 } |
|
69 |
|
70 bool |
|
71 SpeechRecognitionResult::Final() const |
|
72 { |
|
73 return true; // TODO |
|
74 } |
|
75 } // namespace dom |
|
76 } // namespace mozilla |