Bug 732667. Only do checks for :hover selectors when hover state changes on nodes which have relevant hover rules. r=dbaron

This commit is contained in:
Boris Zbarsky 2012-03-12 22:54:15 -05:00
parent 173c545b7b
commit 0b6e42d918
3 changed files with 17 additions and 3 deletions

View File

@ -175,11 +175,14 @@ enum {
// Set if the node is handling a click.
NODE_HANDLING_CLICK = 0x00040000U,
// Set if the node has had :hover selectors matched against it
NODE_HAS_RELEVANT_HOVER_RULES = 0x00080000U,
// Two bits for the script-type ID. Not enough to represent all
// nsIProgrammingLanguage values, but we don't care. In practice,
// we can represent the ones we want, and we can fail the others at
// runtime.
NODE_SCRIPT_TYPE_OFFSET = 19,
NODE_SCRIPT_TYPE_OFFSET = 20,
NODE_SCRIPT_TYPE_SIZE = 2,

View File

@ -8085,8 +8085,14 @@ nsCSSFrameConstructor::ContentStateChanged(nsIContent* aContent,
primaryFrame->ContentStatesChanged(aStateMask);
}
nsRestyleHint rshint =
styleSet->HasStateDependentStyle(presContext, aElement, aStateMask);
if (aStateMask.HasState(NS_EVENT_STATE_HOVER) &&
!aElement->HasFlag(NODE_HAS_RELEVANT_HOVER_RULES)) {
aStateMask &= ~NS_EVENT_STATE_HOVER;
}
nsRestyleHint rshint = aStateMask.IsEmpty() ?
nsRestyleHint(0) :
styleSet->HasStateDependentStyle(presContext, aElement, aStateMask);
if (aStateMask.HasState(NS_EVENT_STATE_HOVER) && rshint != 0) {
++mHoverGeneration;

View File

@ -2114,6 +2114,11 @@ static bool SelectorMatches(Element* aElement,
// selectors ":hover" and ":active".
return false;
} else {
if (aTreeMatchContext.mForStyling &&
statesToCheck.HasAtLeastOneOfStates(NS_EVENT_STATE_HOVER)) {
// Mark the element as having :hover-dependent style
aElement->SetFlags(NODE_HAS_RELEVANT_HOVER_RULES);
}
if (aNodeMatchContext.mStateMask.HasAtLeastOneOfStates(statesToCheck)) {
if (aDependence)
*aDependence = true;