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

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

Issue 23944012: [SVG] Avoid unnecessarily populating hashmap for repeat(n) event (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 3 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
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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 return false; 114 return false;
115 } 115 }
116 116
117 void ConditionEventListener::handleEvent(ScriptExecutionContext*, Event* event) 117 void ConditionEventListener::handleEvent(ScriptExecutionContext*, Event* event)
118 { 118 {
119 if (!m_animation) 119 if (!m_animation)
120 return; 120 return;
121 m_animation->handleConditionEvent(event, m_condition); 121 m_animation->handleConditionEvent(event, m_condition);
122 } 122 }
123 123
124 SVGSMILElement::Condition::Condition(Type type, BeginOrEnd beginOrEnd, const Str ing& baseID, const String& name, SMILTime offset) 124 SVGSMILElement::Condition::Condition(Type type, BeginOrEnd beginOrEnd, const Str ing& baseID, const String& name, SMILTime offset, int repeat)
125 : m_type(type) 125 : m_type(type)
126 , m_beginOrEnd(beginOrEnd) 126 , m_beginOrEnd(beginOrEnd)
127 , m_baseID(baseID) 127 , m_baseID(baseID)
128 , m_name(name) 128 , m_name(name)
129 , m_offset(offset) 129 , m_offset(offset)
130 , m_repeat(repeat)
130 { 131 {
131 } 132 }
132 133
133 SVGSMILElement::SVGSMILElement(const QualifiedName& tagName, Document& doc) 134 SVGSMILElement::SVGSMILElement(const QualifiedName& tagName, Document& doc)
134 : SVGElement(tagName, doc) 135 : SVGElement(tagName, doc)
135 , m_attributeName(anyQName()) 136 , m_attributeName(anyQName())
136 , m_targetElement(0) 137 , m_targetElement(0)
137 , m_conditionsConnected(false) 138 , m_conditionsConnected(false)
138 , m_hasEndEventConditions(false) 139 , m_hasEndEventConditions(false)
139 , m_isWaitingForFirstInterval(true) 140 , m_isWaitingForFirstInterval(true)
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 static void sortTimeList(Vector<SMILTimeWithOrigin>& timeList) 367 static void sortTimeList(Vector<SMILTimeWithOrigin>& timeList)
367 { 368 {
368 std::sort(timeList.begin(), timeList.end()); 369 std::sort(timeList.begin(), timeList.end());
369 } 370 }
370 371
371 bool SVGSMILElement::parseCondition(const String& value, BeginOrEnd beginOrEnd) 372 bool SVGSMILElement::parseCondition(const String& value, BeginOrEnd beginOrEnd)
372 { 373 {
373 String parseString = value.stripWhiteSpace(); 374 String parseString = value.stripWhiteSpace();
374 375
375 double sign = 1.; 376 double sign = 1.;
377 bool ok;
376 size_t pos = parseString.find('+'); 378 size_t pos = parseString.find('+');
377 if (pos == notFound) { 379 if (pos == notFound) {
378 pos = parseString.find('-'); 380 pos = parseString.find('-');
379 if (pos != notFound) 381 if (pos != notFound)
380 sign = -1.; 382 sign = -1.;
381 } 383 }
382 String conditionString; 384 String conditionString;
383 SMILTime offset = 0; 385 SMILTime offset = 0;
384 if (pos == notFound) 386 if (pos == notFound)
385 conditionString = parseString; 387 conditionString = parseString;
(...skipping 14 matching lines...) Expand all
400 if (pos == notFound) 402 if (pos == notFound)
401 nameString = conditionString; 403 nameString = conditionString;
402 else { 404 else {
403 baseID = conditionString.left(pos); 405 baseID = conditionString.left(pos);
404 nameString = conditionString.substring(pos + 1); 406 nameString = conditionString.substring(pos + 1);
405 } 407 }
406 if (nameString.isEmpty()) 408 if (nameString.isEmpty())
407 return false; 409 return false;
408 410
409 Condition::Type type; 411 Condition::Type type;
410 if (nameString == "begin" || nameString == "end") { 412 int repeat = -1;
413 if (nameString.startsWith("repeat(") && nameString.endsWith(')')) {
414 repeat = nameString.substring(7, nameString.length() - 8).toUIntStrict(& ok);
415 if (!ok)
416 return false;
417 nameString = "repeatn";
418 type = Condition::EventBase;
419 } else if (nameString == "begin" || nameString == "end") {
411 if (baseID.isEmpty()) 420 if (baseID.isEmpty())
412 return false; 421 return false;
413 type = Condition::Syncbase; 422 type = Condition::Syncbase;
414 } else if (nameString.startsWith("accesskey(")) { 423 } else if (nameString.startsWith("accesskey(")) {
415 // FIXME: accesskey() support. 424 // FIXME: accesskey() support.
416 type = Condition::AccessKey; 425 type = Condition::AccessKey;
417 } else 426 } else
418 type = Condition::EventBase; 427 type = Condition::EventBase;
419 428
420 m_conditions.append(Condition(type, beginOrEnd, baseID, nameString, offset)) ; 429 m_conditions.append(Condition(type, beginOrEnd, baseID, nameString, offset, repeat));
421 430
422 if (type == Condition::EventBase && beginOrEnd == End) 431 if (type == Condition::EventBase && beginOrEnd == End)
423 m_hasEndEventConditions = true; 432 m_hasEndEventConditions = true;
424 433
425 return true; 434 return true;
426 } 435 }
427 436
428 bool SVGSMILElement::isSMILElement(Node* node) 437 bool SVGSMILElement::isSMILElement(Node* node)
429 { 438 {
430 if (!node) 439 if (!node)
(...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after
1204 m_timeDependents.add(animation); 1213 m_timeDependents.add(animation);
1205 if (m_intervalBegin.isFinite()) 1214 if (m_intervalBegin.isFinite())
1206 animation->createInstanceTimesFromSyncbase(this, NewInterval); 1215 animation->createInstanceTimesFromSyncbase(this, NewInterval);
1207 } 1216 }
1208 1217
1209 void SVGSMILElement::removeTimeDependent(SVGSMILElement* animation) 1218 void SVGSMILElement::removeTimeDependent(SVGSMILElement* animation)
1210 { 1219 {
1211 m_timeDependents.remove(animation); 1220 m_timeDependents.remove(animation);
1212 } 1221 }
1213 1222
1214 void SVGSMILElement::handleConditionEvent(Event*, Condition* condition) 1223 void SVGSMILElement::handleConditionEvent(Event* event, Condition* condition)
1215 { 1224 {
1225 if (event->type() == "repeatn" && event->repeat() != condition->m_repeat)
1226 return;
1227
1216 SMILTime elapsed = this->elapsed(); 1228 SMILTime elapsed = this->elapsed();
1217 if (condition->m_beginOrEnd == Begin) 1229 if (condition->m_beginOrEnd == Begin)
1218 addBeginTime(elapsed, elapsed + condition->m_offset); 1230 addBeginTime(elapsed, elapsed + condition->m_offset);
1219 else 1231 else
1220 addEndTime(elapsed, elapsed + condition->m_offset); 1232 addEndTime(elapsed, elapsed + condition->m_offset);
1221 } 1233 }
1222 1234
1223 void SVGSMILElement::beginByLinkActivation() 1235 void SVGSMILElement::beginByLinkActivation()
1224 { 1236 {
1225 SMILTime elapsed = this->elapsed(); 1237 SMILTime elapsed = this->elapsed();
(...skipping 13 matching lines...) Expand all
1239 smilRepeatNEventSender().dispatchEventSoon(this); 1251 smilRepeatNEventSender().dispatchEventSoon(this);
1240 } 1252 }
1241 1253
1242 void SVGSMILElement::dispatchPendingEvent(SMILEventSender* eventSender) 1254 void SVGSMILElement::dispatchPendingEvent(SMILEventSender* eventSender)
1243 { 1255 {
1244 ASSERT(eventSender == &smilEndEventSender() || eventSender == &smilBeginEven tSender() || eventSender == &smilRepeatEventSender() || eventSender == &smilRepe atNEventSender()); 1256 ASSERT(eventSender == &smilEndEventSender() || eventSender == &smilBeginEven tSender() || eventSender == &smilRepeatEventSender() || eventSender == &smilRepe atNEventSender());
1245 const AtomicString& eventType = eventSender->eventType(); 1257 const AtomicString& eventType = eventSender->eventType();
1246 if (eventType == "repeatn") { 1258 if (eventType == "repeatn") {
1247 unsigned repeatEventCount = m_repeatEventCountList.first(); 1259 unsigned repeatEventCount = m_repeatEventCountList.first();
1248 m_repeatEventCountList.remove(0); 1260 m_repeatEventCountList.remove(0);
1249 dispatchEvent(Event::create(String("repeat(" + String::number(repeatEven tCount) + ")"))); 1261 dispatchEvent(RepeatEvent::create(eventType, repeatEventCount));
1250 } else { 1262 } else {
1251 dispatchEvent(Event::create(eventType)); 1263 dispatchEvent(Event::create(eventType));
1252 } 1264 }
1253 } 1265 }
1254 1266
1255 } 1267 }
OLDNEW
« Source/core/dom/Event.h ('K') | « Source/core/svg/animation/SVGSMILElement.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698