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.
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 "RangeBoundaryPoint.h"
29 #include <wtf/RefCounted.h>
30 #include <wtf/Vector.h>
32 #include "SelectionRect.h"
36 class DocumentFragment
;
40 class Range
: public RefCounted
<Range
> {
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
&);
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(); }
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;
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;
80 String
toHTML() const;
83 PassRefPtr
<DocumentFragment
> createContextualFragment(const String
& html
, ExceptionCode
&) const;
85 void detach(ExceptionCode
&);
86 PassRefPtr
<Range
> cloneRange(ExceptionCode
&) const;
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
&);
96 const Position
& startPosition() const { return m_start
.position(); }
97 const Position
& endPosition() const { return m_end
.position(); }
99 Node
* firstNode() const;
100 Node
* pastLastNode() const;
102 Position
editingStartPosition() const;
104 Node
* shadowTreeRootNode() const;
106 IntRect
boundingBox();
107 void addLineBoxRects(Vector
<IntRect
>&, bool useSelectionHeight
= false);
108 void collectSelectionRects(Vector
<SelectionRect
>&);
110 void nodeChildrenChanged(ContainerNode
*);
111 void nodeWillBeRemoved(Node
*);
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
);
119 void formatForDebugger(char* buffer
, unsigned length
) const;
122 Document
* document() const { return m_ownerDocument
.get(); }
125 Range(PassRefPtr
<Document
>);
126 Range(PassRefPtr
<Document
>, PassRefPtr
<Node
> startContainer
, int startOffset
, PassRefPtr
<Node
> endContainer
, int endOffset
);
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;
135 enum ActionType
{ DELETE_CONTENTS
, EXTRACT_CONTENTS
, CLONE_CONTENTS
};
136 PassRefPtr
<DocumentFragment
> processContents(ActionType
, ExceptionCode
&);
138 RefPtr
<Document
> m_ownerDocument
;
139 RangeBoundaryPoint m_start
;
140 RangeBoundaryPoint m_end
;
143 PassRefPtr
<Range
> rangeOfContents(Node
*);
145 bool operator==(const Range
&, const Range
&);
146 inline bool operator!=(const Range
& a
, const Range
& b
) { return !(a
== b
); }