fix logic
[personal-kdelibs.git] / khtml / xml / dom2_rangeimpl.h
blobf41184df1610849cee015209450a9f2b802f660d
1 /*
2 * This file is part of the DOM implementation for KDE.
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)
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public License
20 * along with this library; see the file COPYING.LIB. If not, write to
21 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
26 #ifndef _DOM2_RangeImpl_h_
27 #define _DOM2_RangeImpl_h_
29 #include "dom/dom2_range.h"
30 #include "misc/shared.h"
32 namespace DOM {
34 class RangeImpl : public khtml::Shared<RangeImpl>
36 friend class DocumentImpl;
37 public:
38 RangeImpl(DocumentImpl *_ownerDocument);
39 RangeImpl(DocumentImpl *_ownerDocument,
40 NodeImpl *_startContainer, long _startOffset,
41 NodeImpl *_endContainer, long _endOffset);
43 ~RangeImpl();
45 NodeImpl *startContainer(int &exceptioncode) const;
46 long startOffset(int &exceptioncode) const;
47 NodeImpl *endContainer(int &exceptioncode) const;
48 long endOffset(int &exceptioncode) const;
49 bool collapsed(int &exceptioncode) const;
51 NodeImpl *commonAncestorContainer(int &exceptioncode);
52 static NodeImpl *commonAncestorContainer(NodeImpl *containerA, NodeImpl *containerB);
53 void setStart ( NodeImpl *refNode, long offset, int &exceptioncode );
54 void setEnd ( NodeImpl *refNode, long offset, int &exceptioncode );
55 void collapse ( bool toStart, int &exceptioncode );
56 short compareBoundaryPoints ( Range::CompareHow how, RangeImpl *sourceRange, int &exceptioncode );
57 static short compareBoundaryPoints ( NodeImpl *containerA, long offsetA, NodeImpl *containerB, long offsetB );
58 bool boundaryPointsValid ( );
59 void deleteContents ( int &exceptioncode );
60 DocumentFragmentImpl *extractContents ( int &exceptioncode );
61 DocumentFragmentImpl *cloneContents ( int &exceptioncode );
62 void insertNode( NodeImpl *newNode, int &exceptioncode );
63 DOMString toString ( int &exceptioncode );
64 /** Converts the selection to HTML. The returned string will have matching
65 * tags, and all td, tr, etc tags will be inside a table tag. CSS is not
66 * used at this stage - This needs to be fixed.
68 * This is guaranteed to produce an xml valid snippet, no matter how crappy the input
69 * html page is. It will have html and body tags.
71 * Any urls in images or links will be expanded to full urls <em>with passwords stripped</em>
72 * for security reasons.
74 * Note: Originally this function didn't have the exceptioncode argument. I added it
75 * since all the other functions do. If this is correct, please remove this comment.
77 * @param exceptioncode This will be set if m_detached is true.
78 * @return A string with html tags for this range.
80 DOMString toHTML ( int &exceptioncode );
82 DocumentFragment createContextualFragment ( const DOMString &html, int &exceptioncode );
84 void detach ( int &exceptioncode );
85 bool isDetached() const;
86 RangeImpl *cloneRange(int &exceptioncode);
88 void setStartAfter( NodeImpl *refNode, int &exceptioncode );
89 void setEndBefore( NodeImpl *refNode, int &exceptioncode );
90 void setEndAfter( NodeImpl *refNode, int &exceptioncode );
91 void selectNode( NodeImpl *refNode, int &exceptioncode );
92 void selectNodeContents( NodeImpl *refNode, int &exceptioncode );
93 void surroundContents( NodeImpl *newParent, int &exceptioncode );
94 void setStartBefore( NodeImpl *refNode, int &exceptioncode );
96 enum ActionType {
97 DELETE_CONTENTS,
98 EXTRACT_CONTENTS,
99 CLONE_CONTENTS
101 DocumentFragmentImpl *processContents ( ActionType action, int &exceptioncode );
103 bool readOnly() { return false; }
105 protected:
106 DocumentImpl *m_ownerDocument;
107 NodeImpl *m_startContainer;
108 unsigned long m_startOffset;
109 NodeImpl *m_endContainer;
110 unsigned long m_endOffset;
111 bool m_detached;
113 private:
114 void checkNodeWOffset( NodeImpl *n, int offset, int &exceptioncode) const;
115 void checkNodeBA( NodeImpl *n, int &exceptioncode ) const;
116 void setStartContainer(NodeImpl *_startContainer);
117 void setEndContainer(NodeImpl *_endContainer);
118 void checkDeleteExtract(int &exceptioncode);
119 bool containedByReadOnly();
120 unsigned long maxEndOffset() const;
121 unsigned long maxStartOffset() const;
124 } // namespace
126 #endif