Bug 978833 patch 18 - Eliminate StyleRule::RuleMatched and call Declaration::SetImmutable directly for style rules (like for @page and keyframe rules). r=heycam

This is just simplification (plus the addition of an assertion).

--HG--
extra : commitid : 8jnKsQbG74s
This commit is contained in:
L. David Baron 2015-11-05 16:44:10 +08:00
parent 7d8e9c1328
commit a511f77fef
9 changed files with 44 additions and 37 deletions

View File

@ -2169,9 +2169,8 @@ CreateDeclaration(nsINode* aNode,
rule->GetDeclaration(), aChanged2, false);
}
rule->RuleMatched();
RefPtr<Declaration> declaration = rule->GetDeclaration();
declaration->SetImmutable();
return declaration.forget();
}

View File

@ -903,8 +903,9 @@ nsSVGElement::WalkContentStyleRules(nsRuleWalker* aRuleWalker)
UpdateContentStyleRule();
if (mContentStyleRule) {
mContentStyleRule->RuleMatched();
aRuleWalker->Forward(mContentStyleRule->GetDeclaration());
css::Declaration* declaration = mContentStyleRule->GetDeclaration();
declaration->SetImmutable();
aRuleWalker->Forward(declaration);
}
return NS_OK;
@ -927,8 +928,9 @@ nsSVGElement::WalkAnimatedContentStyleRules(nsRuleWalker* aRuleWalker)
animContentStyleRule = GetAnimatedContentStyleRule();
}
if (animContentStyleRule) {
animContentStyleRule->RuleMatched();
aRuleWalker->Forward(animContentStyleRule->GetDeclaration());
css::Declaration* declaration = animContentStyleRule->GetDeclaration();
declaration->SetImmutable();
aRuleWalker->Forward(declaration);
}
}
}

View File

@ -72,9 +72,10 @@ private:
// begins life in an invalid state which ends when InitializeEmpty or
// CompressFrom is called upon it. After that, it can be attached to
// exactly one style rule, and will be destroyed when that style rule
// is destroyed. A declaration becomes immutable when its style rule's
// |RuleMatched| method is called; after that, it must be copied before
// it can be modified, which is taken care of by |EnsureMutable|.
// is destroyed. A declaration becomes immutable (via a SetImmutable
// call) when it is matched (put in the rule tree); after that, it must
// be copied before it can be modified, which is taken care of by
// |EnsureMutable|.
class Declaration final : public nsIStyleRule {
public:
@ -408,7 +409,7 @@ private:
friend class ImportantStyleData;
ImportantStyleData mImportantStyleData;
// set by style rules when |RuleMatched| is called;
// set when declaration put in the rule tree;
// also by ToString (hence the 'mutable').
mutable bool mImmutable;
};

View File

@ -2631,8 +2631,9 @@ StyleAnimationValue::ComputeValues(
nsCOMArray<nsIStyleRule> ruleArray;
ruleArray.AppendObject(styleSet->InitialStyleRule());
ruleArray.AppendObject(aStyleRule->GetDeclaration());
aStyleRule->RuleMatched();
css::Declaration* declaration = aStyleRule->GetDeclaration();
ruleArray.AppendObject(declaration);
declaration->SetImmutable();
tmpStyleContext =
styleSet->ResolveStyleByAddingRules(styleContext, ruleArray);
if (!tmpStyleContext) {
@ -2658,8 +2659,9 @@ StyleAnimationValue::ComputeValues(
// value may have been biased by the 'initial' values supplied.
if (!aIsContextSensitive || *aIsContextSensitive) {
nsCOMArray<nsIStyleRule> ruleArray;
ruleArray.AppendObject(aStyleRule->GetDeclaration());
aStyleRule->RuleMatched();
css::Declaration* declaration = aStyleRule->GetDeclaration();
ruleArray.AppendObject(declaration);
declaration->SetImmutable();
tmpStyleContext =
styleSet->ResolveStyleByAddingRules(styleContext, ruleArray);
if (!tmpStyleContext) {

View File

@ -1447,12 +1447,6 @@ NS_INTERFACE_MAP_END
NS_IMPL_ADDREF(StyleRule)
NS_IMPL_RELEASE(StyleRule)
void
StyleRule::RuleMatched()
{
mDeclaration->SetImmutable();
}
/* virtual */ int32_t
StyleRule::GetType() const
{

View File

@ -327,12 +327,6 @@ public:
already_AddRefed<StyleRule>
DeclarationChanged(Declaration* aDecl, bool aHandleContainer);
/**
* The rule processor must call this method before calling
* nsRuleWalker::Forward on this rule during rule matching.
*/
void RuleMatched();
// hooks for DOM rule
void GetCssText(nsAString& aCssText);
void SetCssText(const nsAString& aCssText);

View File

@ -2618,9 +2618,9 @@ void ContentEnumFunc(const RuleValue& value, nsCSSSelector* aSelector,
nodeContext.mIsRelevantLink ?
SelectorMatchesTreeFlags(0) :
eLookForRelevantLink)) {
css::StyleRule *rule = value.mRule;
rule->RuleMatched();
data->mRuleWalker->Forward(rule->GetDeclaration());
css::Declaration* declaration = value.mRule->GetDeclaration();
declaration->SetImmutable();
data->mRuleWalker->Forward(declaration);
// nsStyleSet will deal with the !important rule
}
}
@ -2665,8 +2665,9 @@ nsCSSRuleProcessor::RulesMatching(AnonBoxRuleProcessorData* aData)
nsTArray<RuleValue>& rules = entry->mRules;
for (RuleValue *value = rules.Elements(), *end = value + rules.Length();
value != end; ++value) {
value->mRule->RuleMatched();
aData->mRuleWalker->Forward(value->mRule->GetDeclaration());
css::Declaration* declaration = value->mRule->GetDeclaration();
declaration->SetImmutable();
aData->mRuleWalker->Forward(declaration);
}
}
}

View File

@ -67,8 +67,9 @@ nsHTMLCSSStyleSheet::ElementRulesMatching(nsPresContext* aPresContext,
// just get the one and only style rule from the content's STYLE attribute
css::StyleRule* rule = aElement->GetInlineStyleRule();
if (rule) {
rule->RuleMatched();
aRuleWalker->Forward(rule->GetDeclaration());
css::Declaration* declaration = rule->GetDeclaration();
declaration->SetImmutable();
aRuleWalker->Forward(declaration);
}
rule = aElement->GetSMILOverrideStyleRule();
@ -77,8 +78,9 @@ nsHTMLCSSStyleSheet::ElementRulesMatching(nsPresContext* aPresContext,
if (!restyleManager->SkipAnimationRules()) {
// Animation restyle (or non-restyle traversal of rules)
// Now we can walk SMIL overrride style, without triggering transitions.
rule->RuleMatched();
aRuleWalker->Forward(rule->GetDeclaration());
css::Declaration* declaration = rule->GetDeclaration();
declaration->SetImmutable();
aRuleWalker->Forward(declaration);
}
}
}
@ -96,8 +98,9 @@ nsHTMLCSSStyleSheet::PseudoElementRulesMatching(Element* aPseudoElement,
// just get the one and only style rule from the content's STYLE attribute
css::StyleRule* rule = aPseudoElement->GetInlineStyleRule();
if (rule) {
rule->RuleMatched();
aRuleWalker->Forward(rule->GetDeclaration());
css::Declaration* declaration = rule->GetDeclaration();
declaration->SetImmutable();
aRuleWalker->Forward(declaration);
}
}

View File

@ -17,6 +17,8 @@
#include "mozilla/Likely.h"
#include "mozilla/LookAndFeel.h"
#include "mozilla/css/Declaration.h"
#include "nsAlgorithm.h" // for clamped()
#include "nsRuleNode.h"
#include "nscore.h"
@ -50,6 +52,7 @@
#include "nsCSSPropertySet.h"
#include "mozilla/RuleNodeCacheConditions.h"
#include "nsDeviceContext.h"
#include "nsQueryObject.h"
#if defined(_MSC_VER) || defined(__MINGW32__)
#include <malloc.h>
@ -1553,6 +1556,14 @@ nsRuleNode*
nsRuleNode::Transition(nsIStyleRule* aRule, SheetType aLevel,
bool aIsImportantRule)
{
#ifdef DEBUG
{
RefPtr<css::Declaration> declaration(do_QueryObject(aRule));
MOZ_ASSERT(!declaration || !declaration->IsMutable(),
"caller must call Declaration::SetImmutable first");
}
#endif
nsRuleNode* next = nullptr;
nsRuleNode::Key key(aRule, aLevel, aIsImportantRule);