2
* Copyright (C) 2020 Apple Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
13
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
* THE POSSIBILITY OF SUCH DAMAGE.
26
WI.AnimationCollection = class AnimationCollection extends WI.Collection
28
constructor(animationType)
30
console.assert(!animationType || Object.values(WI.Animation.Type).includes(animationType));
34
this._animationType = animationType || null;
36
if (!this._animationType)
37
this._animationCollectionForTypeMap = null;
42
get animationType() { return this._animationType; }
46
if (this._animationType) {
48
return WI.Animation.displayNameForType(this._animationType, plural);
51
return WI.UIString("Web Animations");
54
objectIsRequiredType(object)
56
if (!(object instanceof WI.Animation))
59
return !this._animationType || object.animationType === this._animationType;
62
animationCollectionForType(animationType)
64
console.assert(Object.values(WI.Animation.Type).includes(animationType));
66
if (this._animationType) {
67
console.assert(animationType === this._animationType);
71
if (!this._animationCollectionForTypeMap)
72
this._animationCollectionForTypeMap = new Map;
74
let animationCollectionForType = this._animationCollectionForTypeMap.get(animationType);
75
if (!animationCollectionForType) {
76
animationCollectionForType = new WI.AnimationCollection(animationType);
77
this._animationCollectionForTypeMap.set(animationType, animationCollectionForType);
79
return animationCollectionForType;
86
super.itemAdded(item);
88
if (!this._animationType) {
89
let animationCollectionForType = this.animationCollectionForType(item.animationType);
90
animationCollectionForType.add(item);
96
if (!this._animationType) {
97
let animationCollectionForType = this.animationCollectionForType(item.animationType);
98
animationCollectionForType.remove(item);
101
super.itemRemoved(item);
106
if (this._animationCollectionForTypeMap) {
107
for (let animationCollectionForType of this._animationCollectionForTypeMap.values())
108
animationCollectionForType.clear();
111
super.itemsCleared(items);