[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/KDE/4.0/kdelibs/khtml/xml
From: Harri Porten <porten () kde ! org>
Date: 2008-01-20 21:41:52
Message-ID: 1200865312.196422.7303.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 764044 by porten:
Fixed insertion of a text node into a range in another one. The expected
result is a bit unclear in the spec. I harmonized some code with WebCore
but went for compatibility with Firefox 3.
M +22 -8 dom2_rangeimpl.cpp
--- branches/KDE/4.0/kdelibs/khtml/xml/dom2_rangeimpl.cpp #764043:764044
@@ -788,7 +788,7 @@
}
// INVALID_NODE_TYPE_ERR: Raised if newNode is an Attr, Entity, Notation, or \
Document node.
- if( newNode->nodeType() == Node::ATTRIBUTE_NODE ||
+ if (newNode->nodeType() == Node::ATTRIBUTE_NODE ||
newNode->nodeType() == Node::ENTITY_NODE ||
newNode->nodeType() == Node::NOTATION_NODE ||
newNode->nodeType() == Node::DOCUMENT_NODE) {
@@ -796,21 +796,36 @@
return;
}
- if( m_startContainer->nodeType() == Node::TEXT_NODE ||
+ long endOffsetDelta = 0;
+ if (m_startContainer->nodeType() == Node::TEXT_NODE ||
m_startContainer->nodeType() == Node::CDATA_SECTION_NODE )
{
+ // ### leaks on exceptions
TextImpl *newText = \
static_cast<TextImpl*>(m_startContainer)->splitText(m_startOffset,exceptioncode); if \
(exceptioncode) return;
+
+ if (m_startContainer == m_endContainer) {
+ endOffsetDelta = -m_startOffset;
+ setEndContainer(newText);
+ // ### what about border cases where start or end are at
+ // ### the margins of the text?
+ }
+
m_startContainer->parentNode()->insertBefore( newNode, newText, \
exceptioncode );
- // ### adapt range?
- }
- else {
+ if (exceptioncode)
+ return;
+ } else {
+ if (m_startContainer == m_endContainer) {
+ bool isFragment = newNode->nodeType() == Node::DOCUMENT_FRAGMENT_NODE;
+ endOffsetDelta = isFragment ? newNode->childNodeCount() : 1;
+ }
+
m_startContainer->insertBefore( newNode, m_startContainer->childNode( \
m_startOffset ), exceptioncode ); if (exceptioncode)
return;
- ++m_endOffset;
}
+ m_endOffset += endOffsetDelta;
}
DOMString RangeImpl::toString( int &exceptioncode )
@@ -869,8 +884,7 @@
if(n->nodeType() == DOM::Node::TEXT_NODE ||
n->nodeType() == DOM::Node::CDATA_SECTION_NODE) {
- DOMString str;
- str = static_cast<TextImpl *>(n)->string();
+ DOMString str = static_cast<TextImpl *>(n)->string();
if( n == m_endContainer || n == m_startContainer)
str = str.copy(); //copy if we are going to modify.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic