Bug 1182978 (part 4) - Use nsTHashtable::Iterator in nsSMILAnimationController. r=birtles.

--HG--
extra : rebase_source : b006ea49ae8bd4e2590d7d85e47f0e4176f208b4
This commit is contained in:
Nicholas Nethercote 2015-07-22 00:26:48 -07:00
parent 96075f1c19
commit a1bc857ec1
2 changed files with 40 additions and 91 deletions

View File

@ -500,16 +500,33 @@ nsSMILAnimationController::DoMilestoneSamples()
// before that. Any other milestones will be dealt with in a subsequent
// sample.
nsSMILMilestone nextMilestone(GetCurrentTime() + 1, true);
mChildContainerTable.EnumerateEntries(GetNextMilestone, &nextMilestone);
for (auto iter = mChildContainerTable.Iter(); !iter.Done(); iter.Next()) {
nsSMILTimeContainer* container = iter.Get()->GetKey();
if (container->IsPausedByType(nsSMILTimeContainer::PAUSE_BEGIN)) {
continue;
}
nsSMILMilestone thisMilestone;
bool didGetMilestone =
container->GetNextMilestoneInParentTime(thisMilestone);
if (didGetMilestone && thisMilestone < nextMilestone) {
nextMilestone = thisMilestone;
}
}
if (nextMilestone.mTime > GetCurrentTime()) {
break;
}
GetMilestoneElementsParams params;
params.mMilestone = nextMilestone;
mChildContainerTable.EnumerateEntries(GetMilestoneElements, &params);
uint32_t length = params.mElements.Length();
nsTArray<nsRefPtr<mozilla::dom::SVGAnimationElement>> elements;
for (auto iter = mChildContainerTable.Iter(); !iter.Done(); iter.Next()) {
nsSMILTimeContainer* container = iter.Get()->GetKey();
if (container->IsPausedByType(nsSMILTimeContainer::PAUSE_BEGIN)) {
continue;
}
container->PopMilestoneElementsAtMilestone(nextMilestone, elements);
}
uint32_t length = elements.Length();
// During the course of a sampling we don't want to actually go backwards.
// Due to negative offsets, early ends and the like, a timed element might
@ -523,7 +540,7 @@ nsSMILAnimationController::DoMilestoneSamples()
sampleTime = std::max(nextMilestone.mTime, sampleTime);
for (uint32_t i = 0; i < length; ++i) {
SVGAnimationElement* elem = params.mElements[i].get();
SVGAnimationElement* elem = elements[i].get();
MOZ_ASSERT(elem, "nullptr animation element in list");
nsSMILTimeContainer* container = elem->GetTimeContainer();
if (!container)
@ -548,53 +565,6 @@ nsSMILAnimationController::DoMilestoneSamples()
}
}
/*static*/ PLDHashOperator
nsSMILAnimationController::GetNextMilestone(TimeContainerPtrKey* aKey,
void* aData)
{
MOZ_ASSERT(aKey, "Null hash key for time container hash table");
MOZ_ASSERT(aKey->GetKey(), "Null time container key in hash table");
MOZ_ASSERT(aData,
"Null data pointer during time container enumeration");
nsSMILMilestone* nextMilestone = static_cast<nsSMILMilestone*>(aData);
nsSMILTimeContainer* container = aKey->GetKey();
if (container->IsPausedByType(nsSMILTimeContainer::PAUSE_BEGIN))
return PL_DHASH_NEXT;
nsSMILMilestone thisMilestone;
bool didGetMilestone =
container->GetNextMilestoneInParentTime(thisMilestone);
if (didGetMilestone && thisMilestone < *nextMilestone) {
*nextMilestone = thisMilestone;
}
return PL_DHASH_NEXT;
}
/*static*/ PLDHashOperator
nsSMILAnimationController::GetMilestoneElements(TimeContainerPtrKey* aKey,
void* aData)
{
MOZ_ASSERT(aKey, "Null hash key for time container hash table");
MOZ_ASSERT(aKey->GetKey(), "Null time container key in hash table");
MOZ_ASSERT(aData,
"Null data pointer during time container enumeration");
GetMilestoneElementsParams* params =
static_cast<GetMilestoneElementsParams*>(aData);
nsSMILTimeContainer* container = aKey->GetKey();
if (container->IsPausedByType(nsSMILTimeContainer::PAUSE_BEGIN))
return PL_DHASH_NEXT;
container->PopMilestoneElementsAtMilestone(params->mMilestone,
params->mElements);
return PL_DHASH_NEXT;
}
/*static*/ void
nsSMILAnimationController::SampleTimedElement(
SVGAnimationElement* aElement, TimeContainerHashtable* aActiveContainers)
@ -731,34 +701,26 @@ nsSMILAnimationController::GetTargetIdentifierForAnimation(
return true;
}
/*static*/ PLDHashOperator
nsSMILAnimationController::AddStyleUpdate(AnimationElementPtrKey* aKey,
void* aData)
{
SVGAnimationElement* animElement = aKey->GetKey();
RestyleTracker* restyleTracker = static_cast<RestyleTracker*>(aData);
nsSMILTargetIdentifier key;
if (!GetTargetIdentifierForAnimation(animElement, key)) {
// Something's wrong/missing about animation's target; skip this animation
return PL_DHASH_NEXT;
}
// mIsCSS true means that the rules are the ones returned from
// Element::GetSMILOverrideStyleRule (via nsSMILCSSProperty objects),
// and mIsCSS false means the rules are nsSMILMappedAttribute objects
// returned from nsSVGElement::GetAnimatedContentStyleRule.
nsRestyleHint rshint = key.mIsCSS ? eRestyle_StyleAttribute_Animations
: eRestyle_SVGAttrAnimations;
restyleTracker->AddPendingRestyle(key.mElement, rshint, nsChangeHint(0));
return PL_DHASH_NEXT;
}
void
nsSMILAnimationController::AddStyleUpdatesTo(RestyleTracker& aTracker)
{
mAnimationElementTable.EnumerateEntries(AddStyleUpdate, &aTracker);
for (auto iter = mAnimationElementTable.Iter(); !iter.Done(); iter.Next()) {
SVGAnimationElement* animElement = iter.Get()->GetKey();
nsSMILTargetIdentifier key;
if (!GetTargetIdentifierForAnimation(animElement, key)) {
// Something's wrong/missing about animation's target; skip this animation
continue;
}
// mIsCSS true means that the rules are the ones returned from
// Element::GetSMILOverrideStyleRule (via nsSMILCSSProperty objects),
// and mIsCSS false means the rules are nsSMILMappedAttribute objects
// returned from nsSVGElement::GetAnimatedContentStyleRule.
nsRestyleHint rshint = key.mIsCSS ? eRestyle_StyleAttribute_Animations
: eRestyle_SVGAttrAnimations;
aTracker.AddPendingRestyle(key.mElement, rshint, nsChangeHint(0));
}
}
//----------------------------------------------------------------------

View File

@ -118,12 +118,6 @@ protected:
typedef nsPtrHashKey<mozilla::dom::SVGAnimationElement> AnimationElementPtrKey;
typedef nsTHashtable<AnimationElementPtrKey> AnimationElementHashtable;
struct GetMilestoneElementsParams
{
nsTArray<nsRefPtr<mozilla::dom::SVGAnimationElement> > mElements;
nsSMILMilestone mMilestone;
};
// Returns mDocument's refresh driver, if it's got one.
nsRefreshDriver* GetRefreshDriver();
@ -141,10 +135,6 @@ protected:
void RewindElements();
void DoMilestoneSamples();
static PLDHashOperator GetNextMilestone(
TimeContainerPtrKey* aKey, void* aData);
static PLDHashOperator GetMilestoneElements(
TimeContainerPtrKey* aKey, void* aData);
static void SampleTimedElement(mozilla::dom::SVGAnimationElement* aElement,
TimeContainerHashtable* aActiveContainers);
@ -153,9 +143,6 @@ protected:
static bool GetTargetIdentifierForAnimation(
mozilla::dom::SVGAnimationElement* aAnimElem, nsSMILTargetIdentifier& aResult);
static PLDHashOperator
AddStyleUpdate(AnimationElementPtrKey* aKey, void* aData);
// Methods for adding/removing time containers
virtual nsresult AddChild(nsSMILTimeContainer& aChild) override;
virtual void RemoveChild(nsSMILTimeContainer& aChild) override;