Skip to content

Commit

Permalink
Backed out 8 changesets (bug 1792501) for causing wpt failures on /cs…
Browse files Browse the repository at this point in the history
…s/selectors/...

Backed out changeset 993b0e6567e6 (bug 1792501)
Backed out changeset 7686c9df9ad4 (bug 1792501)
Backed out changeset cf9f855ad80c (bug 1792501)
Backed out changeset 27abe13a5a48 (bug 1792501)
Backed out changeset f708f940e907 (bug 1792501)
Backed out changeset 2a7c57a69803 (bug 1792501)
Backed out changeset 69f1155100f5 (bug 1792501)
Backed out changeset 3f5f59b76a56 (bug 1792501)
  • Loading branch information
Sandor Molnar committed Sep 14, 2023
1 parent 61f8ecc commit 4bd577f
Show file tree
Hide file tree
Showing 50 changed files with 2,110 additions and 2,975 deletions.
19 changes: 0 additions & 19 deletions dom/base/nsINode.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,25 +207,6 @@ enum class NodeSelectorFlags : uint32_t {
/// DOM mutation.
AllSimpleRestyleFlags =
AllSimpleRestyleFlagsForAppend | HasSlowSelectorLaterSiblings,

// This node was evaluated as an anchor for a relative selector.
RelativeSelectorAnchor = 1 << 5,

// This node was evaluated as an anchor for a relative selector, and that
// relative selector was not the subject of the overall selector.
RelativeSelectorAnchorNonSubject = 1 << 6,

// This node's sibling(s) performed a relative selector search to this node.
RelativeSelectorSearchDirectionSibling = 1 << 7,

// This node's ancestor(s) performed a relative selector search to this node.
RelativeSelectorSearchDirectionAncestor = 1 << 8,

// This node's sibling(s) and ancestor(s), and/or this node's ancestor's
// sibling(s) performed a relative selector search to this node.
RelativeSelectorSearchDirectionAncestorSibling =
RelativeSelectorSearchDirectionSibling |
RelativeSelectorSearchDirectionAncestor,
};

MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(NodeSelectorFlags);
Expand Down
133 changes: 33 additions & 100 deletions layout/base/RestyleManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ RestyleManager::RestyleManager(nsPresContext* aPresContext)

void RestyleManager::ContentInserted(nsIContent* aChild) {
MOZ_ASSERT(aChild->GetParentNode());
if (aChild->IsElement()) {
StyleSet()->MaybeInvalidateForElementInsertion(*aChild->AsElement());
}
RestyleForInsertOrChange(aChild);
}

Expand All @@ -98,10 +95,6 @@ void RestyleManager::ContentAppended(nsIContent* aFirstNewContent) {
}
}
#endif
if (aFirstNewContent->IsElement()) {
StyleSet()->MaybeInvalidateForElementAppend(*aFirstNewContent->AsElement());
}

const auto selectorFlags = container->GetSelectorFlags() &
NodeSelectorFlags::AllSimpleRestyleFlagsForAppend;
if (!selectorFlags) {
Expand Down Expand Up @@ -133,11 +126,8 @@ void RestyleManager::ContentAppended(nsIContent* aFirstNewContent) {

if (selectorFlags & NodeSelectorFlags::HasSlowSelector) {
if (container->IsElement()) {
auto* containerElement = container->AsElement();
PostRestyleEvent(containerElement, RestyleHint::RestyleSubtree(),
PostRestyleEvent(container->AsElement(), RestyleHint::RestyleSubtree(),
nsChangeHint(0));
StyleSet()->MaybeInvalidateRelativeSelectorForNthDependencyFromSibling(
containerElement->GetFirstElementChild());
} else {
RestylePreviousSiblings(aFirstNewContent);
RestyleSiblingsStartingWith(aFirstNewContent);
Expand All @@ -151,11 +141,8 @@ void RestyleManager::ContentAppended(nsIContent* aFirstNewContent) {
for (nsIContent* cur = aFirstNewContent->GetPreviousSibling(); cur;
cur = cur->GetPreviousSibling()) {
if (cur->IsElement()) {
auto* element = cur->AsElement();
PostRestyleEvent(element, RestyleHint::RestyleSubtree(),
PostRestyleEvent(cur->AsElement(), RestyleHint::RestyleSubtree(),
nsChangeHint(0));
StyleSet()->MaybeInvalidateRelativeSelectorForNthEdgeDependency(
*element);
break;
}
}
Expand All @@ -182,7 +169,6 @@ void RestyleManager::RestyleSiblingsStartingWith(nsIContent* aStartingSibling) {

void RestyleManager::RestyleForEmptyChange(Element* aContainer) {
PostRestyleEvent(aContainer, RestyleHint::RestyleSubtree(), nsChangeHint(0));
StyleSet()->MaybeInvalidateRelativeSelectorForEmptyDependency(*aContainer);

// In some cases (:empty + E, :empty ~ E), a change in the content of
// an element requires restyling its parent's siblings.
Expand All @@ -209,11 +195,8 @@ void RestyleManager::MaybeRestyleForEdgeChildChange(nsINode* aContainer,
}
if (content->IsElement()) {
if (passedChild) {
auto* element = content->AsElement();
PostRestyleEvent(element, RestyleHint::RestyleSubtree(),
PostRestyleEvent(content->AsElement(), RestyleHint::RestyleSubtree(),
nsChangeHint(0));
StyleSet()->MaybeInvalidateRelativeSelectorForNthEdgeDependency(
*element);
}
break;
}
Expand All @@ -228,11 +211,8 @@ void RestyleManager::MaybeRestyleForEdgeChildChange(nsINode* aContainer,
}
if (content->IsElement()) {
if (passedChild) {
auto* element = content->AsElement();
PostRestyleEvent(element, RestyleHint::RestyleSubtree(),
PostRestyleEvent(content->AsElement(), RestyleHint::RestyleSubtree(),
nsChangeHint(0));
StyleSet()->MaybeInvalidateRelativeSelectorForNthEdgeDependency(
*element);
}
break;
}
Expand Down Expand Up @@ -395,11 +375,8 @@ void RestyleManager::RestyleForInsertOrChange(nsIContent* aChild) {

if (selectorFlags & NodeSelectorFlags::HasSlowSelector) {
if (container->IsElement()) {
auto* containerElement = container->AsElement();
PostRestyleEvent(containerElement, RestyleHint::RestyleSubtree(),
PostRestyleEvent(container->AsElement(), RestyleHint::RestyleSubtree(),
nsChangeHint(0));
StyleSet()->MaybeInvalidateRelativeSelectorForNthDependencyFromSibling(
containerElement->GetFirstElementChild());
} else {
RestylePreviousSiblings(aChild);
RestyleSiblingsStartingWith(aChild);
Expand All @@ -411,8 +388,6 @@ void RestyleManager::RestyleForInsertOrChange(nsIContent* aChild) {
if (selectorFlags & NodeSelectorFlags::HasSlowSelectorLaterSiblings) {
// Restyle all later siblings.
RestyleSiblingsStartingWith(aChild->GetNextSibling());
StyleSet()->MaybeInvalidateRelativeSelectorForNthDependencyFromSibling(
aChild->GetNextElementSibling());
}

if (selectorFlags & NodeSelectorFlags::HasEdgeChildSelector) {
Expand All @@ -436,18 +411,6 @@ void RestyleManager::ContentRemoved(nsIContent* aOldChild,
// invalidated.
IncrementUndisplayedRestyleGeneration();
}
Element* nextSibling = aFollowingSibling
? aFollowingSibling->IsElement()
? aFollowingSibling->AsElement()
: aFollowingSibling->GetNextElementSibling()
: nullptr;
if (aOldChild->IsElement()) {
Element* prevSibling = aFollowingSibling
? aFollowingSibling->GetPreviousElementSibling()
: container->GetLastElementChild();
StyleSet()->MaybeInvalidateForElementRemove(*aOldChild->AsElement(),
prevSibling, nextSibling);
}

const auto selectorFlags =
container->GetSelectorFlags() & NodeSelectorFlags::AllSimpleRestyleFlags;
Expand Down Expand Up @@ -489,11 +452,8 @@ void RestyleManager::ContentRemoved(nsIContent* aOldChild,

if (selectorFlags & NodeSelectorFlags::HasSlowSelector) {
if (container->IsElement()) {
auto* containerElement = container->AsElement();
PostRestyleEvent(containerElement, RestyleHint::RestyleSubtree(),
PostRestyleEvent(container->AsElement(), RestyleHint::RestyleSubtree(),
nsChangeHint(0));
StyleSet()->MaybeInvalidateRelativeSelectorForNthDependencyFromSibling(
containerElement->GetFirstElementChild());
} else {
RestylePreviousSiblings(aOldChild);
RestyleSiblingsStartingWith(aOldChild);
Expand All @@ -505,8 +465,6 @@ void RestyleManager::ContentRemoved(nsIContent* aOldChild,
if (selectorFlags & NodeSelectorFlags::HasSlowSelectorLaterSiblings) {
// Restyle all later siblings.
RestyleSiblingsStartingWith(aFollowingSibling);
StyleSet()->MaybeInvalidateRelativeSelectorForNthDependencyFromSibling(
nextSibling);
}

if (selectorFlags & NodeSelectorFlags::HasEdgeChildSelector) {
Expand All @@ -520,11 +478,8 @@ void RestyleManager::ContentRemoved(nsIContent* aOldChild,
}
if (content->IsElement()) {
if (reachedFollowingSibling) {
auto* element = content->AsElement();
PostRestyleEvent(element, RestyleHint::RestyleSubtree(),
PostRestyleEvent(content->AsElement(), RestyleHint::RestyleSubtree(),
nsChangeHint(0));
StyleSet()->MaybeInvalidateRelativeSelectorForNthEdgeDependency(
*element);
}
break;
}
Expand All @@ -535,11 +490,8 @@ void RestyleManager::ContentRemoved(nsIContent* aOldChild,
content = content->GetPreviousSibling()) {
if (content->IsElement()) {
if (reachedFollowingSibling) {
auto* element = content->AsElement();
PostRestyleEvent(element, RestyleHint::RestyleSubtree(),
PostRestyleEvent(content->AsElement(), RestyleHint::RestyleSubtree(),
nsChangeHint(0));
StyleSet()->MaybeInvalidateRelativeSelectorForNthEdgeDependency(
*element);
}
break;
}
Expand Down Expand Up @@ -3112,6 +3064,7 @@ ServoElementSnapshot& RestyleManager::SnapshotFor(Element& aElement) {
//
// Can't wait to make ProcessPendingRestyles the only entry-point for styling,
// so this becomes much easier to reason about. Today is not that day though.
MOZ_ASSERT(aElement.HasServoData());
MOZ_ASSERT(!aElement.HasFlag(ELEMENT_HANDLED_SNAPSHOT));

ServoElementSnapshot* snapshot =
Expand Down Expand Up @@ -3402,9 +3355,7 @@ void RestyleManager::ElementStateChanged(Element* aElement,
ElementState previousState = aElement->StyleState() ^ aChangedBits;
snapshot.AddState(previousState);

ServoStyleSet& styleSet = *StyleSet();
MaybeRestyleForNthOfState(styleSet, aElement, aChangedBits);
MaybeRestyleForRelativeSelectorState(styleSet, aElement, aChangedBits);
MaybeRestyleForNthOfState(*StyleSet(), aElement, aChangedBits);
}

void RestyleManager::MaybeRestyleForNthOfState(ServoStyleSet& aStyleSet,
Expand All @@ -3418,7 +3369,7 @@ void RestyleManager::MaybeRestyleForNthOfState(ServoStyleSet& aStyleSet,
}

if (aStyleSet.HasNthOfStateDependency(*aChild, aChangedBits)) {
RestyleSiblingsForNthOf(aChild, parentFlags);
RestyleSiblings(aChild, parentFlags);
}
}

Expand Down Expand Up @@ -3505,11 +3456,7 @@ void RestyleManager::TakeSnapshotForAttributeChange(Element& aElement,
// cause the style to change.
IncrementUndisplayedRestyleGeneration();

// Relative selector invalidation travels ancestor and earlier sibling
// direction, so it's very possible that it invalidates a styled element.
if (!aElement.HasServoData() &&
!(aElement.GetSelectorFlags() &
NodeSelectorFlags::RelativeSelectorSearchDirectionAncestorSibling)) {
if (!aElement.HasServoData()) {
return;
}

Expand Down Expand Up @@ -3551,7 +3498,6 @@ void RestyleManager::AttributeChanged(Element* aElement, int32_t aNameSpaceID,
changeHint |= aElement->GetAttributeChangeHint(aAttribute, aModType);

MaybeRestyleForNthOfAttribute(aElement, aAttribute, aOldValue);
MaybeRestyleForRelativeSelectorAttribute(aElement, aAttribute, aOldValue);

if (aAttribute == nsGkAtoms::style) {
restyleHint |= RestyleHint::RESTYLE_STYLE_ATTRIBUTE;
Expand Down Expand Up @@ -3597,10 +3543,26 @@ void RestyleManager::AttributeChanged(Element* aElement, int32_t aNameSpaceID,
}
}

void RestyleManager::RestyleSiblingsForNthOf(Element* aChild,
NodeSelectorFlags aParentFlags) {
StyleSet()->RestyleSiblingsForNthOf(*aChild,
static_cast<uint32_t>(aParentFlags));
void RestyleManager::RestyleSiblings(Element* aChild,
NodeSelectorFlags aParentFlags) {
const DebugOnly<nsINode*> parentNode = aChild->GetParentNode();
MOZ_ASSERT(parentNode->IsElement() || parentNode->IsShadowRoot());

DebugOnly<bool> restyledSiblings = false;
// NodeSelectorFlags::HasSlowSelector typically indicates restyling the
// parent, but since we know we're restyling for :nth-last-child(.. of
// <selector>), we can restyle only previous siblings without
// under-invalidating.
if (aParentFlags & NodeSelectorFlags::HasSlowSelector) {
RestylePreviousSiblings(aChild->GetPreviousSibling());
restyledSiblings = true;
}
if (aParentFlags & NodeSelectorFlags::HasSlowSelectorLaterSiblings) {
RestyleSiblingsStartingWith(aChild->GetNextSibling());
restyledSiblings = true;
}
MOZ_ASSERT(restyledSiblings,
"How can we restyle siblings without a slow selector flag?");
}

void RestyleManager::MaybeRestyleForNthOfAttribute(
Expand Down Expand Up @@ -3631,37 +3593,8 @@ void RestyleManager::MaybeRestyleForNthOfAttribute(
}

if (mightHaveNthOfDependency) {
RestyleSiblingsForNthOf(aChild, parentFlags);
}
}

void RestyleManager::MaybeRestyleForRelativeSelectorAttribute(
Element* aElement, nsAtom* aAttribute, const nsAttrValue* aOldValue) {
if (!aElement->HasFlag(ELEMENT_HAS_SNAPSHOT)) {
return;
}
auto& styleSet = *StyleSet();
if (aAttribute == nsGkAtoms::id) {
auto* const oldAtom = aOldValue->Type() == nsAttrValue::eAtom
? aOldValue->GetAtomValue()
: nullptr;
styleSet.MaybeInvalidateRelativeSelectorIDDependency(*aElement, oldAtom,
aElement->GetID());
} else if (aAttribute == nsGkAtoms::_class) {
styleSet.MaybeInvalidateRelativeSelectorClassDependency(*aElement);
} else {
styleSet.MaybeInvalidateRelativeSelectorAttributeDependency(*aElement,
aAttribute);
}
}

void RestyleManager::MaybeRestyleForRelativeSelectorState(
ServoStyleSet& aStyleSet, Element* aElement, ElementState aChangedBits) {
if (!aElement->HasFlag(ELEMENT_HAS_SNAPSHOT)) {
return;
RestyleSiblings(aChild, parentFlags);
}
aStyleSet.MaybeInvalidateRelativeSelectorStateDependency(*aElement,
aChangedBits);
}

void RestyleManager::ReparentComputedStyleForFirstLine(nsIFrame* aFrame) {
Expand Down
10 changes: 1 addition & 9 deletions layout/base/RestyleManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,7 @@ class RestyleManager {
/**
* Restyle an element's previous and/or next siblings.
*/
void RestyleSiblingsForNthOf(dom::Element* aChild,
NodeSelectorFlags aParentFlags);
void RestyleSiblings(dom::Element* aChild, NodeSelectorFlags aParentFlags);

/**
* Posts restyle hints for siblings of an element and their descendants if the
Expand All @@ -390,13 +389,6 @@ class RestyleManager {
void MaybeRestyleForNthOfAttribute(dom::Element* aChild, nsAtom* aAttribute,
const nsAttrValue* aOldValue);

void MaybeRestyleForRelativeSelectorAttribute(dom::Element* aElement,
nsAtom* aAttribute,
const nsAttrValue* aOldValue);
void MaybeRestyleForRelativeSelectorState(ServoStyleSet& aStyleSet,
dom::Element* aElement,
dom::ElementState aChangedBits);

// This is only used to reparent things when moving them in/out of the
// ::first-line.
void ReparentComputedStyleForFirstLine(nsIFrame*);
Expand Down
Loading

0 comments on commit 4bd577f

Please sign in to comment.