Bug 1352306 - Part 2: stylo: Only snapshot EventStates if there is some rule that depends on it. r=emilio

MozReview-Commit-ID: J5xhdi7pGSv

--HG--
extra : rebase_source : 91064f1837516c7401cbf12c6ab0b343fa7c51d0
This commit is contained in:
Cameron McCormack 2017-05-09 18:13:45 +08:00
Родитель 7bbb05753b
Коммит 64d3469106
4 изменённых файлов: 29 добавлений и 0 удалений

Просмотреть файл

@ -782,6 +782,16 @@ ServoRestyleManager::ContentStateChanged(nsIContent* aContent,
ContentStateChangedInternal(aElement, aChangedBits, &changeHint,
&restyleHint);
// Don't bother taking a snapshot if no rules depend on these state bits.
//
// We always take a snapshot for the LTR/RTL event states, since Servo doesn't
// track those bits in the same way, and we know that :dir() rules are always
// present in UA style sheets.
if (!aChangedBits.HasAtLeastOneOfStates(DIRECTION_STATES) &&
!StyleSet()->HasStateDependency(aChangedBits)) {
return;
}
ServoElementSnapshot& snapshot = SnapshotFor(aElement);
EventStates previousState = aElement->StyleState() ^ aChangedBits;
snapshot.AddState(previousState);

Просмотреть файл

@ -99,6 +99,9 @@ SERVO_BINDING_FUNC(Servo_StyleSet_ResolveForDeclarations,
SERVO_BINDING_FUNC(Servo_StyleSet_MightHaveAttributeDependency, bool,
RawServoStyleSetBorrowed set,
nsIAtom* local_name)
SERVO_BINDING_FUNC(Servo_StyleSet_HasStateDependency, bool,
RawServoStyleSetBorrowed set,
uint64_t state)
// CSSRuleList
SERVO_BINDING_FUNC(Servo_CssRules_ListTypes, void,

Просмотреть файл

@ -1362,4 +1362,10 @@ ServoStyleSet::MightHaveAttributeDependency(nsIAtom* aAttribute)
return Servo_StyleSet_MightHaveAttributeDependency(mRawSet.get(), aAttribute);
}
bool
ServoStyleSet::HasStateDependency(EventStates aState)
{
return Servo_StyleSet_HasStateDependency(mRawSet.get(), aState.ServoValue());
}
ServoStyleSet* ServoStyleSet::sInServoTraversal = nullptr;

Просмотреть файл

@ -442,6 +442,16 @@ public:
*/
bool MightHaveAttributeDependency(nsIAtom* aAttribute);
/**
* Returns true if a change in event state on an element might require
* us to restyle the element.
*
* This function allows us to skip taking a state snapshot when
* the changed state isn't depended upon by any pseudo-class selectors
* in a style sheet.
*/
bool HasStateDependency(EventStates aState);
private:
// On construction, sets sInServoTraversal to the given ServoStyleSet.
// On destruction, clears sInServoTraversal and calls RunPostTraversalTasks.