MarkupAccumulator.h [plain text]
#ifndef MarkupAccumulator_h
#define MarkupAccumulator_h
#include "markup.h"
#include <wtf/HashMap.h>
#include <wtf/text/StringBuilder.h>
namespace WebCore {
class Attribute;
class DocumentType;
class Element;
class Node;
class Range;
typedef HashMap<AtomicString, AtomicStringImpl*> Namespaces;
enum EntityMask {
EntityAmp = 0x0001,
EntityLt = 0x0002,
EntityGt = 0x0004,
EntityQuot = 0x0008,
EntityNbsp = 0x0010,
EntityMaskInCDATA = 0,
EntityMaskInPCDATA = EntityAmp | EntityLt | EntityGt,
EntityMaskInHTMLPCDATA = EntityMaskInPCDATA | EntityNbsp,
EntityMaskInAttributeValue = EntityAmp | EntityLt | EntityGt | EntityQuot,
EntityMaskInHTMLAttributeValue = EntityMaskInAttributeValue | EntityNbsp,
};
class MarkupAccumulator {
public:
MarkupAccumulator(Vector<Node*>*, EAbsoluteURLs, const Range* = 0, EFragmentSerialization = HTMLFragmentSerialization);
virtual ~MarkupAccumulator();
String serializeNodes(Node& targetNode, Node* nodeToSkip, EChildrenOnly, Vector<QualifiedName>* tagNamesToSkip = nullptr);
static void appendCharactersReplacingEntities(StringBuilder&, const String&, unsigned, unsigned, EntityMask);
protected:
static size_t totalLength(const Vector<String>&);
size_t length() const { return m_markup.length(); }
void concatenateMarkup(StringBuilder&);
virtual void appendString(const String&);
virtual void appendEndTag(const Node&);
virtual void appendCustomAttributes(StringBuilder&, const Element&, Namespaces*);
virtual void appendText(StringBuilder&, const Text&);
virtual void appendElement(StringBuilder&, const Element&, Namespaces*);
void appendStartTag(const Node&, Namespaces* = 0);
void appendOpenTag(StringBuilder&, const Element&, Namespaces*);
void appendCloseTag(StringBuilder&, const Element&);
void appendStartMarkup(StringBuilder&, const Node&, Namespaces*);
void appendEndMarkup(StringBuilder&, const Node&);
void appendAttributeValue(StringBuilder&, const String&, bool);
void appendNodeValue(StringBuilder&, const Node&, const Range*, EntityMask);
void appendNamespace(StringBuilder&, const AtomicString& prefix, const AtomicString& namespaceURI, Namespaces&, bool allowEmptyDefaultNS = false);
void appendXMLDeclaration(StringBuilder&, const Document&);
void appendDocumentType(StringBuilder&, const DocumentType&);
void appendProcessingInstruction(StringBuilder&, const String& target, const String& data);
void appendAttribute(StringBuilder&, const Element&, const Attribute&, Namespaces*);
void appendCDATASection(StringBuilder&, const String&);
bool shouldAddNamespaceElement(const Element&);
bool shouldAddNamespaceAttribute(const Attribute&, Namespaces&);
bool shouldSelfClose(const Node&);
bool elementCannotHaveEndTag(const Node&);
EntityMask entityMaskForText(const Text&) const;
Vector<Node*>* const m_nodes;
const Range* const m_range;
private:
String resolveURLIfNeeded(const Element&, const String&) const;
void appendQuotedURLAttributeValue(StringBuilder&, const Element&, const Attribute&);
void serializeNodesWithNamespaces(Node& targetNode, Node* nodeToSkip, EChildrenOnly, const Namespaces*, Vector<QualifiedName>* tagNamesToSkip);
bool inXMLFragmentSerialization() const { return m_fragmentSerialization == XMLFragmentSerialization; }
void generateUniquePrefix(QualifiedName&, const Namespaces&);
StringBuilder m_markup;
const EAbsoluteURLs m_resolveURLsMethod;
EFragmentSerialization m_fragmentSerialization;
unsigned m_prefixLevel;
};
}
#endif