1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/TextTrackCueList.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,116 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "mozilla/dom/TextTrackCueList.h" 1.10 +#include "mozilla/dom/TextTrackCueListBinding.h" 1.11 +#include "mozilla/dom/TextTrackCue.h" 1.12 + 1.13 +namespace mozilla { 1.14 +namespace dom { 1.15 + 1.16 +class CompareCuesByTime 1.17 +{ 1.18 +public: 1.19 + bool Equals(TextTrackCue* aOne, TextTrackCue* aTwo) const { 1.20 + return aOne->StartTime() == aTwo->StartTime() && 1.21 + aOne->EndTime() == aTwo->EndTime(); 1.22 + } 1.23 + bool LessThan(TextTrackCue* aOne, TextTrackCue* aTwo) const { 1.24 + return aOne->StartTime() < aTwo->StartTime() || 1.25 + (aOne->StartTime() == aTwo->StartTime() && 1.26 + aOne->EndTime() < aTwo->EndTime()); 1.27 + } 1.28 +}; 1.29 + 1.30 +NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_2(TextTrackCueList, mParent, mList) 1.31 + 1.32 +NS_IMPL_CYCLE_COLLECTING_ADDREF(TextTrackCueList) 1.33 +NS_IMPL_CYCLE_COLLECTING_RELEASE(TextTrackCueList) 1.34 +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TextTrackCueList) 1.35 + NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY 1.36 + NS_INTERFACE_MAP_ENTRY(nsISupports) 1.37 +NS_INTERFACE_MAP_END 1.38 + 1.39 +TextTrackCueList::TextTrackCueList(nsISupports* aParent) : mParent(aParent) 1.40 +{ 1.41 + SetIsDOMBinding(); 1.42 +} 1.43 + 1.44 +JSObject* 1.45 +TextTrackCueList::WrapObject(JSContext* aCx) 1.46 +{ 1.47 + return TextTrackCueListBinding::Wrap(aCx, this); 1.48 +} 1.49 + 1.50 +TextTrackCue* 1.51 +TextTrackCueList::IndexedGetter(uint32_t aIndex, bool& aFound) 1.52 +{ 1.53 + aFound = aIndex < mList.Length(); 1.54 + return aFound ? mList[aIndex] : nullptr; 1.55 +} 1.56 + 1.57 +TextTrackCue* 1.58 +TextTrackCueList::operator[](uint32_t aIndex) 1.59 +{ 1.60 + return mList.SafeElementAt(aIndex, nullptr); 1.61 +} 1.62 + 1.63 +TextTrackCue* 1.64 +TextTrackCueList::GetCueById(const nsAString& aId) 1.65 +{ 1.66 + if (aId.IsEmpty()) { 1.67 + return nullptr; 1.68 + } 1.69 + 1.70 + for (uint32_t i = 0; i < mList.Length(); i++) { 1.71 + if (aId.Equals(mList[i]->Id())) { 1.72 + return mList[i]; 1.73 + } 1.74 + } 1.75 + return nullptr; 1.76 +} 1.77 + 1.78 +void 1.79 +TextTrackCueList::AddCue(TextTrackCue& aCue) 1.80 +{ 1.81 + if (mList.Contains(&aCue)) { 1.82 + return; 1.83 + } 1.84 + mList.InsertElementSorted(&aCue, CompareCuesByTime()); 1.85 +} 1.86 + 1.87 +void 1.88 +TextTrackCueList::RemoveCue(TextTrackCue& aCue, ErrorResult& aRv) 1.89 +{ 1.90 + if (!mList.Contains(&aCue)) { 1.91 + aRv.Throw(NS_ERROR_DOM_NOT_FOUND_ERR); 1.92 + return; 1.93 + } 1.94 + mList.RemoveElement(&aCue); 1.95 +} 1.96 + 1.97 +void 1.98 +TextTrackCueList::RemoveCueAt(uint32_t aIndex) 1.99 +{ 1.100 + if (aIndex < mList.Length()) { 1.101 + mList.RemoveElementAt(aIndex); 1.102 + } 1.103 +} 1.104 + 1.105 +void 1.106 +TextTrackCueList::RemoveAll() 1.107 +{ 1.108 + mList.Clear(); 1.109 +} 1.110 + 1.111 +void 1.112 +TextTrackCueList::GetArray(nsTArray<nsRefPtr<TextTrackCue> >& aCues) 1.113 +{ 1.114 + aCues = nsTArray<nsRefPtr<TextTrackCue> >(mList); 1.115 +} 1.116 + 1.117 + 1.118 +} // namespace dom 1.119 +} // namespace mozilla