File indexing completed on 2024-04-28 11:39:28

0001 /*
0002  * This file is part of the DOM implementation for KDE.
0003  *
0004  * Copyright (C) 1999 Lars Knoll <knoll@kde.org>
0005  * Copyright (C) 2000 Gunnstein Lye <gunnstein@netcom.no>
0006  * Copyright (C) 2000 Frederik Holljen <frederik.holljen@hig.no>
0007  * Copyright (C) 2001 Peter Kelly <pmk@post.com>
0008  *
0009  * This library is free software; you can redistribute it and/or
0010  * modify it under the terms of the GNU Library General Public
0011  * License as published by the Free Software Foundation; either
0012  * version 2 of the License, or (at your option) any later version.
0013  *
0014  * This library is distributed in the hope that it will be useful,
0015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0017  * Library General Public License for more details.
0018  *
0019  * You should have received a copy of the GNU Library General Public License
0020  * along with this library; see the file COPYING.LIB.  If not, write to
0021  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0022  * Boston, MA 02110-1301, USA.
0023  *
0024  */
0025 
0026 #ifndef _DOM2_RangeImpl_h_
0027 #define _DOM2_RangeImpl_h_
0028 
0029 #include "dom/dom2_range.h"
0030 #include "misc/shared.h"
0031 
0032 namespace DOM
0033 {
0034 
0035 class RangeImpl : public khtml::Shared<RangeImpl>
0036 {
0037     friend class DocumentImpl;
0038 public:
0039     RangeImpl(DocumentImpl *_ownerDocument);
0040     RangeImpl(DocumentImpl *_ownerDocument,
0041               NodeImpl *_startContainer, long _startOffset,
0042               NodeImpl *_endContainer, long _endOffset);
0043 
0044     ~RangeImpl();
0045 
0046     NodeImpl *startContainer(int &exceptioncode) const;
0047     long startOffset(int &exceptioncode) const;
0048     NodeImpl *endContainer(int &exceptioncode) const;
0049     long endOffset(int &exceptioncode) const;
0050     bool collapsed(int &exceptioncode) const;
0051 
0052     NodeImpl *commonAncestorContainer(int &exceptioncode);
0053     static NodeImpl *commonAncestorContainer(NodeImpl *containerA, NodeImpl *containerB);
0054     void setStart(NodeImpl *refNode, long offset, int &exceptioncode);
0055     void setEnd(NodeImpl *refNode, long offset, int &exceptioncode);
0056     void collapse(bool toStart, int &exceptioncode);
0057     short compareBoundaryPoints(Range::CompareHow how, RangeImpl *sourceRange, int &exceptioncode);
0058     static short compareBoundaryPoints(NodeImpl *containerA, long offsetA, NodeImpl *containerB, long offsetB);
0059     bool boundaryPointsValid();
0060     void deleteContents(int &exceptioncode);
0061     DocumentFragmentImpl *extractContents(int &exceptioncode);
0062     DocumentFragmentImpl *cloneContents(int &exceptioncode);
0063     void insertNode(NodeImpl *newNode, int &exceptioncode);
0064     DOMString toString(int &exceptioncode);
0065     /** Converts the selection  to HTML.  The returned string will have matching
0066      *  tags, and all td, tr, etc tags will be inside a table tag.  CSS is not
0067      *  used at this stage - This needs to be fixed.
0068      *
0069      *  This is guaranteed to produce an xml valid snippet, no matter how crappy the input
0070      *  html page is.  It will have html and body tags.
0071      *
0072      *  Any urls in images or links will be expanded to full urls <em>with passwords stripped</em>
0073      *  for security reasons.
0074      *
0075      *  Note: Originally this function didn't have the exceptioncode argument.  I added it
0076      *  since all the other functions do.  If this is correct, please remove this comment.
0077      *
0078      *  @param exceptioncode This will be set if m_detached is true.
0079      *  @return A string with html tags for this range.
0080      */
0081     DOMString toHTML(int &exceptioncode);
0082 
0083     DocumentFragment createContextualFragment(const DOMString &html, int &exceptioncode);
0084 
0085     void detach(int &exceptioncode);
0086     bool isDetached() const;
0087     RangeImpl *cloneRange(int &exceptioncode);
0088 
0089     void setStartAfter(NodeImpl *refNode, int &exceptioncode);
0090     void setEndBefore(NodeImpl *refNode, int &exceptioncode);
0091     void setEndAfter(NodeImpl *refNode, int &exceptioncode);
0092     void selectNode(NodeImpl *refNode, int &exceptioncode);
0093     void selectNodeContents(NodeImpl *refNode, int &exceptioncode);
0094     void surroundContents(NodeImpl *newParent, int &exceptioncode);
0095     void setStartBefore(NodeImpl *refNode, int &exceptioncode);
0096 
0097     enum ActionType {
0098         DELETE_CONTENTS,
0099         EXTRACT_CONTENTS,
0100         CLONE_CONTENTS
0101     };
0102     DocumentFragmentImpl *processContents(ActionType action, int &exceptioncode);
0103 
0104     bool readOnly()
0105     {
0106         return false;
0107     }
0108 
0109     DocumentImpl *ownerDocument()
0110     {
0111         return m_ownerDocument;
0112     }
0113 
0114 protected:
0115     DocumentImpl *m_ownerDocument;
0116     NodeImpl *m_startContainer;
0117     unsigned long m_startOffset;
0118     NodeImpl *m_endContainer;
0119     unsigned long m_endOffset;
0120     bool m_detached;
0121 
0122 private:
0123     void checkNodeWOffset(NodeImpl *n, int offset, int &exceptioncode) const;
0124     void checkNodeBA(NodeImpl *n, int &exceptioncode) const;
0125     void setStartContainer(NodeImpl *_startContainer);
0126     void setEndContainer(NodeImpl *_endContainer);
0127     void checkDeleteExtract(int &exceptioncode);
0128     bool containedByReadOnly();
0129     unsigned long maxEndOffset() const;
0130     unsigned long maxStartOffset() const;
0131 };
0132 
0133 } // namespace
0134 
0135 #endif
0136