OLD | NEW |
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 1518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1529 | 1529 |
1530 std::ostream& operator<<(std::ostream& ostream, const Node* node) | 1530 std::ostream& operator<<(std::ostream& ostream, const Node* node) |
1531 { | 1531 { |
1532 if (!node) | 1532 if (!node) |
1533 return ostream << "null"; | 1533 return ostream << "null"; |
1534 return ostream << *node; | 1534 return ostream << *node; |
1535 } | 1535 } |
1536 | 1536 |
1537 #ifndef NDEBUG | 1537 #ifndef NDEBUG |
1538 | 1538 |
| 1539 String Node::toString() const |
| 1540 { |
| 1541 // TODO(tkent): We implemented toString() with operator<<. We should |
| 1542 // implement operator<< with toString() instead. |
| 1543 std::stringstream stream; |
| 1544 stream << *this; |
| 1545 return String(stream.str().c_str()); |
| 1546 } |
| 1547 |
1539 void Node::showNode(const char* prefix) const | 1548 void Node::showNode(const char* prefix) const |
1540 { | 1549 { |
1541 std::stringstream stream; | 1550 std::stringstream stream; |
1542 if (prefix) | 1551 if (prefix) |
1543 stream << prefix; | 1552 stream << prefix; |
1544 stream << *this << "\n"; | 1553 stream << *this << "\n"; |
1545 // TODO(tkent): Replace WTFLogAlways with something else. | 1554 // TODO(tkent): Replace WTFLogAlways with something else. |
1546 WTFLogAlways("%s", stream.str().c_str()); | 1555 WTFLogAlways("%s", stream.str().c_str()); |
1547 } | 1556 } |
1548 | 1557 |
1549 void Node::showTreeForThis() const | 1558 String Node::toTreeStringForThis() const |
1550 { | 1559 { |
1551 showTreeAndMark(this, "*"); | 1560 return toMarkedTreeString(this, "*"); |
1552 } | 1561 } |
1553 | 1562 |
1554 void Node::showTreeForThisInFlatTree() const | 1563 String Node::toFlatTreeStringForThis() const |
1555 { | 1564 { |
1556 showTreeAndMarkInFlatTree(this, "*"); | 1565 return toMarkedFlatTreeString(this, "*"); |
1557 } | 1566 } |
1558 | 1567 |
1559 void Node::printNodePathTo(std::ostream& stream) const | 1568 void Node::printNodePathTo(std::ostream& stream) const |
1560 { | 1569 { |
1561 HeapVector<Member<const Node>, 16> chain; | 1570 HeapVector<Member<const Node>, 16> chain; |
1562 const Node* node = this; | 1571 const Node* node = this; |
1563 while (node->parentOrShadowHostNode()) { | 1572 while (node->parentOrShadowHostNode()) { |
1564 chain.append(node); | 1573 chain.append(node); |
1565 node = node->parentOrShadowHostNode(); | 1574 node = node->parentOrShadowHostNode(); |
1566 } | 1575 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1602 break; | 1611 break; |
1603 case kAttributeNode: | 1612 case kAttributeNode: |
1604 stream << "/@" << node->nodeName().utf8().data(); | 1613 stream << "/@" << node->nodeName().utf8().data(); |
1605 break; | 1614 break; |
1606 default: | 1615 default: |
1607 break; | 1616 break; |
1608 } | 1617 } |
1609 } | 1618 } |
1610 } | 1619 } |
1611 | 1620 |
1612 static void traverseTreeAndMark(const String& baseIndent, const Node* rootNode,
const Node* markedNode1, const char* markedLabel1, const Node* markedNode2, cons
t char* markedLabel2) | 1621 static void appendMarkedTree(const String& baseIndent, const Node* rootNode, con
st Node* markedNode1, const char* markedLabel1, const Node* markedNode2, const c
har* markedLabel2, StringBuilder& builder) |
1613 { | 1622 { |
1614 for (const Node& node : NodeTraversal::inclusiveDescendantsOf(*rootNode)) { | 1623 for (const Node& node : NodeTraversal::inclusiveDescendantsOf(*rootNode)) { |
1615 StringBuilder indent; | 1624 StringBuilder indent; |
1616 if (node == markedNode1) | 1625 if (node == markedNode1) |
1617 indent.append(markedLabel1); | 1626 indent.append(markedLabel1); |
1618 if (node == markedNode2) | 1627 if (node == markedNode2) |
1619 indent.append(markedLabel2); | 1628 indent.append(markedLabel2); |
1620 indent.append(baseIndent); | 1629 indent.append(baseIndent); |
1621 for (const Node* tmpNode = &node; tmpNode && tmpNode != rootNode; tmpNod
e = tmpNode->parentOrShadowHostNode()) | 1630 for (const Node* tmpNode = &node; tmpNode && tmpNode != rootNode; tmpNod
e = tmpNode->parentOrShadowHostNode()) |
1622 indent.append('\t'); | 1631 indent.append('\t'); |
1623 node.showNode(indent.toString().utf8().data()); | 1632 builder.append(indent); |
| 1633 builder.append(node.toString()); |
| 1634 builder.append("\n"); |
1624 indent.append('\t'); | 1635 indent.append('\t'); |
1625 | 1636 |
1626 if (node.isElementNode()) { | 1637 if (node.isElementNode()) { |
1627 const Element& element = toElement(node); | 1638 const Element& element = toElement(node); |
1628 if (Element* pseudo = element.pseudoElement(PseudoIdBefore)) | 1639 if (Element* pseudo = element.pseudoElement(PseudoIdBefore)) |
1629 traverseTreeAndMark(indent.toString(), pseudo, markedNode1, mark
edLabel1, markedNode2, markedLabel2); | 1640 appendMarkedTree(indent.toString(), pseudo, markedNode1, markedL
abel1, markedNode2, markedLabel2, builder); |
1630 if (Element* pseudo = element.pseudoElement(PseudoIdAfter)) | 1641 if (Element* pseudo = element.pseudoElement(PseudoIdAfter)) |
1631 traverseTreeAndMark(indent.toString(), pseudo, markedNode1, mark
edLabel1, markedNode2, markedLabel2); | 1642 appendMarkedTree(indent.toString(), pseudo, markedNode1, markedL
abel1, markedNode2, markedLabel2, builder); |
1632 if (Element* pseudo = element.pseudoElement(PseudoIdFirstLetter)) | 1643 if (Element* pseudo = element.pseudoElement(PseudoIdFirstLetter)) |
1633 traverseTreeAndMark(indent.toString(), pseudo, markedNode1, mark
edLabel1, markedNode2, markedLabel2); | 1644 appendMarkedTree(indent.toString(), pseudo, markedNode1, markedL
abel1, markedNode2, markedLabel2, builder); |
1634 if (Element* pseudo = element.pseudoElement(PseudoIdBackdrop)) | 1645 if (Element* pseudo = element.pseudoElement(PseudoIdBackdrop)) |
1635 traverseTreeAndMark(indent.toString(), pseudo, markedNode1, mark
edLabel1, markedNode2, markedLabel2); | 1646 appendMarkedTree(indent.toString(), pseudo, markedNode1, markedL
abel1, markedNode2, markedLabel2, builder); |
1636 } | 1647 } |
1637 | 1648 |
1638 if (node.isShadowRoot()) { | 1649 if (node.isShadowRoot()) { |
1639 if (ShadowRoot* youngerShadowRoot = toShadowRoot(node).youngerShadow
Root()) | 1650 if (ShadowRoot* youngerShadowRoot = toShadowRoot(node).youngerShadow
Root()) |
1640 traverseTreeAndMark(indent.toString(), youngerShadowRoot, marked
Node1, markedLabel1, markedNode2, markedLabel2); | 1651 appendMarkedTree(indent.toString(), youngerShadowRoot, markedNod
e1, markedLabel1, markedNode2, markedLabel2, builder); |
1641 } else if (ShadowRoot* oldestShadowRoot = oldestShadowRootFor(&node)) { | 1652 } else if (ShadowRoot* oldestShadowRoot = oldestShadowRootFor(&node)) { |
1642 traverseTreeAndMark(indent.toString(), oldestShadowRoot, markedNode1
, markedLabel1, markedNode2, markedLabel2); | 1653 appendMarkedTree(indent.toString(), oldestShadowRoot, markedNode1, m
arkedLabel1, markedNode2, markedLabel2, builder); |
1643 } | 1654 } |
1644 } | 1655 } |
1645 } | 1656 } |
1646 | 1657 |
1647 static void traverseTreeAndMarkInFlatTree(const String& baseIndent, const Node*
rootNode, const Node* markedNode1, const char* markedLabel1, const Node* markedN
ode2, const char* markedLabel2) | 1658 static void appendMarkedFlatTree(const String& baseIndent, const Node* rootNode,
const Node* markedNode1, const char* markedLabel1, const Node* markedNode2, con
st char* markedLabel2, StringBuilder& builder) |
1648 { | 1659 { |
1649 for (const Node* node = rootNode; node; node = FlatTreeTraversal::nextSiblin
g(*node)) { | 1660 for (const Node* node = rootNode; node; node = FlatTreeTraversal::nextSiblin
g(*node)) { |
1650 StringBuilder indent; | 1661 StringBuilder indent; |
1651 if (node == markedNode1) | 1662 if (node == markedNode1) |
1652 indent.append(markedLabel1); | 1663 indent.append(markedLabel1); |
1653 if (node == markedNode2) | 1664 if (node == markedNode2) |
1654 indent.append(markedLabel2); | 1665 indent.append(markedLabel2); |
1655 indent.append(baseIndent); | 1666 indent.append(baseIndent); |
1656 node->showNode(indent.toString().utf8().data()); | 1667 builder.append(indent); |
| 1668 builder.append(node->toString()); |
| 1669 builder.append("\n"); |
1657 indent.append('\t'); | 1670 indent.append('\t'); |
1658 | 1671 |
1659 Node* child = FlatTreeTraversal::firstChild(*node); | 1672 if (Node* child = FlatTreeTraversal::firstChild(*node)) |
1660 if (child) | 1673 appendMarkedFlatTree(indent.toString(), child, markedNode1, markedLa
bel1, markedNode2, markedLabel2, builder); |
1661 traverseTreeAndMarkInFlatTree(indent.toString(), child, markedNode1,
markedLabel1, markedNode2, markedLabel2); | |
1662 } | 1674 } |
1663 } | 1675 } |
1664 | 1676 |
1665 void Node::showTreeAndMark(const Node* markedNode1, const char* markedLabel1, co
nst Node* markedNode2, const char* markedLabel2) const | 1677 String Node::toMarkedTreeString(const Node* markedNode1, const char* markedLabel
1, const Node* markedNode2, const char* markedLabel2) const |
1666 { | 1678 { |
1667 const Node* rootNode; | 1679 const Node* rootNode; |
1668 const Node* node = this; | 1680 const Node* node = this; |
1669 while (node->parentOrShadowHostNode() && !isHTMLBodyElement(*node)) | 1681 while (node->parentOrShadowHostNode() && !isHTMLBodyElement(*node)) |
1670 node = node->parentOrShadowHostNode(); | 1682 node = node->parentOrShadowHostNode(); |
1671 rootNode = node; | 1683 rootNode = node; |
1672 | 1684 |
| 1685 StringBuilder builder; |
1673 String startingIndent; | 1686 String startingIndent; |
1674 traverseTreeAndMark(startingIndent, rootNode, markedNode1, markedLabel1, mar
kedNode2, markedLabel2); | 1687 appendMarkedTree(startingIndent, rootNode, markedNode1, markedLabel1, marked
Node2, markedLabel2, builder); |
| 1688 return builder.toString(); |
1675 } | 1689 } |
1676 | 1690 |
1677 void Node::showTreeAndMarkInFlatTree(const Node* markedNode1, const char* marked
Label1, const Node* markedNode2, const char* markedLabel2) const | 1691 String Node::toMarkedFlatTreeString(const Node* markedNode1, const char* markedL
abel1, const Node* markedNode2, const char* markedLabel2) const |
1678 { | 1692 { |
1679 const Node* rootNode; | 1693 const Node* rootNode; |
1680 const Node* node = this; | 1694 const Node* node = this; |
1681 while (node->parentOrShadowHostNode() && !isHTMLBodyElement(*node)) | 1695 while (node->parentOrShadowHostNode() && !isHTMLBodyElement(*node)) |
1682 node = node->parentOrShadowHostNode(); | 1696 node = node->parentOrShadowHostNode(); |
1683 rootNode = node; | 1697 rootNode = node; |
1684 | 1698 |
| 1699 StringBuilder builder; |
1685 String startingIndent; | 1700 String startingIndent; |
1686 traverseTreeAndMarkInFlatTree(startingIndent, rootNode, markedNode1, markedL
abel1, markedNode2, markedLabel2); | 1701 appendMarkedFlatTree(startingIndent, rootNode, markedNode1, markedLabel1, ma
rkedNode2, markedLabel2, builder); |
| 1702 return builder.toString(); |
1687 } | 1703 } |
1688 | 1704 |
1689 static ContainerNode* parentOrShadowHostOrFrameOwner(const Node* node) | 1705 static ContainerNode* parentOrShadowHostOrFrameOwner(const Node* node) |
1690 { | 1706 { |
1691 ContainerNode* parent = node->parentOrShadowHostNode(); | 1707 ContainerNode* parent = node->parentOrShadowHostNode(); |
1692 if (!parent && node->document().frame()) | 1708 if (!parent && node->document().frame()) |
1693 parent = node->document().frame()->deprecatedLocalOwner(); | 1709 parent = node->document().frame()->deprecatedLocalOwner(); |
1694 return parent; | 1710 return parent; |
1695 } | 1711 } |
1696 | 1712 |
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2380 void showNode(const blink::Node* node) | 2396 void showNode(const blink::Node* node) |
2381 { | 2397 { |
2382 if (node) | 2398 if (node) |
2383 node->showNode(""); | 2399 node->showNode(""); |
2384 else | 2400 else |
2385 fprintf(stderr, "Cannot showNode for (nil)\n"); | 2401 fprintf(stderr, "Cannot showNode for (nil)\n"); |
2386 } | 2402 } |
2387 | 2403 |
2388 void showTree(const blink::Node* node) | 2404 void showTree(const blink::Node* node) |
2389 { | 2405 { |
2390 if (node) | 2406 // TODO(tkent): Replace WTFLogAlways with something else. |
2391 node->showTreeForThis(); | 2407 WTFLogAlways("%s", node ? node->toTreeStringForThis().utf8().data() : "Canno
t showTree for <null>"); |
2392 else | |
2393 fprintf(stderr, "Cannot showTree for (nil)\n"); | |
2394 } | 2408 } |
2395 | 2409 |
2396 void showNodePath(const blink::Node* node) | 2410 void showNodePath(const blink::Node* node) |
2397 { | 2411 { |
2398 std::stringstream stream; | 2412 std::stringstream stream; |
2399 if (node) | 2413 if (node) |
2400 node->printNodePathTo(stream); | 2414 node->printNodePathTo(stream); |
2401 else | 2415 else |
2402 stream << "Cannot showNodePath for <null>"; | 2416 stream << "Cannot showNodePath for <null>"; |
2403 stream << "\n"; | 2417 stream << "\n"; |
2404 // TODO(tkent): Replace WTFLogAlways with something else. | 2418 // TODO(tkent): Replace WTFLogAlways with something else. |
2405 WTFLogAlways("%s", stream.str().c_str()); | 2419 WTFLogAlways("%s", stream.str().c_str()); |
2406 } | 2420 } |
2407 | 2421 |
2408 #endif | 2422 #endif |
OLD | NEW |