Bug 1454236: Introduce nsINode::{IsDocumentFragment, AsDocumentFragment}. r?bz
I wonder if we should use some macros to reduce a bit the copy pasta in the As*
functions...
Also whether they should start returning references... In any case, those are
followups.
MozReview-Commit-ID: 7w4518fSHnj
--- a/dom/base/DocumentFragment.h
+++ b/dom/base/DocumentFragment.h
@@ -108,10 +108,23 @@ protected:
nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
bool aPreallocateChildren) const override;
RefPtr<Element> mHost;
};
} // namespace dom
} // namespace mozilla
+inline mozilla::dom::DocumentFragment*
+nsINode::AsDocumentFragment()
+{
+ MOZ_ASSERT(IsDocumentFragment());
+ return static_cast<mozilla::dom::DocumentFragment*>(this);
+}
+
+inline const mozilla::dom::DocumentFragment*
+nsINode::AsDocumentFragment() const
+{
+ MOZ_ASSERT(IsDocumentFragment());
+ return static_cast<const mozilla::dom::DocumentFragment*>(this);
+}
#endif // mozilla_dom_DocumentFragment_h__
--- a/dom/base/nsINode.h
+++ b/dom/base/nsINode.h
@@ -72,16 +72,17 @@ inline bool IsSpaceCharacter(char16_t aC
inline bool IsSpaceCharacter(char aChar) {
return aChar == ' ' || aChar == '\t' || aChar == '\n' || aChar == '\r' ||
aChar == '\f';
}
class AccessibleNode;
struct BoxQuadOptions;
struct ConvertCoordinateOptions;
class DocGroup;
+class DocumentFragment;
class DOMPoint;
class DOMQuad;
class DOMRectReadOnly;
class Element;
class EventHandlerNonNull;
class L10nCallback;
template<typename T> class Optional;
class OwningNodeOrString;
@@ -464,16 +465,32 @@ public:
/**
* Return this node as a document. Asserts IsDocument().
*
* This is defined inline in nsIDocument.h.
*/
inline nsIDocument* AsDocument();
inline const nsIDocument* AsDocument() const;
+ /**
+ * Returns true if this is a document fragment node.
+ */
+ bool IsDocumentFragment() const
+ {
+ return NodeType() == DOCUMENT_FRAGMENT_NODE;
+ }
+
+ /**
+ * Return this node as a document fragment. Asserts IsDocumentFragment().
+ *
+ * This is defined inline in DocumentFragment.h.
+ */
+ inline mozilla::dom::DocumentFragment* AsDocumentFragment();
+ inline const mozilla::dom::DocumentFragment* AsDocumentFragment() const;
+
virtual JSObject* WrapObject(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override;
/**
* returns true if we are in priviliged code or
* layout.css.getBoxQuads.enabled == true.
*/
static bool HasBoxQuadsSupport(JSContext* aCx, JSObject* /* unused */);
@@ -786,17 +803,17 @@ public:
inline bool IsAnyOfMathMLElements(First aFirst, Args... aArgs) const
{
return IsMathMLElement() && IsNodeInternal(aFirst, aArgs...);
}
bool IsShadowRoot() const
{
const bool isShadowRoot = IsInShadowTree() && !GetParentNode();
- MOZ_ASSERT_IF(isShadowRoot, NodeType() == DOCUMENT_FRAGMENT_NODE);
+ MOZ_ASSERT_IF(isShadowRoot, IsDocumentFragment());
return isShadowRoot;
}
/**
* Insert a content node before another or at the end.
* This method handles calling BindToTree on the child appropriately.
*
* @param aKid the content to insert