/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #ifndef nsIContentInlines_h #define nsIContentInlines_h #include "mozilla/StaticPrefs_dom.h" #include "mozilla/dom/ChildIterator.h" #include "mozilla/dom/CustomElementRegistry.h" #include "mozilla/dom/Document.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/HTMLSlotElement.h" #include "mozilla/dom/ShadowRoot.h" #include "nsAtom.h" #include "nsContentUtils.h" #include "nsIContent.h" #include "nsIFrame.h" #include "nsINode.h" inline bool nsINode::HasScopedRegistry() const { if (!mozilla::StaticPrefs::dom_scoped_custom_element_registries_enabled()) { return false; } bool isScoped = false; if (IsElement()) { isScoped = AsElement()->GetCustomElementRegistryState() == CustomElementRegistryState::Scoped; } else if (const auto* shadowRoot = mozilla::dom::ShadowRoot::FromNode(this)) { isScoped = shadowRoot->GetCustomElementRegistryState() == CustomElementRegistryState::Scoped; } else if (IsDocument()) { isScoped = AsDocument()->HasScopedCustomElementRegistry(); } MOZ_ASSERT( isScoped == mozilla::dom::CustomElementRegistry::IsInScopedRegistryMap( const_cast(*this)), "scoped-registry check disagrees with the registry map"); return isScoped; } inline bool nsIContent::IsInHTMLDocument() const { return OwnerDoc()->IsHTMLDocument(); } inline bool nsIContent::IsInChromeDocument() const { return nsContentUtils::IsChromeDoc(OwnerDoc()); } inline void nsIContent::SetPrimaryFrame(nsIFrame* aFrame) { MOZ_ASSERT(!aFrame || IsInUncomposedDoc() || IsInShadowTree(), "This will end badly!"); MOZ_ASSERT(!aFrame || IsInComposedDoc(), "This will end badly!"); // is known to trigger this, see bug 749326 and bug 135040. MOZ_ASSERT(IsHTMLElement(nsGkAtoms::area) || !aFrame || !mPrimaryFrame || aFrame == mPrimaryFrame, "Losing track of existing primary frame"); if (aFrame) { MOZ_ASSERT(!aFrame->IsPlaceholderFrame()); if (MOZ_LIKELY(!IsHTMLElement(nsGkAtoms::area)) || aFrame->GetContent() == this) { aFrame->SetIsPrimaryFrame(true); } } else if (nsIFrame* currentPrimaryFrame = GetPrimaryFrame()) { if (MOZ_LIKELY(!IsHTMLElement(nsGkAtoms::area)) || currentPrimaryFrame->GetContent() == this) { currentPrimaryFrame->SetIsPrimaryFrame(false); } } mPrimaryFrame = aFrame; } /** * Return the parent node of aNode in the specified tree. If aNode is the root * of a native anonymous subtree, this returns the parent as-is. * * When aType is eNormal, return the parent node in the flattened tree. If the * parent node of aNode is a shadow host, return its assigned or nullptr. * If the parent node is a in a shadow, return nullptr if the has * some assigned nodes or otherwise, the (i.e., when the node is a used * fallback content). If the parent node is a shadow root, return its host * element. * * When aType is eForStyle, return the almost same value as when aType is * eNormal. However, if aNode is the root of a native anonymous subtree and the * parent node in the DOM is the document element, return the document. * * When aType is eForSelection, return the parent node in the DOM even if aNode * is not a part of the flattened tree, e.g., it is a child node of a shadow * host but is not assigned to any , or it is a child node of a * which has some assigned nodes. The reason is, Selection API accepts any node * in the DOM as the container. On the other hand, UA shadow tree such as a * shadow for
,