diff options
Diffstat (limited to 'Source/WebCore/dom/TextNodeTraversal.h')
-rw-r--r-- | Source/WebCore/dom/TextNodeTraversal.h | 91 |
1 files changed, 44 insertions, 47 deletions
diff --git a/Source/WebCore/dom/TextNodeTraversal.h b/Source/WebCore/dom/TextNodeTraversal.h index f97493e27..b520e6bfd 100644 --- a/Source/WebCore/dom/TextNodeTraversal.h +++ b/Source/WebCore/dom/TextNodeTraversal.h @@ -23,8 +23,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef TextNodeTraversal_h -#define TextNodeTraversal_h +#pragma once #include "NodeTraversal.h" #include "Text.h" @@ -37,84 +36,82 @@ namespace WebCore { namespace TextNodeTraversal { // First text child of the node. -Text* firstChild(const Node*); -Text* firstChild(const ContainerNode*); +Text* firstChild(const Node&); +Text* firstChild(const ContainerNode&); // First text descendant of the node. -Text* firstWithin(const Node*); -Text* firstWithin(const ContainerNode*); +Text* firstWithin(const Node&); +Text* firstWithin(const ContainerNode&); // Pre-order traversal skipping non-text nodes. -Text* next(const Node*); -Text* next(const Node*, const Node* stayWithin); -Text* next(const Text*); -Text* next(const Text*, const Node* stayWithin); +Text* next(const Node&); +Text* next(const Node&, const Node* stayWithin); +Text* next(const Text&); +Text* next(const Text&, const Node* stayWithin); // Next text sibling. -Text* nextSibling(const Node*); +Text* nextSibling(const Node&); // Concatenated text contents of a subtree. -String contentsAsString(const Node*); -String contentsAsString(const ContainerNode*); -void appendContents(const ContainerNode*, StringBuilder& result); +String contentsAsString(const Node&); +String contentsAsString(const ContainerNode&); +void appendContents(const ContainerNode&, StringBuilder& result); } namespace TextNodeTraversal { template <class NodeType> -inline Text* firstTextChildTemplate(NodeType* current) +inline Text* firstTextChildTemplate(NodeType& current) { - Node* node = current->firstChild(); - while (node && !node->isTextNode()) + Node* node = current.firstChild(); + while (node && !is<Text>(*node)) node = node->nextSibling(); - return toText(node); + return downcast<Text>(node); } -inline Text* firstChild(const Node* current) { return firstTextChildTemplate(current); } -inline Text* firstChild(const ContainerNode* current) { return firstTextChildTemplate(current); } +inline Text* firstChild(const Node& current) { return firstTextChildTemplate(current); } +inline Text* firstChild(const ContainerNode& current) { return firstTextChildTemplate(current); } template <class NodeType> -inline Text* firstTextWithinTemplate(NodeType* current) +inline Text* firstTextWithinTemplate(NodeType& current) { - Node* node = current->firstChild(); - while (node && !node->isTextNode()) - node = NodeTraversal::next(node, current); - return toText(node); + Node* node = current.firstChild(); + while (node && !is<Text>(*node)) + node = NodeTraversal::next(*node, ¤t); + return downcast<Text>(node); } -inline Text* firstWithin(const Node* current) { return firstTextWithinTemplate(current); } -inline Text* firstWithin(const ContainerNode* current) { return firstTextWithinTemplate(current); } +inline Text* firstWithin(const Node& current) { return firstTextWithinTemplate(current); } +inline Text* firstWithin(const ContainerNode& current) { return firstTextWithinTemplate(current); } template <class NodeType> -inline Text* traverseNextTextTemplate(NodeType* current) +inline Text* traverseNextTextTemplate(NodeType& current) { Node* node = NodeTraversal::next(current); - while (node && !node->isTextNode()) - node = NodeTraversal::next(node); - return toText(node); + while (node && !is<Text>(*node)) + node = NodeTraversal::next(*node); + return downcast<Text>(node); } -inline Text* next(const Node* current) { return traverseNextTextTemplate(current); } -inline Text* next(const Text* current) { return traverseNextTextTemplate(current); } +inline Text* next(const Node& current) { return traverseNextTextTemplate(current); } +inline Text* next(const Text& current) { return traverseNextTextTemplate(current); } template <class NodeType> -inline Text* traverseNextTextTemplate(NodeType* current, const Node* stayWithin) +inline Text* traverseNextTextTemplate(NodeType& current, const Node* stayWithin) { Node* node = NodeTraversal::next(current, stayWithin); - while (node && !node->isTextNode()) - node = NodeTraversal::next(node, stayWithin); - return toText(node); + while (node && !is<Text>(*node)) + node = NodeTraversal::next(*node, stayWithin); + return downcast<Text>(node); } -inline Text* next(const Node* current, const Node* stayWithin) { return traverseNextTextTemplate(current, stayWithin); } -inline Text* next(const Text* current, const Node* stayWithin) { return traverseNextTextTemplate(current, stayWithin); } +inline Text* next(const Node& current, const Node* stayWithin) { return traverseNextTextTemplate(current, stayWithin); } +inline Text* next(const Text& current, const Node* stayWithin) { return traverseNextTextTemplate(current, stayWithin); } -inline Text* nextSibling(const Node* current) +inline Text* nextSibling(const Node& current) { - Node* node = current->nextSibling(); - while (node && !node->isTextNode()) + Node* node = current.nextSibling(); + while (node && !is<Text>(*node)) node = node->nextSibling(); - return toText(node); + return downcast<Text>(node); } -} -} - -#endif +} // namespace TextNodeTraversal +} // namespace WebCore |