Bug 996796 patch 5 - Move the guts of UpdateThrottledStyle into nsStyleSet, where it can be reused. r=heycam

This commit is contained in:
L. David Baron 2014-08-02 19:37:43 -07:00
parent f402ea6beb
commit 29e1f8c013
3 changed files with 65 additions and 48 deletions

View File

@ -248,53 +248,10 @@ CommonAnimationManager::UpdateThrottledStyle(dom::Element* aElement,
}
nsStyleContext* oldStyle = primaryFrame->StyleContext();
nsRuleNode* ruleNode = oldStyle->RuleNode();
nsTArray<nsStyleSet::RuleAndLevel> rules;
do {
if (ruleNode->IsRoot()) {
break;
}
nsStyleSet::RuleAndLevel curRule;
curRule.mLevel = ruleNode->GetLevel();
if (curRule.mLevel == nsStyleSet::eAnimationSheet) {
ElementAnimationCollection* collection =
mPresContext->AnimationManager()->GetElementAnimations(
aElement,
oldStyle->GetPseudoType(),
false);
NS_ASSERTION(collection,
"Rule has level eAnimationSheet without animation on manager");
mPresContext->AnimationManager()->UpdateStyleAndEvents(
collection, mPresContext->RefreshDriver()->MostRecentRefresh(),
EnsureStyleRule_IsNotThrottled);
curRule.mRule = collection->mStyleRule;
} else if (curRule.mLevel == nsStyleSet::eTransitionSheet) {
ElementAnimationCollection* collection =
mPresContext->TransitionManager()->GetElementTransitions(
aElement,
oldStyle->GetPseudoType(),
false);
NS_ASSERTION(collection,
"Rule has level eTransitionSheet without transition on manager");
collection->EnsureStyleRuleFor(
mPresContext->RefreshDriver()->MostRecentRefresh(),
EnsureStyleRule_IsNotThrottled);
curRule.mRule = collection->mStyleRule;
} else {
curRule.mRule = ruleNode->GetRule();
}
if (curRule.mRule) {
rules.AppendElement(curRule);
}
} while ((ruleNode = ruleNode->GetParent()));
nsRefPtr<nsStyleContext> newStyle = mPresContext->PresShell()->StyleSet()->
ResolveStyleForRules(aParentStyle, oldStyle, rules);
nsStyleSet* styleSet = mPresContext->StyleSet();
nsRefPtr<nsStyleContext> newStyle =
styleSet->ResolveStyleWithReplacement(aElement, aParentStyle, oldStyle);
// We absolutely must call CalcStyleDifference in order to ensure the
// new context has all the structs cached that the old context had.
@ -306,8 +263,7 @@ CommonAnimationManager::UpdateThrottledStyle(dom::Element* aElement,
primaryFrame->SetStyleContext(newStyle);
ReparentBeforeAndAfter(aElement, primaryFrame, newStyle,
mPresContext->PresShell()->StyleSet());
ReparentBeforeAndAfter(aElement, primaryFrame, newStyle, styleSet);
return newStyle;
}

View File

@ -1320,6 +1320,60 @@ nsStyleSet::ResolveStyleByAddingRules(nsStyleContext* aBaseContext,
nullptr, flags);
}
already_AddRefed<nsStyleContext>
nsStyleSet::ResolveStyleWithReplacement(Element* aElement,
nsStyleContext* aNewParentContext,
nsStyleContext* aOldStyleContext)
{
nsRuleNode* ruleNode = aOldStyleContext->RuleNode();
nsTArray<nsStyleSet::RuleAndLevel> rules;
do {
if (ruleNode->IsRoot()) {
break;
}
nsStyleSet::RuleAndLevel curRule;
curRule.mLevel = ruleNode->GetLevel();
if (curRule.mLevel == nsStyleSet::eAnimationSheet) {
nsAnimationManager* animationManager = PresContext()->AnimationManager();
ElementAnimationCollection* collection = animationManager->GetElementAnimations(
aElement, aOldStyleContext->GetPseudoType(), false);
NS_ASSERTION(collection,
"Rule has level eAnimationSheet without animation on manager");
animationManager->UpdateStyleAndEvents(
collection, PresContext()->RefreshDriver()->MostRecentRefresh(),
EnsureStyleRule_IsNotThrottled);
curRule.mRule = collection->mStyleRule;
} else if (curRule.mLevel == nsStyleSet::eTransitionSheet) {
nsPresContext* presContext = PresContext();
ElementAnimationCollection* collection =
presContext->TransitionManager()->GetElementTransitions(
aElement,
aOldStyleContext->GetPseudoType(),
false);
NS_ASSERTION(collection,
"Rule has level eTransitionSheet without transition on manager");
collection->EnsureStyleRuleFor(
presContext->RefreshDriver()->MostRecentRefresh(),
EnsureStyleRule_IsNotThrottled);
curRule.mRule = collection->mStyleRule;
} else {
curRule.mRule = ruleNode->GetRule();
}
if (curRule.mRule) {
rules.AppendElement(curRule);
}
} while ((ruleNode = ruleNode->GetParent()));
// FIXME: Does this handle visited contexts correctly???
return ResolveStyleForRules(aNewParentContext, aOldStyleContext, rules);
}
already_AddRefed<nsStyleContext>
nsStyleSet::ResolveStyleForNonElement(nsStyleContext* aParentContext)
{

View File

@ -134,6 +134,13 @@ class nsStyleSet
ResolveStyleByAddingRules(nsStyleContext* aBaseContext,
const nsCOMArray<nsIStyleRule> &aRules);
// Resolve style by replacing the animation and transition rules, but
// otherwise maintaining the status quo.
already_AddRefed<nsStyleContext>
ResolveStyleWithReplacement(mozilla::dom::Element* aElement,
nsStyleContext* aNewParentContext,
nsStyleContext* aOldStyleContext);
// Get a style context for a non-element (which no rules will match),
// such as text nodes, placeholder frames, and the nsFirstLetterFrame
// for everything after the first letter.