Bug 1454251: Remove nsINode::eCOMMENT. r?bz
MozReview-Commit-ID: AbSPU25fFbM
--- a/dom/base/Comment.cpp
+++ b/dom/base/Comment.cpp
@@ -20,22 +20,16 @@ namespace mozilla {
namespace dom {
Comment::~Comment()
{
}
NS_IMPL_ISUPPORTS_INHERITED(Comment, CharacterData, nsIDOMNode)
-bool
-Comment::IsNodeOfType(uint32_t aFlags) const
-{
- return !(aFlags & ~eCOMMENT);
-}
-
already_AddRefed<CharacterData>
Comment::CloneDataNode(mozilla::dom::NodeInfo *aNodeInfo, bool aCloneText) const
{
RefPtr<mozilla::dom::NodeInfo> ni = aNodeInfo;
RefPtr<Comment> it = new Comment(ni.forget());
if (aCloneText) {
it->mText = mText;
}
--- a/dom/base/Comment.h
+++ b/dom/base/Comment.h
@@ -34,22 +34,21 @@ public:
}
explicit Comment(nsNodeInfoManager* aNodeInfoManager)
: CharacterData(aNodeInfoManager->GetCommentNodeInfo())
{
Init();
}
+ NS_IMPL_FROMNODE_HELPER(Comment, IsComment())
+
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
- // nsINode
- virtual bool IsNodeOfType(uint32_t aFlags) const override;
-
virtual already_AddRefed<CharacterData>
CloneDataNode(mozilla::dom::NodeInfo *aNodeInfo,
bool aCloneText) const override;
virtual nsIDOMNode* AsDOMNode() override { return this; }
#ifdef DEBUG
virtual void List(FILE* out, int32_t aIndent) const override;
virtual void DumpContent(FILE* out = stdout, int32_t aIndent = 0,
--- a/dom/base/nsINode.h
+++ b/dom/base/nsINode.h
@@ -411,18 +411,16 @@ public:
/**
* Bit-flags to pass (or'ed together) to IsNodeOfType()
*/
enum {
/** nsIAttribute nodes */
eATTRIBUTE = 1 << 2,
/** xml processing instructions */
ePROCESSING_INSTRUCTION = 1 << 4,
- /** comment nodes */
- eCOMMENT = 1 << 5,
/** form control elements */
eHTML_FORM_CONTROL = 1 << 6,
/** animation elements */
eANIMATION = 1 << 10,
/** filter elements that implement SVGFilterPrimitiveStandardAttributes */
eFILTER = 1 << 11,
/** SVGGeometryElement */
eSHAPE = 1 << 12
@@ -572,16 +570,24 @@ public:
{
uint32_t nodeType = NodeType();
return nodeType == TEXT_NODE ||
nodeType == CDATA_SECTION_NODE ||
nodeType == PROCESSING_INSTRUCTION_NODE ||
nodeType == COMMENT_NODE;
}
+ /**
+ * Return whether the node is a Comment node.
+ */
+ bool IsComment() const
+ {
+ return NodeType() == COMMENT_NODE;
+ }
+
virtual nsIDOMNode* AsDOMNode() = 0;
/**
* Return if this node has any children.
*/
bool HasChildren() const { return !!mFirstChild; }
/**
--- a/dom/base/nsTreeSanitizer.cpp
+++ b/dom/base/nsTreeSanitizer.cpp
@@ -1494,17 +1494,17 @@ nsTreeSanitizer::SanitizeChildren(nsINod
false,
false);
}
node = node->GetNextNode(aRoot);
continue;
}
NS_ASSERTION(!node->GetFirstChild(), "How come non-element node had kids?");
nsIContent* next = node->GetNextNonChildNode(aRoot);
- if (!mAllowComments && node->IsNodeOfType(nsINode::eCOMMENT)) {
+ if (!mAllowComments && node->IsComment()) {
node->RemoveFromParent();
}
node = next;
}
}
void
nsTreeSanitizer::RemoveAllAttributes(Element* aElement)
--- a/dom/xslt/xpath/txXPathTreeWalker.h
+++ b/dom/xslt/xpath/txXPathTreeWalker.h
@@ -240,18 +240,17 @@ txXPathNodeUtils::isProcessingInstructio
return aNode.isContent() &&
aNode.Content()->IsNodeOfType(nsINode::ePROCESSING_INSTRUCTION);
}
/* static */
inline bool
txXPathNodeUtils::isComment(const txXPathNode& aNode)
{
- return aNode.isContent() &&
- aNode.Content()->IsNodeOfType(nsINode::eCOMMENT);
+ return aNode.isContent() && aNode.Content()->IsComment();
}
/* static */
inline bool
txXPathNodeUtils::isText(const txXPathNode& aNode)
{
return aNode.isContent() &&
aNode.Content()->IsText();
--- a/editor/libeditor/HTMLEditorDataTransfer.cpp
+++ b/editor/libeditor/HTMLEditorDataTransfer.cpp
@@ -1986,19 +1986,19 @@ nsresult FindTargetNode(nsINode *aStart,
if (!aResult) {
aResult = aStart;
}
return NS_OK;
}
do {
// Is this child the magical cookie?
- if (child->IsNodeOfType(nsINode::eCOMMENT)) {
+ if (auto* comment = Comment::FromNode(child)) {
nsAutoString data;
- static_cast<Comment*>(child.get())->GetData(data);
+ comment->GetData(data);
if (data.EqualsLiteral(kInsertCookie)) {
// Yes it is! Return an error so we bubble out and short-circuit the
// search.
aResult = aStart;
child->Remove();
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -5509,17 +5509,17 @@ nsCSSFrameConstructor::ShouldCreateItems
}
// don't create a whitespace frame if aParent doesn't want it
if (!NeedFrameFor(aState, aParentFrame, aContent)) {
return false;
}
// never create frames for comments or PIs
- if (aContent->IsNodeOfType(nsINode::eCOMMENT) ||
+ if (aContent->IsComment() ||
aContent->IsNodeOfType(nsINode::ePROCESSING_INSTRUCTION)) {
return false;
}
return true;
}
void
@@ -6345,17 +6345,17 @@ nsCSSFrameConstructor::IsValidSibling(ns
StyleDisplay::TableCaption == siblingDisplay ||
StyleDisplay::TableHeaderGroup == siblingDisplay ||
StyleDisplay::TableRowGroup == siblingDisplay ||
StyleDisplay::TableFooterGroup == siblingDisplay ||
LayoutFrameType::Menu == parentType) {
// if we haven't already, resolve a style to find the display type of
// aContent.
if (UNSET_DISPLAY == aDisplay) {
- if (aContent->IsNodeOfType(nsINode::eCOMMENT) ||
+ if (aContent->IsComment() ||
aContent->IsNodeOfType(nsINode::ePROCESSING_INSTRUCTION)) {
// Comments and processing instructions never have frames, so we should
// not try to generate styles for them.
return false;
}
// FIXME(emilio): This is buggy some times, see bug 1424656.
RefPtr<ComputedStyle> computedStyle = ResolveComputedStyle(aContent);
const nsStyleDisplay* display = computedStyle->StyleDisplay();
@@ -10103,17 +10103,17 @@ nsCSSFrameConstructor::AddFCItemsForAnon
nsIContent* content = aAnonymousItems[i].mContent;
// Gecko-styled nodes should have no pending 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->GetPrimaryFrame(),
"Should have no existing frame");
- MOZ_ASSERT(!content->IsNodeOfType(nsINode::eCOMMENT) &&
+ MOZ_ASSERT(!content->IsComment() &&
!content->IsNodeOfType(nsINode::ePROCESSING_INSTRUCTION),
"Why is someone creating garbage anonymous content");
// Make sure we eagerly performed the servo cascade when the anonymous
// nodes were created.
MOZ_ASSERT(!content->IsElement() || content->AsElement()->HasServoData());
RefPtr<ComputedStyle> computedStyle = ResolveComputedStyle(content);
@@ -11450,17 +11450,17 @@ nsCSSFrameConstructor::BuildInlineChildI
} else {
// Use the content tree child list:
FlattenedChildIterator iter(parentContent);
for (nsIContent* content = iter.GetNextChild(); content; content = iter.GetNextChild()) {
// Manually check for comments/PIs, since we don't have a frame to pass to
// AddFrameConstructionItems. We know our parent is a non-replaced inline,
// so there is no need to do the NeedFrameFor check.
content->UnsetFlags(NODE_DESCENDANTS_NEED_FRAMES | NODE_NEEDS_FRAME);
- if (content->IsNodeOfType(nsINode::eCOMMENT) ||
+ if (content->IsComment() ||
content->IsNodeOfType(nsINode::ePROCESSING_INSTRUCTION)) {
continue;
}
RefPtr<ComputedStyle> childContext = ResolveComputedStyle(content);
AddFrameConstructionItemsInternal(aState, content, nullptr,
iter.XBLInvolved(), childContext,
flags, nullptr,
--- a/layout/style/nsStyleUtil.cpp
+++ b/layout/style/nsStyleUtil.cpp
@@ -741,33 +741,33 @@ nsStyleUtil::ColorComponentToFloat(uint8
}
/* static */ bool
nsStyleUtil::IsSignificantChild(nsIContent* aChild,
bool aWhitespaceIsSignificant)
{
bool isText = aChild->IsText();
- if (!isText && !aChild->IsNodeOfType(nsINode::eCOMMENT) &&
+ if (!isText && !aChild->IsComment() &&
!aChild->IsNodeOfType(nsINode::ePROCESSING_INSTRUCTION)) {
return true;
}
return isText && aChild->TextLength() != 0 &&
(aWhitespaceIsSignificant ||
!aChild->TextIsOnlyWhitespace());
}
/* static */ bool
nsStyleUtil::ThreadSafeIsSignificantChild(const nsIContent* aChild,
bool aWhitespaceIsSignificant)
{
bool isText = aChild->IsText();
- if (!isText && !aChild->IsNodeOfType(nsINode::eCOMMENT) &&
+ if (!isText && !aChild->IsComment() &&
!aChild->IsNodeOfType(nsINode::ePROCESSING_INSTRUCTION)) {
return true;
}
return isText && aChild->TextLength() != 0 &&
(aWhitespaceIsSignificant ||
!aChild->ThreadSafeTextIsOnlyWhitespace());
}
--- a/toolkit/components/find/nsFind.cpp
+++ b/toolkit/components/find/nsFind.cpp
@@ -854,27 +854,27 @@ nsFind::IsVisibleNode(nsINode* aDOMNode)
}
bool
nsFind::SkipNode(nsIContent* aContent)
{
#ifdef HAVE_BIDI_ITERATOR
// We may not need to skip comment nodes, now that IsTextNode distinguishes
// them from real text nodes.
- return aContent->IsNodeOfType(nsINode::eCOMMENT) ||
+ return aContent->IsComment() ||
aContent->IsAnyOfHTMLElements(sScriptAtom, sNoframesAtom, sSelectAtom);
#else /* HAVE_BIDI_ITERATOR */
// Temporary: eventually we will have an iterator to do this, but for now, we
// have to climb up the tree for each node and see whether any parent is a
// skipped node, and take the performance hit.
nsIContent* content = aContent;
while (content) {
- if (aContent->IsNodeOfType(nsINode::eCOMMENT) ||
+ if (aContent->IsComment() ||
content->IsAnyOfHTMLElements(nsGkAtoms::script,
nsGkAtoms::noframes,
nsGkAtoms::select)) {
#ifdef DEBUG_FIND
printf("Skipping node: ");
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(content));
DumpNode(node);
#endif