bool SVGSMILElement::parseCondition(const String& value, BeginOrEnd beginOrEnd) { String parseString = value.stripWhiteSpace(); double sign = 1.; bool ok; size_t pos = parseString.find('+'); if (pos == notFound) { pos = parseString.find('-'); if (pos != notFound) sign = -1.; } String conditionString; SMILTime offset = 0; if (pos == notFound) conditionString = parseString; else { conditionString = parseString.left(pos).stripWhiteSpace(); String offsetString = parseString.substring(pos + 1).stripWhiteSpace(); offset = parseOffsetValue(offsetString); if (offset.isUnresolved()) return false; offset = offset * sign; } if (conditionString.isEmpty()) return false; pos = conditionString.find('.'); String baseID; String nameString; if (pos == notFound) nameString = conditionString; else { baseID = conditionString.left(pos); nameString = conditionString.substring(pos + 1); } if (nameString.isEmpty()) return false; Condition::Type type; int repeats = -1; if (nameString.startsWith("repeat(") && nameString.endsWith(')')) { // FIXME: For repeat events we just need to add the data carrying TimeEvent class and // fire the events at appropiate times. repeats = nameString.substring(7, nameString.length() - 8).toUIntStrict(&ok); if (!ok) return false; nameString = "repeat"; type = Condition::EventBase; } else if (nameString == "begin" || nameString == "end") { if (baseID.isEmpty()) return false; type = Condition::Syncbase; } else if (nameString.startsWith("accesskey(")) { // FIXME: accesskey() support. type = Condition::AccessKey; } else type = Condition::EventBase; m_conditions.append(Condition(type, beginOrEnd, baseID, nameString, offset, repeats)); if (type == Condition::EventBase && beginOrEnd == End) m_hasEndEventConditions = true; return true; }
bool SVGSMILElement::parseCondition(const String& value, BeginOrEnd beginOrEnd) { String parseString = value.stripWhiteSpace(); double sign = 1.; bool ok; size_t pos = parseString.find('+'); if (pos == kNotFound) { pos = parseString.find('-'); if (pos != kNotFound) sign = -1.; } String conditionString; SMILTime offset = 0; if (pos == kNotFound) conditionString = parseString; else { conditionString = parseString.left(pos).stripWhiteSpace(); String offsetString = parseString.substring(pos + 1).stripWhiteSpace(); offset = parseOffsetValue(offsetString); if (offset.isUnresolved()) return false; offset = offset * sign; } if (conditionString.isEmpty()) return false; pos = conditionString.find('.'); String baseID; String nameString; if (pos == kNotFound) nameString = conditionString; else { baseID = conditionString.left(pos); nameString = conditionString.substring(pos + 1); } if (nameString.isEmpty()) return false; Condition::Type type; int repeat = -1; if (nameString.startsWith("repeat(") && nameString.endsWith(')')) { repeat = nameString.substring(7, nameString.length() - 8).toUIntStrict(&ok); if (!ok) return false; nameString = "repeatn"; type = Condition::EventBase; } else if (nameString == "begin" || nameString == "end") { if (baseID.isEmpty()) return false; UseCounter::count(&document(), UseCounter::SVGSMILBeginOrEndSyncbaseValue); type = Condition::Syncbase; } else if (nameString.startsWith("accesskey(")) { // FIXME: accesskey() support. type = Condition::AccessKey; } else { UseCounter::count(&document(), UseCounter::SVGSMILBeginOrEndEventValue); type = Condition::EventBase; } m_conditions.append( Condition::create(type, beginOrEnd, baseID, nameString, offset, repeat)); if (type == Condition::EventBase && beginOrEnd == End) m_hasEndEventConditions = true; return true; }
float SVGSMILElement::calculateAnimationPercentAndRepeat(SMILTime elapsed, unsigned& repeat) const { SMILTime simpleDuration = this->simpleDuration(); repeat = 0; if (simpleDuration.isIndefinite()) { repeat = 0; return 0.f; } if (simpleDuration == 0) { repeat = 0; return 1.f; } ASSERT(m_intervalBegin.isFinite()); ASSERT(simpleDuration.isFinite()); SMILTime activeTime = elapsed - m_intervalBegin; SMILTime repeatingDuration = this->repeatingDuration(); if (elapsed >= m_intervalEnd || activeTime > repeatingDuration) { repeat = static_cast<unsigned>(repeatingDuration.value() / simpleDuration.value()); if (fmod(repeatingDuration.value(), simpleDuration.value() == 0.)) repeat--; return 1.f; } repeat = static_cast<unsigned>(activeTime.value() / simpleDuration.value()); SMILTime simpleTime = fmod(activeTime.value(), simpleDuration.value()); return narrowPrecisionToFloat(simpleTime.value() / simpleDuration.value()); }
void SMILTimeContainer::updateAnimations(SMILTime elapsed, bool seekToTime) { SMILTime earliestFireTime = SMILTime::unresolved(); #ifndef NDEBUG // This boolean will catch any attempts to schedule/unschedule scheduledAnimations during this critical section. // Similarly, any elements removed will unschedule themselves, so this will catch modification of animationsToApply. m_preventScheduledAnimationsChanges = true; #endif AnimationsVector animationsToApply; GroupedAnimationsMap::iterator end = m_scheduledAnimations.end(); for (GroupedAnimationsMap::iterator it = m_scheduledAnimations.begin(); it != end; ++it) { AnimationsVector* scheduled = it->value.get(); // Sort according to priority. Elements with later begin time have higher priority. // In case of a tie, document order decides. // FIXME: This should also consider timing relationships between the elements. Dependents // have higher priority. sortByPriority(*scheduled, elapsed); SVGSMILElement* resultElement = 0; unsigned size = scheduled->size(); for (unsigned n = 0; n < size; n++) { SVGSMILElement* animation = scheduled->at(n); ASSERT(animation->timeContainer() == this); ASSERT(animation->targetElement()); ASSERT(animation->hasValidAttributeName()); // Results are accumulated to the first animation that animates and contributes to a particular element/attribute pair. if (!resultElement) { if (!animation->hasValidAttributeType()) continue; resultElement = animation; } // This will calculate the contribution from the animation and add it to the resultsElement. if (!animation->progress(elapsed, resultElement, seekToTime) && resultElement == animation) resultElement = 0; SMILTime nextFireTime = animation->nextProgressTime(); if (nextFireTime.isFinite()) earliestFireTime = std::min(nextFireTime, earliestFireTime); } if (resultElement) animationsToApply.append(resultElement); } unsigned animationsToApplySize = animationsToApply.size(); if (!animationsToApplySize) { #ifndef NDEBUG m_preventScheduledAnimationsChanges = false; #endif startTimer(earliestFireTime, animationFrameDelay); return; } // Apply results to target elements. for (unsigned i = 0; i < animationsToApplySize; ++i) animationsToApply[i]->applyResultsToTarget(); #ifndef NDEBUG m_preventScheduledAnimationsChanges = false; #endif startTimer(earliestFireTime, animationFrameDelay); }
SMILTime SMILTimeContainer::updateAnimations(SMILTime elapsed, bool seekToTime) { SMILTime earliestFireTime = SMILTime::unresolved(); #if ENABLE(ASSERT) // This boolean will catch any attempts to schedule/unschedule scheduledAnimations during this critical section. // Similarly, any elements removed will unschedule themselves, so this will catch modification of animationsToApply. m_preventScheduledAnimationsChanges = true; #endif if (m_documentOrderIndexesDirty) updateDocumentOrderIndexes(); WillBeHeapHashSet<ElementAttributePair> invalidKeys; using AnimationsVector = WillBeHeapVector<RefPtrWillBeMember<SVGSMILElement>>; AnimationsVector animationsToApply; for (const auto& entry : m_scheduledAnimations) { if (!entry.key.first || entry.value->isEmpty()) { invalidKeys.add(entry.key); continue; } AnimationsLinkedHashSet* scheduled = entry.value.get(); // Sort according to priority. Elements with later begin time have higher priority. // In case of a tie, document order decides. // FIXME: This should also consider timing relationships between the elements. Dependents // have higher priority. AnimationsVector scheduledAnimations; copyToVector(*scheduled, scheduledAnimations); std::sort(scheduledAnimations.begin(), scheduledAnimations.end(), PriorityCompare(elapsed)); SVGSMILElement* resultElement = nullptr; for (const auto& itAnimation : scheduledAnimations) { SVGSMILElement* animation = itAnimation.get(); ASSERT(animation->timeContainer() == this); ASSERT(animation->targetElement()); ASSERT(animation->hasValidAttributeName()); // Results are accumulated to the first animation that animates and contributes to a particular element/attribute pair. // FIXME: we should ensure that resultElement is of an appropriate type. if (!resultElement) { if (!animation->hasValidAttributeType()) continue; resultElement = animation; } // This will calculate the contribution from the animation and add it to the resultsElement. if (!animation->progress(elapsed, resultElement, seekToTime) && resultElement == animation) resultElement = nullptr; SMILTime nextFireTime = animation->nextProgressTime(); if (nextFireTime.isFinite()) earliestFireTime = std::min(nextFireTime, earliestFireTime); } if (resultElement) animationsToApply.append(resultElement); } m_scheduledAnimations.removeAll(invalidKeys); std::sort(animationsToApply.begin(), animationsToApply.end(), PriorityCompare(elapsed)); unsigned animationsToApplySize = animationsToApply.size(); if (!animationsToApplySize) { #if ENABLE(ASSERT) m_preventScheduledAnimationsChanges = false; #endif return earliestFireTime; } // Apply results to target elements. for (unsigned i = 0; i < animationsToApplySize; ++i) animationsToApply[i]->applyResultsToTarget(); #if ENABLE(ASSERT) m_preventScheduledAnimationsChanges = false; #endif for (unsigned i = 0; i < animationsToApplySize; ++i) { if (animationsToApply[i]->inDocument() && animationsToApply[i]->isSVGDiscardElement()) { RefPtrWillBeRawPtr<SVGSMILElement> animDiscard = animationsToApply[i]; RefPtrWillBeRawPtr<SVGElement> targetElement = animDiscard->targetElement(); if (targetElement && targetElement->inDocument()) { targetElement->remove(IGNORE_EXCEPTION); ASSERT(!targetElement->inDocument()); } if (animDiscard->inDocument()) { animDiscard->remove(IGNORE_EXCEPTION); ASSERT(!animDiscard->inDocument()); } } } return earliestFireTime; }