#ifndef MarkupAccumulator_h
#define MarkupAccumulator_h
#include "core/editing/markup.h"
#include "wtf/HashMap.h"
#include "wtf/Vector.h"
#include "wtf/text/StringBuilder.h"
namespace WebCore {
class Attribute;
class DocumentType;
class Element;
class Node;
class Range;
typedef HashMap<StringImpl*, StringImpl*> Namespaces;
enum EntityMask {
EntityAmp = 0x0001,
EntityLt = 0x0002,
EntityGt = 0x0004,
EntityQuot = 0x0008,
EntityNbsp = 0x0010,
EntityMaskInCDATA = 0,
EntityMaskInPCDATA = EntityAmp | EntityLt | EntityGt,
EntityMaskInHTMLPCDATA = EntityMaskInPCDATA | EntityNbsp,
EntityMaskInAttributeValue = EntityAmp | EntityQuot | EntityLt | EntityGt,
EntityMaskInHTMLAttributeValue = EntityAmp | EntityQuot | EntityNbsp,
};
enum SerializationType {
AsOwnerDocument,
ForcedXML
};
class MarkupAccumulator {
WTF_MAKE_NONCOPYABLE(MarkupAccumulator);
public:
MarkupAccumulator(Vector<Node*>*, EAbsoluteURLs, const Range* = 0, SerializationType = AsOwnerDocument);
virtual ~MarkupAccumulator();
String serializeNodes(Node& targetNode, EChildrenOnly, Vector<QualifiedName>* tagNamesToSkip = 0);
static void appendComment(StringBuilder&, const String&);
static void appendCharactersReplacingEntities(StringBuilder&, const String&, unsigned, unsigned, EntityMask);
protected:
void appendString(const String&);
void appendStartTag(Node&, Namespaces* = 0);
virtual void appendEndTag(const Node&);
static size_t totalLength(const Vector<String>&);
size_t length() const { return m_markup.length(); }
void concatenateMarkup(StringBuilder&);
void appendAttributeValue(StringBuilder&, const String&, bool);
virtual void appendCustomAttributes(StringBuilder&, const Element&, Namespaces*);
bool shouldAddNamespaceElement(const Element&, Namespaces&);
bool shouldAddNamespaceAttribute(const Attribute&, Namespaces&);
void appendNamespace(StringBuilder&, const AtomicString& prefix, const AtomicString& namespaceURI, Namespaces&);
EntityMask entityMaskForText(const Text&) const;
virtual void appendText(StringBuilder&, Text&);
void appendXMLDeclaration(StringBuilder&, const Document&);
void appendDocumentType(StringBuilder&, const DocumentType&);
void appendProcessingInstruction(StringBuilder&, const String& target, const String& data);
virtual void appendElement(StringBuilder&, Element&, Namespaces*);
void appendOpenTag(StringBuilder&, const Element&, Namespaces*);
void appendCloseTag(StringBuilder&, const Element&);
void appendAttribute(StringBuilder&, const Element&, const Attribute&, Namespaces*);
void appendCDATASection(StringBuilder&, const String&);
void appendStartMarkup(StringBuilder&, Node&, Namespaces*);
bool shouldSelfClose(const Node&);
bool elementCannotHaveEndTag(const Node&);
void appendEndMarkup(StringBuilder&, const Node&);
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, EChildrenOnly, const Namespaces*, Vector<QualifiedName>* tagNamesToSkip);
bool serializeAsHTMLDocument(const Node&) const;
StringBuilder m_markup;
const EAbsoluteURLs m_resolveURLsMethod;
SerializationType m_serializationType;
};
}
#endif