Bug 773296 - Part 19: Compare style structs even for the same rule node when variables have changed. r=dbaron

This makes updates work correctly when variable values change.
Rather than handling nsStyleVariables with a DO_STRUCT_DIFFERENCE,
we explicitly compare the two nsStyleVariables objects in
nsStyleContext::CalcStyleDifference before looking at the other
style structs.  This is because we need to force those other
style structs to be compared if variable values are changing.
nsStyleVariables::CalcDifference still returns 0, since the change in
variable values themselves doesn't require any updates.
This commit is contained in:
Cameron McCormack 2013-12-12 13:09:45 +11:00
parent ba08f38dc0
commit 3fdf3d9eee
3 changed files with 39 additions and 2 deletions

View File

@ -42,6 +42,28 @@ CSSVariableValues::operator=(const CSSVariableValues& aOther)
return *this;
}
bool
CSSVariableValues::operator==(const CSSVariableValues& aOther) const
{
if (mVariables.Length() != aOther.mVariables.Length()) {
return false;
}
for (size_t thisIndex = 0; thisIndex < mVariables.Length(); ++thisIndex) {
size_t otherIndex;
if (!aOther.mVariableIDs.Get(mVariables[thisIndex].mVariableName,
&otherIndex)) {
return false;
}
const nsString& otherValue = aOther.mVariables[otherIndex].mValue;
if (!mVariables[thisIndex].mValue.Equals(otherValue)) {
return false;
}
}
return true;
}
bool
CSSVariableValues::Get(const nsAString& aName, nsString& aValue) const
{

View File

@ -26,6 +26,10 @@ public:
#endif
CSSVariableValues& operator=(const CSSVariableValues& aOther);
bool operator==(const CSSVariableValues& aOther) const;
bool operator!=(const CSSVariableValues& aOther) const
{ return !(*this == aOther); }
/**
* Gets the value of a variable in this set of computed variables.
*

View File

@ -440,7 +440,19 @@ nsStyleContext::CalcStyleDifference(nsStyleContext* aOther,
// by font-size changing, so we don't need to worry about them like
// we worry about 'inherit' values.)
bool compare = mRuleNode != aOther->mRuleNode;
DebugOnly<int> styleStructCount = 0;
// If we had any change in variable values, then we'll need to examine
// all of the other style structs too, even if the new style context has
// the same rule node as the old one.
const nsStyleVariables* thisVariables = PeekStyleVariables();
if (thisVariables) {
const nsStyleVariables* otherVariables = aOther->StyleVariables();
if (thisVariables->mVariables != otherVariables->mVariables) {
compare = true;
}
}
DebugOnly<int> styleStructCount = 1; // count Variables already
#define DO_STRUCT_DIFFERENCE(struct_) \
PR_BEGIN_MACRO \
@ -490,7 +502,6 @@ nsStyleContext::CalcStyleDifference(nsStyleContext* aOther,
DO_STRUCT_DIFFERENCE(TextReset);
DO_STRUCT_DIFFERENCE(Background);
DO_STRUCT_DIFFERENCE(Color);
DO_STRUCT_DIFFERENCE(Variables);
#undef DO_STRUCT_DIFFERENCE