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

Side by Side 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, 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/EphemeralRangeTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. 5 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved.
6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 6 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 7 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 1485 matching lines...) Expand 10 before | Expand all | Expand 10 after
1496 return; 1496 return;
1497 const AtomicString& value = toElement(node).getAttribute(name); 1497 const AtomicString& value = toElement(node).getAttribute(name);
1498 if (value.isEmpty()) 1498 if (value.isEmpty())
1499 return; 1499 return;
1500 ostream << ' ' << name.toString().utf8().data() << '=' << value; 1500 ostream << ' ' << name.toString().utf8().data() << '=' << value;
1501 } 1501 }
1502 1502
1503 // |std::ostream| version of |Node::showNode| 1503 // |std::ostream| version of |Node::showNode|
1504 std::ostream& operator<<(std::ostream& ostream, const Node& node) 1504 std::ostream& operator<<(std::ostream& ostream, const Node& node)
1505 { 1505 {
1506 if (node.getNodeType() == Node::kProcessingInstructionNode)
1507 return ostream << "?" << node.nodeName().utf8().data();
1508 if (node.isShadowRoot()) {
1509 // nodeName of ShadowRoot is #document-fragment. It's confused with
1510 // DocumentFragment.
1511 return ostream << "#shadow-root";
1512 }
1513 if (node.isDocumentTypeNode())
1514 return ostream << "DOCTYPE " << node.nodeName().utf8().data();
1515
1506 // We avoid to print "" by utf8().data(). 1516 // We avoid to print "" by utf8().data().
1507 ostream << node.nodeName().utf8().data(); 1517 ostream << node.nodeName().utf8().data();
1508 if (node.isTextNode()) 1518 if (node.isTextNode())
1509 return ostream << " " << node.nodeValue(); 1519 return ostream << " " << node.nodeValue();
1510 dumpAttributeDesc(node, HTMLNames::idAttr, ostream); 1520 dumpAttributeDesc(node, HTMLNames::idAttr, ostream);
1511 dumpAttributeDesc(node, HTMLNames::classAttr, ostream); 1521 dumpAttributeDesc(node, HTMLNames::classAttr, ostream);
1512 dumpAttributeDesc(node, HTMLNames::styleAttr, ostream); 1522 dumpAttributeDesc(node, HTMLNames::styleAttr, ostream);
1523 if (hasEditableStyle(node))
1524 ostream << " (editable)";
1525 if (node.document().focusedElement() == &node)
1526 ostream << " (focused)";
1513 return ostream; 1527 return ostream;
1514 } 1528 }
1515 1529
1516 std::ostream& operator<<(std::ostream& ostream, const Node* node) 1530 std::ostream& operator<<(std::ostream& ostream, const Node* node)
1517 { 1531 {
1518 if (!node) 1532 if (!node)
1519 return ostream << "null"; 1533 return ostream << "null";
1520 return ostream << *node; 1534 return ostream << *node;
1521 } 1535 }
1522 1536
1523 #ifndef NDEBUG 1537 #ifndef NDEBUG
1524 1538
1525 static void appendAttributeDesc(const Node* node, StringBuilder& stringBuilder, const QualifiedName& name, const char* attrDesc)
1526 {
1527 if (!node->isElementNode())
1528 return;
1529
1530 String attr = toElement(node)->getAttribute(name);
1531 if (attr.isEmpty())
1532 return;
1533
1534 stringBuilder.append(attrDesc);
1535 stringBuilder.append("=\"");
1536 stringBuilder.append(attr);
1537 stringBuilder.append("\"");
1538 }
1539
1540 void Node::showNode(const char* prefix) const 1539 void Node::showNode(const char* prefix) const
1541 { 1540 {
1542 if (!prefix) 1541 std::stringstream stream;
1543 prefix = ""; 1542 if (prefix)
1544 if (isTextNode()) { 1543 stream << prefix;
1545 String value = nodeValue(); 1544 stream << *this << "\n";
1546 value.replace('\\', "\\\\"); 1545 WTFLogAlways("%s", stream.str().c_str());
1547 value.replace('\n', "\\n");
1548 WTFLogAlways("%s%s\t%p \"%s\"\n", prefix, nodeName().utf8().data(), this , value.utf8().data());
1549 } else if (isDocumentTypeNode()) {
1550 WTFLogAlways("%sDOCTYPE %s\t%p\n", prefix, nodeName().utf8().data(), thi s);
1551 } else if (getNodeType() == kProcessingInstructionNode) {
1552 WTFLogAlways("%s?%s\t%p\n", prefix, nodeName().utf8().data(), this);
1553 } else if (isShadowRoot()) {
1554 // nodeName of ShadowRoot is #document-fragment. It's confused with
1555 // DocumentFragment.
1556 WTFLogAlways("%s#shadow-root\t%p\n", prefix, this);
1557 } else {
1558 StringBuilder attrs;
1559 appendAttributeDesc(this, attrs, idAttr, " ID");
1560 appendAttributeDesc(this, attrs, classAttr, " CLASS");
1561 appendAttributeDesc(this, attrs, styleAttr, " STYLE");
1562 if (hasEditableStyle(*this))
1563 attrs.append(" (editable)");
1564 if (document().focusedElement() == this)
1565 attrs.append(" (focused)");
1566 WTFLogAlways("%s%s\t%p%s\n", prefix, nodeName().utf8().data(), this, att rs.toString().utf8().data());
1567 }
1568 } 1546 }
1569 1547
1570 void Node::showTreeForThis() const 1548 void Node::showTreeForThis() const
1571 { 1549 {
1572 showTreeAndMark(this, "*"); 1550 showTreeAndMark(this, "*");
1573 } 1551 }
1574 1552
1575 void Node::showTreeForThisInFlatTree() const 1553 void Node::showTreeForThisInFlatTree() const
1576 { 1554 {
1577 showTreeAndMarkInFlatTree(this, "*"); 1555 showTreeAndMarkInFlatTree(this, "*");
(...skipping 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
2429 2407
2430 void showNodePath(const blink::Node* node) 2408 void showNodePath(const blink::Node* node)
2431 { 2409 {
2432 if (node) 2410 if (node)
2433 node->showNodePathForThis(); 2411 node->showNodePathForThis();
2434 else 2412 else
2435 fprintf(stderr, "Cannot showNodePath for (nil)\n"); 2413 fprintf(stderr, "Cannot showNodePath for (nil)\n");
2436 } 2414 }
2437 2415
2438 #endif 2416 #endif
OLDNEW
« 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