| 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/AnimationNode.h" | 9 #include "core/animation/AnimationNode.h" |
| 10 #include "core/animation/AnimationPlayer.h" | 10 #include "core/animation/AnimationPlayer.h" |
| 11 #include "core/animation/ElementAnimation.h" | 11 #include "core/animation/ElementAnimation.h" |
| 12 #include "core/css/CSSKeyframeRule.h" |
| 13 #include "core/css/CSSKeyframesRule.h" |
| 12 #include "core/inspector/InspectorDOMAgent.h" | 14 #include "core/inspector/InspectorDOMAgent.h" |
| 15 #include "core/inspector/InspectorStyleSheet.h" |
| 13 | 16 |
| 14 namespace blink { | 17 namespace blink { |
| 15 | 18 |
| 16 InspectorAnimationAgent::InspectorAnimationAgent(InspectorDOMAgent* domAgent) | 19 InspectorAnimationAgent::InspectorAnimationAgent(InspectorDOMAgent* domAgent) |
| 17 : InspectorBaseAgent<InspectorAnimationAgent>("Animation") | 20 : InspectorBaseAgent<InspectorAnimationAgent>("Animation") |
| 18 , m_domAgent(domAgent) | 21 , m_domAgent(domAgent) |
| 19 , m_frontend(0) | 22 , m_frontend(0) |
| 20 { | 23 { |
| 21 } | 24 } |
| 22 | 25 |
| 23 void InspectorAnimationAgent::setFrontend(InspectorFrontend* frontend) | 26 void InspectorAnimationAgent::setFrontend(InspectorFrontend* frontend) |
| 24 { | 27 { |
| 25 m_frontend = frontend->animation(); | 28 m_frontend = frontend->animation(); |
| 26 } | 29 } |
| 27 | 30 |
| 28 void InspectorAnimationAgent::clearFrontend() | 31 void InspectorAnimationAgent::clearFrontend() |
| 29 { | 32 { |
| 30 m_frontend = nullptr; | 33 m_frontend = nullptr; |
| 31 } | 34 } |
| 32 | 35 |
| 33 void InspectorAnimationAgent::reset() | 36 void InspectorAnimationAgent::reset() |
| 34 { | 37 { |
| 35 m_idToAnimationPlayer.clear(); | 38 m_idToAnimationPlayer.clear(); |
| 36 } | 39 } |
| 37 | 40 |
| 41 static PassRefPtr<TypeBuilder::Animation::AnimationNode> buildObjectForAnimation
Node(AnimationNode* animationNode) |
| 42 { |
| 43 RefPtr<TypeBuilder::Animation::AnimationNode> animationObject = TypeBuilder:
:Animation::AnimationNode::create() |
| 44 .setStartDelay(animationNode->specifiedTiming().startDelay) |
| 45 .setPlaybackRate(animationNode->specifiedTiming().playbackRate) |
| 46 .setIterationStart(animationNode->specifiedTiming().iterationStart) |
| 47 .setIterationCount(animationNode->specifiedTiming().iterationCount) |
| 48 .setDuration(animationNode->duration()) |
| 49 .setDirection(animationNode->specifiedTiming().direction) |
| 50 .setFillMode(animationNode->specifiedTiming().fillMode) |
| 51 .setTimeFraction(animationNode->timeFraction()) |
| 52 .setName(animationNode->name()); |
| 53 return animationObject.release(); |
| 54 } |
| 55 |
| 56 static String playerId(AnimationPlayer& player) |
| 57 { |
| 58 return String::number(player.sequenceNumber()); |
| 59 } |
| 60 |
| 61 static PassRefPtr<TypeBuilder::Animation::AnimationPlayer> buildObjectForAnimati
onPlayer(AnimationPlayer& animationPlayer, PassRefPtr<TypeBuilder::Animation::Ke
yframesRule> keyframeRule = nullptr) |
| 62 { |
| 63 RefPtr<TypeBuilder::Animation::AnimationNode> animationObject = buildObjectF
orAnimationNode(animationPlayer.source()); |
| 64 if (keyframeRule) |
| 65 animationObject->setKeyframesRule(keyframeRule); |
| 66 |
| 67 RefPtr<TypeBuilder::Animation::AnimationPlayer> playerObject = TypeBuilder::
Animation::AnimationPlayer::create() |
| 68 .setId(playerId(animationPlayer)) |
| 69 .setPausedState(animationPlayer.paused()) |
| 70 .setPlayState(animationPlayer.playState()) |
| 71 .setPlaybackRate(animationPlayer.playbackRate()) |
| 72 .setStartTime(animationPlayer.startTime()) |
| 73 .setCurrentTime(animationPlayer.currentTime()) |
| 74 .setSource(animationObject.release()); |
| 75 return playerObject.release(); |
| 76 } |
| 77 |
| 78 static PassRefPtr<TypeBuilder::Animation::KeyframeStyle> buildObjectForStyleKeyf
rame(StyleKeyframe* keyframe) |
| 79 { |
| 80 RefPtrWillBeRawPtr<InspectorStyle> inspectorStyle = InspectorStyle::create(I
nspectorCSSId(), keyframe->mutableProperties().ensureCSSStyleDeclaration(), 0); |
| 81 RefPtr<TypeBuilder::Animation::KeyframeStyle> keyframeObject = TypeBuilder::
Animation::KeyframeStyle::create() |
| 82 .setOffset(keyframe->keyText()) |
| 83 .setStyle(inspectorStyle->buildObjectForStyle()); |
| 84 return keyframeObject.release(); |
| 85 } |
| 86 |
| 87 static PassRefPtr<TypeBuilder::Animation::KeyframesRule> buildObjectForStyleRule
Keyframes(const StyleRuleKeyframes* keyframesRule) |
| 88 { |
| 89 RefPtr<TypeBuilder::Array<TypeBuilder::Animation::KeyframeStyle> > keyframes
= TypeBuilder::Array<TypeBuilder::Animation::KeyframeStyle>::create(); |
| 90 const WillBeHeapVector<RefPtrWillBeMember<StyleKeyframe> >& styleKeyframes =
keyframesRule->keyframes(); |
| 91 for (const auto& styleKeyframe : styleKeyframes) |
| 92 keyframes->addItem(buildObjectForStyleKeyframe(styleKeyframe.get())); |
| 93 |
| 94 RefPtr<TypeBuilder::Animation::KeyframesRule> keyframesObject = TypeBuilder:
:Animation::KeyframesRule::create() |
| 95 .setKeyframes(keyframes); |
| 96 keyframesObject->setName(keyframesRule->name()); |
| 97 return keyframesObject.release(); |
| 98 } |
| 99 |
| 100 static PassRefPtr<TypeBuilder::Animation::KeyframesRule> buildObjectForKeyframes
Rule(const Element& element, const AnimationPlayer& player) |
| 101 { |
| 102 StyleResolver& styleResolver = element.ownerDocument()->ensureStyleResolver(
); |
| 103 // FIXME: Add support for web anim |
| 104 CSSAnimations& cssAnimations = element.activeAnimations()->cssAnimations(); |
| 105 const AtomicString animationName = cssAnimations.getAnimationNameForInspecto
r(player); |
| 106 ASSERT(animationName); |
| 107 const StyleRuleKeyframes* keyframes = cssAnimations.matchScopedKeyframesRule
(&styleResolver, &element, animationName.impl()); |
| 108 |
| 109 return buildObjectForStyleRuleKeyframes(keyframes); |
| 110 } |
| 111 |
| 38 void InspectorAnimationAgent::getAnimationPlayersForNode(ErrorString* errorStrin
g, int nodeId, RefPtr<TypeBuilder::Array<TypeBuilder::Animation::AnimationPlayer
> >& animationPlayersArray) | 112 void InspectorAnimationAgent::getAnimationPlayersForNode(ErrorString* errorStrin
g, int nodeId, RefPtr<TypeBuilder::Array<TypeBuilder::Animation::AnimationPlayer
> >& animationPlayersArray) |
| 39 { | 113 { |
| 40 animationPlayersArray = TypeBuilder::Array<TypeBuilder::Animation::Animation
Player>::create(); | 114 animationPlayersArray = TypeBuilder::Array<TypeBuilder::Animation::Animation
Player>::create(); |
| 41 Element* element = m_domAgent->assertElement(errorString, nodeId); | 115 Element* element = m_domAgent->assertElement(errorString, nodeId); |
| 42 if (!element) | 116 if (!element) |
| 43 return; | 117 return; |
| 44 m_idToAnimationPlayer.clear(); | 118 m_idToAnimationPlayer.clear(); |
| 45 WillBeHeapVector<RefPtrWillBeMember<AnimationPlayer> > players = ElementAnim
ation::getAnimationPlayers(*element); | 119 WillBeHeapVector<RefPtrWillBeMember<AnimationPlayer> > players = ElementAnim
ation::getAnimationPlayers(*element); |
| 46 for (WillBeHeapVector<RefPtrWillBeMember<AnimationPlayer> >::iterator it = p
layers.begin(); it != players.end(); ++it) { | 120 for (WillBeHeapVector<RefPtrWillBeMember<AnimationPlayer> >::iterator it = p
layers.begin(); it != players.end(); ++it) { |
| 47 AnimationPlayer& player = *(it->get()); | 121 AnimationPlayer& player = *(it->get()); |
| 48 m_idToAnimationPlayer.set(playerId(player), &player); | 122 m_idToAnimationPlayer.set(playerId(player), &player); |
| 49 RefPtr<TypeBuilder::Animation::AnimationPlayer> animationPlayerObject =
buildObjectForAnimationPlayer(player); | 123 RefPtr<TypeBuilder::Animation::AnimationPlayer> animationPlayerObject; |
| 124 // FIXME: Add support for web animations |
| 125 if (!element->activeAnimations()->cssAnimations().getAnimationNameForIns
pector(player).isNull()) { |
| 126 RefPtr<TypeBuilder::Animation::KeyframesRule> keyframeRule = buildOb
jectForKeyframesRule(*element, player); |
| 127 animationPlayerObject = buildObjectForAnimationPlayer(player, keyfra
meRule.release()); |
| 128 } else { |
| 129 animationPlayerObject = buildObjectForAnimationPlayer(player); |
| 130 } |
| 50 animationPlayersArray->addItem(animationPlayerObject); | 131 animationPlayersArray->addItem(animationPlayerObject); |
| 51 } | 132 } |
| 52 } | 133 } |
| 53 | 134 |
| 54 void InspectorAnimationAgent::pauseAnimationPlayer(ErrorString* errorString, con
st String& id, RefPtr<TypeBuilder::Animation::AnimationPlayer>& animationPlayer) | 135 void InspectorAnimationAgent::pauseAnimationPlayer(ErrorString* errorString, con
st String& id, RefPtr<TypeBuilder::Animation::AnimationPlayer>& animationPlayer) |
| 55 { | 136 { |
| 56 AnimationPlayer* player = assertAnimationPlayer(errorString, id); | 137 AnimationPlayer* player = assertAnimationPlayer(errorString, id); |
| 57 if (!player) | 138 if (!player) |
| 58 return; | 139 return; |
| 59 player->pause(); | 140 player->pause(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 90 AnimationPlayer* InspectorAnimationAgent::assertAnimationPlayer(ErrorString* err
orString, const String& id) | 171 AnimationPlayer* InspectorAnimationAgent::assertAnimationPlayer(ErrorString* err
orString, const String& id) |
| 91 { | 172 { |
| 92 AnimationPlayer* player = m_idToAnimationPlayer.get(id); | 173 AnimationPlayer* player = m_idToAnimationPlayer.get(id); |
| 93 if (!player) { | 174 if (!player) { |
| 94 *errorString = "Could not find animation player with given id"; | 175 *errorString = "Could not find animation player with given id"; |
| 95 return 0; | 176 return 0; |
| 96 } | 177 } |
| 97 return player; | 178 return player; |
| 98 } | 179 } |
| 99 | 180 |
| 100 String InspectorAnimationAgent::playerId(AnimationPlayer& player) | |
| 101 { | |
| 102 return String::number(player.sequenceNumber()); | |
| 103 } | |
| 104 | |
| 105 PassRefPtr<TypeBuilder::Animation::AnimationPlayer> InspectorAnimationAgent::bui
ldObjectForAnimationPlayer(AnimationPlayer& animationPlayer) | |
| 106 { | |
| 107 RefPtr<TypeBuilder::Animation::AnimationPlayer> playerObject = TypeBuilder::
Animation::AnimationPlayer::create() | |
| 108 .setId(playerId(animationPlayer)) | |
| 109 .setPausedState(animationPlayer.paused()) | |
| 110 .setPlayState(animationPlayer.playState()) | |
| 111 .setPlaybackRate(animationPlayer.playbackRate()) | |
| 112 .setStartTime(animationPlayer.startTime()) | |
| 113 .setCurrentTime(animationPlayer.currentTime()) | |
| 114 .setSource(buildObjectForAnimationNode(*(animationPlayer.source()))); | |
| 115 return playerObject.release(); | |
| 116 } | |
| 117 | |
| 118 PassRefPtr<TypeBuilder::Animation::AnimationNode> InspectorAnimationAgent::build
ObjectForAnimationNode(AnimationNode& animationNode) | |
| 119 { | |
| 120 RefPtr<TypeBuilder::Animation::AnimationNode> animationObject = TypeBuilder:
:Animation::AnimationNode::create() | |
| 121 .setStartDelay(animationNode.specifiedTiming().startDelay) | |
| 122 .setPlaybackRate(animationNode.specifiedTiming().playbackRate) | |
| 123 .setIterationStart(animationNode.specifiedTiming().iterationStart) | |
| 124 .setIterationCount(animationNode.specifiedTiming().iterationCount) | |
| 125 .setDuration(animationNode.duration()) | |
| 126 .setDirection(animationNode.specifiedTiming().direction) | |
| 127 .setFillMode(animationNode.specifiedTiming().fillMode) | |
| 128 .setTimeFraction(animationNode.timeFraction()) | |
| 129 .setName(animationNode.name()); | |
| 130 return animationObject.release(); | |
| 131 } | |
| 132 | |
| 133 void InspectorAnimationAgent::trace(Visitor* visitor) | 181 void InspectorAnimationAgent::trace(Visitor* visitor) |
| 134 { | 182 { |
| 135 #if ENABLE(OILPAN) | 183 #if ENABLE(OILPAN) |
| 136 visitor->trace(m_idToAnimationPlayer); | 184 visitor->trace(m_idToAnimationPlayer); |
| 137 visitor->trace(m_domAgent); | 185 visitor->trace(m_domAgent); |
| 138 #endif | 186 #endif |
| 139 InspectorBaseAgent::trace(visitor); | 187 InspectorBaseAgent::trace(visitor); |
| 140 } | 188 } |
| 141 | 189 |
| 142 } | 190 } |
| OLD | NEW |