Upstream version 5.34.98.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / animation / AnimationStack.cpp
1 /*
2  * Copyright (C) 2013 Google 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 are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #include "config.h"
32 #include "core/animation/AnimationStack.h"
33
34 #include "core/animation/css/CSSAnimations.h"
35
36 namespace WebCore {
37
38 namespace {
39
40 void copyToCompositableValueMap(const AnimationEffect::CompositableValueList* source, AnimationEffect::CompositableValueMap& target)
41 {
42     if (!source)
43         return;
44     for (AnimationEffect::CompositableValueList::const_iterator iter = source->begin(); iter != source->end(); ++iter)
45         target.set(iter->first, iter->second);
46 }
47
48 } // namespace
49
50 bool AnimationStack::affects(CSSPropertyID property) const
51 {
52     for (size_t i = 0; i < m_activeAnimations.size(); ++i) {
53         if (m_activeAnimations[i]->affects(property))
54             return true;
55     }
56     return false;
57 }
58
59 bool AnimationStack::hasActiveAnimationsOnCompositor(CSSPropertyID property) const
60 {
61     for (size_t i = 0; i < m_activeAnimations.size(); ++i) {
62         if (m_activeAnimations[i]->hasActiveAnimationsOnCompositor(property))
63             return true;
64     }
65     return false;
66 }
67
68 AnimationEffect::CompositableValueMap AnimationStack::compositableValues(const AnimationStack* animationStack, const Vector<InertAnimation*>* newAnimations, const HashSet<const Player*>* cancelledPlayers, Animation::Priority priority)
69 {
70     AnimationEffect::CompositableValueMap result;
71
72     if (animationStack) {
73         const Vector<Animation*>& animations = animationStack->m_activeAnimations;
74         for (size_t i = 0; i < animations.size(); ++i) {
75             Animation* animation = animations[i];
76             if (animation->priority() != priority)
77                 continue;
78             if (cancelledPlayers && cancelledPlayers->contains(animation->player()))
79                 continue;
80             copyToCompositableValueMap(animation->compositableValues(), result);
81         }
82     }
83
84     if (newAnimations) {
85         for (size_t i = 0; i < newAnimations->size(); ++i)
86             copyToCompositableValueMap(newAnimations->at(i)->sample().get(), result);
87     }
88
89     return result;
90 }
91
92 } // namespace WebCore