From 10bf8705d0d9b6b258f9e5042a0ea67f405f5df0 Mon Sep 17 00:00:00 2001 From: FranklinDM Date: Mon, 25 Mar 2024 02:09:12 +0800 Subject: [PATCH] Issue #2112 - Part 6: Remove IsStyledByServo function and callers --- dom/base/Element.cpp | 22 +---------- dom/base/Element.h | 4 +- dom/base/FragmentOrElement.cpp | 48 ----------------------- dom/base/nsDocument.cpp | 5 --- dom/base/nsGenericDOMDataNode.cpp | 18 --------- dom/base/nsIContent.h | 7 ---- dom/base/nsIDocument.h | 4 -- dom/base/nsINode.h | 50 +----------------------- layout/base/RestyleManager.cpp | 8 ---- layout/base/RestyleTracker.cpp | 3 -- layout/base/nsCSSFrameConstructor.cpp | 15 ++++--- layout/generic/nsFrameSetFrame.cpp | 4 +- layout/style/nsDOMCSSAttrDeclaration.cpp | 9 +---- 13 files changed, 16 insertions(+), 181 deletions(-) diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp index 37878eaa20..4137b593c2 100644 --- a/dom/base/Element.cpp +++ b/dom/base/Element.cpp @@ -1615,7 +1615,7 @@ Element::BindToTree(nsIDocument* aDocument, nsIContent* aParent, // And clear the lazy frame construction bits. NODE_NEEDS_FRAME | NODE_DESCENDANTS_NEED_FRAMES); // And the restyle bits - UnsetRestyleFlagsIfGecko(); + UnsetRestyleFlags(); } else if (IsInShadowTree()) { // We're not in a document, but we did get inserted into a shadow tree. // Since we won't have any restyle data in the document's restyle trackers, @@ -1625,7 +1625,7 @@ Element::BindToTree(nsIDocument* aDocument, nsIContent* aParent, // inserted into a document. UnsetFlags(NODE_FORCE_XBL_BINDINGS | NODE_NEEDS_FRAME | NODE_DESCENDANTS_NEED_FRAMES); - UnsetRestyleFlagsIfGecko(); + UnsetRestyleFlags(); } else { // If we're not in the doc and not in a shadow tree, // update our subtree pointer. @@ -1766,18 +1766,6 @@ Element::BindToTree(nsIDocument* aDocument, nsIContent* aParent, } } - // It would be cleanest to mark nodes as dirty when (a) they're created and - // (b) they're unbound from a tree. However, we can't easily do (a) right now, - // because IsStyledByServo() is not always easy to check at node creation time, - // and the bits have different meaning in the non-IsStyledByServo case. - // - // So for now, we just mark nodes as dirty when they're inserted into a - // document or shadow tree. - if (IsStyledByServo() && IsInComposedDoc()) { - MOZ_ASSERT(!HasServoData()); - SetIsDirtyForServo(); - } - // XXXbz script execution during binding can trigger some of these // postcondition asserts.... But we do want that, since things will // generally be quite broken when that happens. @@ -1904,12 +1892,6 @@ Element::UnbindFromTree(bool aDeep, bool aNullParent) ClearInDocument(); - // Computed styled data isn't useful for detached nodes, and we'll need to - // recomputed it anyway if we ever insert the nodes back into a document. - if (IsStyledByServo()) { - ClearServoData(); - } - // Editable descendant count only counts descendants that // are in the uncomposed document. ResetEditableDescendantCount(); diff --git a/dom/base/Element.h b/dom/base/Element.h index 7dae897e77..2d711c201b 100644 --- a/dom/base/Element.h +++ b/dom/base/Element.h @@ -1662,9 +1662,9 @@ inline const mozilla::dom::Element* nsINode::AsElement() const return static_cast(this); } -inline void nsINode::UnsetRestyleFlagsIfGecko() +inline void nsINode::UnsetRestyleFlags() { - if (IsElement() && !IsStyledByServo()) { + if (IsElement()) { UnsetFlags(ELEMENT_ALL_RESTYLE_FLAGS); } } diff --git a/dom/base/FragmentOrElement.cpp b/dom/base/FragmentOrElement.cpp index 354e92193b..126267fe93 100644 --- a/dom/base/FragmentOrElement.cpp +++ b/dom/base/FragmentOrElement.cpp @@ -2531,51 +2531,3 @@ FragmentOrElement::SetIsElementInStyleScopeFlagOnShadowTree(bool aInStyleScope) shadowRoot->SetIsElementInStyleScopeFlagOnSubtree(aInStyleScope); } } - -#ifdef DEBUG -static void -AssertDirtyDescendantsBitPropagated(nsINode* aNode) -{ - MOZ_ASSERT(aNode->HasDirtyDescendantsForServo()); - nsINode* parent = aNode->GetFlattenedTreeParentNode(); - if (!parent->IsContent()) { - MOZ_ASSERT(parent == aNode->OwnerDoc()); - MOZ_ASSERT(parent->HasDirtyDescendantsForServo()); - } else { - AssertDirtyDescendantsBitPropagated(parent); - } -} -#else -static void AssertDirtyDescendantsBitPropagated(nsINode* aNode) {} -#endif - -void -nsIContent::MarkAncestorsAsHavingDirtyDescendantsForServo() -{ - MOZ_ASSERT(IsInComposedDoc()); - - // Get the parent in the flattened tree. - nsINode* parent = GetFlattenedTreeParentNode(); - - // Loop until we hit a base case. - while (true) { - - // Base case: the document. - if (!parent->IsContent()) { - MOZ_ASSERT(parent == OwnerDoc()); - parent->SetHasDirtyDescendantsForServo(); - return; - } - - // Base case: the parent is already marked, and therefore - // so are all its ancestors. - if (parent->HasDirtyDescendantsForServo()) { - AssertDirtyDescendantsBitPropagated(parent); - return; - } - - // Mark the parent and iterate. - parent->SetHasDirtyDescendantsForServo(); - parent = parent->GetFlattenedTreeParentNode(); - } -} diff --git a/dom/base/nsDocument.cpp b/dom/base/nsDocument.cpp index 39d5c6447b..a74a81d7cf 100644 --- a/dom/base/nsDocument.cpp +++ b/dom/base/nsDocument.cpp @@ -2277,11 +2277,6 @@ nsDocument::IsWebComponentsEnabled(JSContext* aCx, JSObject* aObject) do_QueryInterface(nsJSUtils::GetStaticScriptGlobal(global)); nsIDocument* doc = window ? window->GetExtantDoc() : nullptr; - if (doc && doc->IsStyledByServo()) { - NS_WARNING("stylo: Web Components not supported yet"); - return false; - } - return true; } diff --git a/dom/base/nsGenericDOMDataNode.cpp b/dom/base/nsGenericDOMDataNode.cpp index d045c0424e..ebb135d88b 100644 --- a/dom/base/nsGenericDOMDataNode.cpp +++ b/dom/base/nsGenericDOMDataNode.cpp @@ -555,18 +555,6 @@ nsGenericDOMDataNode::BindToTree(nsIDocument* aDocument, nsIContent* aParent, UpdateEditableState(false); - // It would be cleanest to mark nodes as dirty when (a) they're created and - // (b) they're unbound from a tree. However, we can't easily do (a) right now, - // because IsStyledByServo() is not always easy to check at node creation time, - // and the bits have different meaning in the non-IsStyledByServo case. - // - // So for now, we just mark nodes as dirty when they're inserted into a - // document or shadow tree. - if (IsStyledByServo() && IsInComposedDoc()) { - MOZ_ASSERT(!HasServoData()); - SetIsDirtyForServo(); - } - NS_POSTCONDITION(aDocument == GetUncomposedDoc(), "Bound to wrong document"); NS_POSTCONDITION(aParent == GetParent(), "Bound to wrong parent"); NS_POSTCONDITION(aBindingParent == GetBindingParent(), @@ -598,12 +586,6 @@ nsGenericDOMDataNode::UnbindFromTree(bool aDeep, bool aNullParent) } ClearInDocument(); - // Computed styled data isn't useful for detached nodes, and we'll need to - // recomputed it anyway if we ever insert the nodes back into a document. - if (IsStyledByServo()) { - ClearServoData(); - } - if (aNullParent || !mParent->IsInShadowTree()) { UnsetFlags(NODE_IS_IN_SHADOW_TREE); diff --git a/dom/base/nsIContent.h b/dom/base/nsIContent.h index 4d7d76e251..4e2f1e09fb 100644 --- a/dom/base/nsIContent.h +++ b/dom/base/nsIContent.h @@ -933,13 +933,6 @@ public: mozilla::dom::Element* GetEditingHost(); - /** - * Set NODE_HAS_DIRTY_DESCENDANTS_FOR_SERVO all the way up the flattened - * parent chain to the document. If an ancestor is found with the bit already - * set, this method asserts that all of its ancestors also have the bit set. - */ - void MarkAncestorsAsHavingDirtyDescendantsForServo(); - /** * Determining language. Look at the nearest ancestor element that has a lang * attribute in the XML namespace or is an HTML/SVG element and has a lang in diff --git a/dom/base/nsIDocument.h b/dom/base/nsIDocument.h index 6ae4eb4f55..b38149c78d 100644 --- a/dom/base/nsIDocument.h +++ b/dom/base/nsIDocument.h @@ -1158,10 +1158,6 @@ public: void UpdateStyleBackendType(); - bool IsStyledByServo() const { - return GetStyleBackendType() == mozilla::StyleBackendType::Servo; - } - /** * Get this document's StyleImageLoader. This is guaranteed to not return null. */ diff --git a/dom/base/nsINode.h b/dom/base/nsINode.h index a33c088928..3f4693a593 100644 --- a/dom/base/nsINode.h +++ b/dom/base/nsINode.h @@ -1018,55 +1018,7 @@ public: virtual nsPIDOMWindowOuter* GetOwnerGlobalForBindings() override; virtual nsIGlobalObject* GetOwnerGlobal() const override; - /** - * Returns true if this is a node belonging to a document that uses the Servo - * style system. - */ - bool IsStyledByServo() const { return false; } - - bool IsDirtyForServo() const - { - MOZ_ASSERT(IsStyledByServo()); - return HasFlag(NODE_IS_DIRTY_FOR_SERVO); - } - - bool HasDirtyDescendantsForServo() const - { - MOZ_ASSERT(IsStyledByServo()); - return HasFlag(NODE_HAS_DIRTY_DESCENDANTS_FOR_SERVO); - } - - void SetIsDirtyForServo() { - MOZ_ASSERT(IsStyledByServo()); - SetFlags(NODE_IS_DIRTY_FOR_SERVO); - } - - void SetHasDirtyDescendantsForServo() { - MOZ_ASSERT(IsStyledByServo()); - SetFlags(NODE_HAS_DIRTY_DESCENDANTS_FOR_SERVO); - } - - void SetIsDirtyAndHasDirtyDescendantsForServo() { - MOZ_ASSERT(IsStyledByServo()); - SetFlags(NODE_HAS_DIRTY_DESCENDANTS_FOR_SERVO | NODE_IS_DIRTY_FOR_SERVO); - } - - void UnsetIsDirtyForServo() { - MOZ_ASSERT(IsStyledByServo()); - UnsetFlags(NODE_IS_DIRTY_FOR_SERVO); - } - - void UnsetHasDirtyDescendantsForServo() { - MOZ_ASSERT(IsStyledByServo()); - UnsetFlags(NODE_HAS_DIRTY_DESCENDANTS_FOR_SERVO); - } - - void UnsetIsDirtyAndHasDirtyDescendantsForServo() { - MOZ_ASSERT(IsStyledByServo()); - UnsetFlags(NODE_HAS_DIRTY_DESCENDANTS_FOR_SERVO | NODE_IS_DIRTY_FOR_SERVO); - } - - inline void UnsetRestyleFlagsIfGecko(); + inline void UnsetRestyleFlags(); /** * Adds a mutation observer to be notified when this node, or any of its diff --git a/layout/base/RestyleManager.cpp b/layout/base/RestyleManager.cpp index bb1fc8808b..8bbbe6407b 100644 --- a/layout/base/RestyleManager.cpp +++ b/layout/base/RestyleManager.cpp @@ -1417,7 +1417,6 @@ ElementRestyler::ElementRestyler(nsPresContext* aPresContext, , mLoggingDepth(aRestyleTracker.LoggingDepth() + 1) #endif { - MOZ_ASSERT_IF(mContent, !mContent->IsStyledByServo()); } ElementRestyler::ElementRestyler(const ElementRestyler& aParentRestyler, @@ -1452,7 +1451,6 @@ ElementRestyler::ElementRestyler(const ElementRestyler& aParentRestyler, , mLoggingDepth(aParentRestyler.mLoggingDepth + 1) #endif { - MOZ_ASSERT_IF(mContent, !mContent->IsStyledByServo()); if (aConstructorFlags & FOR_OUT_OF_FLOW_CHILD) { // Note that the out-of-flow may not be a geometric descendant of // the frame where we started the reresolve. Therefore, even if @@ -1501,7 +1499,6 @@ ElementRestyler::ElementRestyler(ParentContextFromChildFrame, , mLoggingDepth(aParentRestyler.mLoggingDepth + 1) #endif { - MOZ_ASSERT_IF(mContent, !mContent->IsStyledByServo()); } ElementRestyler::ElementRestyler(nsPresContext* aPresContext, @@ -1715,7 +1712,6 @@ ElementRestyler::ConditionallyRestyleChildren(nsIFrame* aFrame, { MOZ_ASSERT(aFrame->GetContent()); MOZ_ASSERT(aFrame->GetContent()->IsElement()); - MOZ_ASSERT(!aFrame->GetContent()->IsStyledByServo()); ConditionallyRestyleUndisplayedDescendants(aFrame, aRestyleRoot); ConditionallyRestyleContentChildren(aFrame, aRestyleRoot); @@ -1729,7 +1725,6 @@ ElementRestyler::ConditionallyRestyleContentChildren(nsIFrame* aFrame, { MOZ_ASSERT(aFrame->GetContent()); MOZ_ASSERT(aFrame->GetContent()->IsElement()); - MOZ_ASSERT(!aFrame->GetContent()->IsStyledByServo()); if (aFrame->GetContent()->HasFlag(mRestyleTracker.RootBit())) { aRestyleRoot = aFrame->GetContent()->AsElement(); @@ -1821,7 +1816,6 @@ ElementRestyler::ConditionallyRestyleUndisplayedNodes( if (aUndisplayedParent && aUndisplayedParent->IsElement() && aUndisplayedParent->HasFlag(mRestyleTracker.RootBit())) { - MOZ_ASSERT(!aUndisplayedParent->IsStyledByServo()); aRestyleRoot = aUndisplayedParent->AsElement(); } @@ -1848,7 +1842,6 @@ void ElementRestyler::ConditionallyRestyleContentDescendants(Element* aElement, Element* aRestyleRoot) { - MOZ_ASSERT(!aElement->IsStyledByServo()); if (aElement->HasFlag(mRestyleTracker.RootBit())) { aRestyleRoot = aElement; } @@ -1879,7 +1872,6 @@ ElementRestyler::ConditionallyRestyle(nsIFrame* aFrame, Element* aRestyleRoot) bool ElementRestyler::ConditionallyRestyle(Element* aElement, Element* aRestyleRoot) { - MOZ_ASSERT(!aElement->IsStyledByServo()); LOG_RESTYLE("considering element %s for eRestyle_SomeDescendants", ElementTagToString(aElement).get()); LOG_RESTYLE_INDENT(); diff --git a/layout/base/RestyleTracker.cpp b/layout/base/RestyleTracker.cpp index a954fda1a3..7a7849c77f 100644 --- a/layout/base/RestyleTracker.cpp +++ b/layout/base/RestyleTracker.cpp @@ -166,8 +166,6 @@ RestyleTracker::DoProcessRestyles() AutoTArray, RESTYLE_ARRAY_STACKSIZE> laterSiblingArr; for (auto iter = mPendingRestyles.Iter(); !iter.Done(); iter.Next()) { auto element = static_cast(iter.Key()); - MOZ_ASSERT(!element->IsStyledByServo(), - "Should not have Servo-styled elements here"); // Only collect the entries that actually need restyling by us (and // haven't, for example, already been restyled). // It's important to not mess with the flags on entries not in our @@ -180,7 +178,6 @@ RestyleTracker::DoProcessRestyles() } for (uint32_t i = 0; i < laterSiblingArr.Length(); ++i) { Element* element = laterSiblingArr[i]; - MOZ_ASSERT(!element->IsStyledByServo()); for (nsIContent* sibling = element->GetNextSibling(); sibling; sibling = sibling->GetNextSibling()) { diff --git a/layout/base/nsCSSFrameConstructor.cpp b/layout/base/nsCSSFrameConstructor.cpp index a0cc4acb21..7b17c6a318 100644 --- a/layout/base/nsCSSFrameConstructor.cpp +++ b/layout/base/nsCSSFrameConstructor.cpp @@ -2442,7 +2442,7 @@ nsCSSFrameConstructor::ConstructDocElementFrame(Element* aDocEle // this document. Unlike in AddFrameConstructionItems, it's safe to // unset all element restyle flags, since we don't have any // siblings. - aDocElement->UnsetRestyleFlagsIfGecko(); + aDocElement->UnsetRestyleFlags(); // --------- CREATE AREA OR BOX FRAME ------- // FIXME: Should this use ResolveStyleContext? (The calls in this @@ -5585,7 +5585,7 @@ nsCSSFrameConstructor::ShouldCreateItemsForChild(nsFrameConstructorState& aState nsContainerFrame* aParentFrame) { aContent->UnsetFlags(NODE_DESCENDANTS_NEED_FRAMES | NODE_NEEDS_FRAME); - if (aContent->IsElement() && !aContent->IsStyledByServo()) { + if (aContent->IsElement()) { // We can't just remove our pending restyle flags, since we may // have restyle-later-siblings set on us. But we _can_ remove the // "is possible restyle root" flags, and need to. Otherwise we can @@ -10504,14 +10504,13 @@ nsCSSFrameConstructor::AddFCItemsForAnonymousContent( { for (uint32_t i = 0; i < aAnonymousItems.Length(); ++i) { nsIContent* content = aAnonymousItems[i].mContent; - // Gecko-styled nodes should have no pending restyle flags. - MOZ_ASSERT_IF(!content->IsStyledByServo(), - !content->IsElement() || - !(content->GetFlags() & ELEMENT_ALL_RESTYLE_FLAGS)); // Assert some things about this content MOZ_ASSERT(!(content->GetFlags() & (NODE_DESCENDANTS_NEED_FRAMES | NODE_NEEDS_FRAME)), "Should not be marked as needing frames"); + MOZ_ASSERT(!content->IsElement() || + !(content->GetFlags() & ELEMENT_ALL_RESTYLE_FLAGS), + "Should have no pending restyle flags"); MOZ_ASSERT(!content->GetPrimaryFrame(), "Should have no existing frame"); MOZ_ASSERT(!content->IsNodeOfType(nsINode::eCOMMENT) && @@ -10753,7 +10752,7 @@ nsCSSFrameConstructor::ProcessChildren(nsFrameConstructorState& aState, // Frame construction item construction should not post // restyles, so removing restyle flags here is safe. - child->UnsetRestyleFlagsIfGecko(); + child->UnsetRestyleFlags(); if (addChildItems) { AddFrameConstructionItems(aState, child, iter.XBLInvolved(), insertion, itemsToConstruct); @@ -11917,7 +11916,7 @@ nsCSSFrameConstructor::BuildInlineChildItems(nsFrameConstructorState& aState, // restyle root" flags in AddFrameConstructionItems. But note // that we can remove all restyle flags, just like in // ProcessChildren and for the same reason. - content->UnsetRestyleFlagsIfGecko(); + content->UnsetRestyleFlags(); RefPtr childContext = ResolveStyleContext(parentStyleContext, content, &aState); diff --git a/layout/generic/nsFrameSetFrame.cpp b/layout/generic/nsFrameSetFrame.cpp index a3970b5a98..01d9f78154 100644 --- a/layout/generic/nsFrameSetFrame.cpp +++ b/layout/generic/nsFrameSetFrame.cpp @@ -281,7 +281,7 @@ nsHTMLFramesetFrame::Init(nsIContent* aContent, for (uint32_t i = childX; i < numChildren; i++) { nsIContent *child = mContent->GetChildAt(i); child->UnsetFlags(NODE_DESCENDANTS_NEED_FRAMES | NODE_NEEDS_FRAME); - child->UnsetRestyleFlagsIfGecko(); + child->UnsetRestyleFlags(); } break; } @@ -289,7 +289,7 @@ nsHTMLFramesetFrame::Init(nsIContent* aContent, child->UnsetFlags(NODE_DESCENDANTS_NEED_FRAMES | NODE_NEEDS_FRAME); // Also clear the restyle flags in the child like // nsCSSFrameConstructor::ProcessChildren does. - child->UnsetRestyleFlagsIfGecko(); + child->UnsetRestyleFlags(); // IMPORTANT: This must match the conditions in // nsCSSFrameConstructor::ContentAppended/Inserted/Removed diff --git a/layout/style/nsDOMCSSAttrDeclaration.cpp b/layout/style/nsDOMCSSAttrDeclaration.cpp index d79d2f8e2f..f2117dc0df 100644 --- a/layout/style/nsDOMCSSAttrDeclaration.cpp +++ b/layout/style/nsDOMCSSAttrDeclaration.cpp @@ -18,7 +18,6 @@ #include "nsWrapperCacheInlines.h" #include "nsIFrame.h" #include "ActiveLayerTracker.h" -#include "ServoDeclarationBlock.h" #include "StyleSetHandle.h" #include "DeclarationBlockInlines.h" @@ -134,12 +133,8 @@ nsDOMCSSAttributeDeclaration::GetCSSDeclaration(Operation aOperation) // cannot fail RefPtr decl; - if (mElement->IsStyledByServo()) { - decl = new ServoDeclarationBlock(); - } else { - decl = new css::Declaration(); - decl->AsGecko()->InitializeEmpty(); - } + decl = new css::Declaration(); + decl->AsGecko()->InitializeEmpty(); // this *can* fail (inside SetAttrAndNotify, at least). nsresult rv;