| 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 1524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1535 } | 1535 } |
| 1536 | 1536 |
| 1537 #ifndef NDEBUG | 1537 #ifndef NDEBUG |
| 1538 | 1538 |
| 1539 void Node::showNode(const char* prefix) const | 1539 void Node::showNode(const char* prefix) const |
| 1540 { | 1540 { |
| 1541 std::stringstream stream; | 1541 std::stringstream stream; |
| 1542 if (prefix) | 1542 if (prefix) |
| 1543 stream << prefix; | 1543 stream << prefix; |
| 1544 stream << *this << "\n"; | 1544 stream << *this << "\n"; |
| 1545 // TODO(tkent): Replace WTFLogAlways with something else. |
| 1545 WTFLogAlways("%s", stream.str().c_str()); | 1546 WTFLogAlways("%s", stream.str().c_str()); |
| 1546 } | 1547 } |
| 1547 | 1548 |
| 1548 void Node::showTreeForThis() const | 1549 void Node::showTreeForThis() const |
| 1549 { | 1550 { |
| 1550 showTreeAndMark(this, "*"); | 1551 showTreeAndMark(this, "*"); |
| 1551 } | 1552 } |
| 1552 | 1553 |
| 1553 void Node::showTreeForThisInFlatTree() const | 1554 void Node::showTreeForThisInFlatTree() const |
| 1554 { | 1555 { |
| 1555 showTreeAndMarkInFlatTree(this, "*"); | 1556 showTreeAndMarkInFlatTree(this, "*"); |
| 1556 } | 1557 } |
| 1557 | 1558 |
| 1558 void Node::showNodePathForThis() const | 1559 void Node::printNodePathTo(std::ostream& stream) const |
| 1559 { | 1560 { |
| 1560 HeapVector<Member<const Node>, 16> chain; | 1561 HeapVector<Member<const Node>, 16> chain; |
| 1561 const Node* node = this; | 1562 const Node* node = this; |
| 1562 while (node->parentOrShadowHostNode()) { | 1563 while (node->parentOrShadowHostNode()) { |
| 1563 chain.append(node); | 1564 chain.append(node); |
| 1564 node = node->parentOrShadowHostNode(); | 1565 node = node->parentOrShadowHostNode(); |
| 1565 } | 1566 } |
| 1566 for (unsigned index = chain.size(); index > 0; --index) { | 1567 for (unsigned index = chain.size(); index > 0; --index) { |
| 1567 const Node* node = chain[index - 1]; | 1568 const Node* node = chain[index - 1]; |
| 1568 if (node->isShadowRoot()) { | 1569 if (node->isShadowRoot()) { |
| 1569 int count = 0; | 1570 int count = 0; |
| 1570 for (const ShadowRoot* shadowRoot = toShadowRoot(node)->olderShadowR
oot(); shadowRoot; shadowRoot = shadowRoot->olderShadowRoot()) | 1571 for (const ShadowRoot* shadowRoot = toShadowRoot(node)->olderShadowR
oot(); shadowRoot; shadowRoot = shadowRoot->olderShadowRoot()) |
| 1571 ++count; | 1572 ++count; |
| 1572 WTFLogAlways("/#shadow-root[%d]", count); | 1573 stream << "/#shadow-root[" << count << "]"; |
| 1573 continue; | 1574 continue; |
| 1574 } | 1575 } |
| 1575 | 1576 |
| 1576 switch (node->getNodeType()) { | 1577 switch (node->getNodeType()) { |
| 1577 case kElementNode: { | 1578 case kElementNode: { |
| 1578 WTFLogAlways("/%s", node->nodeName().utf8().data()); | 1579 stream << "/" << node->nodeName().utf8().data(); |
| 1579 | 1580 |
| 1580 const Element* element = toElement(node); | 1581 const Element* element = toElement(node); |
| 1581 const AtomicString& idattr = element->getIdAttribute(); | 1582 const AtomicString& idattr = element->getIdAttribute(); |
| 1582 bool hasIdAttr = !idattr.isNull() && !idattr.isEmpty(); | 1583 bool hasIdAttr = !idattr.isNull() && !idattr.isEmpty(); |
| 1583 if (node->previousSibling() || node->nextSibling()) { | 1584 if (node->previousSibling() || node->nextSibling()) { |
| 1584 int count = 0; | 1585 int count = 0; |
| 1585 for (const Node* previous = node->previousSibling(); previous; p
revious = previous->previousSibling()) { | 1586 for (const Node* previous = node->previousSibling(); previous; p
revious = previous->previousSibling()) { |
| 1586 if (previous->nodeName() == node->nodeName()) { | 1587 if (previous->nodeName() == node->nodeName()) { |
| 1587 ++count; | 1588 ++count; |
| 1588 } | 1589 } |
| 1589 } | 1590 } |
| 1590 if (hasIdAttr) | 1591 if (hasIdAttr) |
| 1591 WTFLogAlways("[@id=\"%s\" and position()=%d]", idattr.utf8()
.data(), count); | 1592 stream << "[@id=\"" << idattr.utf8().data() << "\" and posit
ion()=" << count << "]"; |
| 1592 else | 1593 else |
| 1593 WTFLogAlways("[%d]", count); | 1594 stream << "[" << count << "]"; |
| 1594 } else if (hasIdAttr) { | 1595 } else if (hasIdAttr) { |
| 1595 WTFLogAlways("[@id=\"%s\"]", idattr.utf8().data()); | 1596 stream << "[@id=\"" << idattr.utf8().data() << "\"]"; |
| 1596 } | 1597 } |
| 1597 break; | 1598 break; |
| 1598 } | 1599 } |
| 1599 case kTextNode: | 1600 case kTextNode: |
| 1600 WTFLogAlways("/text()"); | 1601 stream << "/text()"; |
| 1601 break; | 1602 break; |
| 1602 case kAttributeNode: | 1603 case kAttributeNode: |
| 1603 WTFLogAlways("/@%s", node->nodeName().utf8().data()); | 1604 stream << "/@" << node->nodeName().utf8().data(); |
| 1604 break; | 1605 break; |
| 1605 default: | 1606 default: |
| 1606 break; | 1607 break; |
| 1607 } | 1608 } |
| 1608 } | 1609 } |
| 1609 WTFLogAlways("\n"); | |
| 1610 } | 1610 } |
| 1611 | 1611 |
| 1612 static void traverseTreeAndMark(const String& baseIndent, const Node* rootNode,
const Node* markedNode1, const char* markedLabel1, const Node* markedNode2, cons
t char* markedLabel2) | 1612 static void traverseTreeAndMark(const String& baseIndent, const Node* rootNode,
const Node* markedNode1, const char* markedLabel1, const Node* markedNode2, cons
t char* markedLabel2) |
| 1613 { | 1613 { |
| 1614 for (const Node& node : NodeTraversal::inclusiveDescendantsOf(*rootNode)) { | 1614 for (const Node& node : NodeTraversal::inclusiveDescendantsOf(*rootNode)) { |
| 1615 StringBuilder indent; | 1615 StringBuilder indent; |
| 1616 if (node == markedNode1) | 1616 if (node == markedNode1) |
| 1617 indent.append(markedLabel1); | 1617 indent.append(markedLabel1); |
| 1618 if (node == markedNode2) | 1618 if (node == markedNode2) |
| 1619 indent.append(markedLabel2); | 1619 indent.append(markedLabel2); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1687 } | 1687 } |
| 1688 | 1688 |
| 1689 static ContainerNode* parentOrShadowHostOrFrameOwner(const Node* node) | 1689 static ContainerNode* parentOrShadowHostOrFrameOwner(const Node* node) |
| 1690 { | 1690 { |
| 1691 ContainerNode* parent = node->parentOrShadowHostNode(); | 1691 ContainerNode* parent = node->parentOrShadowHostNode(); |
| 1692 if (!parent && node->document().frame()) | 1692 if (!parent && node->document().frame()) |
| 1693 parent = node->document().frame()->deprecatedLocalOwner(); | 1693 parent = node->document().frame()->deprecatedLocalOwner(); |
| 1694 return parent; | 1694 return parent; |
| 1695 } | 1695 } |
| 1696 | 1696 |
| 1697 static void showSubTreeAcrossFrame(const Node* node, const Node* markedNode, con
st String& indent) | 1697 static void printSubTreeAcrossFrame(const Node* node, const Node* markedNode, co
nst String& indent, std::ostream& stream) |
| 1698 { | 1698 { |
| 1699 if (node == markedNode) | 1699 if (node == markedNode) |
| 1700 fputs("*", stderr); | 1700 stream << "*"; |
| 1701 fputs(indent.utf8().data(), stderr); | 1701 stream << indent.utf8().data() << *node << "\n"; |
| 1702 node->showNode(); | |
| 1703 if (node->isShadowRoot()) { | 1702 if (node->isShadowRoot()) { |
| 1704 if (ShadowRoot* youngerShadowRoot = toShadowRoot(node)->youngerShadowRoo
t()) | 1703 if (ShadowRoot* youngerShadowRoot = toShadowRoot(node)->youngerShadowRoo
t()) |
| 1705 showSubTreeAcrossFrame(youngerShadowRoot, markedNode, indent + "\t")
; | 1704 printSubTreeAcrossFrame(youngerShadowRoot, markedNode, indent + "\t"
, stream); |
| 1706 } else { | 1705 } else { |
| 1707 if (node->isFrameOwnerElement()) | 1706 if (node->isFrameOwnerElement()) |
| 1708 showSubTreeAcrossFrame(toHTMLFrameOwnerElement(node)->contentDocumen
t(), markedNode, indent + "\t"); | 1707 printSubTreeAcrossFrame(toHTMLFrameOwnerElement(node)->contentDocume
nt(), markedNode, indent + "\t", stream); |
| 1709 if (ShadowRoot* oldestShadowRoot = oldestShadowRootFor(node)) | 1708 if (ShadowRoot* oldestShadowRoot = oldestShadowRootFor(node)) |
| 1710 showSubTreeAcrossFrame(oldestShadowRoot, markedNode, indent + "\t"); | 1709 printSubTreeAcrossFrame(oldestShadowRoot, markedNode, indent + "\t",
stream); |
| 1711 } | 1710 } |
| 1712 for (const Node* child = node->firstChild(); child; child = child->nextSibli
ng()) | 1711 for (const Node* child = node->firstChild(); child; child = child->nextSibli
ng()) |
| 1713 showSubTreeAcrossFrame(child, markedNode, indent + "\t"); | 1712 printSubTreeAcrossFrame(child, markedNode, indent + "\t", stream); |
| 1714 } | 1713 } |
| 1715 | 1714 |
| 1716 void Node::showTreeForThisAcrossFrame() const | 1715 void Node::showTreeForThisAcrossFrame() const |
| 1717 { | 1716 { |
| 1718 const Node* rootNode = this; | 1717 const Node* rootNode = this; |
| 1719 while (parentOrShadowHostOrFrameOwner(rootNode)) | 1718 while (parentOrShadowHostOrFrameOwner(rootNode)) |
| 1720 rootNode = parentOrShadowHostOrFrameOwner(rootNode); | 1719 rootNode = parentOrShadowHostOrFrameOwner(rootNode); |
| 1721 showSubTreeAcrossFrame(rootNode, this, ""); | 1720 std::stringstream stream; |
| 1721 printSubTreeAcrossFrame(rootNode, this, "", stream); |
| 1722 // TODO(tkent): Replace WTFLogAlways with something else. |
| 1723 WTFLogAlways("%s", stream.str().c_str()); |
| 1722 } | 1724 } |
| 1723 | 1725 |
| 1724 #endif | 1726 #endif |
| 1725 | 1727 |
| 1726 // -------- | 1728 // -------- |
| 1727 | 1729 |
| 1728 Element* Node::enclosingLinkEventParentOrSelf() const | 1730 Element* Node::enclosingLinkEventParentOrSelf() const |
| 1729 { | 1731 { |
| 1730 const Node* result = nullptr; | 1732 const Node* result = nullptr; |
| 1731 for (const Node* node = this; node; node = FlatTreeTraversal::parent(*node))
{ | 1733 for (const Node* node = this; node; node = FlatTreeTraversal::parent(*node))
{ |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2386 void showTree(const blink::Node* node) | 2388 void showTree(const blink::Node* node) |
| 2387 { | 2389 { |
| 2388 if (node) | 2390 if (node) |
| 2389 node->showTreeForThis(); | 2391 node->showTreeForThis(); |
| 2390 else | 2392 else |
| 2391 fprintf(stderr, "Cannot showTree for (nil)\n"); | 2393 fprintf(stderr, "Cannot showTree for (nil)\n"); |
| 2392 } | 2394 } |
| 2393 | 2395 |
| 2394 void showNodePath(const blink::Node* node) | 2396 void showNodePath(const blink::Node* node) |
| 2395 { | 2397 { |
| 2398 std::stringstream stream; |
| 2396 if (node) | 2399 if (node) |
| 2397 node->showNodePathForThis(); | 2400 node->printNodePathTo(stream); |
| 2398 else | 2401 else |
| 2399 fprintf(stderr, "Cannot showNodePath for (nil)\n"); | 2402 stream << "Cannot showNodePath for <null>"; |
| 2403 stream << "\n"; |
| 2404 // TODO(tkent): Replace WTFLogAlways with something else. |
| 2405 WTFLogAlways("%s", stream.str().c_str()); |
| 2400 } | 2406 } |
| 2401 | 2407 |
| 2402 #endif | 2408 #endif |
| OLD | NEW |