[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/KDE/4.0/kdelibs/khtml/xml
From: Germain Garand <germain () ebooksfrance ! org>
Date: 2008-04-03 4:24:12
Message-ID: 1207196652.662931.21294.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 793181 by ggarand:
automatically merged revision 793178:
merge some ad hoc changes to RangeImpl::surroundContents, whose main
rationale is "keep Acid3's 11th test happy".
I tried hard to make up a sound explanation for those, digging
deep into the specification's arcane semantics, but eventually,
I don't think I really convinced myself, and certainly not Harri.
He says: "it's a pragmatic solution".
And that's what it is.
CCBUG:156947
M +37 -11 dom2_rangeimpl.cpp
M +2 -0 dom2_rangeimpl.h
M +6 -0 dom_nodeimpl.h
M +3 -0 dom_textimpl.h
M +5 -0 dom_xmlimpl.cpp
M +2 -0 dom_xmlimpl.h
--- branches/KDE/4.0/kdelibs/khtml/xml/dom2_rangeimpl.cpp #793180:793181
@@ -6,7 +6,7 @@
* (C) 2000 Gunnstein Lye (gunnstein@netcom.no)
* (C) 2000 Frederik Holljen (frederik.holljen@hig.no)
* (C) 2001 Peter Kelly (pmk@post.com)
- * Copyright (C) 2003 Apple Computer, Inc.
+ * Copyright (C) 2003-2008 Apple Computer, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@@ -1428,7 +1428,7 @@
setStartContainer(refNode);
m_startOffset = 0;
setEndContainer(refNode);
- m_endOffset = refNode->childNodeCount();
+ m_endOffset = maxEndOffset();
}
void RangeImpl::surroundContents( NodeImpl *newParent, int &exceptioncode )
@@ -1488,7 +1488,17 @@
// HIERARCHY_REQUEST_ERR: Raised if the container of the start of the Range is \
of a type that
// does not allow children of the type of newParent or if newParent is an \
ancestor of the container
// or if node would end up with a child node of a type not allowed by the type \
of node.
- if (!m_startContainer->childTypeAllowed(newParent->nodeType())) {
+
+ // If m_startContainer is a character data node, it will be split and it will be \
its parent that will + // need to accept newParent (or in the case of a comment, \
it logically "would" be inserted into the parent, + // although this will fail \
below for another reason). +
+ NodeImpl* parentOfNewParent = m_startContainer;
+
+ if (parentOfNewParent->offsetInCharacters())
+ parentOfNewParent = parentOfNewParent->parentNode();
+
+ if (!parentOfNewParent->childTypeAllowed(newParent->nodeType())) {
exceptioncode = DOMException::HIERARCHY_REQUEST_ERR;
return;
}
@@ -1504,22 +1514,18 @@
// BAD_BOUNDARYPOINTS_ERR: Raised if the Range partially selects a non-text \
node. if (m_startContainer->nodeType() != Node::TEXT_NODE &&
- m_startContainer->nodeType() != Node::COMMENT_NODE &&
- m_startContainer->nodeType() != Node::CDATA_SECTION_NODE &&
- m_startContainer->nodeType() != Node::PROCESSING_INSTRUCTION_NODE) {
+ m_startContainer->nodeType() != Node::CDATA_SECTION_NODE) {
- if (m_startOffset > 0 && m_startOffset < m_startContainer->childNodeCount()) \
{ + if (m_startOffset > 0 && m_startOffset < maxStartOffset()) {
exceptioncode = RangeException::BAD_BOUNDARYPOINTS_ERR + \
RangeException::_EXCEPTION_OFFSET; return;
}
}
if (m_endContainer->nodeType() != Node::TEXT_NODE &&
- m_endContainer->nodeType() != Node::COMMENT_NODE &&
- m_endContainer->nodeType() != Node::CDATA_SECTION_NODE &&
- m_endContainer->nodeType() != Node::PROCESSING_INSTRUCTION_NODE) {
+ m_endContainer->nodeType() != Node::CDATA_SECTION_NODE) {
- if (m_endOffset > 0 && m_endOffset < m_endContainer->childNodeCount()) {
+ if (m_endOffset > 0 && m_endOffset < maxEndOffset()) {
exceptioncode = RangeException::BAD_BOUNDARYPOINTS_ERR + \
RangeException::_EXCEPTION_OFFSET; return;
}
@@ -1542,6 +1548,26 @@
selectNode( newParent, exceptioncode );
}
+
+unsigned long RangeImpl::maxStartOffset() const
+{
+ if (!m_startContainer)
+ return 0;
+ if (!m_startContainer->offsetInCharacters())
+ return m_startContainer->childNodeCount();
+ return m_startContainer->maxCharacterOffset();
+}
+
+unsigned long RangeImpl::maxEndOffset() const
+{
+ if (!m_endContainer)
+ return 0;
+ if (!m_endContainer->offsetInCharacters())
+ return m_endContainer->childNodeCount();
+ return m_endContainer->maxCharacterOffset();
+}
+
+
void RangeImpl::setStartBefore( NodeImpl *refNode, int &exceptioncode )
{
if (m_detached) {
--- branches/KDE/4.0/kdelibs/khtml/xml/dom2_rangeimpl.h #793180:793181
@@ -117,6 +117,8 @@
void setEndContainer(NodeImpl *_endContainer);
void checkDeleteExtract(int &exceptioncode);
bool containedByReadOnly();
+ unsigned long maxEndOffset() const;
+ unsigned long maxStartOffset() const;
};
} // namespace
--- branches/KDE/4.0/kdelibs/khtml/xml/dom_nodeimpl.h #793180:793181
@@ -339,6 +339,12 @@
bool isAncestor( NodeImpl *other );
virtual bool childAllowed( NodeImpl *newChild );
+ // Used to determine whether range offsets use characters or node indices.
+ virtual bool offsetInCharacters() const { return false; }
+ // Number of DOM 16-bit units contained in node. Note that rendered text length \
can be different - e.g. because of + // css-transform:capitalize breaking up \
precomposed characters and ligatures. + virtual int maxCharacterOffset() const { \
return 0; } +
/**
* Returns the minimum caret offset that is allowed for this node.
*
--- branches/KDE/4.0/kdelibs/khtml/xml/dom_textimpl.h #793180:793181
@@ -67,6 +67,9 @@
virtual void checkCharDataOperation( const unsigned long offset, int \
&exceptioncode );
+ virtual bool offsetInCharacters() const { return true; }
+ virtual int maxCharacterOffset() const { return static_cast<int>(length()); }
+
virtual long minOffset() const;
virtual long maxOffset() const;
--- branches/KDE/4.0/kdelibs/khtml/xml/dom_xmlimpl.cpp #793180:793181
@@ -465,6 +465,11 @@
return result;
}
+int ProcessingInstructionImpl::maxCharacterOffset() const
+{
+ return m_data ? static_cast<int>(m_data->length()) : 0;
+}
+
// -------------------------------------------------------------------------
XMLAttributeReader::XMLAttributeReader(const QString& _attrString)
--- branches/KDE/4.0/kdelibs/khtml/xml/dom_xmlimpl.h #793180:793181
@@ -155,6 +155,8 @@
virtual DOMString toString() const;
+ virtual bool offsetInCharacters() const { return true; }
+ virtual int maxCharacterOffset() const;
protected:
DOMStringImpl *m_target;
DOMStringImpl *m_data;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic