1 | /* |
---|
2 | * Licensed to the Apache Software Foundation (ASF) under one or more |
---|
3 | * contributor license agreements. See the NOTICE file distributed with |
---|
4 | * this work for additional information regarding copyright ownership. |
---|
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 |
---|
6 | * (the "License"); you may not use this file except in compliance with |
---|
7 | * the License. You may obtain a copy of the License at |
---|
8 | * |
---|
9 | * http://www.apache.org/licenses/LICENSE-2.0 |
---|
10 | * |
---|
11 | * Unless required by applicable law or agreed to in writing, software |
---|
12 | * distributed under the License is distributed on an "AS IS" BASIS, |
---|
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
14 | * See the License for the specific language governing permissions and |
---|
15 | * limitations under the License. |
---|
16 | */ |
---|
17 | |
---|
18 | /* |
---|
19 | * $Id: DOMRangeImpl.hpp 641193 2008-03-26 08:06:57Z borisk $ |
---|
20 | */ |
---|
21 | |
---|
22 | #if !defined(XERCESC_INCLUDE_GUARD_DOMRANGEIMPL_HPP) |
---|
23 | #define XERCESC_INCLUDE_GUARD_DOMRANGEIMPL_HPP |
---|
24 | |
---|
25 | // |
---|
26 | // This file is part of the internal implementation of the C++ XML DOM. |
---|
27 | // It should NOT be included or used directly by application programs. |
---|
28 | // |
---|
29 | // Applications should include the file <xercesc/dom/DOM.hpp> for the entire |
---|
30 | // DOM API, or xercesc/dom/DOM*.hpp for individual DOM classes, where the class |
---|
31 | // name is substituded for the *. |
---|
32 | // |
---|
33 | |
---|
34 | #include <xercesc/util/XercesDefs.hpp> |
---|
35 | #include <xercesc/dom/DOMRange.hpp> |
---|
36 | #include <icxercesc/util/PlatformUtils.hpp> |
---|
37 | |
---|
38 | XERCES_CPP_NAMESPACE_BEGIN |
---|
39 | |
---|
40 | |
---|
41 | |
---|
42 | class DOMNode; |
---|
43 | class DOMDocumentFragment; |
---|
44 | class DOMDocument; |
---|
45 | class DOMText; |
---|
46 | class MemoryManager; |
---|
47 | |
---|
48 | class CDOM_EXPORT DOMRangeImpl: public DOMRange { |
---|
49 | protected: |
---|
50 | enum TraversalType { |
---|
51 | EXTRACT_CONTENTS = 1, |
---|
52 | CLONE_CONTENTS = 2, |
---|
53 | DELETE_CONTENTS = 3 |
---|
54 | }; |
---|
55 | |
---|
56 | enum TraversePoint { |
---|
57 | BEFORE = -1, |
---|
58 | START = 0, |
---|
59 | AFTER = 1 |
---|
60 | }; |
---|
61 | |
---|
62 | //private data |
---|
63 | |
---|
64 | DOMNode* fStartContainer; |
---|
65 | XMLSize_t fStartOffset; |
---|
66 | DOMNode* fEndContainer; |
---|
67 | XMLSize_t fEndOffset; |
---|
68 | bool fCollapsed; |
---|
69 | DOMDocument* fDocument; |
---|
70 | bool fDetached; |
---|
71 | |
---|
72 | DOMNode* fRemoveChild; |
---|
73 | MemoryManager* fMemoryManager; |
---|
74 | |
---|
75 | public: |
---|
76 | //c'tor |
---|
77 | DOMRangeImpl(DOMDocument* doc, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager); |
---|
78 | DOMRangeImpl(const DOMRangeImpl& other); |
---|
79 | |
---|
80 | //d'tor |
---|
81 | ~DOMRangeImpl(); |
---|
82 | |
---|
83 | //getter functions |
---|
84 | virtual DOMNode* getStartContainer() const; |
---|
85 | virtual XMLSize_t getStartOffset() const; |
---|
86 | virtual DOMNode* getEndContainer() const; |
---|
87 | virtual XMLSize_t getEndOffset() const; |
---|
88 | virtual bool getCollapsed() const; |
---|
89 | virtual const DOMNode* getCommonAncestorContainer() const; |
---|
90 | |
---|
91 | //setter functions |
---|
92 | virtual void setStart(const DOMNode *parent, XMLSize_t offset); |
---|
93 | virtual void setEnd(const DOMNode *parent, XMLSize_t offset); |
---|
94 | |
---|
95 | virtual void setStartBefore(const DOMNode *refNode); |
---|
96 | virtual void setStartAfter(const DOMNode *refNode); |
---|
97 | virtual void setEndBefore(const DOMNode *refNode); |
---|
98 | virtual void setEndAfter(const DOMNode *refNode); |
---|
99 | |
---|
100 | //misc functions |
---|
101 | virtual void collapse(bool toStart); |
---|
102 | virtual void selectNode(const DOMNode *node); |
---|
103 | virtual void selectNodeContents(const DOMNode *node); |
---|
104 | |
---|
105 | //Functions related to comparing range Boundrary-Points |
---|
106 | virtual short compareBoundaryPoints(CompareHow how, const DOMRange* range) const; |
---|
107 | virtual void deleteContents(); |
---|
108 | virtual DOMDocumentFragment* extractContents(); |
---|
109 | virtual DOMDocumentFragment* cloneContents() const; |
---|
110 | virtual void insertNode(DOMNode* node); |
---|
111 | |
---|
112 | //Misc functions |
---|
113 | virtual void surroundContents(DOMNode *node); |
---|
114 | virtual DOMRange* cloneRange() const; |
---|
115 | virtual const XMLCh* toString() const; |
---|
116 | virtual void detach(); |
---|
117 | virtual void release(); |
---|
118 | |
---|
119 | //getter functions |
---|
120 | DOMDocument* getDocument(); |
---|
121 | |
---|
122 | // functions to inform all existing valid ranges about a change |
---|
123 | void updateSplitInfo(DOMNode* oldNode, DOMNode* startNode, XMLSize_t offset); |
---|
124 | void updateRangeForInsertedNode(DOMNode* node); |
---|
125 | void receiveReplacedText(DOMNode* node); |
---|
126 | void updateRangeForDeletedText(DOMNode* node, XMLSize_t offset, XMLSize_t count); |
---|
127 | void updateRangeForInsertedText(DOMNode* node, XMLSize_t offset, XMLSize_t count); |
---|
128 | void updateRangeForDeletedNode(DOMNode* node); |
---|
129 | |
---|
130 | protected: |
---|
131 | //setter functions |
---|
132 | void setStartContainer(const DOMNode* node); |
---|
133 | void setStartOffset(XMLSize_t offset) ; |
---|
134 | void setEndContainer(const DOMNode* node); |
---|
135 | void setEndOffset(XMLSize_t offset) ; |
---|
136 | |
---|
137 | //misc functions |
---|
138 | void validateNode(const DOMNode* node) const; |
---|
139 | bool isValidAncestorType(const DOMNode* node) const; |
---|
140 | bool hasLegalRootContainer(const DOMNode* node) const; |
---|
141 | bool isLegalContainedNode(const DOMNode* node ) const; |
---|
142 | void checkIndex(const DOMNode* node, XMLSize_t offset) const; |
---|
143 | static bool isAncestorOf(const DOMNode* a, const DOMNode* b); |
---|
144 | |
---|
145 | XMLSize_t indexOf(const DOMNode* child, const DOMNode* parent) const; |
---|
146 | |
---|
147 | const DOMNode* commonAncestorOf(const DOMNode* pointA, const DOMNode* pointB) const; |
---|
148 | DOMNode* nextNode(const DOMNode* node, bool visitChildren) const; |
---|
149 | DOMDocumentFragment* traverseContents(TraversalType type); |
---|
150 | void checkReadOnly(DOMNode* start, DOMNode* end, |
---|
151 | XMLSize_t starOffset, XMLSize_t endOffset); |
---|
152 | void recurseTreeAndCheck(DOMNode* start, DOMNode* end); |
---|
153 | DOMNode* removeChild(DOMNode* parent, DOMNode* child); |
---|
154 | |
---|
155 | DOMDocumentFragment* traverseSameContainer( int how ); |
---|
156 | DOMDocumentFragment* traverseCommonStartContainer( DOMNode *endAncestor, int how ); |
---|
157 | DOMDocumentFragment* traverseCommonEndContainer( DOMNode *startAncestor, int how ); |
---|
158 | DOMDocumentFragment* traverseCommonAncestors( DOMNode *startAncestor, DOMNode *endAncestor, int how ); |
---|
159 | DOMNode* traverseRightBoundary( DOMNode *root, int how ); |
---|
160 | DOMNode* traverseLeftBoundary( DOMNode *root, int how ); |
---|
161 | DOMNode* traverseNode( DOMNode *n, bool isFullySelected, bool isLeft, int how ); |
---|
162 | DOMNode* traverseFullySelected( DOMNode *n, int how ); |
---|
163 | DOMNode* traversePartiallySelected( DOMNode *n, int how ); |
---|
164 | DOMNode* traverseTextNode( DOMNode *n, bool isLeft, int how ); |
---|
165 | DOMNode* getSelectedNode( DOMNode *container, int offset ); |
---|
166 | |
---|
167 | private: |
---|
168 | // ----------------------------------------------------------------------- |
---|
169 | // Unimplemented constructors and operators |
---|
170 | // ----------------------------------------------------------------------- |
---|
171 | DOMRangeImpl & operator = (const DOMRangeImpl &); |
---|
172 | }; |
---|
173 | |
---|
174 | XERCES_CPP_NAMESPACE_END |
---|
175 | |
---|
176 | #endif |
---|