OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 |
| 7 #include "core/inspector/InspectorAnimationAgent.h" |
| 8 |
| 9 #include "core/animation/AnimationNode.h" |
| 10 #include "core/animation/AnimationPlayer.h" |
| 11 #include "core/animation/ElementAnimation.h" |
| 12 #include "core/inspector/InspectorDOMAgent.h" |
| 13 |
| 14 namespace blink { |
| 15 |
| 16 InspectorAnimationAgent::InspectorAnimationAgent(InspectorDOMAgent* domAgent) |
| 17 : InspectorBaseAgent<InspectorAnimationAgent>("Animation") |
| 18 , m_domAgent(domAgent) |
| 19 , m_frontend(0) |
| 20 { |
| 21 } |
| 22 |
| 23 void InspectorAnimationAgent::setFrontend(InspectorFrontend* frontend) |
| 24 { |
| 25 m_frontend = frontend->animation(); |
| 26 } |
| 27 |
| 28 void InspectorAnimationAgent::clearFrontend() |
| 29 { |
| 30 m_frontend = nullptr; |
| 31 } |
| 32 |
| 33 void InspectorAnimationAgent::reset() |
| 34 { |
| 35 m_idToAnimationPlayer.clear(); |
| 36 } |
| 37 |
| 38 void InspectorAnimationAgent::getAnimationPlayersForNode(ErrorString* errorStrin
g, int nodeId, RefPtr<TypeBuilder::Array<TypeBuilder::Animation::AnimationPlayer
> >& animationPlayersArray) |
| 39 { |
| 40 animationPlayersArray = TypeBuilder::Array<TypeBuilder::Animation::Animation
Player>::create(); |
| 41 Element* element = m_domAgent->assertElement(errorString, nodeId); |
| 42 if (!element) |
| 43 return; |
| 44 m_idToAnimationPlayer.clear(); |
| 45 WillBeHeapVector<RefPtrWillBeMember<AnimationPlayer> > players = ElementAnim
ation::getAnimationPlayers(*element); |
| 46 for (WillBeHeapVector<RefPtrWillBeMember<AnimationPlayer> >::iterator it = p
layers.begin(); it != players.end(); ++it) { |
| 47 AnimationPlayer& player = *(it->get()); |
| 48 m_idToAnimationPlayer.set(playerId(player), &player); |
| 49 RefPtr<TypeBuilder::Animation::AnimationPlayer> animationPlayerObject =
buildObjectForAnimationPlayer(player); |
| 50 animationPlayersArray->addItem(animationPlayerObject); |
| 51 } |
| 52 } |
| 53 |
| 54 void InspectorAnimationAgent::pauseAnimationPlayer(ErrorString* errorString, con
st String& id, RefPtr<TypeBuilder::Animation::AnimationPlayer>& animationPlayer) |
| 55 { |
| 56 AnimationPlayer* player = assertAnimationPlayer(errorString, id); |
| 57 if (!player) |
| 58 return; |
| 59 player->pause(); |
| 60 animationPlayer = buildObjectForAnimationPlayer(*player); |
| 61 } |
| 62 |
| 63 void InspectorAnimationAgent::playAnimationPlayer(ErrorString* errorString, cons
t String& id, RefPtr<TypeBuilder::Animation::AnimationPlayer>& animationPlayer) |
| 64 { |
| 65 AnimationPlayer* player = assertAnimationPlayer(errorString, id); |
| 66 if (!player) |
| 67 return; |
| 68 player->play(); |
| 69 animationPlayer = buildObjectForAnimationPlayer(*player); |
| 70 } |
| 71 |
| 72 void InspectorAnimationAgent::setAnimationPlayerCurrentTime(ErrorString* errorSt
ring, const String& id, double currentTime, RefPtr<TypeBuilder::Animation::Anima
tionPlayer>& animationPlayer) |
| 73 { |
| 74 AnimationPlayer* player = assertAnimationPlayer(errorString, id); |
| 75 if (!player) |
| 76 return; |
| 77 player->setCurrentTime(currentTime); |
| 78 animationPlayer = buildObjectForAnimationPlayer(*player); |
| 79 } |
| 80 |
| 81 void InspectorAnimationAgent::getAnimationPlayerState(ErrorString* errorString,
const String& id, double* currentTime, bool* isRunning) |
| 82 { |
| 83 AnimationPlayer* player = assertAnimationPlayer(errorString, id); |
| 84 if (!player) |
| 85 return; |
| 86 *currentTime = player->currentTime(); |
| 87 *isRunning = player->playing(); |
| 88 } |
| 89 |
| 90 AnimationPlayer* InspectorAnimationAgent::assertAnimationPlayer(ErrorString* err
orString, const String& id) |
| 91 { |
| 92 AnimationPlayer* player = m_idToAnimationPlayer.get(id); |
| 93 if (!player) { |
| 94 *errorString = "Could not find animation player with given id"; |
| 95 return 0; |
| 96 } |
| 97 return player; |
| 98 } |
| 99 |
| 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) |
| 134 { |
| 135 #if ENABLE(OILPAN) |
| 136 visitor->trace(m_idToAnimationPlayer); |
| 137 #endif |
| 138 InspectorBaseAgent::trace(visitor); |
| 139 } |
| 140 |
| 141 } |
OLD | NEW |