|
1 /* |
|
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. |
|
7 * |
|
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. |
|
12 * |
|
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. |
|
17 * |
|
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. |
|
22 * |
|
23 */ |
|
24 |
|
25 #ifndef Range_h |
|
26 #define Range_h |
|
27 |
|
28 #include "FloatQuad.h" |
|
29 #include "RangeBoundaryPoint.h" |
|
30 #include <wtf/Forward.h> |
|
31 #include <wtf/RefCounted.h> |
|
32 |
|
33 namespace WebCore { |
|
34 |
|
35 class ClientRect; |
|
36 class ClientRectList; |
|
37 class DocumentFragment; |
|
38 class NodeWithIndex; |
|
39 class Text; |
|
40 |
|
41 class Range : public RefCounted<Range> { |
|
42 public: |
|
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&); |
|
46 ~Range(); |
|
47 |
|
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(); } |
|
53 |
|
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; |
|
59 |
|
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; |
|
80 |
|
81 String toHTML() const; |
|
82 String text() const; |
|
83 |
|
84 PassRefPtr<DocumentFragment> createContextualFragment(const String& html, ExceptionCode&) const; |
|
85 |
|
86 void detach(ExceptionCode&); |
|
87 PassRefPtr<Range> cloneRange(ExceptionCode&) const; |
|
88 |
|
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&); |
|
96 |
|
97 const Position startPosition() const { return m_start.toPosition(); } |
|
98 const Position endPosition() const { return m_end.toPosition(); } |
|
99 |
|
100 Node* firstNode() const; |
|
101 Node* pastLastNode() const; |
|
102 |
|
103 Position editingStartPosition() const; |
|
104 |
|
105 Node* shadowTreeRootNode() const; |
|
106 |
|
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); |
|
112 |
|
113 void nodeChildrenChanged(ContainerNode*); |
|
114 void nodeChildrenWillBeRemoved(ContainerNode*); |
|
115 void nodeWillBeRemoved(Node*); |
|
116 |
|
117 void textInserted(Node*, unsigned offset, unsigned length); |
|
118 void textRemoved(Node*, unsigned offset, unsigned length); |
|
119 void textNodesMerged(NodeWithIndex& oldNode, unsigned offset); |
|
120 void textNodeSplit(Text* oldNode); |
|
121 |
|
122 // Expand range to a unit (word or sentence or block or document) boundary. |
|
123 // Please refer to https://bugs.webkit.org/show_bug.cgi?id=27632 comment #5 |
|
124 // for details. |
|
125 void expand(const String&, ExceptionCode&); |
|
126 |
|
127 PassRefPtr<ClientRectList> getClientRects() const; |
|
128 PassRefPtr<ClientRect> getBoundingClientRect() const; |
|
129 |
|
130 #ifndef NDEBUG |
|
131 void formatForDebugger(char* buffer, unsigned length) const; |
|
132 #endif |
|
133 |
|
134 private: |
|
135 Range(PassRefPtr<Document>); |
|
136 Range(PassRefPtr<Document>, PassRefPtr<Node> startContainer, int startOffset, PassRefPtr<Node> endContainer, int endOffset); |
|
137 |
|
138 Node* checkNodeWOffset(Node*, int offset, ExceptionCode&) const; |
|
139 void checkNodeBA(Node*, ExceptionCode&) const; |
|
140 void checkDeleteExtract(ExceptionCode&); |
|
141 bool containedByReadOnly() const; |
|
142 int maxStartOffset() const; |
|
143 int maxEndOffset() const; |
|
144 |
|
145 enum ActionType { DELETE_CONTENTS, EXTRACT_CONTENTS, CLONE_CONTENTS }; |
|
146 PassRefPtr<DocumentFragment> processContents(ActionType, ExceptionCode&); |
|
147 |
|
148 void getBorderAndTextQuads(Vector<FloatQuad>&) const; |
|
149 |
|
150 RefPtr<Document> m_ownerDocument; |
|
151 RangeBoundaryPoint m_start; |
|
152 RangeBoundaryPoint m_end; |
|
153 }; |
|
154 |
|
155 PassRefPtr<Range> rangeOfContents(Node*); |
|
156 |
|
157 bool areRangesEqual(const Range*, const Range*); |
|
158 |
|
159 } // namespace |
|
160 |
|
161 #ifndef NDEBUG |
|
162 // Outside the WebCore namespace for ease of invocation from gdb. |
|
163 void showTree(const WebCore::Range*); |
|
164 #endif |
|
165 |
|
166 #endif |