2 * (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Gunnstein Lye (gunnstein@netcom.no)
4 * (C) 2000 Frederik Holljen (frederik.holljen@hig.no)
5 * (C) 2001 Peter Kelly (pmk@post.com)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
28 #include "FloatQuad.h"
29 #include "RangeBoundaryPoint.h"
30 #include <wtf/Forward.h>
31 #include <wtf/RefCounted.h>
37 class DocumentFragment
;
41 class Range
: public RefCounted
<Range
> {
43 static PassRefPtr
<Range
> create(PassRefPtr
<Document
>);
44 static PassRefPtr
<Range
> create(PassRefPtr
<Document
>, PassRefPtr
<Node
> startContainer
, int startOffset
, PassRefPtr
<Node
> endContainer
, int endOffset
);
45 static PassRefPtr
<Range
> create(PassRefPtr
<Document
>, const Position
&, const Position
&);
48 Document
* ownerDocument() const { return m_ownerDocument
.get(); }
49 Node
* startContainer() const { return m_start
.container(); }
50 int startOffset() const { return m_start
.offset(); }
51 Node
* endContainer() const { return m_end
.container(); }
52 int endOffset() const { return m_end
.offset(); }
54 Node
* startContainer(ExceptionCode
&) const;
55 int startOffset(ExceptionCode
&) const;
56 Node
* endContainer(ExceptionCode
&) const;
57 int endOffset(ExceptionCode
&) const;
58 bool collapsed(ExceptionCode
&) const;
60 Node
* commonAncestorContainer(ExceptionCode
&) const;
61 static Node
* commonAncestorContainer(Node
* containerA
, Node
* containerB
);
62 void setStart(PassRefPtr
<Node
> container
, int offset
, ExceptionCode
&);
63 void setEnd(PassRefPtr
<Node
> container
, int offset
, ExceptionCode
&);
64 void collapse(bool toStart
, ExceptionCode
&);
65 bool isPointInRange(Node
* refNode
, int offset
, ExceptionCode
&);
66 short comparePoint(Node
* refNode
, int offset
, ExceptionCode
&) const;
67 enum CompareResults
{ NODE_BEFORE
, NODE_AFTER
, NODE_BEFORE_AND_AFTER
, NODE_INSIDE
};
68 CompareResults
compareNode(Node
* refNode
, ExceptionCode
&) const;
69 enum CompareHow
{ START_TO_START
, START_TO_END
, END_TO_END
, END_TO_START
};
70 short compareBoundaryPoints(CompareHow
, const Range
* sourceRange
, ExceptionCode
&) const;
71 static short compareBoundaryPoints(Node
* containerA
, int offsetA
, Node
* containerB
, int offsetB
);
72 static short compareBoundaryPoints(const RangeBoundaryPoint
& boundaryA
, const RangeBoundaryPoint
& boundaryB
);
73 bool boundaryPointsValid() const;
74 bool intersectsNode(Node
* refNode
, ExceptionCode
&);
75 void deleteContents(ExceptionCode
&);
76 PassRefPtr
<DocumentFragment
> extractContents(ExceptionCode
&);
77 PassRefPtr
<DocumentFragment
> cloneContents(ExceptionCode
&);
78 void insertNode(PassRefPtr
<Node
>, ExceptionCode
&);
79 String
toString(ExceptionCode
&) const;
81 String
toHTML() const;
84 PassRefPtr
<DocumentFragment
> createContextualFragment(const String
& html
, ExceptionCode
&) const;
86 void detach(ExceptionCode
&);
87 PassRefPtr
<Range
> cloneRange(ExceptionCode
&) const;
89 void setStartAfter(Node
*, ExceptionCode
&);
90 void setEndBefore(Node
*, ExceptionCode
&);
91 void setEndAfter(Node
*, ExceptionCode
&);
92 void selectNode(Node
*, ExceptionCode
&);
93 void selectNodeContents(Node
*, ExceptionCode
&);
94 void surroundContents(PassRefPtr
<Node
>, ExceptionCode
&);
95 void setStartBefore(Node
*, ExceptionCode
&);
97 const Position
startPosition() const { return m_start
.toPosition(); }
98 const Position
endPosition() const { return m_end
.toPosition(); }
100 Node
* firstNode() const;
101 Node
* pastLastNode() const;
103 Position
editingStartPosition() const;
105 Node
* shadowTreeRootNode() const;
107 IntRect
boundingBox();
108 // Not transform-friendly
109 void textRects(Vector
<IntRect
>&, bool useSelectionHeight
= false);
110 // Transform-friendly
111 void textQuads(Vector
<FloatQuad
>&, bool useSelectionHeight
= false);
113 void nodeChildrenChanged(ContainerNode
*);
114 void nodeWillBeRemoved(Node
*);
116 void textInserted(Node
*, unsigned offset
, unsigned length
);
117 void textRemoved(Node
*, unsigned offset
, unsigned length
);
118 void textNodesMerged(NodeWithIndex
& oldNode
, unsigned offset
);
119 void textNodeSplit(Text
* oldNode
);
121 // Expand range to a unit (word or sentence or block or document) boundary.
122 // Please refer to https://bugs.webkit.org/show_bug.cgi?id=27632 comment #5
124 void expand(const String
&, ExceptionCode
&);
126 PassRefPtr
<ClientRectList
> getClientRects() const;
127 PassRefPtr
<ClientRect
> getBoundingClientRect() const;
130 void formatForDebugger(char* buffer
, unsigned length
) const;
134 Range(PassRefPtr
<Document
>);
135 Range(PassRefPtr
<Document
>, PassRefPtr
<Node
> startContainer
, int startOffset
, PassRefPtr
<Node
> endContainer
, int endOffset
);
137 Node
* checkNodeWOffset(Node
*, int offset
, ExceptionCode
&) const;
138 void checkNodeBA(Node
*, ExceptionCode
&) const;
139 void checkDeleteExtract(ExceptionCode
&);
140 bool containedByReadOnly() const;
141 int maxStartOffset() const;
142 int maxEndOffset() const;
144 enum ActionType
{ DELETE_CONTENTS
, EXTRACT_CONTENTS
, CLONE_CONTENTS
};
145 PassRefPtr
<DocumentFragment
> processContents(ActionType
, ExceptionCode
&);
147 void getBorderAndTextQuads(Vector
<FloatQuad
>&) const;
149 RefPtr
<Document
> m_ownerDocument
;
150 RangeBoundaryPoint m_start
;
151 RangeBoundaryPoint m_end
;
154 PassRefPtr
<Range
> rangeOfContents(Node
*);
156 bool operator==(const Range
&, const Range
&);
157 inline bool operator!=(const Range
& a
, const Range
& b
) { return !(a
== b
); }