Commit 9d0702c2 authored by tkent's avatar tkent Committed by Commit bot

Use Node stream printer in Node::showNode().

This is a preparation to remove WTFLogAlwasy() from Node.cpp.
This CL has no behavior changes.

BUG=638849

Review-Url: https://codereview.chromium.org/2282683002
Cr-Commit-Position: refs/heads/master@{#414726}
parent 2fdf3d97
...@@ -1503,6 +1503,16 @@ static void dumpAttributeDesc(const Node& node, const QualifiedName& name, std:: ...@@ -1503,6 +1503,16 @@ static void dumpAttributeDesc(const Node& node, const QualifiedName& name, std::
// |std::ostream| version of |Node::showNode| // |std::ostream| version of |Node::showNode|
std::ostream& operator<<(std::ostream& ostream, const Node& node) std::ostream& operator<<(std::ostream& ostream, const Node& node)
{ {
if (node.getNodeType() == Node::kProcessingInstructionNode)
return ostream << "?" << node.nodeName().utf8().data();
if (node.isShadowRoot()) {
// nodeName of ShadowRoot is #document-fragment. It's confused with
// DocumentFragment.
return ostream << "#shadow-root";
}
if (node.isDocumentTypeNode())
return ostream << "DOCTYPE " << node.nodeName().utf8().data();
// We avoid to print "" by utf8().data(). // We avoid to print "" by utf8().data().
ostream << node.nodeName().utf8().data(); ostream << node.nodeName().utf8().data();
if (node.isTextNode()) if (node.isTextNode())
...@@ -1510,6 +1520,10 @@ std::ostream& operator<<(std::ostream& ostream, const Node& node) ...@@ -1510,6 +1520,10 @@ std::ostream& operator<<(std::ostream& ostream, const Node& node)
dumpAttributeDesc(node, HTMLNames::idAttr, ostream); dumpAttributeDesc(node, HTMLNames::idAttr, ostream);
dumpAttributeDesc(node, HTMLNames::classAttr, ostream); dumpAttributeDesc(node, HTMLNames::classAttr, ostream);
dumpAttributeDesc(node, HTMLNames::styleAttr, ostream); dumpAttributeDesc(node, HTMLNames::styleAttr, ostream);
if (hasEditableStyle(node))
ostream << " (editable)";
if (node.document().focusedElement() == &node)
ostream << " (focused)";
return ostream; return ostream;
} }
...@@ -1522,49 +1536,13 @@ std::ostream& operator<<(std::ostream& ostream, const Node* node) ...@@ -1522,49 +1536,13 @@ std::ostream& operator<<(std::ostream& ostream, const Node* node)
#ifndef NDEBUG #ifndef NDEBUG
static void appendAttributeDesc(const Node* node, StringBuilder& stringBuilder, const QualifiedName& name, const char* attrDesc)
{
if (!node->isElementNode())
return;
String attr = toElement(node)->getAttribute(name);
if (attr.isEmpty())
return;
stringBuilder.append(attrDesc);
stringBuilder.append("=\"");
stringBuilder.append(attr);
stringBuilder.append("\"");
}
void Node::showNode(const char* prefix) const void Node::showNode(const char* prefix) const
{ {
if (!prefix) std::stringstream stream;
prefix = ""; if (prefix)
if (isTextNode()) { stream << prefix;
String value = nodeValue(); stream << *this << "\n";
value.replace('\\', "\\\\"); WTFLogAlways("%s", stream.str().c_str());
value.replace('\n', "\\n");
WTFLogAlways("%s%s\t%p \"%s\"\n", prefix, nodeName().utf8().data(), this, value.utf8().data());
} else if (isDocumentTypeNode()) {
WTFLogAlways("%sDOCTYPE %s\t%p\n", prefix, nodeName().utf8().data(), this);
} else if (getNodeType() == kProcessingInstructionNode) {
WTFLogAlways("%s?%s\t%p\n", prefix, nodeName().utf8().data(), this);
} else if (isShadowRoot()) {
// nodeName of ShadowRoot is #document-fragment. It's confused with
// DocumentFragment.
WTFLogAlways("%s#shadow-root\t%p\n", prefix, this);
} else {
StringBuilder attrs;
appendAttributeDesc(this, attrs, idAttr, " ID");
appendAttributeDesc(this, attrs, classAttr, " CLASS");
appendAttributeDesc(this, attrs, styleAttr, " STYLE");
if (hasEditableStyle(*this))
attrs.append(" (editable)");
if (document().focusedElement() == this)
attrs.append(" (focused)");
WTFLogAlways("%s%s\t%p%s\n", prefix, nodeName().utf8().data(), this, attrs.toString().utf8().data());
}
} }
void Node::showTreeForThis() const void Node::showTreeForThis() const
......
...@@ -83,7 +83,7 @@ TEST_F(EphemeralRangeTest, rangeShadowTraversal) ...@@ -83,7 +83,7 @@ TEST_F(EphemeralRangeTest, rangeShadowTraversal)
// In this case FlatTree traverse should differs from DOM tree traverse. // In this case FlatTree traverse should differs from DOM tree traverse.
EXPECT_EQ( EXPECT_EQ(
"[BODY][P id=\"host\"][B id=\"one\"][INPUT][DIV id=\"inner-editor\"][#text \"some\"]", "[BODY][P id=\"host\"][B id=\"one\"][INPUT][DIV id=\"inner-editor\" (editable)][#text \"some\"]",
traverseRange<FlatTreeTraversal>(getBodyRange())); traverseRange<FlatTreeTraversal>(getBodyRange()));
EXPECT_EQ( EXPECT_EQ(
traverseRange<FlatTreeTraversal>(getBodyRange()), traverseRange<FlatTreeTraversal>(getBodyRange()),
...@@ -123,7 +123,7 @@ TEST_F(EphemeralRangeTest, rangeTraversalLimited) ...@@ -123,7 +123,7 @@ TEST_F(EphemeralRangeTest, rangeTraversalLimited)
EXPECT_EQ(traverseRange<>(fromBToSpan), traverseRange(EphemeralRange(fromBToSpan))); EXPECT_EQ(traverseRange<>(fromBToSpan), traverseRange(EphemeralRange(fromBToSpan)));
EXPECT_EQ( EXPECT_EQ(
"[B id=\"one\"][INPUT][DIV id=\"inner-editor\"][#text \"some\"][SPAN id=\"two\"]", "[B id=\"one\"][INPUT][DIV id=\"inner-editor\" (editable)][#text \"some\"][SPAN id=\"two\"]",
traverseRange<FlatTreeTraversal>(fromBToSpan)); traverseRange<FlatTreeTraversal>(fromBToSpan));
EXPECT_EQ( EXPECT_EQ(
traverseRange<FlatTreeTraversal>(fromBToSpan), traverseRange<FlatTreeTraversal>(fromBToSpan),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment