#ifndef DOMPatchSupport_h
#define DOMPatchSupport_h
#include "ExceptionCode.h"
#include <wtf/HashMap.h>
#include <wtf/OwnPtr.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/Vector.h>
#include <wtf/text/WTFString.h>
namespace WebCore {
class ContainerNode;
class DOMEditor;
class Document;
class Node;
#if ENABLE(INSPECTOR)
class DOMPatchSupport {
WTF_MAKE_NONCOPYABLE(DOMPatchSupport);
public:
static void patchDocument(Document*, const String& markup);
DOMPatchSupport(DOMEditor*, Document*);
virtual ~DOMPatchSupport();
void patchDocument(const String& markup);
Node* patchNode(Node*, const String& markup, ExceptionCode&);
private:
struct Digest;
typedef Vector<pair<Digest*, size_t> > ResultMap;
typedef HashMap<String, Digest*> UnusedNodesMap;
bool innerPatchNode(Digest* oldNode, Digest* newNode, ExceptionCode&);
std::pair<ResultMap, ResultMap> diff(const Vector<OwnPtr<Digest> >& oldChildren, const Vector<OwnPtr<Digest> >& newChildren);
bool innerPatchChildren(ContainerNode*, const Vector<OwnPtr<Digest> >& oldChildren, const Vector<OwnPtr<Digest> >& newChildren, ExceptionCode&);
PassOwnPtr<Digest> createDigest(Node*, UnusedNodesMap*);
bool insertBeforeAndMarkAsUsed(ContainerNode*, Digest*, Node* anchor, ExceptionCode&);
bool removeChildAndMoveToNew(Digest*, ExceptionCode&);
void markNodeAsUsed(Digest*);
#ifdef DEBUG_DOM_PATCH_SUPPORT
void dumpMap(const ResultMap&, const String& name);
#endif
DOMEditor* m_domEditor;
Document* m_document;
UnusedNodesMap m_unusedNodesMap;
};
#endif // ENABLE(INSPECTOR)
}
#endif // !defined(DOMPatchSupport_h)