[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/KDE/4.0/kdelibs/khtml/xml
From: Maks Orlovich <maksim () kde ! org>
Date: 2008-03-30 18:24:41
Message-ID: 1206901481.234712.18371.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 791908 by orlovich:
Fix up the full-blown Attr codes to properly take care of their kids.
Patch by Harri, w/some tweaks from me to the ID-cache handling
and a removal of a no-longer-need hack in textContent
M +47 -24 dom_elementimpl.cpp
M +2 -0 dom_elementimpl.h
M +0 -3 dom_nodeimpl.cpp
--- branches/KDE/4.0/kdelibs/khtml/xml/dom_elementimpl.cpp #791907:791908
@@ -63,7 +63,6 @@
AttrImpl::AttrImpl(ElementImpl* element, DocumentImpl* docPtr, NodeImpl::Id attrId,
DOMStringImpl *value, DOMStringImpl *prefix)
: NodeBaseImpl(docPtr),
- m_element(element),
m_attrId(attrId)
{
m_value = value;
@@ -73,6 +72,14 @@
if (m_prefix)
m_prefix->ref();
m_specified = true; // we don't yet support default attributes
+
+ // When creating the text node initially, we want element = 0,
+ // so we don't attempt to update the getElementById cache or
+ // call parseAttribute, etc. This is because we're normally lazily,
+ // from previous attributes, so there is nothing really changing
+ m_element = 0;
+ createTextChild();
+ m_element = element;
}
AttrImpl::~AttrImpl()
@@ -148,12 +155,44 @@
return n;
}
+void AttrImpl::createTextChild()
+{
+ // add a text node containing the attribute value
+ if (m_value->length() > 0) {
+ TextImpl* textNode = ownerDocument()->createTextNode(m_value);
+ int exceptioncode;
+ appendChild(textNode, exceptioncode);
+ assert(exceptioncode == 0);
+ }
+}
+
+void AttrImpl::childrenChanged()
+{
+ NodeBaseImpl::childrenChanged();
+
+ // update value
+ DOMStringImpl* oldVal = m_value;
+ m_value = new DOMStringImpl(0, 0);
+ m_value->ref();
+ for (NodeImpl* n = firstChild(); n; n = n->nextSibling()) {
+ DOMStringImpl* data = static_cast<const TextImpl*>(n)->string();
+ m_value->append(data);
+ }
+
+ if (m_element) {
+ if (m_attrId == ATTR_ID)
+ m_element->updateId(oldVal, m_value);
+ m_element->parseAttribute(m_attrId, m_value);
+ m_element->attributeChanged(m_attrId);
+ }
+
+ oldVal->deref();
+}
+
void AttrImpl::setValue( const DOMString &v, int &exceptioncode )
{
exceptioncode = 0;
- // ### according to the DOM docs, we should create an unparsed Text child
- // node here
// do not interprete entities in the string, its literal!
// NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly
@@ -171,17 +210,9 @@
if (m_value == v.implementation())
return;
- if (m_element && m_attrId == ATTR_ID)
- m_element->updateId(m_value, v.implementation());
-
- m_value->deref();
- m_value = v.implementation();
- m_value->ref();
-
- if (m_element) {
- m_element->parseAttribute(m_attrId,m_value);
- m_element->attributeChanged(m_attrId);
- }
+ int e = 0;
+ removeChildren();
+ appendChild(ownerDocument()->createTextNode(v.implementation()), e);
}
void AttrImpl::setNodeValue( const DOMString &v, int &exceptioncode )
@@ -229,15 +260,7 @@
// maybe easier to just use text value and ignore existing
// entity refs?
- if ( firstChild() ) {
- result += "=\"";
-
- for (NodeImpl *child = firstChild(); child != NULL; child = child->nextSibling()) {
- result += child->toString();
- }
-
- result += "\"";
- } else if ( !nodeValue().isEmpty() ){
+ if ( !nodeValue().isEmpty() ) {
//remove the else once the AttributeImpl changes are merged
result += "=\"";
result += nodeValue();
@@ -1217,7 +1240,7 @@
if (id == ATTR_ID)
m_element->updateId(m_attrs[i].val(), 0);
Node removed(m_attrs[i].createAttr(m_element,m_element->docPtr()));
- m_attrs[i].free();
+ m_attrs[i].free(); // Also sets the remove'd ownerElement to 0
memmove(m_attrs+i,m_attrs+i+1,(m_attrCount-i-1)*sizeof(AttributeImpl));
m_attrCount--;
m_attrs = (AttributeImpl*)realloc(m_attrs,m_attrCount*sizeof(AttributeImpl));
--- branches/KDE/4.0/kdelibs/khtml/xml/dom_elementimpl.h #791907:791908
@@ -60,6 +60,7 @@
private:
AttrImpl(const AttrImpl &other);
AttrImpl &operator = (const AttrImpl &other);
+ void createTextChild();
public:
// DOM methods & attributes for Attr
@@ -88,6 +89,7 @@
virtual bool childAllowed( NodeImpl *newChild );
virtual bool childTypeAllowed( unsigned short type );
virtual NodeImpl::Id id() const { return m_attrId; }
+ virtual void childrenChanged();
virtual DOMString toString() const;
--- branches/KDE/4.0/kdelibs/khtml/xml/dom_nodeimpl.cpp #791907:791908
@@ -226,9 +226,6 @@
case Node::DOCUMENT_FRAGMENT_NODE: {
DOMString s = "";
- if (nodeType() == Node::ATTRIBUTE_NODE)
- s += nodeValue();
-
for (NodeImpl *child = firstChild(); child; child = child->nextSibling()) {
if (child->nodeType() == Node::COMMENT_NODE ||
child->nodeType() == Node::PROCESSING_INSTRUCTION_NODE)
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic