diff options
Diffstat (limited to 'Source/WebCore/dom/Range.h')
-rw-r--r-- | Source/WebCore/dom/Range.h | 175 |
1 files changed, 82 insertions, 93 deletions
diff --git a/Source/WebCore/dom/Range.h b/Source/WebCore/dom/Range.h index 877b860bd..5570b5520 100644 --- a/Source/WebCore/dom/Range.h +++ b/Source/WebCore/dom/Range.h @@ -22,10 +22,8 @@ * */ -#ifndef Range_h -#define Range_h +#pragma once -#include "ExceptionCodePlaceholder.h" #include "FloatRect.h" #include "FragmentScriptingPermission.h" #include "IntRect.h" @@ -44,81 +42,71 @@ class DocumentFragment; class FloatQuad; class Node; class NodeWithIndex; -class Text; -#if PLATFORM(IOS) class SelectionRect; +class Text; class VisiblePosition; -#endif class Range : public RefCounted<Range> { public: - static PassRefPtr<Range> create(Document&); - static PassRefPtr<Range> create(Document&, PassRefPtr<Node> startContainer, int startOffset, PassRefPtr<Node> endContainer, int endOffset); - static PassRefPtr<Range> create(Document&, const Position&, const Position&); - static PassRefPtr<Range> create(ScriptExecutionContext&); -#if PLATFORM(IOS) - // FIXME: Consider making this a static non-member, non-friend function. - static PassRefPtr<Range> create(Document&, const VisiblePosition&, const VisiblePosition&); -#endif - ~Range(); - - Document& ownerDocument() const { return const_cast<Document&>(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(ExceptionCode&) const; - int startOffset(ExceptionCode&) const; - Node* endContainer(ExceptionCode&) const; - int endOffset(ExceptionCode&) const; - bool collapsed(ExceptionCode&) const; - - Node* commonAncestorContainer(ExceptionCode&) const; - static Node* commonAncestorContainer(Node* containerA, Node* containerB); - void setStart(PassRefPtr<Node> container, int offset, ExceptionCode& = ASSERT_NO_EXCEPTION); - void setEnd(PassRefPtr<Node> container, int offset, ExceptionCode& = ASSERT_NO_EXCEPTION); - void collapse(bool toStart, ExceptionCode&); - bool isPointInRange(Node* refNode, int offset, ExceptionCode&); - short comparePoint(Node* refNode, int offset, ExceptionCode&) const; + WEBCORE_EXPORT static Ref<Range> create(Document&); + WEBCORE_EXPORT static Ref<Range> create(Document&, RefPtr<Node>&& startContainer, int startOffset, RefPtr<Node>&& endContainer, int endOffset); + WEBCORE_EXPORT static Ref<Range> create(Document&, const Position&, const Position&); + WEBCORE_EXPORT static Ref<Range> create(Document&, const VisiblePosition&, const VisiblePosition&); + WEBCORE_EXPORT ~Range(); + + Document& ownerDocument() const { return m_ownerDocument; } + + Node& startContainer() const { ASSERT(m_start.container()); return *m_start.container(); } + unsigned startOffset() const { return m_start.offset(); } + Node& endContainer() const { ASSERT(m_end.container()); return *m_end.container(); } + unsigned endOffset() const { return m_end.offset(); } + bool collapsed() const { return m_start == m_end; } + + Node* commonAncestorContainer() const { return commonAncestorContainer(&startContainer(), &endContainer()); } + WEBCORE_EXPORT static Node* commonAncestorContainer(Node* containerA, Node* containerB); + WEBCORE_EXPORT ExceptionOr<void> setStart(Ref<Node>&& container, unsigned offset); + WEBCORE_EXPORT ExceptionOr<void> setEnd(Ref<Node>&& container, unsigned offset); + WEBCORE_EXPORT void collapse(bool toStart); + WEBCORE_EXPORT ExceptionOr<bool> isPointInRange(Node& refNode, unsigned offset); + WEBCORE_EXPORT ExceptionOr<short> comparePoint(Node& refNode, unsigned offset) const; enum CompareResults { NODE_BEFORE, NODE_AFTER, NODE_BEFORE_AND_AFTER, NODE_INSIDE }; - CompareResults compareNode(Node* refNode, ExceptionCode&) const; + WEBCORE_EXPORT ExceptionOr<CompareResults> compareNode(Node& refNode) const; enum CompareHow { START_TO_START, START_TO_END, END_TO_END, END_TO_START }; - short compareBoundaryPoints(CompareHow, const Range* sourceRange, ExceptionCode&) const; - static short compareBoundaryPoints(Node* containerA, int offsetA, Node* containerB, int offsetB, ExceptionCode&); - static short compareBoundaryPoints(const RangeBoundaryPoint& boundaryA, const RangeBoundaryPoint& boundaryB, ExceptionCode&); - bool boundaryPointsValid() const; - bool intersectsNode(Node* refNode, ExceptionCode&); - void deleteContents(ExceptionCode&); - PassRefPtr<DocumentFragment> extractContents(ExceptionCode&); - PassRefPtr<DocumentFragment> cloneContents(ExceptionCode&); - void insertNode(PassRefPtr<Node>, ExceptionCode&); - String toString(ExceptionCode&) const; + WEBCORE_EXPORT ExceptionOr<short> compareBoundaryPoints(CompareHow, const Range& sourceRange) const; + WEBCORE_EXPORT ExceptionOr<short> compareBoundaryPointsForBindings(unsigned short compareHow, const Range& sourceRange) const; + static ExceptionOr<short> compareBoundaryPoints(Node* containerA, unsigned offsetA, Node* containerB, unsigned offsetB); + static ExceptionOr<short> compareBoundaryPoints(const RangeBoundaryPoint& boundaryA, const RangeBoundaryPoint& boundaryB); + WEBCORE_EXPORT bool boundaryPointsValid() const; + WEBCORE_EXPORT ExceptionOr<bool> intersectsNode(Node& refNode) const; + WEBCORE_EXPORT ExceptionOr<void> deleteContents(); + WEBCORE_EXPORT ExceptionOr<Ref<DocumentFragment>> extractContents(); + WEBCORE_EXPORT ExceptionOr<Ref<DocumentFragment>> cloneContents(); + WEBCORE_EXPORT ExceptionOr<void> insertNode(Ref<Node>&&); + WEBCORE_EXPORT String toString() const; String toHTML() const; - String text() const; + WEBCORE_EXPORT String text() const; - PassRefPtr<DocumentFragment> createContextualFragment(const String& html, ExceptionCode&); + WEBCORE_EXPORT ExceptionOr<Ref<DocumentFragment>> createContextualFragment(const String& html); - void detach(ExceptionCode&); - PassRefPtr<Range> cloneRange(ExceptionCode&) const; + WEBCORE_EXPORT void detach(); + WEBCORE_EXPORT Ref<Range> cloneRange() const; - void setStartAfter(Node*, ExceptionCode& = ASSERT_NO_EXCEPTION); - void setEndBefore(Node*, ExceptionCode& = ASSERT_NO_EXCEPTION); - void setEndAfter(Node*, ExceptionCode& = ASSERT_NO_EXCEPTION); - void selectNode(Node*, ExceptionCode& = ASSERT_NO_EXCEPTION); - void selectNodeContents(Node*, ExceptionCode&); - void surroundContents(PassRefPtr<Node>, ExceptionCode&); - void setStartBefore(Node*, ExceptionCode&); + WEBCORE_EXPORT ExceptionOr<void> setStartAfter(Node&); + WEBCORE_EXPORT ExceptionOr<void> setEndBefore(Node&); + WEBCORE_EXPORT ExceptionOr<void> setEndAfter(Node&); + WEBCORE_EXPORT ExceptionOr<void> selectNode(Node&); + WEBCORE_EXPORT ExceptionOr<void> selectNodeContents(Node&); + WEBCORE_EXPORT ExceptionOr<void> surroundContents(Node&); + WEBCORE_EXPORT ExceptionOr<void> setStartBefore(Node&); const Position startPosition() const { return m_start.toPosition(); } const Position endPosition() const { return m_end.toPosition(); } - void setStart(const Position&, ExceptionCode& = ASSERT_NO_EXCEPTION); - void setEnd(const Position&, ExceptionCode& = ASSERT_NO_EXCEPTION); + WEBCORE_EXPORT ExceptionOr<void> setStart(const Position&); + WEBCORE_EXPORT ExceptionOr<void> setEnd(const Position&); - Node* firstNode() const; - Node* pastLastNode() const; + WEBCORE_EXPORT Node* firstNode() const; + WEBCORE_EXPORT Node* pastLastNode() const; ShadowRoot* shadowRoot() const; @@ -129,20 +117,20 @@ public: }; // Not transform-friendly - void textRects(Vector<IntRect>&, bool useSelectionHeight = false, RangeInFixedPosition* = 0) const; - IntRect boundingBox() const; + WEBCORE_EXPORT void absoluteTextRects(Vector<IntRect>&, bool useSelectionHeight = false, RangeInFixedPosition* = nullptr) const; + WEBCORE_EXPORT IntRect absoluteBoundingBox() const; // Transform-friendly - void textQuads(Vector<FloatQuad>&, bool useSelectionHeight = false, RangeInFixedPosition* = 0) const; - void getBorderAndTextQuads(Vector<FloatQuad>&) const; - FloatRect boundingRect() const; + WEBCORE_EXPORT void absoluteTextQuads(Vector<FloatQuad>&, bool useSelectionHeight = false, RangeInFixedPosition* = nullptr) const; + WEBCORE_EXPORT FloatRect absoluteBoundingRect() const; #if PLATFORM(IOS) - void collectSelectionRects(Vector<SelectionRect>&); + WEBCORE_EXPORT void collectSelectionRects(Vector<SelectionRect>&); + WEBCORE_EXPORT int collectSelectionRectsWithoutUnionInteriorLines(Vector<SelectionRect>&); #endif void nodeChildrenChanged(ContainerNode&); void nodeChildrenWillBeRemoved(ContainerNode&); - void nodeWillBeRemoved(Node*); + void nodeWillBeRemoved(Node&); void textInserted(Node*, unsigned offset, unsigned length); void textRemoved(Node*, unsigned offset, unsigned length); @@ -152,49 +140,50 @@ public: // Expand range to a unit (word or sentence or block or document) boundary. // Please refer to https://bugs.webkit.org/show_bug.cgi?id=27632 comment #5 // for details. - void expand(const String&, ExceptionCode&); + WEBCORE_EXPORT ExceptionOr<void> expand(const String&); - PassRefPtr<ClientRectList> getClientRects() const; - PassRefPtr<ClientRect> getBoundingClientRect() const; + Ref<ClientRectList> getClientRects() const; + Ref<ClientRect> getBoundingClientRect() const; -#ifndef NDEBUG +#if ENABLE(TREE_DEBUGGING) void formatForDebugger(char* buffer, unsigned length) const; #endif + WEBCORE_EXPORT bool contains(const Range&) const; + bool contains(const VisiblePosition&) const; + + enum ActionType { Delete, Extract, Clone }; + private: explicit Range(Document&); - Range(Document&, PassRefPtr<Node> startContainer, int startOffset, PassRefPtr<Node> endContainer, int endOffset); + Range(Document&, Node* startContainer, int startOffset, Node* endContainer, int endOffset); void setDocument(Document&); + ExceptionOr<Node*> checkNodeWOffset(Node&, unsigned offset) const; + ExceptionOr<RefPtr<DocumentFragment>> processContents(ActionType); - Node* checkNodeWOffset(Node*, int offset, ExceptionCode&) const; - void checkNodeBA(Node*, ExceptionCode&) const; - void checkDeleteExtract(ExceptionCode&); - bool containedByReadOnly() const; - int maxStartOffset() const; - int maxEndOffset() const; - - enum ActionType { Delete, Extract, Clone }; - PassRefPtr<DocumentFragment> processContents(ActionType, ExceptionCode&); - static PassRefPtr<Node> processContentsBetweenOffsets(ActionType, PassRefPtr<DocumentFragment>, Node*, unsigned startOffset, unsigned endOffset, ExceptionCode&); - static void processNodes(ActionType, Vector<RefPtr<Node>>&, PassRefPtr<Node> oldContainer, PassRefPtr<Node> newContainer, ExceptionCode&); - enum ContentsProcessDirection { ProcessContentsForward, ProcessContentsBackward }; - static PassRefPtr<Node> processAncestorsAndTheirSiblings(ActionType, Node* container, ContentsProcessDirection, PassRefPtr<Node> clonedContainer, Node* commonRoot, ExceptionCode&); + enum class CoordinateSpace { Absolute, Client }; + Vector<FloatQuad> borderAndTextQuads(CoordinateSpace) const; + FloatRect boundingRect(CoordinateSpace) const; Ref<Document> m_ownerDocument; RangeBoundaryPoint m_start; RangeBoundaryPoint m_end; }; -PassRefPtr<Range> rangeOfContents(Node&); +WEBCORE_EXPORT Ref<Range> rangeOfContents(Node&); -bool areRangesEqual(const Range*, const Range*); +WEBCORE_EXPORT bool areRangesEqual(const Range*, const Range*); +bool rangesOverlap(const Range*, const Range*); + +inline bool documentOrderComparator(const Node* a, const Node* b) +{ + return Range::compareBoundaryPoints(const_cast<Node*>(a), 0, const_cast<Node*>(b), 0).releaseReturnValue() < 0; +} } // namespace -#ifndef NDEBUG -// Outside the WebCore namespace for ease of invocation from gdb. +#if ENABLE(TREE_DEBUGGING) +// Outside the WebCore namespace for ease of invocation from the debugger. void showTree(const WebCore::Range*); #endif - -#endif |