~mmach/netext73/webkit2gtk

« back to all changes in this revision

Viewing changes to Source/WebInspectorUI/UserInterface/Models/AnimationCollection.js

  • Committer: mmach
  • Date: 2023-06-16 17:21:37 UTC
  • Revision ID: netbit73@gmail.com-20230616172137-2rqx6yr96ga9g3kp
1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2020 Apple Inc. All rights reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without
 
5
 * modification, are permitted provided that the following conditions
 
6
 * are met:
 
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.
 
12
 *
 
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.
 
24
 */
 
25
 
 
26
WI.AnimationCollection = class AnimationCollection extends WI.Collection
 
27
{
 
28
    constructor(animationType)
 
29
    {
 
30
        console.assert(!animationType || Object.values(WI.Animation.Type).includes(animationType));
 
31
 
 
32
        super();
 
33
 
 
34
        this._animationType = animationType || null;
 
35
 
 
36
        if (!this._animationType)
 
37
            this._animationCollectionForTypeMap = null;
 
38
    }
 
39
 
 
40
    // Public
 
41
 
 
42
    get animationType() { return this._animationType; }
 
43
 
 
44
    get displayName()
 
45
    {
 
46
        if (this._animationType) {
 
47
            const plural = true;
 
48
            return WI.Animation.displayNameForType(this._animationType, plural);
 
49
        }
 
50
 
 
51
        return WI.UIString("Web Animations");
 
52
    }
 
53
 
 
54
    objectIsRequiredType(object)
 
55
    {
 
56
        if (!(object instanceof WI.Animation))
 
57
            return false;
 
58
 
 
59
        return !this._animationType || object.animationType === this._animationType;
 
60
    }
 
61
 
 
62
    animationCollectionForType(animationType)
 
63
    {
 
64
        console.assert(Object.values(WI.Animation.Type).includes(animationType));
 
65
 
 
66
        if (this._animationType) {
 
67
            console.assert(animationType === this._animationType);
 
68
            return this;
 
69
        }
 
70
 
 
71
        if (!this._animationCollectionForTypeMap)
 
72
            this._animationCollectionForTypeMap = new Map;
 
73
 
 
74
        let animationCollectionForType = this._animationCollectionForTypeMap.get(animationType);
 
75
        if (!animationCollectionForType) {
 
76
            animationCollectionForType = new WI.AnimationCollection(animationType);
 
77
            this._animationCollectionForTypeMap.set(animationType, animationCollectionForType);
 
78
        }
 
79
        return animationCollectionForType;
 
80
    }
 
81
 
 
82
    // Protected
 
83
 
 
84
    itemAdded(item)
 
85
    {
 
86
        super.itemAdded(item);
 
87
 
 
88
        if (!this._animationType) {
 
89
            let animationCollectionForType = this.animationCollectionForType(item.animationType);
 
90
            animationCollectionForType.add(item);
 
91
        }
 
92
    }
 
93
 
 
94
    itemRemoved(item)
 
95
    {
 
96
        if (!this._animationType) {
 
97
            let animationCollectionForType = this.animationCollectionForType(item.animationType);
 
98
            animationCollectionForType.remove(item);
 
99
        }
 
100
 
 
101
        super.itemRemoved(item);
 
102
    }
 
103
 
 
104
    itemsCleared(items)
 
105
    {
 
106
        if (this._animationCollectionForTypeMap) {
 
107
            for (let animationCollectionForType of this._animationCollectionForTypeMap.values())
 
108
                animationCollectionForType.clear();
 
109
        }
 
110
 
 
111
        super.itemsCleared(items);
 
112
    }
 
113
};