00001 #ifndef RangeImpl_HEADER_GUARD_
00002 #define RangeImpl_HEADER_GUARD_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 #include "DOM_Node.hpp"
00066 #include "RefCountedImpl.hpp"
00067 #include "DOM_Range.hpp"
00068 #include "DOM_Text.hpp"
00069 #include "DOM_Document.hpp"
00070 #include <xercesc/util/RefVectorOf.hpp>
00071
00072
00073 typedef RefVectorOf<RangeImpl> Ranges;
00074
00075 class CDOM_EXPORT RangeImpl : public RefCountedImpl {
00076 public:
00077
00078 RangeImpl(DOM_Document doc);
00079 RangeImpl(const RangeImpl& other);
00080
00081
00082 ~RangeImpl();
00083
00084
00085 virtual void unreferenced();
00086
00087
00088
00089 DOM_Node getStartContainer() const;
00090 unsigned int getStartOffset() const;
00091 DOM_Node getEndContainer() const;
00092 unsigned int getEndOffset() const;
00093
00094
00095
00096 void collapse(bool toStart);
00097 bool getCollapsed() const;
00098
00099 void setStartBefore(const DOM_Node& node);
00100 void setStartAfter(const DOM_Node& node);
00101 void setEndBefore(const DOM_Node& node);
00102 void setEndAfter(const DOM_Node& node);
00103
00104 void setStart(const DOM_Node& node, unsigned int offset);
00105 void setEnd(const DOM_Node& node, unsigned int offset);
00106
00107 void selectNode(const DOM_Node& node);
00108 void selectNodeContents(const DOM_Node& node);
00109
00110 short compareBoundaryPoints(DOM_Range::CompareHow how, RangeImpl* range) const;
00111
00112 void detach();
00113
00114 void deleteContents();
00115
00116 RangeImpl* cloneRange() const;
00117 DOMString toString() const;
00118
00119 DOM_Document getDocument();
00120 void surroundContents(DOM_Node& node);
00121 DOM_DocumentFragment extractContents();
00122 DOM_DocumentFragment cloneContents() const;
00123 void insertNode(DOM_Node& newNode);
00124 const DOM_Node getCommonAncestorContainer() const;
00125
00126
00127 void updateSplitInfo(TextImpl* oldNode, TextImpl* startNode, unsigned int offset);
00128 void updateRangeForInsertedNode(NodeImpl* node);
00129 void receiveReplacedText(NodeImpl* node);
00130 void updateRangeForDeletedText(DOM_Node& node, unsigned int offset, int count);
00131 void updateRangeForDeletedNode(NodeImpl* node);
00132
00133 private:
00134 enum TraversalType {
00135 EXTRACT_CONTENTS = 1,
00136 CLONE_CONTENTS = 2,
00137 DELETE_CONTENTS = 3
00138 };
00139
00140 enum TraversePoint {
00141 BEFORE = -1,
00142 START = 0,
00143 AFTER = 1
00144 };
00145
00146
00147 void setStartContainer(const DOM_Node& node);
00148 void setStartOffset(unsigned int offset) ;
00149 void setEndContainer(const DOM_Node& node);
00150 void setEndOffset(unsigned int offset) ;
00151
00152
00153 void validateNode(const DOM_Node& node) const;
00154 bool isValidAncestorType(const DOM_Node& node) const;
00155 bool hasLegalRootContainer(const DOM_Node& node) const;
00156 bool isLegalContainedNode(const DOM_Node& node ) const;
00157 void checkIndex(const DOM_Node& node, unsigned int offset) const;
00158 static bool isAncestorOf(const DOM_Node& a, const DOM_Node& b);
00159
00160 unsigned short indexOf(const DOM_Node& child, const DOM_Node& parent) const;
00161
00162 const DOM_Node commonAncestorOf(const DOM_Node& pointA, const DOM_Node& pointB) const;
00163 DOM_Node nextNode(const DOM_Node& node, bool visitChildren) const;
00164 DOM_DocumentFragment traverseContents(TraversalType type);
00165 void checkReadOnly(DOM_Node& start, DOM_Node& end,
00166 unsigned int starOffset, unsigned int endOffset);
00167 void recurseTreeAndCheck(DOM_Node& start, DOM_Node& end);
00168 DOM_Node removeChild(DOM_Node& parent, DOM_Node& child);
00169
00170 DOM_DocumentFragment traverseSameContainer( int how );
00171 DOM_DocumentFragment traverseCommonStartContainer( DOM_Node endAncestor, int how );
00172 DOM_DocumentFragment traverseCommonEndContainer( DOM_Node startAncestor, int how );
00173 DOM_DocumentFragment traverseCommonAncestors( DOM_Node startAncestor, DOM_Node endAncestor, int how );
00174 DOM_Node traverseRightBoundary( DOM_Node root, int how );
00175 DOM_Node traverseLeftBoundary( DOM_Node root, int how );
00176 DOM_Node traverseNode( DOM_Node n, bool isFullySelected, bool isLeft, int how );
00177 DOM_Node traverseFullySelected( DOM_Node n, int how );
00178 DOM_Node traversePartiallySelected( DOM_Node n, int how );
00179 DOM_Node traverseTextNode( DOM_Node n, bool isLeft, int how );
00180 DOM_Node getSelectedNode( DOM_Node container, int offset );
00181
00182
00183
00184 DOM_Node fStartContainer;
00185 unsigned int fStartOffset;
00186 DOM_Node fEndContainer;
00187 unsigned int fEndOffset;
00188 bool fCollapsed;
00189 DOM_Document fDocument;
00190 bool fDetached;
00191
00192 DOM_Node fRemoveChild;
00193
00194 };
00195
00196 #endif