| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "core/inspector/InspectorAnimationAgent.h" | 7 #include "core/inspector/InspectorAnimationAgent.h" |
| 8 | 8 |
| 9 #include "core/animation/Animation.h" | 9 #include "core/animation/Animation.h" |
| 10 #include "core/animation/AnimationEffect.h" | 10 #include "core/animation/AnimationEffect.h" |
| 11 #include "core/animation/AnimationNode.h" | 11 #include "core/animation/AnimationNode.h" |
| 12 #include "core/animation/AnimationPlayer.h" | 12 #include "core/animation/AnimationPlayer.h" |
| 13 #include "core/animation/ElementAnimation.h" | 13 #include "core/animation/ElementAnimation.h" |
| 14 #include "core/animation/KeyframeEffectModel.h" | 14 #include "core/animation/KeyframeEffectModel.h" |
| 15 #include "core/animation/StringKeyframe.h" | 15 #include "core/animation/StringKeyframe.h" |
| 16 #include "core/css/CSSKeyframeRule.h" | 16 #include "core/css/CSSKeyframeRule.h" |
| 17 #include "core/css/CSSKeyframesRule.h" | 17 #include "core/css/CSSKeyframesRule.h" |
| 18 #include "core/inspector/InspectorDOMAgent.h" | 18 #include "core/inspector/InspectorDOMAgent.h" |
| 19 #include "core/inspector/InspectorNodeIds.h" |
| 19 #include "core/inspector/InspectorStyleSheet.h" | 20 #include "core/inspector/InspectorStyleSheet.h" |
| 20 #include "platform/Decimal.h" | 21 #include "platform/Decimal.h" |
| 21 | 22 |
| 22 namespace blink { | 23 namespace blink { |
| 23 | 24 |
| 24 InspectorAnimationAgent::InspectorAnimationAgent(InspectorDOMAgent* domAgent) | 25 InspectorAnimationAgent::InspectorAnimationAgent(InspectorDOMAgent* domAgent) |
| 25 : InspectorBaseAgent<InspectorAnimationAgent>("Animation") | 26 : InspectorBaseAgent<InspectorAnimationAgent>("Animation") |
| 26 , m_domAgent(domAgent) | 27 , m_domAgent(domAgent) |
| 27 , m_frontend(0) | 28 , m_frontend(0) |
| 28 { | 29 { |
| 29 } | 30 } |
| 30 | 31 |
| 31 void InspectorAnimationAgent::setFrontend(InspectorFrontend* frontend) | 32 void InspectorAnimationAgent::setFrontend(InspectorFrontend* frontend) |
| 32 { | 33 { |
| 33 m_frontend = frontend->animation(); | 34 m_frontend = frontend->animation(); |
| 34 } | 35 } |
| 35 | 36 |
| 36 void InspectorAnimationAgent::clearFrontend() | 37 void InspectorAnimationAgent::clearFrontend() |
| 37 { | 38 { |
| 38 m_frontend = nullptr; | 39 m_frontend = nullptr; |
| 39 reset(); | 40 reset(); |
| 40 } | 41 } |
| 41 | 42 |
| 42 void InspectorAnimationAgent::reset() | 43 void InspectorAnimationAgent::reset() |
| 43 { | 44 { |
| 44 m_idToAnimationPlayer.clear(); | 45 m_idToAnimationPlayer.clear(); |
| 45 } | 46 } |
| 46 | 47 |
| 47 static PassRefPtr<TypeBuilder::Animation::AnimationNode> buildObjectForAnimation
Node(AnimationNode* animationNode) | 48 PassRefPtr<TypeBuilder::Animation::AnimationNode> InspectorAnimationAgent::build
ObjectForAnimationNode(AnimationNode* animationNode) |
| 48 { | 49 { |
| 49 RefPtr<TypeBuilder::Animation::AnimationNode> animationObject = TypeBuilder:
:Animation::AnimationNode::create() | 50 RefPtr<TypeBuilder::Animation::AnimationNode> animationObject = TypeBuilder:
:Animation::AnimationNode::create() |
| 50 .setStartDelay(animationNode->specifiedTiming().startDelay) | 51 .setStartDelay(animationNode->specifiedTiming().startDelay) |
| 51 .setPlaybackRate(animationNode->specifiedTiming().playbackRate) | 52 .setPlaybackRate(animationNode->specifiedTiming().playbackRate) |
| 52 .setIterationStart(animationNode->specifiedTiming().iterationStart) | 53 .setIterationStart(animationNode->specifiedTiming().iterationStart) |
| 53 .setIterationCount(animationNode->specifiedTiming().iterationCount) | 54 .setIterationCount(animationNode->specifiedTiming().iterationCount) |
| 54 .setDuration(animationNode->duration()) | 55 .setDuration(animationNode->duration()) |
| 55 .setDirection(animationNode->specifiedTiming().direction) | 56 .setDirection(animationNode->specifiedTiming().direction) |
| 56 .setFillMode(animationNode->specifiedTiming().fillMode) | 57 .setFillMode(animationNode->specifiedTiming().fillMode) |
| 57 .setTimeFraction(animationNode->timeFraction()) | 58 .setTimeFraction(animationNode->timeFraction()) |
| 58 .setName(animationNode->name()); | 59 .setName(animationNode->name()) |
| 60 .setBackendNodeId(InspectorNodeIds::idForNode(toAnimation(animationNode)
->target())); |
| 59 return animationObject.release(); | 61 return animationObject.release(); |
| 60 } | 62 } |
| 61 | 63 |
| 62 static String playerId(AnimationPlayer& player) | 64 static String playerId(AnimationPlayer& player) |
| 63 { | 65 { |
| 64 return String::number(player.sequenceNumber()); | 66 return String::number(player.sequenceNumber()); |
| 65 } | 67 } |
| 66 | 68 |
| 67 static PassRefPtr<TypeBuilder::Animation::AnimationPlayer> buildObjectForAnimati
onPlayer(AnimationPlayer& animationPlayer, PassRefPtr<TypeBuilder::Animation::Ke
yframesRule> keyframeRule = nullptr) | 69 PassRefPtr<TypeBuilder::Animation::AnimationPlayer> InspectorAnimationAgent::bui
ldObjectForAnimationPlayer(AnimationPlayer& animationPlayer, PassRefPtr<TypeBuil
der::Animation::KeyframesRule> keyframeRule) |
| 68 { | 70 { |
| 69 RefPtr<TypeBuilder::Animation::AnimationNode> animationObject = buildObjectF
orAnimationNode(animationPlayer.source()); | 71 RefPtr<TypeBuilder::Animation::AnimationNode> animationObject = buildObjectF
orAnimationNode(animationPlayer.source()); |
| 70 if (keyframeRule) | 72 if (keyframeRule) |
| 71 animationObject->setKeyframesRule(keyframeRule); | 73 animationObject->setKeyframesRule(keyframeRule); |
| 72 | 74 |
| 73 RefPtr<TypeBuilder::Animation::AnimationPlayer> playerObject = TypeBuilder::
Animation::AnimationPlayer::create() | 75 RefPtr<TypeBuilder::Animation::AnimationPlayer> playerObject = TypeBuilder::
Animation::AnimationPlayer::create() |
| 74 .setId(playerId(animationPlayer)) | 76 .setId(playerId(animationPlayer)) |
| 75 .setPausedState(animationPlayer.paused()) | 77 .setPausedState(animationPlayer.paused()) |
| 76 .setPlayState(animationPlayer.playState()) | 78 .setPlayState(animationPlayer.playState()) |
| 77 .setPlaybackRate(animationPlayer.playbackRate()) | 79 .setPlaybackRate(animationPlayer.playbackRate()) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 if (!keyframe.get()->isStringKeyframe()) | 131 if (!keyframe.get()->isStringKeyframe()) |
| 130 continue; | 132 continue; |
| 131 const StringKeyframe* stringKeyframe = toStringKeyframe(keyframe.get()); | 133 const StringKeyframe* stringKeyframe = toStringKeyframe(keyframe.get()); |
| 132 keyframes->addItem(buildObjectForStringKeyframe(stringKeyframe)); | 134 keyframes->addItem(buildObjectForStringKeyframe(stringKeyframe)); |
| 133 } | 135 } |
| 134 RefPtr<TypeBuilder::Animation::KeyframesRule> keyframesObject = TypeBuilder:
:Animation::KeyframesRule::create() | 136 RefPtr<TypeBuilder::Animation::KeyframesRule> keyframesObject = TypeBuilder:
:Animation::KeyframesRule::create() |
| 135 .setKeyframes(keyframes); | 137 .setKeyframes(keyframes); |
| 136 return keyframesObject.release(); | 138 return keyframesObject.release(); |
| 137 } | 139 } |
| 138 | 140 |
| 139 static PassRefPtr<TypeBuilder::Animation::KeyframesRule> buildObjectForKeyframes
Rule(const Element& element, const AnimationPlayer& player) | 141 static PassRefPtr<TypeBuilder::Animation::KeyframesRule> buildObjectForKeyframes
Rule(const AnimationPlayer& player) |
| 140 { | 142 { |
| 141 StyleResolver& styleResolver = element.ownerDocument()->ensureStyleResolver(
); | 143 const Element* element = toAnimation(player.source())->target(); |
| 142 CSSAnimations& cssAnimations = element.activeAnimations()->cssAnimations(); | 144 StyleResolver& styleResolver = element->ownerDocument()->ensureStyleResolver
(); |
| 145 CSSAnimations& cssAnimations = element->activeAnimations()->cssAnimations(); |
| 143 const AtomicString animationName = cssAnimations.getAnimationNameForInspecto
r(player); | 146 const AtomicString animationName = cssAnimations.getAnimationNameForInspecto
r(player); |
| 144 RefPtr<TypeBuilder::Animation::KeyframesRule> keyframeRule; | 147 RefPtr<TypeBuilder::Animation::KeyframesRule> keyframeRule; |
| 145 | 148 |
| 146 if (!animationName.isNull()) { | 149 if (!animationName.isNull()) { |
| 147 // CSS Animations | 150 // CSS Animations |
| 148 const StyleRuleKeyframes* keyframes = cssAnimations.matchScopedKeyframes
Rule(&styleResolver, &element, animationName.impl()); | 151 const StyleRuleKeyframes* keyframes = cssAnimations.matchScopedKeyframes
Rule(&styleResolver, element, animationName.impl()); |
| 149 keyframeRule = buildObjectForStyleRuleKeyframes(keyframes); | 152 keyframeRule = buildObjectForStyleRuleKeyframes(keyframes); |
| 150 } else { | 153 } else { |
| 151 // Web Animations | 154 // Web Animations |
| 152 keyframeRule = buildObjectForAnimationKeyframes(toAnimation(player.sourc
e())); | 155 keyframeRule = buildObjectForAnimationKeyframes(toAnimation(player.sourc
e())); |
| 153 } | 156 } |
| 154 | 157 |
| 155 return keyframeRule; | 158 return keyframeRule; |
| 156 } | 159 } |
| 157 | 160 |
| 158 void InspectorAnimationAgent::getAnimationPlayersForNode(ErrorString* errorStrin
g, int nodeId, RefPtr<TypeBuilder::Array<TypeBuilder::Animation::AnimationPlayer
> >& animationPlayersArray) | 161 PassRefPtr<TypeBuilder::Array<TypeBuilder::Animation::AnimationPlayer> > Inspect
orAnimationAgent::buildArrayForAnimationPlayers(Element& element, const WillBeHe
apVector<RefPtrWillBeMember<AnimationPlayer> > players) |
| 159 { | 162 { |
| 160 animationPlayersArray = TypeBuilder::Array<TypeBuilder::Animation::Animation
Player>::create(); | 163 RefPtr<TypeBuilder::Array<TypeBuilder::Animation::AnimationPlayer> > animati
onPlayersArray = TypeBuilder::Array<TypeBuilder::Animation::AnimationPlayer>::cr
eate(); |
| 164 for (const auto& it : players) { |
| 165 AnimationPlayer& player = *(it.get()); |
| 166 Animation* animation = toAnimation(player.source()); |
| 167 if (!element.contains(animation->target())) |
| 168 continue; |
| 169 m_idToAnimationPlayer.set(playerId(player), &player); |
| 170 RefPtr<TypeBuilder::Animation::KeyframesRule> keyframeRule = buildObject
ForKeyframesRule(player); |
| 171 animationPlayersArray->addItem(buildObjectForAnimationPlayer(player, key
frameRule)); |
| 172 } |
| 173 return animationPlayersArray.release(); |
| 174 } |
| 175 |
| 176 void InspectorAnimationAgent::getAnimationPlayersForNode(ErrorString* errorStrin
g, int nodeId, bool includeSubtreeAnimations, RefPtr<TypeBuilder::Array<TypeBuil
der::Animation::AnimationPlayer> >& animationPlayersArray) |
| 177 { |
| 161 Element* element = m_domAgent->assertElement(errorString, nodeId); | 178 Element* element = m_domAgent->assertElement(errorString, nodeId); |
| 162 if (!element) | 179 if (!element) |
| 163 return; | 180 return; |
| 164 m_idToAnimationPlayer.clear(); | 181 m_idToAnimationPlayer.clear(); |
| 165 WillBeHeapVector<RefPtrWillBeMember<AnimationPlayer> > players = ElementAnim
ation::getAnimationPlayers(*element); | 182 WillBeHeapVector<RefPtrWillBeMember<AnimationPlayer> > players; |
| 166 for (WillBeHeapVector<RefPtrWillBeMember<AnimationPlayer> >::iterator it = p
layers.begin(); it != players.end(); ++it) { | 183 if (!includeSubtreeAnimations) |
| 167 AnimationPlayer& player = *(it->get()); | 184 players = ElementAnimation::getAnimationPlayers(*element); |
| 168 m_idToAnimationPlayer.set(playerId(player), &player); | 185 else |
| 169 RefPtr<TypeBuilder::Animation::KeyframesRule> keyframeRule = buildObject
ForKeyframesRule(*element, player); | 186 players = element->ownerDocument()->timeline().getAnimationPlayers(); |
| 170 animationPlayersArray->addItem(buildObjectForAnimationPlayer(player, key
frameRule)); | 187 animationPlayersArray = buildArrayForAnimationPlayers(*element, players); |
| 171 } | |
| 172 } | 188 } |
| 173 | 189 |
| 174 void InspectorAnimationAgent::pauseAnimationPlayer(ErrorString* errorString, con
st String& id, RefPtr<TypeBuilder::Animation::AnimationPlayer>& animationPlayer) | 190 void InspectorAnimationAgent::pauseAnimationPlayer(ErrorString* errorString, con
st String& id, RefPtr<TypeBuilder::Animation::AnimationPlayer>& animationPlayer) |
| 175 { | 191 { |
| 176 AnimationPlayer* player = assertAnimationPlayer(errorString, id); | 192 AnimationPlayer* player = assertAnimationPlayer(errorString, id); |
| 177 if (!player) | 193 if (!player) |
| 178 return; | 194 return; |
| 179 player->pause(); | 195 player->pause(); |
| 180 animationPlayer = buildObjectForAnimationPlayer(*player); | 196 animationPlayer = buildObjectForAnimationPlayer(*player); |
| 181 } | 197 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 void InspectorAnimationAgent::trace(Visitor* visitor) | 236 void InspectorAnimationAgent::trace(Visitor* visitor) |
| 221 { | 237 { |
| 222 #if ENABLE(OILPAN) | 238 #if ENABLE(OILPAN) |
| 223 visitor->trace(m_idToAnimationPlayer); | 239 visitor->trace(m_idToAnimationPlayer); |
| 224 visitor->trace(m_domAgent); | 240 visitor->trace(m_domAgent); |
| 225 #endif | 241 #endif |
| 226 InspectorBaseAgent::trace(visitor); | 242 InspectorBaseAgent::trace(visitor); |
| 227 } | 243 } |
| 228 | 244 |
| 229 } | 245 } |
| OLD | NEW |