|
1 /* |
|
2 * This file is part of the DOM implementation for KDE. |
|
3 * |
|
4 * (C) 1999 Lars Knoll (knoll@kde.org) |
|
5 * (C) 2000 Gunnstein Lye (gunnstein@netcom.no) |
|
6 * (C) 2000 Frederik Holljen (frederik.holljen@hig.no) |
|
7 * (C) 2001 Peter Kelly (pmk@post.com) |
|
8 * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. |
|
9 * |
|
10 * This library is free software; you can redistribute it and/or |
|
11 * modify it under the terms of the GNU Library General Public |
|
12 * License as published by the Free Software Foundation; either |
|
13 * version 2 of the License, or (at your option) any later version. |
|
14 * |
|
15 * This library is distributed in the hope that it will be useful, |
|
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
18 * Library General Public License for more details. |
|
19 * |
|
20 * You should have received a copy of the GNU Library General Public License |
|
21 * along with this library; see the file COPYING.LIB. If not, write to |
|
22 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
23 * Boston, MA 02110-1301, USA. |
|
24 * |
|
25 */ |
|
26 |
|
27 #ifndef Range_h |
|
28 #define Range_h |
|
29 |
|
30 #include "Shared.h" |
|
31 #include <wtf/Forward.h> |
|
32 #include <wtf/RefPtr.h> |
|
33 #include <wtf/Vector.h> |
|
34 |
|
35 namespace WebCore { |
|
36 |
|
37 typedef int ExceptionCode; |
|
38 |
|
39 class DocumentFragment; |
|
40 class Document; |
|
41 class IntRect; |
|
42 class Node; |
|
43 class Position; |
|
44 class String; |
|
45 |
|
46 class Range : public Shared<Range> |
|
47 { |
|
48 public: |
|
49 Range(Document*); |
|
50 Range(Document*, Node* startContainer, int startOffset, Node* endContainer, int endOffset); |
|
51 Range(Document*, const Position&, const Position&); |
|
52 ~Range(); |
|
53 |
|
54 Document* ownerDocument() const { return m_ownerDocument.get(); } |
|
55 |
|
56 Node* startContainer(ExceptionCode&) const; |
|
57 int startOffset(ExceptionCode&) const; |
|
58 Node* endContainer(ExceptionCode&) const; |
|
59 int endOffset(ExceptionCode&) const; |
|
60 bool collapsed(ExceptionCode&) const; |
|
61 |
|
62 Node* commonAncestorContainer(ExceptionCode&) const; |
|
63 static Node* commonAncestorContainer(Node* containerA, Node* containerB); |
|
64 void setStart(Node* container, int offset, ExceptionCode&); |
|
65 void setEnd(Node* container, int offset, ExceptionCode&); |
|
66 void collapse(bool toStart, ExceptionCode&); |
|
67 bool isPointInRange(Node* refNode, int offset, ExceptionCode& ec); |
|
68 short comparePoint(Node* refNode, int offset, ExceptionCode& ec); |
|
69 enum CompareResults { NODE_BEFORE, NODE_AFTER, NODE_BEFORE_AND_AFTER, NODE_INSIDE }; |
|
70 CompareResults compareNode(Node* refNode, ExceptionCode&); |
|
71 enum CompareHow { START_TO_START, START_TO_END, END_TO_END, END_TO_START }; |
|
72 short compareBoundaryPoints(CompareHow, const Range* sourceRange, ExceptionCode&) const; |
|
73 static short compareBoundaryPoints(Node* containerA, int offsetA, Node* containerB, int offsetB); |
|
74 static short compareBoundaryPoints(const Position&, const Position&); |
|
75 bool boundaryPointsValid() const; |
|
76 bool intersectsNode(Node* refNode, ExceptionCode&); |
|
77 void deleteContents(ExceptionCode&); |
|
78 PassRefPtr<DocumentFragment> extractContents(ExceptionCode&); |
|
79 PassRefPtr<DocumentFragment> cloneContents(ExceptionCode&); |
|
80 void insertNode(PassRefPtr<Node>, ExceptionCode&); |
|
81 String toString(ExceptionCode&) const; |
|
82 |
|
83 String toHTML() const; |
|
84 String text() const; |
|
85 |
|
86 PassRefPtr<DocumentFragment> createContextualFragment(const String& html, ExceptionCode&) const; |
|
87 |
|
88 void detach(ExceptionCode&); |
|
89 bool isDetached() const; |
|
90 PassRefPtr<Range> cloneRange(ExceptionCode&) const; |
|
91 |
|
92 void setStartAfter(Node*, ExceptionCode&); |
|
93 void setEndBefore(Node*, ExceptionCode&); |
|
94 void setEndAfter(Node*, ExceptionCode&); |
|
95 void selectNode(Node*, ExceptionCode&); |
|
96 void selectNodeContents(Node*, ExceptionCode&); |
|
97 void surroundContents(PassRefPtr<Node>, ExceptionCode&); |
|
98 void setStartBefore(Node*, ExceptionCode&); |
|
99 |
|
100 enum ActionType { |
|
101 DELETE_CONTENTS, |
|
102 EXTRACT_CONTENTS, |
|
103 CLONE_CONTENTS |
|
104 }; |
|
105 PassRefPtr<DocumentFragment> processContents(ActionType, ExceptionCode&); |
|
106 |
|
107 Position startPosition() const; |
|
108 Position endPosition() const; |
|
109 |
|
110 Node* startNode() const; |
|
111 Node* pastEndNode() const; |
|
112 |
|
113 Position editingStartPosition() const; |
|
114 |
|
115 IntRect boundingBox(); |
|
116 void addLineBoxRects(Vector<IntRect>&, bool useSelectionHeight = false); |
|
117 |
|
118 #ifndef NDEBUG |
|
119 void formatForDebugger(char* buffer, unsigned length) const; |
|
120 #endif |
|
121 |
|
122 private: |
|
123 RefPtr<Document> m_ownerDocument; |
|
124 RefPtr<Node> m_startContainer; |
|
125 unsigned m_startOffset; |
|
126 RefPtr<Node> m_endContainer; |
|
127 unsigned m_endOffset; |
|
128 bool m_detached; |
|
129 |
|
130 void checkNodeWOffset(Node*, int offset, ExceptionCode&) const; |
|
131 void checkNodeBA(Node*, ExceptionCode&) const; |
|
132 void checkDeleteExtract(ExceptionCode&); |
|
133 bool containedByReadOnly() const; |
|
134 }; |
|
135 |
|
136 PassRefPtr<Range> rangeOfContents(Node*); |
|
137 |
|
138 bool operator==(const Range&, const Range&); |
|
139 inline bool operator!=(const Range& a, const Range& b) { return !(a == b); } |
|
140 |
|
141 } // namespace |
|
142 |
|
143 #endif |