Bug 1352306 - Part 1: stylo: Only snapshot attributes if there is some rule that depends on that attribute. r=emilio

MozReview-Commit-ID: Emey96ovc2a
This commit is contained in:
Cameron McCormack 2017-05-08 16:04:31 +08:00
parent 690fa8991e
commit 1ba1986481
4 changed files with 32 additions and 2 deletions

View File

@ -815,10 +815,22 @@ ServoRestyleManager::AttributeWillChange(Element* aElement,
return;
}
bool influencesOtherPseudoClassState =
AttributeInfluencesOtherPseudoClassState(aElement, aAttribute);
if (!influencesOtherPseudoClassState &&
!((aNameSpaceID == kNameSpaceID_None &&
(aAttribute == nsGkAtoms::id ||
aAttribute == nsGkAtoms::_class)) ||
aAttribute == nsGkAtoms::lang ||
StyleSet()->MightHaveAttributeDependency(aAttribute))) {
return;
}
ServoElementSnapshot& snapshot = SnapshotFor(aElement);
snapshot.AddAttrs(aElement, aNameSpaceID, aAttribute);
if (AttributeInfluencesOtherPseudoClassState(aElement, aAttribute)) {
if (influencesOtherPseudoClassState) {
snapshot.AddOtherPseudoClassState(aElement);
}
@ -833,7 +845,6 @@ ServoRestyleManager::AttributeChanged(Element* aElement, int32_t aNameSpaceID,
const nsAttrValue* aOldValue)
{
MOZ_ASSERT(!mInStyleRefresh);
MOZ_ASSERT(!mSnapshots.Get(aElement) || mSnapshots.Get(aElement)->HasAttrs());
nsIFrame* primaryFrame = aElement->GetPrimaryFrame();
if (primaryFrame) {

View File

@ -96,6 +96,9 @@ SERVO_BINDING_FUNC(Servo_StyleSet_ResolveForDeclarations,
RawServoStyleSetBorrowed set,
ServoComputedValuesBorrowedOrNull parent_style,
RawServoDeclarationBlockBorrowed declarations)
SERVO_BINDING_FUNC(Servo_StyleSet_MightHaveAttributeDependency, bool,
RawServoStyleSetBorrowed set,
nsIAtom* local_name)
// CSSRuleList
SERVO_BINDING_FUNC(Servo_CssRules_ListTypes, void,

View File

@ -1356,4 +1356,10 @@ ServoStyleSet::RunPostTraversalTasks()
}
}
bool
ServoStyleSet::MightHaveAttributeDependency(nsIAtom* aAttribute)
{
return Servo_StyleSet_MightHaveAttributeDependency(mRawSet.get(), aAttribute);
}
ServoStyleSet* ServoStyleSet::sInServoTraversal = nullptr;

View File

@ -432,6 +432,16 @@ public:
mNeedsRestyleAfterEnsureUniqueInner = true;
}
/**
* Returns true if a modification to an an attribute with the specified
* local name might require us to restyle the element.
*
* This function allows us to skip taking a an attribute snapshot when
* the modified attribute doesn't appear in an attribute selector in
* a style sheet.
*/
bool MightHaveAttributeDependency(nsIAtom* aAttribute);
private:
// On construction, sets sInServoTraversal to the given ServoStyleSet.
// On destruction, clears sInServoTraversal and calls RunPostTraversalTasks.