Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(454)

Side by Side Diff: third_party/WebKit/Source/core/svg/animation/SVGSMILElement.cpp

Issue 2096253002: Remove EventSender from SVGSMILElement (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: include fix Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/svg/animation/SVGSMILElement.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2008 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 11 matching lines...) Expand all
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "core/svg/animation/SVGSMILElement.h" 26 #include "core/svg/animation/SVGSMILElement.h"
27 27
28 #include "bindings/core/v8/ExceptionStatePlaceholder.h" 28 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
29 #include "bindings/core/v8/ScriptEventListener.h" 29 #include "bindings/core/v8/ScriptEventListener.h"
30 #include "core/XLinkNames.h" 30 #include "core/XLinkNames.h"
31 #include "core/dom/Document.h" 31 #include "core/dom/Document.h"
32 #include "core/dom/TaskRunnerHelper.h"
32 #include "core/events/Event.h" 33 #include "core/events/Event.h"
33 #include "core/events/EventListener.h" 34 #include "core/events/EventListener.h"
34 #include "core/events/EventSender.h"
35 #include "core/svg/SVGDocumentExtensions.h" 35 #include "core/svg/SVGDocumentExtensions.h"
36 #include "core/svg/SVGSVGElement.h" 36 #include "core/svg/SVGSVGElement.h"
37 #include "core/svg/SVGURIReference.h" 37 #include "core/svg/SVGURIReference.h"
38 #include "core/svg/animation/SMILTimeContainer.h" 38 #include "core/svg/animation/SMILTimeContainer.h"
39 #include "platform/heap/Handle.h" 39 #include "platform/heap/Handle.h"
40 #include "wtf/MathExtras.h" 40 #include "wtf/MathExtras.h"
41 #include "wtf/StdLibExtras.h" 41 #include "wtf/StdLibExtras.h"
42 #include "wtf/Vector.h" 42 #include "wtf/Vector.h"
43 #include <algorithm> 43 #include <algorithm>
44 44
(...skipping 25 matching lines...) Expand all
70 private: 70 private:
71 int m_repeat; 71 int m_repeat;
72 }; 72 };
73 73
74 inline RepeatEvent* toRepeatEvent(Event* event) 74 inline RepeatEvent* toRepeatEvent(Event* event)
75 { 75 {
76 ASSERT_WITH_SECURITY_IMPLICATION(!event || event->type() == "repeatn"); 76 ASSERT_WITH_SECURITY_IMPLICATION(!event || event->type() == "repeatn");
77 return static_cast<RepeatEvent*>(event); 77 return static_cast<RepeatEvent*>(event);
78 } 78 }
79 79
80 static SMILEventSender& smilEndEventSender()
81 {
82 DEFINE_STATIC_LOCAL(SMILEventSender, sender, (SMILEventSender::create(EventT ypeNames::endEvent)));
83 return sender;
84 }
85
86 static SMILEventSender& smilBeginEventSender()
87 {
88 DEFINE_STATIC_LOCAL(SMILEventSender, sender, (SMILEventSender::create(EventT ypeNames::beginEvent)));
89 return sender;
90 }
91
92 static SMILEventSender& smilRepeatEventSender()
93 {
94 DEFINE_STATIC_LOCAL(SMILEventSender, sender, (SMILEventSender::create(EventT ypeNames::repeatEvent)));
95 return sender;
96 }
97
98 static SMILEventSender& smilRepeatNEventSender()
99 {
100 DEFINE_STATIC_LOCAL(SMILEventSender, sender, (SMILEventSender::create(Atomic String("repeatn"))));
101 return sender;
102 }
103
104 // This is used for duration type time values that can't be negative. 80 // This is used for duration type time values that can't be negative.
105 static const double invalidCachedTime = -1.; 81 static const double invalidCachedTime = -1.;
106 82
107 class ConditionEventListener final : public EventListener { 83 class ConditionEventListener final : public EventListener {
108 public: 84 public:
109 static ConditionEventListener* create(SVGSMILElement* animation, SVGSMILElem ent::Condition* condition) 85 static ConditionEventListener* create(SVGSMILElement* animation, SVGSMILElem ent::Condition* condition)
110 { 86 {
111 return new ConditionEventListener(animation, condition); 87 return new ConditionEventListener(animation, condition);
112 } 88 }
113 89
(...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after
1163 unsigned repeat = 0; 1139 unsigned repeat = 0;
1164 float percent = calculateAnimationPercentAndRepeat(elapsed, repeat); 1140 float percent = calculateAnimationPercentAndRepeat(elapsed, repeat);
1165 RestartedInterval restartedInterval = maybeRestartInterval(elapsed); 1141 RestartedInterval restartedInterval = maybeRestartInterval(elapsed);
1166 1142
1167 ActiveState oldActiveState = m_activeState; 1143 ActiveState oldActiveState = m_activeState;
1168 m_activeState = determineActiveState(elapsed); 1144 m_activeState = determineActiveState(elapsed);
1169 bool animationIsContributing = isContributing(elapsed); 1145 bool animationIsContributing = isContributing(elapsed);
1170 1146
1171 if (animationIsContributing) { 1147 if (animationIsContributing) {
1172 if (oldActiveState == Inactive || restartedInterval == DidRestartInterva l) { 1148 if (oldActiveState == Inactive || restartedInterval == DidRestartInterva l) {
1173 smilBeginEventSender().dispatchEventSoon(this); 1149 scheduleEvent(EventTypeNames::beginEvent);
1174 startedActiveInterval(); 1150 startedActiveInterval();
1175 } 1151 }
1176 1152
1177 if (repeat && repeat != m_lastRepeat) 1153 if (repeat && repeat != m_lastRepeat)
1178 dispatchRepeatEvents(repeat); 1154 scheduleRepeatEvents(repeat);
1179 1155
1180 m_lastPercent = percent; 1156 m_lastPercent = percent;
1181 m_lastRepeat = repeat; 1157 m_lastRepeat = repeat;
1182 } 1158 }
1183 1159
1184 if ((oldActiveState == Active && m_activeState != Active) || restartedInterv al == DidRestartInterval) { 1160 if ((oldActiveState == Active && m_activeState != Active) || restartedInterv al == DidRestartInterval) {
1185 smilEndEventSender().dispatchEventSoon(this); 1161 scheduleEvent(EventTypeNames::endEvent);
1186 endedActiveInterval(); 1162 endedActiveInterval();
1187 } 1163 }
1188 1164
1189 // Triggering all the pending events if the animation timeline is changed. 1165 // Triggering all the pending events if the animation timeline is changed.
1190 if (seekToTime) { 1166 if (seekToTime) {
1191 if (m_activeState == Inactive) 1167 if (m_activeState == Inactive)
1192 smilBeginEventSender().dispatchEventSoon(this); 1168 scheduleEvent(EventTypeNames::beginEvent);
1193 1169
1194 if (repeat) { 1170 if (repeat) {
1195 for (unsigned repeatEventCount = 1; repeatEventCount < repeat; repea tEventCount++) 1171 for (unsigned repeatEventCount = 1; repeatEventCount < repeat; repea tEventCount++)
1196 dispatchRepeatEvents(repeatEventCount); 1172 scheduleRepeatEvents(repeatEventCount);
1197 if (m_activeState == Inactive) 1173 if (m_activeState == Inactive)
1198 dispatchRepeatEvents(repeat); 1174 scheduleRepeatEvents(repeat);
1199 } 1175 }
1200 1176
1201 if (m_activeState == Inactive || m_activeState == Frozen) 1177 if (m_activeState == Inactive || m_activeState == Frozen)
1202 smilEndEventSender().dispatchEventSoon(this); 1178 scheduleEvent(EventTypeNames::endEvent);
1203 } 1179 }
1204 1180
1205 m_nextProgressTime = calculateNextProgressTime(elapsed); 1181 m_nextProgressTime = calculateNextProgressTime(elapsed);
1206 return animationIsContributing; 1182 return animationIsContributing;
1207 } 1183 }
1208 1184
1209 void SVGSMILElement::notifyDependentsIntervalChanged() 1185 void SVGSMILElement::notifyDependentsIntervalChanged()
1210 { 1186 {
1211 ASSERT(m_interval.begin.isFinite()); 1187 ASSERT(m_interval.begin.isFinite());
1212 // |loopBreaker| is used to avoid infinite recursions which may be caused fr om: 1188 // |loopBreaker| is used to avoid infinite recursions which may be caused fr om:
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 return; 1261 return;
1286 addBeginTime(elapsed, elapsed); 1262 addBeginTime(elapsed, elapsed);
1287 } 1263 }
1288 1264
1289 void SVGSMILElement::endedActiveInterval() 1265 void SVGSMILElement::endedActiveInterval()
1290 { 1266 {
1291 clearTimesWithDynamicOrigins(m_beginTimes); 1267 clearTimesWithDynamicOrigins(m_beginTimes);
1292 clearTimesWithDynamicOrigins(m_endTimes); 1268 clearTimesWithDynamicOrigins(m_endTimes);
1293 } 1269 }
1294 1270
1295 void SVGSMILElement::dispatchRepeatEvents(unsigned count) 1271 void SVGSMILElement::scheduleRepeatEvents(unsigned count)
1296 { 1272 {
1297 m_repeatEventCountList.append(count); 1273 m_repeatEventCountList.append(count);
1298 smilRepeatEventSender().dispatchEventSoon(this); 1274 scheduleEvent(EventTypeNames::repeatEvent);
1299 smilRepeatNEventSender().dispatchEventSoon(this); 1275 scheduleEvent(AtomicString("repeatn"));
1300 } 1276 }
1301 1277
1302 void SVGSMILElement::dispatchPendingEvent(SMILEventSender* eventSender) 1278 void SVGSMILElement::scheduleEvent(const AtomicString& eventType)
1303 { 1279 {
1304 ASSERT(eventSender == &smilEndEventSender() || eventSender == &smilBeginEven tSender() || eventSender == &smilRepeatEventSender() || eventSender == &smilRepe atNEventSender()); 1280 TaskRunnerHelper::get(TaskType::DOMManipulation, &document())->postTask(BLIN K_FROM_HERE, WTF::bind(&SVGSMILElement::dispatchPendingEvent, wrapPersistent(thi s), eventType));
1305 const AtomicString& eventType = eventSender->eventType(); 1281 }
1282
1283 void SVGSMILElement::dispatchPendingEvent(const AtomicString& eventType)
1284 {
1285 DCHECK(eventType == EventTypeNames::endEvent || eventType == EventTypeNames: :beginEvent || eventType == EventTypeNames::repeatEvent || eventType == "repeatn ");
1306 if (eventType == "repeatn") { 1286 if (eventType == "repeatn") {
1307 unsigned repeatEventCount = m_repeatEventCountList.first(); 1287 unsigned repeatEventCount = m_repeatEventCountList.first();
1308 m_repeatEventCountList.remove(0); 1288 m_repeatEventCountList.remove(0);
1309 dispatchEvent(RepeatEvent::create(eventType, repeatEventCount)); 1289 dispatchEvent(RepeatEvent::create(eventType, repeatEventCount));
1310 } else { 1290 } else {
1311 dispatchEvent(Event::create(eventType)); 1291 dispatchEvent(Event::create(eventType));
1312 } 1292 }
1313 } 1293 }
1314 1294
1315 void SVGSMILElement::schedule() 1295 void SVGSMILElement::schedule()
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1348 { 1328 {
1349 visitor->trace(m_targetElement); 1329 visitor->trace(m_targetElement);
1350 visitor->trace(m_timeContainer); 1330 visitor->trace(m_timeContainer);
1351 visitor->trace(m_conditions); 1331 visitor->trace(m_conditions);
1352 visitor->trace(m_syncBaseDependents); 1332 visitor->trace(m_syncBaseDependents);
1353 SVGElement::trace(visitor); 1333 SVGElement::trace(visitor);
1354 SVGTests::trace(visitor); 1334 SVGTests::trace(visitor);
1355 } 1335 }
1356 1336
1357 } // namespace blink 1337 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/svg/animation/SVGSMILElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698