]> git.saurik.com Git - iphone-api.git/blob - WebCore/Range.h
Add support for new WinterBoard Settings features.
[iphone-api.git] / WebCore / Range.h
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 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 "RangeBoundaryPoint.h"
29 #include <wtf/RefCounted.h>
30 #include <wtf/Vector.h>
31
32 #include "SelectionRect.h"
33
34 namespace WebCore {
35
36 class DocumentFragment;
37 class NodeWithIndex;
38 class Text;
39
40 class Range : public RefCounted<Range> {
41 public:
42 static PassRefPtr<Range> create(PassRefPtr<Document>);
43 static PassRefPtr<Range> create(PassRefPtr<Document>, PassRefPtr<Node> startContainer, int startOffset, PassRefPtr<Node> endContainer, int endOffset);
44 static PassRefPtr<Range> create(PassRefPtr<Document>, const Position&, const Position&);
45 ~Range();
46
47 Document* ownerDocument() const { return m_ownerDocument.get(); }
48 Node* startContainer() const { return m_start.container(); }
49 int startOffset() const { return m_start.offset(); }
50 Node* endContainer() const { return m_end.container(); }
51 int endOffset() const { return m_end.offset(); }
52
53 Node* startContainer(ExceptionCode&) const;
54 int startOffset(ExceptionCode&) const;
55 Node* endContainer(ExceptionCode&) const;
56 int endOffset(ExceptionCode&) const;
57 bool collapsed(ExceptionCode&) const;
58
59 Node* commonAncestorContainer(ExceptionCode&) const;
60 static Node* commonAncestorContainer(Node* containerA, Node* containerB);
61 void setStart(PassRefPtr<Node> container, int offset, ExceptionCode&);
62 void setEnd(PassRefPtr<Node> container, int offset, ExceptionCode&);
63 void collapse(bool toStart, ExceptionCode&);
64 bool isPointInRange(Node* refNode, int offset, ExceptionCode& ec);
65 short comparePoint(Node* refNode, int offset, ExceptionCode& ec);
66 enum CompareResults { NODE_BEFORE, NODE_AFTER, NODE_BEFORE_AND_AFTER, NODE_INSIDE };
67 CompareResults compareNode(Node* refNode, ExceptionCode&);
68 enum CompareHow { START_TO_START, START_TO_END, END_TO_END, END_TO_START };
69 short compareBoundaryPoints(CompareHow, const Range* sourceRange, ExceptionCode&) const;
70 static short compareBoundaryPoints(Node* containerA, int offsetA, Node* containerB, int offsetB);
71 static short compareBoundaryPoints(const Position&, const Position&);
72 bool boundaryPointsValid() const;
73 bool intersectsNode(Node* refNode, ExceptionCode&);
74 void deleteContents(ExceptionCode&);
75 PassRefPtr<DocumentFragment> extractContents(ExceptionCode&);
76 PassRefPtr<DocumentFragment> cloneContents(ExceptionCode&);
77 void insertNode(PassRefPtr<Node>, ExceptionCode&);
78 String toString(ExceptionCode&) const;
79
80 String toHTML() const;
81 String text() const;
82
83 PassRefPtr<DocumentFragment> createContextualFragment(const String& html, ExceptionCode&) const;
84
85 void detach(ExceptionCode&);
86 PassRefPtr<Range> cloneRange(ExceptionCode&) const;
87
88 void setStartAfter(Node*, ExceptionCode&);
89 void setEndBefore(Node*, ExceptionCode&);
90 void setEndAfter(Node*, ExceptionCode&);
91 void selectNode(Node*, ExceptionCode&);
92 void selectNodeContents(Node*, ExceptionCode&);
93 void surroundContents(PassRefPtr<Node>, ExceptionCode&);
94 void setStartBefore(Node*, ExceptionCode&);
95
96 const Position& startPosition() const { return m_start.position(); }
97 const Position& endPosition() const { return m_end.position(); }
98
99 Node* firstNode() const;
100 Node* pastLastNode() const;
101
102 Position editingStartPosition() const;
103
104 Node* shadowTreeRootNode() const;
105
106 IntRect boundingBox();
107 void addLineBoxRects(Vector<IntRect>&, bool useSelectionHeight = false);
108 void collectSelectionRects(Vector<SelectionRect>&);
109
110 void nodeChildrenChanged(ContainerNode*);
111 void nodeWillBeRemoved(Node*);
112
113 void textInserted(Node*, unsigned offset, unsigned length);
114 void textRemoved(Node*, unsigned offset, unsigned length);
115 void textNodesMerged(NodeWithIndex& oldNode, unsigned offset);
116 void textNodeSplit(Text* oldNode);
117
118 #ifndef NDEBUG
119 void formatForDebugger(char* buffer, unsigned length) const;
120 #endif
121
122 Document* document() const { return m_ownerDocument.get(); }
123
124 private:
125 Range(PassRefPtr<Document>);
126 Range(PassRefPtr<Document>, PassRefPtr<Node> startContainer, int startOffset, PassRefPtr<Node> endContainer, int endOffset);
127
128 Node* checkNodeWOffset(Node*, int offset, ExceptionCode&) const;
129 void checkNodeBA(Node*, ExceptionCode&) const;
130 void checkDeleteExtract(ExceptionCode&);
131 bool containedByReadOnly() const;
132 int maxStartOffset() const;
133 int maxEndOffset() const;
134
135 enum ActionType { DELETE_CONTENTS, EXTRACT_CONTENTS, CLONE_CONTENTS };
136 PassRefPtr<DocumentFragment> processContents(ActionType, ExceptionCode&);
137
138 RefPtr<Document> m_ownerDocument;
139 RangeBoundaryPoint m_start;
140 RangeBoundaryPoint m_end;
141 };
142
143 PassRefPtr<Range> rangeOfContents(Node*);
144
145 bool operator==(const Range&, const Range&);
146 inline bool operator!=(const Range& a, const Range& b) { return !(a == b); }
147
148 } // namespace
149
150 #endif