diff --git a/src/dom/DOM_Range.cpp b/src/dom/DOM_Range.cpp index d65b3588945f18a69caf84e1bdc59b8f61b78985..0cde6eb389bc73c2cbd8ef887c190cfd0a0f6a2b 100644 --- a/src/dom/DOM_Range.cpp +++ b/src/dom/DOM_Range.cpp @@ -126,55 +126,55 @@ bool DOM_Range::operator == (const DOM_NullPtr * other) const //getter functions -DOM_Node& DOM_Range::getStartContainer() +DOM_Node DOM_Range::getStartContainer() const { return ((RangeImpl *)fImpl)->getStartContainer(); } -unsigned int DOM_Range::getStartOffset() +unsigned int DOM_Range::getStartOffset() const { return ((RangeImpl *)fImpl)->getStartOffset(); } -DOM_Node& DOM_Range::getEndContainer() +DOM_Node DOM_Range::getEndContainer() const { return ((RangeImpl *)fImpl)->getEndContainer(); } -unsigned int DOM_Range::getEndOffset() +unsigned int DOM_Range::getEndOffset() const { return ((RangeImpl *)fImpl)->getEndOffset(); } -const DOM_Node& DOM_Range::getCommonAncestorContainer() +const DOM_Node DOM_Range::getCommonAncestorContainer() const { return ((RangeImpl *)fImpl)->getCommonAncestorContainer(); } //setter functions -void DOM_Range::setStart(DOM_Node parent, unsigned int offset) +void DOM_Range::setStart(const DOM_Node& parent, unsigned int offset) { this->fImpl->setStart(parent, offset); } -void DOM_Range::setEnd(DOM_Node parent, unsigned int offset) +void DOM_Range::setEnd(const DOM_Node& parent, unsigned int offset) { this->fImpl->setEnd(parent, offset); } -void DOM_Range::setStartBefore(DOM_Node refNode) +void DOM_Range::setStartBefore(const DOM_Node& refNode) { this->fImpl->setStartBefore(refNode); } -void DOM_Range::setStartAfter(DOM_Node refNode) +void DOM_Range::setStartAfter(const DOM_Node& refNode) { this->fImpl->setStartAfter(refNode); } -void DOM_Range::setEndBefore(DOM_Node refNode) +void DOM_Range::setEndBefore(const DOM_Node& refNode) { this->fImpl->setEndBefore(refNode); } -void DOM_Range::setEndAfter(DOM_Node refNode) +void DOM_Range::setEndAfter(const DOM_Node& refNode) { this->fImpl->setEndAfter(refNode); } @@ -185,22 +185,22 @@ void DOM_Range::collapse(bool toStart) this->fImpl->collapse(toStart); } -bool DOM_Range::getCollapsed() +bool DOM_Range::getCollapsed() const { return ((RangeImpl *)fImpl)->getCollapsed(); } -void DOM_Range::selectNode(DOM_Node node) +void DOM_Range::selectNode(const DOM_Node& node) { ((RangeImpl *)fImpl)->selectNode(node); } -void DOM_Range::selectNodeContents(DOM_Node node) +void DOM_Range::selectNodeContents(const DOM_Node& node) { ((RangeImpl *)fImpl)->selectNodeContents(node); } //Functions related to comparing ange Boundrary-Points -short DOM_Range::compareBoundaryPoints(CompareHow how, const DOM_Range& range) +short DOM_Range::compareBoundaryPoints(CompareHow how, const DOM_Range& range) const { return ((RangeImpl *)fImpl)->compareBoundaryPoints(how, range.fImpl); } @@ -215,7 +215,7 @@ DOM_DocumentFragment DOM_Range::extractContents() return ((RangeImpl *)fImpl)->extractContents(); } -DOM_DocumentFragment DOM_Range::cloneContents() +DOM_DocumentFragment DOM_Range::cloneContents() const { return ((RangeImpl *)fImpl)->cloneContents(); } @@ -226,17 +226,17 @@ void DOM_Range::insertNode(DOM_Node& node) } //Misc functions -void DOM_Range::surroundContents(DOM_Node node) +void DOM_Range::surroundContents(DOM_Node& node) { ((RangeImpl *)fImpl)->surroundContents(node); } -DOM_Range DOM_Range::cloneRange() +DOM_Range DOM_Range::cloneRange() const { return DOM_Range( ((RangeImpl *)fImpl)->cloneRange() ); } -DOMString DOM_Range::toString() +DOMString DOM_Range::toString() const { return ((RangeImpl *)fImpl)->toString(); } diff --git a/src/dom/DOM_Range.hpp b/src/dom/DOM_Range.hpp index a64a367b15b1e63190e1e110f04f67879c12090a..94524d03b423a2c8176af0bba9b6286fd88f580e 100644 --- a/src/dom/DOM_Range.hpp +++ b/src/dom/DOM_Range.hpp @@ -93,37 +93,37 @@ public: bool operator == (const DOM_NullPtr * other) const; //getter functions - DOM_Node& getStartContainer(); - unsigned int getStartOffset(); - DOM_Node& getEndContainer(); - unsigned int getEndOffset(); - bool getCollapsed(); - const DOM_Node& getCommonAncestorContainer(); + DOM_Node getStartContainer() const; + unsigned int getStartOffset() const; + DOM_Node getEndContainer() const; + unsigned int getEndOffset() const; + bool getCollapsed() const; + const DOM_Node getCommonAncestorContainer() const; //setter functions - void setStart(DOM_Node parent, unsigned int offset); - void setEnd(DOM_Node parent, unsigned int offset); + void setStart(const DOM_Node &parent, unsigned int offset); + void setEnd(const DOM_Node &parent, unsigned int offset); - void setStartBefore(DOM_Node refNode); - void setStartAfter(DOM_Node refNode); - void setEndBefore(DOM_Node refNode); - void setEndAfter(DOM_Node refNode); + void setStartBefore(const DOM_Node &refNode); + void setStartAfter(const DOM_Node &refNode); + void setEndBefore(const DOM_Node &refNode); + void setEndAfter(const DOM_Node &refNode); //misc functions void collapse(bool toStart); - void selectNode(DOM_Node node); - void selectNodeContents(DOM_Node node); + void selectNode(const DOM_Node &node); + void selectNodeContents(const DOM_Node &node); //Functions related to comparing range Boundrary-Points - short compareBoundaryPoints(CompareHow how, const DOM_Range& range); + short compareBoundaryPoints(CompareHow how, const DOM_Range& range) const; void deleteContents(); DOM_DocumentFragment extractContents(); - DOM_DocumentFragment cloneContents(); + DOM_DocumentFragment cloneContents() const; void insertNode(DOM_Node& node); //Misc functions - void surroundContents(DOM_Node node); - DOM_Range cloneRange(); - DOMString toString(); + void surroundContents(DOM_Node &node); + DOM_Range cloneRange() const; + DOMString toString() const; void detach(); diff --git a/src/dom/RangeImpl.cpp b/src/dom/RangeImpl.cpp index 54e11868daa08b00c291b9e93fb5e1eb92c80aa7..707c19b79723464169f70712b495d6dbc33602ad 100644 --- a/src/dom/RangeImpl.cpp +++ b/src/dom/RangeImpl.cpp @@ -84,7 +84,6 @@ RangeImpl::RangeImpl(DOM_Document doc) fEndOffset(0), fDetached(false), fCollapsed(true), - fCommonAncestorContainer(0), fRemoveChild(0) { } @@ -98,7 +97,6 @@ RangeImpl::RangeImpl(const RangeImpl& other) fEndOffset = other.fEndOffset; fDetached = other.fDetached; fCollapsed = other.fCollapsed; - fCommonAncestorContainer = other.fCommonAncestorContainer; fRemoveChild = other.fRemoveChild; } @@ -126,29 +124,29 @@ void RangeImpl::unreferenced() //------------------------------- -DOM_Node& RangeImpl::getStartContainer() +DOM_Node RangeImpl::getStartContainer() const { return fStartContainer; } -unsigned int RangeImpl::getStartOffset() +unsigned int RangeImpl::getStartOffset() const { return fStartOffset; } -DOM_Node& RangeImpl::getEndContainer() +DOM_Node RangeImpl::getEndContainer() const { return fEndContainer; } -unsigned int RangeImpl::getEndOffset() +unsigned int RangeImpl::getEndOffset() const { return fEndOffset; } -bool RangeImpl::getCollapsed() +bool RangeImpl::getCollapsed() const { if (fDetached) { @@ -185,12 +183,7 @@ void RangeImpl::setEndOffset(unsigned int offset) fEndOffset = offset; } -void RangeImpl::setCommonAncestorContainer(const DOM_Node& node) -{ - fCommonAncestorContainer = node; -} - -void RangeImpl::setStart(DOM_Node& refNode, unsigned int offset) +void RangeImpl::setStart(const DOM_Node& refNode, unsigned int offset) { checkIndex(refNode, offset); @@ -210,7 +203,7 @@ void RangeImpl::setStart(DOM_Node& refNode, unsigned int offset) fCollapsed = false; } -void RangeImpl::setEnd(DOM_Node& refNode, unsigned int offset) +void RangeImpl::setEnd(const DOM_Node& refNode, unsigned int offset) { checkIndex(refNode, offset); @@ -230,7 +223,7 @@ void RangeImpl::setEnd(DOM_Node& refNode, unsigned int offset) fCollapsed = false; } -void RangeImpl::setStartBefore(DOM_Node& refNode) +void RangeImpl::setStartBefore(const DOM_Node& refNode) { validateNode(refNode); @@ -257,7 +250,7 @@ void RangeImpl::setStartBefore(DOM_Node& refNode) fCollapsed = false; } -void RangeImpl::setStartAfter(DOM_Node& refNode) +void RangeImpl::setStartAfter(const DOM_Node& refNode) { validateNode(refNode); @@ -282,7 +275,7 @@ void RangeImpl::setStartAfter(DOM_Node& refNode) fCollapsed = false; } -void RangeImpl::setEndBefore(DOM_Node& refNode) +void RangeImpl::setEndBefore(const DOM_Node& refNode) { validateNode(refNode); @@ -308,7 +301,7 @@ void RangeImpl::setEndBefore(DOM_Node& refNode) fCollapsed = false; } -void RangeImpl::setEndAfter(DOM_Node& refNode) +void RangeImpl::setEndAfter(const DOM_Node& refNode) { validateNode(refNode); @@ -346,8 +339,7 @@ void RangeImpl::detach() fEndContainer = 0; fEndOffset = 0; fCollapsed = true; - fCommonAncestorContainer = 0; - + fRemoveChild = 0; } @@ -368,7 +360,7 @@ void RangeImpl::collapse(bool toStart) fCollapsed = true; } -void RangeImpl::selectNode(DOM_Node& refNode) +void RangeImpl::selectNode(const DOM_Node& refNode) { validateNode(refNode); short type = refNode.getNodeType(); @@ -410,7 +402,7 @@ void RangeImpl::selectNode(DOM_Node& refNode) } } -void RangeImpl::selectNodeContents(DOM_Node& node) +void RangeImpl::selectNodeContents(const DOM_Node& node) { validateNode(node); short type = node.getNodeType(); @@ -494,7 +486,7 @@ void RangeImpl::surroundContents(DOM_Node& newParent) } -short RangeImpl::compareBoundaryPoints(DOM_Range::CompareHow how, RangeImpl* srcRange) +short RangeImpl::compareBoundaryPoints(DOM_Range::CompareHow how, RangeImpl* srcRange) const { if (fDocument != srcRange->fDocument) { throw DOM_DOMException( @@ -763,9 +755,10 @@ DOM_DocumentFragment RangeImpl::extractContents() return traverseContents(EXTRACT_CONTENTS); } -DOM_DocumentFragment RangeImpl::cloneContents() +DOM_DocumentFragment RangeImpl::cloneContents() const { - return traverseContents(CLONE_CONTENTS); + // cast off const. + return ((RangeImpl *)this)->traverseContents(CLONE_CONTENTS); } @@ -843,7 +836,7 @@ void RangeImpl::insertNode(DOM_Node& newNode) } -RangeImpl* RangeImpl::cloneRange() +RangeImpl* RangeImpl::cloneRange() const { if( fDetached) { throw DOM_DOMException( @@ -857,7 +850,7 @@ RangeImpl* RangeImpl::cloneRange() return range; } -DOMString RangeImpl::toString() +DOMString RangeImpl::toString() const { if( fDetached) { throw DOM_DOMException( @@ -914,9 +907,9 @@ DOM_Document RangeImpl::getDocument() return fDocument; } -const DOM_Node& RangeImpl::getCommonAncestorContainer() +const DOM_Node RangeImpl::getCommonAncestorContainer() const { - return fCommonAncestorContainer = commonAncestorOf(fStartContainer, fEndContainer); + return commonAncestorOf(fStartContainer, fEndContainer); } @@ -924,7 +917,7 @@ const DOM_Node& RangeImpl::getCommonAncestorContainer() //private functions //--------------------- -bool RangeImpl::isValidAncestorType(DOM_Node& node) +bool RangeImpl::isValidAncestorType(const DOM_Node& node) const { for (DOM_Node aNode = node; aNode!=null; aNode = aNode.getParentNode()) { short type = aNode.getNodeType(); @@ -943,7 +936,7 @@ bool RangeImpl::isAncestorOf(const DOM_Node& a, const DOM_Node& b) { return false; } -unsigned short RangeImpl::indexOf(const DOM_Node& child, const DOM_Node& parent) +unsigned short RangeImpl::indexOf(const DOM_Node& child, const DOM_Node& parent) const { unsigned short i = 0; if (child.getParentNode() != parent) return -1; @@ -953,7 +946,7 @@ unsigned short RangeImpl::indexOf(const DOM_Node& child, const DOM_Node& parent) return i; } -void RangeImpl::validateNode(DOM_Node& node) +void RangeImpl::validateNode(const DOM_Node& node) const { if( fDetached) { throw DOM_DOMException( @@ -967,7 +960,7 @@ void RangeImpl::validateNode(DOM_Node& node) } -DOM_Node RangeImpl::commonAncestorOf(DOM_Node& pointA, DOM_Node& pointB) +const DOM_Node RangeImpl::commonAncestorOf(const DOM_Node& pointA, const DOM_Node& pointB) const { if (fDetached) throw DOM_DOMException(DOM_DOMException::INVALID_STATE_ERR, null); @@ -1013,7 +1006,7 @@ DOM_Node RangeImpl::commonAncestorOf(DOM_Node& pointA, DOM_Node& pointB) return DOM_Node(commonAncestor); } -void RangeImpl::checkIndex(DOM_Node& node, unsigned int offset) +void RangeImpl::checkIndex(const DOM_Node& node, unsigned int offset) const { validateNode(node); @@ -1043,7 +1036,8 @@ void RangeImpl::checkIndex(DOM_Node& node, unsigned int offset) } -DOM_Node RangeImpl::nextNode(const DOM_Node& node, bool visitChildren) { +DOM_Node RangeImpl::nextNode(const DOM_Node& node, bool visitChildren) const +{ if (node == null) return null; diff --git a/src/dom/RangeImpl.hpp b/src/dom/RangeImpl.hpp index 2ef146ca147455e698ef9e2f7559f4a50963c425..b26ef2aa8d69ddeb444ef5523d6e45824c77d5c1 100644 --- a/src/dom/RangeImpl.hpp +++ b/src/dom/RangeImpl.hpp @@ -86,42 +86,42 @@ public: //getter functions - DOM_Node& getStartContainer(); - unsigned int getStartOffset(); - DOM_Node& getEndContainer(); - unsigned int getEndOffset(); + DOM_Node getStartContainer() const; + unsigned int getStartOffset() const; + DOM_Node getEndContainer() const; + unsigned int getEndOffset() const; void collapse(bool toStart); - bool getCollapsed(); + bool getCollapsed() const; - void setStartBefore(DOM_Node& node); - void setStartAfter(DOM_Node& node); - void setEndBefore(DOM_Node& node); - void setEndAfter(DOM_Node& node); + void setStartBefore(const DOM_Node& node); + void setStartAfter(const DOM_Node& node); + void setEndBefore(const DOM_Node& node); + void setEndAfter(const DOM_Node& node); - void setStart(DOM_Node& node, unsigned int offset); - void setEnd(DOM_Node& node, unsigned int offset); + void setStart(const DOM_Node& node, unsigned int offset); + void setEnd(const DOM_Node& node, unsigned int offset); - void selectNode(DOM_Node& node); - void selectNodeContents(DOM_Node& node); + void selectNode(const DOM_Node& node); + void selectNodeContents(const DOM_Node& node); - short compareBoundaryPoints(DOM_Range::CompareHow how, RangeImpl* range); + short compareBoundaryPoints(DOM_Range::CompareHow how, RangeImpl* range) const; void detach(); void deleteContents(); - RangeImpl* cloneRange(); - DOMString toString(); + RangeImpl* cloneRange() const; + DOMString toString() const; DOM_Document getDocument(); void surroundContents(DOM_Node& node); DOM_DocumentFragment extractContents(); - DOM_DocumentFragment cloneContents(); + DOM_DocumentFragment cloneContents() const; void insertNode(DOM_Node& newNode); - const DOM_Node& getCommonAncestorContainer(); + const DOM_Node getCommonAncestorContainer() const; // functions to inform all existing valid ranges about a change void updateSplitInfo(TextImpl* oldNode, TextImpl* startNode); @@ -147,18 +147,17 @@ private: void setStartOffset(unsigned int offset) ; void setEndContainer(const DOM_Node& node); void setEndOffset(unsigned int offset) ; - void setCommonAncestorContainer(const DOM_Node& node) ; //misc functions - void validateNode(DOM_Node& node); - bool isValidAncestorType(DOM_Node& node); - void checkIndex(DOM_Node& node, unsigned int offset); + void validateNode(const DOM_Node& node) const; + bool isValidAncestorType(const DOM_Node& node) const; + void checkIndex(const DOM_Node& node, unsigned int offset) const; static bool isAncestorOf(const DOM_Node& a, const DOM_Node& b); - unsigned short indexOf(const DOM_Node& child, const DOM_Node& parent); + unsigned short indexOf(const DOM_Node& child, const DOM_Node& parent) const; - DOM_Node commonAncestorOf(DOM_Node& pointA, DOM_Node& pointB); - DOM_Node nextNode(const DOM_Node& node, bool visitChildren); + const DOM_Node commonAncestorOf(const DOM_Node& pointA, const DOM_Node& pointB) const; + DOM_Node nextNode(const DOM_Node& node, bool visitChildren) const; DOM_DocumentFragment traverseContents(TraversalType type); void checkReadOnly(DOM_Node& start, DOM_Node& end, unsigned int starOffset, unsigned int endOffset); @@ -172,7 +171,6 @@ private: DOM_Node fEndContainer; unsigned int fEndOffset; bool fCollapsed; - DOM_Node fCommonAncestorContainer; DOM_Document fDocument; bool fDetached;