#ifndef Range_h
#define Range_h
#include "bindings/v8/ExceptionStatePlaceholder.h"
#include "bindings/v8/ScriptWrappable.h"
#include "core/dom/RangeBoundaryPoint.h"
#include "platform/geometry/FloatRect.h"
#include "platform/geometry/IntRect.h"
#include "platform/heap/Handle.h"
#include "wtf/Forward.h"
#include "wtf/RefCounted.h"
#include "wtf/Vector.h"
namespace WebCore {
class ClientRect;
class ClientRectList;
class ContainerNode;
class Document;
class DocumentFragment;
class ExceptionState;
class FloatQuad;
class Node;
class NodeWithIndex;
class Text;
class Range FINAL : public RefCountedWillBeGarbageCollectedFinalized<Range>, public ScriptWrappable {
public:
static PassRefPtrWillBeRawPtr<Range> create(Document&);
static PassRefPtrWillBeRawPtr<Range> create(Document&, Node* startContainer, int startOffset, Node* endContainer, int endOffset);
static PassRefPtrWillBeRawPtr<Range> create(Document&, const Position&, const Position&);
~Range();
Document& ownerDocument() const { ASSERT(m_ownerDocument); return *m_ownerDocument.get(); }
Node* startContainer() const { return m_start.container(); }
int startOffset() const { return m_start.offset(); }
Node* endContainer() const { return m_end.container(); }
int endOffset() const { return m_end.offset(); }
Node* startContainer(ExceptionState&) const;
int startOffset(ExceptionState&) const;
Node* endContainer(ExceptionState&) const;
int endOffset(ExceptionState&) const;
bool collapsed(ExceptionState&) const;
Node* commonAncestorContainer(ExceptionState&) const;
static Node* commonAncestorContainer(Node* containerA, Node* containerB);
void setStart(PassRefPtr<Node> container, int offset, ExceptionState& = ASSERT_NO_EXCEPTION);
void setEnd(PassRefPtr<Node> container, int offset, ExceptionState& = ASSERT_NO_EXCEPTION);
void collapse(bool toStart, ExceptionState&);
bool isPointInRange(Node* refNode, int offset, ExceptionState&);
short comparePoint(Node* refNode, int offset, ExceptionState&) const;
enum CompareResults { NODE_BEFORE, NODE_AFTER, NODE_BEFORE_AND_AFTER, NODE_INSIDE };
CompareResults compareNode(Node* refNode, ExceptionState&) const;
enum CompareHow { START_TO_START, START_TO_END, END_TO_END, END_TO_START };
short compareBoundaryPoints(CompareHow, const Range* sourceRange, ExceptionState&) const;
static short compareBoundaryPoints(Node* containerA, int offsetA, Node* containerB, int offsetB, ExceptionState&);
static short compareBoundaryPoints(const RangeBoundaryPoint& boundaryA, const RangeBoundaryPoint& boundaryB, ExceptionState&);
bool boundaryPointsValid() const;
bool intersectsNode(Node* refNode, ExceptionState&);
void deleteContents(ExceptionState&);
PassRefPtr<DocumentFragment> extractContents(ExceptionState&);
PassRefPtr<DocumentFragment> cloneContents(ExceptionState&);
void insertNode(PassRefPtr<Node>, ExceptionState&);
String toString(ExceptionState&) const;
String toHTML() const;
String text() const;
PassRefPtr<DocumentFragment> createContextualFragment(const String& html, ExceptionState&);
void detach(ExceptionState&);
PassRefPtrWillBeRawPtr<Range> cloneRange(ExceptionState&) const;
void setStartAfter(Node*, ExceptionState& = ASSERT_NO_EXCEPTION);
void setEndBefore(Node*, ExceptionState& = ASSERT_NO_EXCEPTION);
void setEndAfter(Node*, ExceptionState& = ASSERT_NO_EXCEPTION);
void selectNode(Node*, ExceptionState& = ASSERT_NO_EXCEPTION);
void selectNodeContents(Node*, ExceptionState&);
void surroundContents(PassRefPtr<Node>, ExceptionState&);
void setStartBefore(Node*, ExceptionState& = ASSERT_NO_EXCEPTION);
const Position startPosition() const { return m_start.toPosition(); }
const Position endPosition() const { return m_end.toPosition(); }
void setStart(const Position&, ExceptionState& = ASSERT_NO_EXCEPTION);
void setEnd(const Position&, ExceptionState& = ASSERT_NO_EXCEPTION);
Node* firstNode() const;
Node* pastLastNode() const;
ShadowRoot* shadowRoot() const;
enum RangeInFixedPosition {
NotFixedPosition,
PartiallyFixedPosition,
EntirelyFixedPosition
};
void textRects(Vector<IntRect>&, bool useSelectionHeight = false, RangeInFixedPosition* = 0) const;
IntRect boundingBox() const;
void textQuads(Vector<FloatQuad>&, bool useSelectionHeight = false, RangeInFixedPosition* = 0) const;
void getBorderAndTextQuads(Vector<FloatQuad>&) const;
FloatRect boundingRect() const;
void nodeChildrenChanged(ContainerNode*);
void nodeChildrenWillBeRemoved(ContainerNode&);
void nodeWillBeRemoved(Node&);
void didInsertText(Node*, unsigned offset, unsigned length);
void didRemoveText(Node*, unsigned offset, unsigned length);
void didMergeTextNodes(const NodeWithIndex& oldNode, unsigned offset);
void didSplitTextNode(Text& oldNode);
void expand(const String&, ExceptionState&);
PassRefPtr<ClientRectList> getClientRects() const;
PassRefPtr<ClientRect> getBoundingClientRect() const;
#ifndef NDEBUG
void formatForDebugger(char* buffer, unsigned length) const;
#endif
void trace(Visitor*);
private:
explicit Range(Document&);
Range(Document&, Node* startContainer, int startOffset, Node* endContainer, int endOffset);
void setDocument(Document&);
Node* checkNodeWOffset(Node*, int offset, ExceptionState&) const;
void checkNodeBA(Node*, ExceptionState&) const;
void checkDeleteExtract(ExceptionState&);
int maxStartOffset() const;
int maxEndOffset() const;
enum ActionType { DELETE_CONTENTS, EXTRACT_CONTENTS, CLONE_CONTENTS };
PassRefPtr<DocumentFragment> processContents(ActionType, ExceptionState&);
static PassRefPtr<Node> processContentsBetweenOffsets(ActionType, PassRefPtr<DocumentFragment>, Node*, unsigned startOffset, unsigned endOffset, ExceptionState&);
static void processNodes(ActionType, Vector<RefPtr<Node> >&, PassRefPtr<Node> oldContainer, PassRefPtr<Node> newContainer, ExceptionState&);
enum ContentsProcessDirection { ProcessContentsForward, ProcessContentsBackward };
static PassRefPtr<Node> processAncestorsAndTheirSiblings(ActionType, Node* container, ContentsProcessDirection, PassRefPtr<Node> clonedContainer, Node* commonRoot, ExceptionState&);
RefPtr<Document> m_ownerDocument;
RangeBoundaryPoint m_start;
RangeBoundaryPoint m_end;
};
PassRefPtrWillBeRawPtr<Range> rangeOfContents(Node*);
bool areRangesEqual(const Range*, const Range*);
}
#ifndef NDEBUG
void showTree(const WebCore::Range*);
#endif
#endif