TextNodeTraversal.h [plain text]
#pragma once
#include "NodeTraversal.h"
#include "Text.h"
namespace WTF {
class StringBuilder;
}
namespace WebCore {
namespace TextNodeTraversal {
Text* firstChild(const Node&);
Text* firstChild(const ContainerNode&);
Text* firstWithin(const Node&);
Text* firstWithin(const ContainerNode&);
Text* next(const Node&);
Text* next(const Node&, const Node* stayWithin);
Text* next(const Text&);
Text* next(const Text&, const Node* stayWithin);
Text* nextSibling(const Node&);
String contentsAsString(const Node&);
String contentsAsString(const ContainerNode&);
void appendContents(const ContainerNode&, StringBuilder& result);
String childTextContent(const ContainerNode&);
}
namespace TextNodeTraversal {
template <class NodeType>
inline Text* firstTextChildTemplate(NodeType& current)
{
Node* node = current.firstChild();
while (node && !is<Text>(*node))
node = node->nextSibling();
return downcast<Text>(node);
}
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)
{
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); }
template <class NodeType>
inline Text* traverseNextTextTemplate(NodeType& current)
{
Node* node = NodeTraversal::next(current);
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); }
template <class NodeType>
inline Text* traverseNextTextTemplate(NodeType& current, const Node* stayWithin)
{
Node* node = NodeTraversal::next(current, stayWithin);
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* nextSibling(const Node& current)
{
Node* node = current.nextSibling();
while (node && !is<Text>(*node))
node = node->nextSibling();
return downcast<Text>(node);
}
} }