From 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c Mon Sep 17 00:00:00 2001 From: Lorry Tar Creator Date: Tue, 27 Jun 2017 06:07:23 +0000 Subject: webkitgtk-2.16.5 --- Source/WebCore/dom/Range.h | 175 +++++++++++++++++++++------------------------ 1 file changed, 82 insertions(+), 93 deletions(-) (limited to 'Source/WebCore/dom/Range.h') 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 { public: - static PassRefPtr create(Document&); - static PassRefPtr create(Document&, PassRefPtr startContainer, int startOffset, PassRefPtr endContainer, int endOffset); - static PassRefPtr create(Document&, const Position&, const Position&); - static PassRefPtr create(ScriptExecutionContext&); -#if PLATFORM(IOS) - // FIXME: Consider making this a static non-member, non-friend function. - static PassRefPtr create(Document&, const VisiblePosition&, const VisiblePosition&); -#endif - ~Range(); - - Document& ownerDocument() const { return const_cast(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 container, int offset, ExceptionCode& = ASSERT_NO_EXCEPTION); - void setEnd(PassRefPtr 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 create(Document&); + WEBCORE_EXPORT static Ref create(Document&, RefPtr&& startContainer, int startOffset, RefPtr&& endContainer, int endOffset); + WEBCORE_EXPORT static Ref create(Document&, const Position&, const Position&); + WEBCORE_EXPORT static Ref 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 setStart(Ref&& container, unsigned offset); + WEBCORE_EXPORT ExceptionOr setEnd(Ref&& container, unsigned offset); + WEBCORE_EXPORT void collapse(bool toStart); + WEBCORE_EXPORT ExceptionOr isPointInRange(Node& refNode, unsigned offset); + WEBCORE_EXPORT ExceptionOr 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 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 extractContents(ExceptionCode&); - PassRefPtr cloneContents(ExceptionCode&); - void insertNode(PassRefPtr, ExceptionCode&); - String toString(ExceptionCode&) const; + WEBCORE_EXPORT ExceptionOr compareBoundaryPoints(CompareHow, const Range& sourceRange) const; + WEBCORE_EXPORT ExceptionOr compareBoundaryPointsForBindings(unsigned short compareHow, const Range& sourceRange) const; + static ExceptionOr compareBoundaryPoints(Node* containerA, unsigned offsetA, Node* containerB, unsigned offsetB); + static ExceptionOr compareBoundaryPoints(const RangeBoundaryPoint& boundaryA, const RangeBoundaryPoint& boundaryB); + WEBCORE_EXPORT bool boundaryPointsValid() const; + WEBCORE_EXPORT ExceptionOr intersectsNode(Node& refNode) const; + WEBCORE_EXPORT ExceptionOr deleteContents(); + WEBCORE_EXPORT ExceptionOr> extractContents(); + WEBCORE_EXPORT ExceptionOr> cloneContents(); + WEBCORE_EXPORT ExceptionOr insertNode(Ref&&); + WEBCORE_EXPORT String toString() const; String toHTML() const; - String text() const; + WEBCORE_EXPORT String text() const; - PassRefPtr createContextualFragment(const String& html, ExceptionCode&); + WEBCORE_EXPORT ExceptionOr> createContextualFragment(const String& html); - void detach(ExceptionCode&); - PassRefPtr cloneRange(ExceptionCode&) const; + WEBCORE_EXPORT void detach(); + WEBCORE_EXPORT Ref 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, ExceptionCode&); - void setStartBefore(Node*, ExceptionCode&); + WEBCORE_EXPORT ExceptionOr setStartAfter(Node&); + WEBCORE_EXPORT ExceptionOr setEndBefore(Node&); + WEBCORE_EXPORT ExceptionOr setEndAfter(Node&); + WEBCORE_EXPORT ExceptionOr selectNode(Node&); + WEBCORE_EXPORT ExceptionOr selectNodeContents(Node&); + WEBCORE_EXPORT ExceptionOr surroundContents(Node&); + WEBCORE_EXPORT ExceptionOr 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 setStart(const Position&); + WEBCORE_EXPORT ExceptionOr 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&, bool useSelectionHeight = false, RangeInFixedPosition* = 0) const; - IntRect boundingBox() const; + WEBCORE_EXPORT void absoluteTextRects(Vector&, bool useSelectionHeight = false, RangeInFixedPosition* = nullptr) const; + WEBCORE_EXPORT IntRect absoluteBoundingBox() const; // Transform-friendly - void textQuads(Vector&, bool useSelectionHeight = false, RangeInFixedPosition* = 0) const; - void getBorderAndTextQuads(Vector&) const; - FloatRect boundingRect() const; + WEBCORE_EXPORT void absoluteTextQuads(Vector&, bool useSelectionHeight = false, RangeInFixedPosition* = nullptr) const; + WEBCORE_EXPORT FloatRect absoluteBoundingRect() const; #if PLATFORM(IOS) - void collectSelectionRects(Vector&); + WEBCORE_EXPORT void collectSelectionRects(Vector&); + WEBCORE_EXPORT int collectSelectionRectsWithoutUnionInteriorLines(Vector&); #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 expand(const String&); - PassRefPtr getClientRects() const; - PassRefPtr getBoundingClientRect() const; + Ref getClientRects() const; + Ref 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 startContainer, int startOffset, PassRefPtr endContainer, int endOffset); + Range(Document&, Node* startContainer, int startOffset, Node* endContainer, int endOffset); void setDocument(Document&); + ExceptionOr checkNodeWOffset(Node&, unsigned offset) const; + ExceptionOr> 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 processContents(ActionType, ExceptionCode&); - static PassRefPtr processContentsBetweenOffsets(ActionType, PassRefPtr, Node*, unsigned startOffset, unsigned endOffset, ExceptionCode&); - static void processNodes(ActionType, Vector>&, PassRefPtr oldContainer, PassRefPtr newContainer, ExceptionCode&); - enum ContentsProcessDirection { ProcessContentsForward, ProcessContentsBackward }; - static PassRefPtr processAncestorsAndTheirSiblings(ActionType, Node* container, ContentsProcessDirection, PassRefPtr clonedContainer, Node* commonRoot, ExceptionCode&); + enum class CoordinateSpace { Absolute, Client }; + Vector borderAndTextQuads(CoordinateSpace) const; + FloatRect boundingRect(CoordinateSpace) const; Ref m_ownerDocument; RangeBoundaryPoint m_start; RangeBoundaryPoint m_end; }; -PassRefPtr rangeOfContents(Node&); +WEBCORE_EXPORT Ref 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(a), 0, const_cast(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 -- cgit v1.2.1