Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Unified Diff: third_party/WebKit/Source/core/dom/Node.cpp

Issue 2282683002: Use Node stream printer in Node::showNode(). (Closed)
Patch Set: Do not print addresses Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/EphemeralRangeTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/dom/Node.cpp
diff --git a/third_party/WebKit/Source/core/dom/Node.cpp b/third_party/WebKit/Source/core/dom/Node.cpp
index 0ee6691334b48849c31dbd2aef235208e515b00c..decda39fd58187d3630a4637e22dce476dbaa205 100644
--- a/third_party/WebKit/Source/core/dom/Node.cpp
+++ b/third_party/WebKit/Source/core/dom/Node.cpp
@@ -1503,6 +1503,16 @@ static void dumpAttributeDesc(const Node& node, const QualifiedName& name, std::
// |std::ostream| version of |Node::showNode|
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().
ostream << node.nodeName().utf8().data();
if (node.isTextNode())
@@ -1510,6 +1520,10 @@ std::ostream& operator<<(std::ostream& ostream, const Node& node)
dumpAttributeDesc(node, HTMLNames::idAttr, ostream);
dumpAttributeDesc(node, HTMLNames::classAttr, ostream);
dumpAttributeDesc(node, HTMLNames::styleAttr, ostream);
+ if (hasEditableStyle(node))
+ ostream << " (editable)";
+ if (node.document().focusedElement() == &node)
+ ostream << " (focused)";
return ostream;
}
@@ -1522,49 +1536,13 @@ std::ostream& operator<<(std::ostream& ostream, const Node* node)
#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
{
- if (!prefix)
- prefix = "";
- if (isTextNode()) {
- String value = nodeValue();
- value.replace('\\', "\\\\");
- 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());
- }
+ std::stringstream stream;
+ if (prefix)
+ stream << prefix;
+ stream << *this << "\n";
+ WTFLogAlways("%s", stream.str().c_str());
}
void Node::showTreeForThis() const
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/EphemeralRangeTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698