TextNodeTraversal.h [plain text]
#ifndef TextNodeTraversal_h
#define TextNodeTraversal_h
#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);
}
namespace TextNodeTraversal {
template <class NodeType>
inline Text* firstTextChildTemplate(NodeType* current)
{
Node* node = current->firstChild();
while (node && !node->isTextNode())
node = node->nextSibling();
return toText(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 && !node->isTextNode())
node = NodeTraversal::next(node, current);
return toText(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 && !node->isTextNode())
node = NodeTraversal::next(node);
return toText(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 && !node->isTextNode())
node = NodeTraversal::next(node, stayWithin);
return toText(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 && !node->isTextNode())
node = node->nextSibling();
return toText(node);
}
}
}
#endif