OLD | NEW |
---|---|
(Empty) | |
1 // | |
2 // Copyright 2014 The Chromium Authors. All rights reserved. | |
3 // Use of this source code is governed by a BSD-style license that can be | |
4 // found in the LICENSE file. | |
vsevik
2014/10/16 08:13:52
nit: I don't think lines 1 and 5 are necessary
samli
2014/10/16 22:59:30
Done.
| |
5 // | |
6 | |
7 #include "config.h" | |
8 | |
9 #include "core/inspector/InspectorAnimationAgent.h" | |
10 | |
11 #include "core/animation/AnimationNode.h" | |
12 #include "core/animation/AnimationPlayer.h" | |
13 #include "core/animation/ElementAnimation.h" | |
14 #include "core/inspector/InspectorDOMAgent.h" | |
15 | |
16 namespace blink { | |
17 | |
18 InspectorAnimationAgent::InspectorAnimationAgent(InspectorDOMAgent* domAgent) | |
19 : InspectorBaseAgent<InspectorAnimationAgent>("Animation") | |
20 , m_domAgent(domAgent) | |
21 , m_frontend(0) | |
22 { | |
23 } | |
24 | |
25 void InspectorAnimationAgent::setFrontend(InspectorFrontend* frontend) | |
26 { | |
27 m_frontend = frontend->animation(); | |
28 } | |
29 | |
30 void InspectorAnimationAgent::clearFrontend() | |
31 { | |
32 m_frontend = nullptr; | |
33 } | |
34 | |
35 | |
vsevik
2014/10/16 08:13:52
Please remove extra line here
samli
2014/10/16 22:59:30
Done.
| |
36 void InspectorAnimationAgent::reset() | |
37 { | |
38 m_idToAnimationPlayer.clear(); | |
39 } | |
40 | |
41 void InspectorAnimationAgent::getAnimationPlayersForNode(ErrorString* errorStrin g, int nodeId, RefPtr<TypeBuilder::Array<TypeBuilder::Animation::AnimationPlayer > >& animationPlayersArray) | |
42 { | |
43 animationPlayersArray = TypeBuilder::Array<TypeBuilder::Animation::Animation Player>::create(); | |
44 Element* element = m_domAgent->assertElement(errorString, nodeId); | |
45 if (!element) | |
46 return; | |
47 m_idToAnimationPlayer.clear(); | |
48 WillBeHeapVector<RefPtrWillBeMember<AnimationPlayer> > players = ElementAnim ation::getAnimationPlayers(*element); | |
49 for (WillBeHeapVector<RefPtrWillBeMember<AnimationPlayer> >::iterator it = p layers.begin(); it != players.end(); ++it) { | |
50 AnimationPlayer& player = *(it->get()); | |
51 m_idToAnimationPlayer.set(playerId(player), &player); | |
52 RefPtr<TypeBuilder::Animation::AnimationPlayer> animationPlayerObject = buildObjectForAnimationPlayer(player); | |
53 animationPlayersArray->addItem(animationPlayerObject); | |
54 } | |
55 } | |
56 | |
57 void InspectorAnimationAgent::pauseAnimationPlayer(ErrorString* errorString, con st String& id, RefPtr<TypeBuilder::Animation::AnimationPlayer>& animationPlayer) | |
58 { | |
59 AnimationPlayer* player = assertAnimationPlayer(errorString, id); | |
60 if (!player) | |
61 return; | |
62 player->pause(); | |
63 animationPlayer = buildObjectForAnimationPlayer(*player); | |
64 } | |
65 | |
66 void InspectorAnimationAgent::playAnimationPlayer(ErrorString* errorString, cons t String& id, RefPtr<TypeBuilder::Animation::AnimationPlayer>& animationPlayer) | |
67 { | |
68 AnimationPlayer* player = assertAnimationPlayer(errorString, id); | |
69 if (!player) | |
70 return; | |
71 player->play(); | |
72 animationPlayer = buildObjectForAnimationPlayer(*player); | |
73 } | |
74 | |
75 void InspectorAnimationAgent::setAnimationPlayerCurrentTime(ErrorString* errorSt ring, const String& id, double currentTime, RefPtr<TypeBuilder::Animation::Anima tionPlayer>& animationPlayer) | |
76 { | |
77 AnimationPlayer* player = assertAnimationPlayer(errorString, id); | |
78 if (!player) | |
79 return; | |
80 player->setCurrentTime(currentTime); | |
81 animationPlayer = buildObjectForAnimationPlayer(*player); | |
82 } | |
83 | |
84 void InspectorAnimationAgent::getAnimationPlayerState(ErrorString* errorString, const String& id, double* currentTime, bool* isRunning) | |
85 { | |
86 AnimationPlayer* player = assertAnimationPlayer(errorString, id); | |
87 if (!player) | |
88 return; | |
89 *currentTime = player->currentTime(); | |
90 *isRunning = player->playing(); | |
91 } | |
92 | |
93 AnimationPlayer* InspectorAnimationAgent::assertAnimationPlayer(ErrorString* err orString, const String& id) | |
94 { | |
95 AnimationPlayer* player = m_idToAnimationPlayer.get(id); | |
96 if (!player) { | |
97 *errorString = "Could not find animation player with given id"; | |
98 return 0; | |
99 } | |
100 return player; | |
101 } | |
102 | |
103 String InspectorAnimationAgent::playerId(AnimationPlayer& player) | |
104 { | |
105 return String::number(player.sequenceNumber()); | |
106 } | |
107 | |
108 PassRefPtr<TypeBuilder::Animation::AnimationPlayer> InspectorAnimationAgent::bui ldObjectForAnimationPlayer(AnimationPlayer& animationPlayer) | |
109 { | |
110 RefPtr<TypeBuilder::Animation::AnimationPlayer> playerObject = TypeBuilder:: Animation::AnimationPlayer::create() | |
111 .setId(playerId(animationPlayer)) | |
112 .setPausedState(animationPlayer.paused()) | |
113 .setPlayState(animationPlayer.playState()) | |
114 .setPlaybackRate(animationPlayer.playbackRate()) | |
115 .setStartTime(animationPlayer.startTime()) | |
116 .setCurrentTime(animationPlayer.currentTime()) | |
117 .setSource(buildObjectForAnimationNode(*(animationPlayer.source()))); | |
118 return playerObject.release(); | |
119 } | |
120 | |
121 PassRefPtr<TypeBuilder::Animation::AnimationNode> InspectorAnimationAgent::build ObjectForAnimationNode(AnimationNode& animationNode) | |
122 { | |
123 RefPtr<TypeBuilder::Animation::AnimationNode> animationObject = TypeBuilder: :Animation::AnimationNode::create() | |
124 .setStartDelay(animationNode.specifiedTiming().startDelay) | |
125 .setPlaybackRate(animationNode.specifiedTiming().playbackRate) | |
126 .setIterationStart(animationNode.specifiedTiming().iterationStart) | |
127 .setIterationCount(animationNode.specifiedTiming().iterationCount) | |
128 .setDuration(animationNode.duration()) | |
129 .setDirection(animationNode.specifiedTiming().direction) | |
130 .setFillMode(animationNode.specifiedTiming().fillMode) | |
131 .setTimeFraction(animationNode.timeFraction()) | |
132 .setName(animationNode.name()); | |
133 return animationObject.release(); | |
134 } | |
135 | |
136 void InspectorAnimationAgent::trace(Visitor* visitor) | |
137 { | |
138 #if ENABLE(OILPAN) | |
139 visitor->trace(m_idToAnimationPlayer); | |
140 #endif | |
141 InspectorBaseAgent::trace(visitor); | |
142 } | |
143 | |
144 } | |
OLD | NEW |