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 : 48247c1dd2e5b091224bc5fff2e1249b880e157b
This commit is contained in:
Cameron McCormack 2017-05-09 18:13:45 +08:00
Родитель baddd12434
Коммит 9aa3f6dbf6
4 изменённых файлов: 29 добавлений и 0 удалений

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

@ -588,6 +588,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);

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

@ -85,6 +85,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

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

@ -1161,4 +1161,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;

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

@ -349,6 +349,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.