/src/mozilla-central/dom/animation/AnimationEventDispatcher.cpp
Line | Count | Source (jump to first uncovered line) |
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 "mozilla/AnimationEventDispatcher.h" |
8 | | |
9 | | #include "mozilla/EventDispatcher.h" |
10 | | #include "nsRefreshDriver.h" |
11 | | |
12 | | namespace mozilla { |
13 | | |
14 | | NS_IMPL_CYCLE_COLLECTION_CLASS(AnimationEventDispatcher) |
15 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(AnimationEventDispatcher) |
16 | 0 | tmp->ClearEventQueue(); |
17 | 0 | NS_IMPL_CYCLE_COLLECTION_UNLINK_END |
18 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(AnimationEventDispatcher) |
19 | 0 | for (auto& info : tmp->mPendingEvents) { |
20 | 0 | ImplCycleCollectionTraverse(cb, info.mTarget, |
21 | 0 | "mozilla::AnimationEventDispatcher.mPendingEvents.mTarget"); |
22 | 0 | ImplCycleCollectionTraverse(cb, info.mAnimation, |
23 | 0 | "mozilla::AnimationEventDispatcher.mPendingEvents.mAnimation"); |
24 | 0 | } |
25 | 0 | NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END |
26 | | |
27 | | NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(AnimationEventDispatcher, AddRef) |
28 | | NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(AnimationEventDispatcher, Release) |
29 | | |
30 | | void |
31 | | AnimationEventDispatcher::Disconnect() |
32 | 0 | { |
33 | 0 | if (mIsObserving) { |
34 | 0 | MOZ_ASSERT(mPresContext && mPresContext->RefreshDriver(), |
35 | 0 | "The pres context and the refresh driver should be still " |
36 | 0 | "alive if we haven't disassociated from the refresh driver"); |
37 | 0 | mPresContext->RefreshDriver()->CancelPendingAnimationEvents(this); |
38 | 0 | mIsObserving = false; |
39 | 0 | } |
40 | 0 | mPresContext = nullptr; |
41 | 0 | } |
42 | | |
43 | | void |
44 | | AnimationEventDispatcher::QueueEvent(AnimationEventInfo&& aEvent) |
45 | 0 | { |
46 | 0 | mPendingEvents.AppendElement(std::move(aEvent)); |
47 | 0 | mIsSorted = false; |
48 | 0 | ScheduleDispatch(); |
49 | 0 | } |
50 | | |
51 | | void |
52 | | AnimationEventDispatcher::QueueEvents(nsTArray<AnimationEventInfo>&& aEvents) |
53 | 0 | { |
54 | 0 | mPendingEvents.AppendElements(std::move(aEvents)); |
55 | 0 | mIsSorted = false; |
56 | 0 | ScheduleDispatch(); |
57 | 0 | } |
58 | | |
59 | | void |
60 | | AnimationEventDispatcher::ScheduleDispatch() |
61 | 0 | { |
62 | 0 | MOZ_ASSERT(mPresContext, "The pres context should be valid"); |
63 | 0 | if (!mIsObserving) { |
64 | 0 | mPresContext->RefreshDriver()->ScheduleAnimationEventDispatch(this); |
65 | 0 | mIsObserving = true; |
66 | 0 | } |
67 | 0 | } |
68 | | |
69 | | } // namespace mozilla |
70 | | |