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

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

Issue 478273002: Use NaN/Inf to represent unresolved/indefinite SMILTimes (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Updated patch. Created 6 years, 4 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 | « Source/core/svg/animation/SMILTime.cpp ('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 472 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 m_hasEndEventConditions = true; 483 m_hasEndEventConditions = true;
484 484
485 return true; 485 return true;
486 } 486 }
487 487
488 void SVGSMILElement::parseBeginOrEnd(const String& parseString, BeginOrEnd begin OrEnd) 488 void SVGSMILElement::parseBeginOrEnd(const String& parseString, BeginOrEnd begin OrEnd)
489 { 489 {
490 Vector<SMILTimeWithOrigin>& timeList = beginOrEnd == Begin ? m_beginTimes : m_endTimes; 490 Vector<SMILTimeWithOrigin>& timeList = beginOrEnd == Begin ? m_beginTimes : m_endTimes;
491 if (beginOrEnd == End) 491 if (beginOrEnd == End)
492 m_hasEndEventConditions = false; 492 m_hasEndEventConditions = false;
493 HashSet<double> existing; 493 HashSet<SMILTime> existing;
494 for (unsigned n = 0; n < timeList.size(); ++n) 494 for (unsigned n = 0; n < timeList.size(); ++n) {
495 existing.add(timeList[n].time().value()); 495 if (!timeList[n].time().isUnresolved())
496 existing.add(timeList[n].time().value());
497 }
496 Vector<String> splitString; 498 Vector<String> splitString;
497 parseString.split(';', splitString); 499 parseString.split(';', splitString);
498 for (unsigned n = 0; n < splitString.size(); ++n) { 500 for (unsigned n = 0; n < splitString.size(); ++n) {
499 SMILTime value = parseClockValue(splitString[n]); 501 SMILTime value = parseClockValue(splitString[n]);
500 if (value.isUnresolved()) 502 if (value.isUnresolved())
501 parseCondition(splitString[n], beginOrEnd); 503 parseCondition(splitString[n], beginOrEnd);
502 else if (!existing.contains(value.value())) 504 else if (!existing.contains(value.value()))
503 timeList.append(SMILTimeWithOrigin(value, SMILTimeWithOrigin::Parser Origin)); 505 timeList.append(SMILTimeWithOrigin(value, SMILTimeWithOrigin::Parser Origin));
504 } 506 }
505 sortTimeList(timeList); 507 sortTimeList(timeList);
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 return m_cachedMin = (result.isUnresolved() || result < 0) ? 0 : result; 801 return m_cachedMin = (result.isUnresolved() || result < 0) ? 0 : result;
800 } 802 }
801 803
802 SMILTime SVGSMILElement::simpleDuration() const 804 SMILTime SVGSMILElement::simpleDuration() const
803 { 805 {
804 return std::min(dur(), SMILTime::indefinite()); 806 return std::min(dur(), SMILTime::indefinite());
805 } 807 }
806 808
807 void SVGSMILElement::addBeginTime(SMILTime eventTime, SMILTime beginTime, SMILTi meWithOrigin::Origin origin) 809 void SVGSMILElement::addBeginTime(SMILTime eventTime, SMILTime beginTime, SMILTi meWithOrigin::Origin origin)
808 { 810 {
809 ASSERT(!std::isnan(beginTime.value()));
810 m_beginTimes.append(SMILTimeWithOrigin(beginTime, origin)); 811 m_beginTimes.append(SMILTimeWithOrigin(beginTime, origin));
811 sortTimeList(m_beginTimes); 812 sortTimeList(m_beginTimes);
812 beginListChanged(eventTime); 813 beginListChanged(eventTime);
813 } 814 }
814 815
815 void SVGSMILElement::addEndTime(SMILTime eventTime, SMILTime endTime, SMILTimeWi thOrigin::Origin origin) 816 void SVGSMILElement::addEndTime(SMILTime eventTime, SMILTime endTime, SMILTimeWi thOrigin::Origin origin)
816 { 817 {
817 ASSERT(!std::isnan(endTime.value()));
818 m_endTimes.append(SMILTimeWithOrigin(endTime, origin)); 818 m_endTimes.append(SMILTimeWithOrigin(endTime, origin));
819 sortTimeList(m_endTimes); 819 sortTimeList(m_endTimes);
820 endListChanged(eventTime); 820 endListChanged(eventTime);
821 } 821 }
822 822
823 inline bool compareTimes(const SMILTimeWithOrigin& left, const SMILTimeWithOrigi n& right) 823 inline bool compareTimes(const SMILTimeWithOrigin& left, const SMILTimeWithOrigi n& right)
824 { 824 {
825 return left.time() < right.time(); 825 return left.time() < right.time();
826 } 826 }
827 827
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
865 865
866 SMILTime SVGSMILElement::repeatingDuration() const 866 SMILTime SVGSMILElement::repeatingDuration() const
867 { 867 {
868 // Computing the active duration 868 // Computing the active duration
869 // http://www.w3.org/TR/SMIL2/smil-timing.html#Timing-ComputingActiveDur 869 // http://www.w3.org/TR/SMIL2/smil-timing.html#Timing-ComputingActiveDur
870 SMILTime repeatCount = this->repeatCount(); 870 SMILTime repeatCount = this->repeatCount();
871 SMILTime repeatDur = this->repeatDur(); 871 SMILTime repeatDur = this->repeatDur();
872 SMILTime simpleDuration = this->simpleDuration(); 872 SMILTime simpleDuration = this->simpleDuration();
873 if (!simpleDuration || (repeatDur.isUnresolved() && repeatCount.isUnresolved ())) 873 if (!simpleDuration || (repeatDur.isUnresolved() && repeatCount.isUnresolved ()))
874 return simpleDuration; 874 return simpleDuration;
875 repeatDur = std::min(repeatDur, SMILTime::indefinite());
875 SMILTime repeatCountDuration = simpleDuration * repeatCount; 876 SMILTime repeatCountDuration = simpleDuration * repeatCount;
876 return std::min(repeatCountDuration, std::min(repeatDur, SMILTime::indefinit e())); 877 if (!repeatCountDuration.isUnresolved())
878 return std::min(repeatDur, repeatCountDuration);
879 return repeatDur;
877 } 880 }
878 881
879 SMILTime SVGSMILElement::resolveActiveEnd(SMILTime resolvedBegin, SMILTime resol vedEnd) const 882 SMILTime SVGSMILElement::resolveActiveEnd(SMILTime resolvedBegin, SMILTime resol vedEnd) const
880 { 883 {
881 // Computing the active duration 884 // Computing the active duration
882 // http://www.w3.org/TR/SMIL2/smil-timing.html#Timing-ComputingActiveDur 885 // http://www.w3.org/TR/SMIL2/smil-timing.html#Timing-ComputingActiveDur
883 SMILTime preliminaryActiveDuration; 886 SMILTime preliminaryActiveDuration;
884 if (!resolvedEnd.isUnresolved() && dur().isUnresolved() && repeatDur().isUnr esolved() && repeatCount().isUnresolved()) 887 if (!resolvedEnd.isUnresolved() && dur().isUnresolved() && repeatDur().isUnr esolved() && repeatCount().isUnresolved())
885 preliminaryActiveDuration = resolvedEnd - resolvedBegin; 888 preliminaryActiveDuration = resolvedEnd - resolvedBegin;
886 else if (!resolvedEnd.isFinite()) 889 else if (!resolvedEnd.isFinite())
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 } 936 }
934 937
935 void SVGSMILElement::resolveFirstInterval() 938 void SVGSMILElement::resolveFirstInterval()
936 { 939 {
937 SMILInterval firstInterval = resolveInterval(FirstInterval); 940 SMILInterval firstInterval = resolveInterval(FirstInterval);
938 ASSERT(!firstInterval.begin.isIndefinite()); 941 ASSERT(!firstInterval.begin.isIndefinite());
939 942
940 if (!firstInterval.begin.isUnresolved() && firstInterval != m_interval) { 943 if (!firstInterval.begin.isUnresolved() && firstInterval != m_interval) {
941 m_interval = firstInterval; 944 m_interval = firstInterval;
942 notifyDependentsIntervalChanged(); 945 notifyDependentsIntervalChanged();
943 m_nextProgressTime = std::min(m_nextProgressTime, m_interval.begin); 946 m_nextProgressTime = m_nextProgressTime.isUnresolved() ? m_interval.begi n : std::min(m_nextProgressTime, m_interval.begin);
944 947
945 if (m_timeContainer) 948 if (m_timeContainer)
946 m_timeContainer->notifyIntervalsChanged(); 949 m_timeContainer->notifyIntervalsChanged();
947 } 950 }
948 } 951 }
949 952
950 bool SVGSMILElement::resolveNextInterval() 953 bool SVGSMILElement::resolveNextInterval()
951 { 954 {
952 SMILInterval nextInterval = resolveInterval(NextInterval); 955 SMILInterval nextInterval = resolveInterval(NextInterval);
953 ASSERT(!nextInterval.begin.isIndefinite()); 956 ASSERT(!nextInterval.begin.isIndefinite());
954 957
955 if (!nextInterval.begin.isUnresolved() && nextInterval.begin != m_interval.b egin) { 958 if (!nextInterval.begin.isUnresolved() && nextInterval.begin != m_interval.b egin) {
956 m_interval = nextInterval; 959 m_interval = nextInterval;
957 notifyDependentsIntervalChanged(); 960 notifyDependentsIntervalChanged();
958 m_nextProgressTime = std::min(m_nextProgressTime, m_interval.begin); 961 m_nextProgressTime = m_nextProgressTime.isUnresolved() ? m_interval.begi n : std::min(m_nextProgressTime, m_interval.begin);
959 return true; 962 return true;
960 } 963 }
961 964
962 return false; 965 return false;
963 } 966 }
964 967
965 SMILTime SVGSMILElement::nextProgressTime() const 968 SMILTime SVGSMILElement::nextProgressTime() const
966 { 969 {
967 return m_nextProgressTime; 970 return m_nextProgressTime;
968 } 971 }
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 if (condition->type() == Condition::Syncbase && condition->syncBase() == syncBase) { 1270 if (condition->type() == Condition::Syncbase && condition->syncBase() == syncBase) {
1268 ASSERT(condition->name() == "begin" || condition->name() == "end"); 1271 ASSERT(condition->name() == "begin" || condition->name() == "end");
1269 // No nested time containers in SVG, no need for crazy time space co nversions. Phew! 1272 // No nested time containers in SVG, no need for crazy time space co nversions. Phew!
1270 SMILTime time = 0; 1273 SMILTime time = 0;
1271 if (condition->name() == "begin") 1274 if (condition->name() == "begin")
1272 time = syncBase->m_interval.begin + condition->offset(); 1275 time = syncBase->m_interval.begin + condition->offset();
1273 else 1276 else
1274 time = syncBase->m_interval.end + condition->offset(); 1277 time = syncBase->m_interval.end + condition->offset();
1275 if (!time.isFinite()) 1278 if (!time.isFinite())
1276 continue; 1279 continue;
1280 SMILTime elapsed = this->elapsed();
1281 if (elapsed.isUnresolved())
1282 continue;
1277 if (condition->beginOrEnd() == Begin) 1283 if (condition->beginOrEnd() == Begin)
1278 addBeginTime(elapsed(), time); 1284 addBeginTime(elapsed, time);
1279 else 1285 else
1280 addEndTime(elapsed(), time); 1286 addEndTime(elapsed, time);
1281 } 1287 }
1282 } 1288 }
1283 } 1289 }
1284 1290
1285 void SVGSMILElement::addSyncBaseDependent(SVGSMILElement* animation) 1291 void SVGSMILElement::addSyncBaseDependent(SVGSMILElement* animation)
1286 { 1292 {
1287 m_syncBaseDependents.add(animation); 1293 m_syncBaseDependents.add(animation);
1288 if (m_interval.begin.isFinite()) 1294 if (m_interval.begin.isFinite())
1289 animation->createInstanceTimesFromSyncbase(this); 1295 animation->createInstanceTimesFromSyncbase(this);
1290 } 1296 }
1291 1297
1292 void SVGSMILElement::removeSyncBaseDependent(SVGSMILElement* animation) 1298 void SVGSMILElement::removeSyncBaseDependent(SVGSMILElement* animation)
1293 { 1299 {
1294 m_syncBaseDependents.remove(animation); 1300 m_syncBaseDependents.remove(animation);
1295 } 1301 }
1296 1302
1297 void SVGSMILElement::handleConditionEvent(Event* event, Condition* condition) 1303 void SVGSMILElement::handleConditionEvent(Event* event, Condition* condition)
1298 { 1304 {
1299 if (event->type() == "repeatn" && toRepeatEvent(event)->repeat() != conditio n->repeat()) 1305 if (event->type() == "repeatn" && toRepeatEvent(event)->repeat() != conditio n->repeat())
1300 return; 1306 return;
1301 1307
1302 SMILTime elapsed = this->elapsed(); 1308 SMILTime elapsed = this->elapsed();
1309 if (elapsed.isUnresolved())
1310 return;
1303 if (condition->beginOrEnd() == Begin) 1311 if (condition->beginOrEnd() == Begin)
1304 addBeginTime(elapsed, elapsed + condition->offset()); 1312 addBeginTime(elapsed, elapsed + condition->offset());
1305 else 1313 else
1306 addEndTime(elapsed, elapsed + condition->offset()); 1314 addEndTime(elapsed, elapsed + condition->offset());
1307 } 1315 }
1308 1316
1309 void SVGSMILElement::beginByLinkActivation() 1317 void SVGSMILElement::beginByLinkActivation()
1310 { 1318 {
1311 SMILTime elapsed = this->elapsed(); 1319 SMILTime elapsed = this->elapsed();
1320 if (elapsed.isUnresolved())
1321 return;
1312 addBeginTime(elapsed, elapsed); 1322 addBeginTime(elapsed, elapsed);
1313 } 1323 }
1314 1324
1315 void SVGSMILElement::endedActiveInterval() 1325 void SVGSMILElement::endedActiveInterval()
1316 { 1326 {
1317 clearTimesWithDynamicOrigins(m_beginTimes); 1327 clearTimesWithDynamicOrigins(m_beginTimes);
1318 clearTimesWithDynamicOrigins(m_endTimes); 1328 clearTimesWithDynamicOrigins(m_endTimes);
1319 } 1329 }
1320 1330
1321 void SVGSMILElement::dispatchRepeatEvents(unsigned count) 1331 void SVGSMILElement::dispatchRepeatEvents(unsigned count)
(...skipping 30 matching lines...) Expand all
1352 #if ENABLE(OILPAN) 1362 #if ENABLE(OILPAN)
1353 visitor->trace(m_targetElement); 1363 visitor->trace(m_targetElement);
1354 visitor->trace(m_timeContainer); 1364 visitor->trace(m_timeContainer);
1355 visitor->trace(m_conditions); 1365 visitor->trace(m_conditions);
1356 visitor->trace(m_syncBaseDependents); 1366 visitor->trace(m_syncBaseDependents);
1357 #endif 1367 #endif
1358 SVGElement::trace(visitor); 1368 SVGElement::trace(visitor);
1359 } 1369 }
1360 1370
1361 } 1371 }
OLDNEW
« no previous file with comments | « Source/core/svg/animation/SMILTime.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698