| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "config.h" | |
| 6 #include "core/testing/CoreTestHelpers.h" | |
| 7 | |
| 8 #include "core/dom/Document.h" | |
| 9 #include "core/dom/Range.h" | |
| 10 #include "core/dom/Text.h" | |
| 11 #include "core/html/HTMLElement.h" | |
| 12 #include "wtf/text/StringBuilder.h" | |
| 13 #include <ios> | |
| 14 #include <ostream> // NOLINT | |
| 15 | |
| 16 namespace blink { | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 // Copied from "dom/Node.cpp". | |
| 21 void appendAttributeDesc(const Node& node, StringBuilder& stringBuilder, const Q
ualifiedName& name, const char* attrDesc) | |
| 22 { | |
| 23 if (!node.isElementNode()) | |
| 24 return; | |
| 25 | |
| 26 String attr = toElement(node).getAttribute(name); | |
| 27 if (attr.isEmpty()) | |
| 28 return; | |
| 29 | |
| 30 stringBuilder.append(attrDesc); | |
| 31 stringBuilder.appendLiteral("=\""); | |
| 32 stringBuilder.append(attr); | |
| 33 stringBuilder.appendLiteral("\""); | |
| 34 } | |
| 35 | |
| 36 template <typename PositionType> | |
| 37 std::ostream& printPosition(std::ostream& ostream, const PositionType& position) | |
| 38 { | |
| 39 if (position.isNull()) | |
| 40 return ostream << "null"; | |
| 41 ostream << position.anchorNode() << "@"; | |
| 42 if (position.isOffsetInAnchor()) | |
| 43 return ostream << position.offsetInContainerNode(); | |
| 44 return ostream << position.anchorType(); | |
| 45 } | |
| 46 | |
| 47 } // namespace | |
| 48 | |
| 49 std::ostream& operator<<(std::ostream& ostream, PositionAnchorType anchorType) | |
| 50 { | |
| 51 switch (anchorType) { | |
| 52 case PositionAnchorType::AfterAnchor: | |
| 53 return ostream << "afterAnchor"; | |
| 54 case PositionAnchorType::AfterChildren: | |
| 55 return ostream << "afterChildren"; | |
| 56 case PositionAnchorType::BeforeAnchor: | |
| 57 return ostream << "beforeAnchor"; | |
| 58 case PositionAnchorType::BeforeChildren: | |
| 59 return ostream << "beforeChildren"; | |
| 60 case PositionAnchorType::OffsetInAnchor: | |
| 61 return ostream << "offsetInAnchor"; | |
| 62 } | |
| 63 ASSERT_NOT_REACHED(); | |
| 64 return ostream << "anchorType=" << static_cast<int>(anchorType); | |
| 65 } | |
| 66 | |
| 67 // |std::ostream| version of |Node::showNode| | |
| 68 std::ostream& operator<<(std::ostream& ostream, const Node& node) | |
| 69 { | |
| 70 ostream << node.nodeName().utf8().data(); | |
| 71 if (node.isTextNode()) | |
| 72 return ostream << " " << node.nodeValue(); | |
| 73 StringBuilder attrs; | |
| 74 appendAttributeDesc(node, attrs, HTMLNames::idAttr, " ID"); | |
| 75 appendAttributeDesc(node, attrs, HTMLNames::classAttr, " CLASS"); | |
| 76 appendAttributeDesc(node, attrs, HTMLNames::styleAttr, " STYLE"); | |
| 77 return ostream << attrs.toString().utf8().data(); | |
| 78 } | |
| 79 | |
| 80 std::ostream& operator<<(std::ostream& ostream, const Node* node) | |
| 81 { | |
| 82 if (!node) | |
| 83 return ostream << "null"; | |
| 84 return ostream << *node; | |
| 85 } | |
| 86 | |
| 87 std::ostream& operator<<(std::ostream& ostream, const Position& position) | |
| 88 { | |
| 89 return printPosition(ostream, position); | |
| 90 } | |
| 91 | |
| 92 std::ostream& operator<<(std::ostream& ostream, const PositionInComposedTree& po
sition) | |
| 93 { | |
| 94 return printPosition(ostream, position); | |
| 95 } | |
| 96 | |
| 97 } // namespace blink | |
| OLD | NEW |