Reviewed by Darin.
authorharrison <harrison@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Aug 2005 23:09:20 +0000 (23:09 +0000)
committerharrison <harrison@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 19 Aug 2005 23:09:20 +0000 (23:09 +0000)
        Landed by David Harrison.

        Test cases added: None.  Fixes existing tests.

        * khtml/ecma/kjs_dom.cpp:
        Attribute values are writable

        * khtml/xml/dom_docimpl.cpp:
        (DocumentImpl::createAttributeNS):
        Update for new AttrImpl constructor.

        * khtml/xml/dom_elementimpl.cpp:
        (AttributeImpl::allocateImpl):
        Update for new AttrImpl constructor.

        (AttrImpl::AttrImpl):
        Initialize m_ignoreChildCount to 0. If createTextChild.
        is true, create a child text node with the contents
        of the attribute value.

        (AttrImpl::setValue):
        Remove all children and create a new text node with the contents
        of the attribute value.

        (AttrImpl::cloneNode):
        Make sure to clone any children.

        (AttrImpl::childrenChanged):
        If m_ignoreChildrenChanged is 0, update the attribute value.

        * khtml/xml/dom_elementimpl.h:
        Add childrenChanged, update AttrImpl constructor and
        add m_ignoreChildrenChanged to AttrImpl.

        * khtml/xml/dom_nodeimpl.cpp:
        (DOM::NodeImpl::normalize):
        If an element has attributes, make sure to normalize them.

        * layout-tests/dom/html/level1/core/hc_attrappendchild1-expected.txt:
        * layout-tests/dom/html/level1/core/hc_attrappendchild3-expected.txt:
        * layout-tests/dom/html/level1/core/hc_attrappendchild6-expected.txt:
        * layout-tests/dom/html/level1/core/hc_attrchildnodes1-expected.txt:
        * layout-tests/dom/html/level1/core/hc_attrchildnodes2-expected.txt:
        * layout-tests/dom/html/level1/core/hc_attrclonenode1-expected.txt:
        * layout-tests/dom/html/level1/core/hc_attrcreatetextnode-expected.txt:
        * layout-tests/dom/html/level1/core/hc_attrfirstchild-expected.txt:
        * layout-tests/dom/html/level1/core/hc_attrhaschildnodes-expected.txt:
        * layout-tests/dom/html/level1/core/hc_attrinsertbefore1-expected.txt:
        * layout-tests/dom/html/level1/core/hc_attrinsertbefore2-expected.txt:
        * layout-tests/dom/html/level1/core/hc_attrinsertbefore3-expected.txt:
        * layout-tests/dom/html/level1/core/hc_attrinsertbefore4-expected.txt:
        * layout-tests/dom/html/level1/core/hc_attrlastchild-expected.txt:
        * layout-tests/dom/html/level1/core/hc_attrnormalize-expected.txt:
        * layout-tests/dom/html/level1/core/hc_attrremovechild1-expected.txt:
        * layout-tests/dom/html/level1/core/hc_attrreplacechild1-expected.txt:
        * layout-tests/dom/html/level1/core/hc_attrreplacechild2-expected.txt:
        * layout-tests/dom/html/level1/core/hc_attrsetvalue1-expected.txt:
        * layout-tests/dom/html/level1/core/hc_attrsetvalue2-expected.txt:
        * layout-tests/dom/html/level1/core/hc_elementnormalize2-expected.txt:
        These tests pass now.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@10270 268f45cc-cd09-0410-ab3c-d52691b4dbfc

27 files changed:
LayoutTests/dom/html/level1/core/hc_attrappendchild1-expected.txt
LayoutTests/dom/html/level1/core/hc_attrappendchild3-expected.txt
LayoutTests/dom/html/level1/core/hc_attrappendchild6-expected.txt
LayoutTests/dom/html/level1/core/hc_attrchildnodes1-expected.txt
LayoutTests/dom/html/level1/core/hc_attrchildnodes2-expected.txt
LayoutTests/dom/html/level1/core/hc_attrclonenode1-expected.txt
LayoutTests/dom/html/level1/core/hc_attrcreatetextnode-expected.txt
LayoutTests/dom/html/level1/core/hc_attrfirstchild-expected.txt
LayoutTests/dom/html/level1/core/hc_attrhaschildnodes-expected.txt
LayoutTests/dom/html/level1/core/hc_attrinsertbefore1-expected.txt
LayoutTests/dom/html/level1/core/hc_attrinsertbefore2-expected.txt
LayoutTests/dom/html/level1/core/hc_attrinsertbefore3-expected.txt
LayoutTests/dom/html/level1/core/hc_attrinsertbefore4-expected.txt
LayoutTests/dom/html/level1/core/hc_attrlastchild-expected.txt
LayoutTests/dom/html/level1/core/hc_attrnormalize-expected.txt
LayoutTests/dom/html/level1/core/hc_attrremovechild1-expected.txt
LayoutTests/dom/html/level1/core/hc_attrreplacechild1-expected.txt
LayoutTests/dom/html/level1/core/hc_attrreplacechild2-expected.txt
LayoutTests/dom/html/level1/core/hc_attrsetvalue1-expected.txt
LayoutTests/dom/html/level1/core/hc_attrsetvalue2-expected.txt
LayoutTests/dom/html/level1/core/hc_elementnormalize2-expected.txt
WebCore/ChangeLog-2005-08-23
WebCore/khtml/ecma/kjs_dom.cpp
WebCore/khtml/xml/dom_docimpl.cpp
WebCore/khtml/xml/dom_elementimpl.cpp
WebCore/khtml/xml/dom_elementimpl.h
WebCore/khtml/xml/dom_nodeimpl.cpp

index 8bd8a69..dfd0980 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrappendchild1   
-Status:        failure
-Detail:        attrValue: assertEquals failed, actual Yes, expected Yesterday.
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrappendchild1
+Status:        Success
index bf364a9..514c75c 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrappendchild3   
-Status:        failure
-Detail:        attrValue: assertEquals failed, actual Yes, expected Yesterday.
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrappendchild3
+Status:        Success
index e0cba02..83e105c 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrappendchild6   
-Status:        failure
-Detail:        attrValue: assertEquals failed, actual , expected Yesterday.
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrappendchild6
+Status:        Success
index 6480b15..6e7bdc3 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrchildnodes1    
-Status:        failure
-Detail:        childNodesSize: assertEquals failed, actual 0, expected 1.
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrchildnodes1
+Status:        Success
index 58795ab..db98264 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrchildnodes2    
-Status:        failure
-Detail:        childNodesSize: assertEquals failed, actual 1, expected 2.
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrchildnodes2
+Status:        Success
index 14e0e59..c385eac 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrclonenode1     
-Status:        failure
-Detail:        attrValue: assertEquals failed, actual Yes, expected Yesterday.
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrclonenode1
+Status:        Success
index 847b7b3..e9fc2af 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrcreatetextnode 
-Status:        failure
-Detail:        value: assertEquals failed, actual Yα, expected Y&ent1;.
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrcreatetextnode
+Status:        Success
index 8e47f8c..a08ebfe 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrfirstchild     
-Status:        failure
-Detail:        textNodeNotNull: assertNotNull failed
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrfirstchild
+Status:        Success
index 4c2fabd..fefcead 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrhaschildnodes  
-Status:        failure
-Detail:        hasChildrenIsTrue: assertTrue failed
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrhaschildnodes
+Status:        Success
index f8c658a..631492a 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrinsertbefore1  
-Status:        failure
-Detail:        attrValue: assertEquals failed, actual Yes, expected Yesterday.
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrinsertbefore1
+Status:        Success
index fce3384..b2f67e1 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrinsertbefore2  
-Status:        failure
-Detail:        attrValue: assertEquals failed, actual Yes, expected terdayYes.
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrinsertbefore2
+Status:        Success
index 0ff7f41..ccdb3e3 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrinsertbefore3  
-Status:        failure
-Detail:        attrValue: assertEquals failed, actual Yes, expected Yesterday.
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrinsertbefore3
+Status:        Success
index f77f8ec..264d475 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrinsertbefore4  
-Status:        failure
-Detail:        attrValue: assertEquals failed, actual Yes, expected terdayYes.
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrinsertbefore4
+Status:        Success
index 4560215..14472ba 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrlastchild      
-Status:        failure
-Detail:        textNodeNotNull: assertNotNull failed
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrlastchild
+Status:        Success
index a37f724..b852409 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrnormalize      
-Status:        failure
-Detail:        attrNodeValue: assertEquals failed, actual Yes, expected Yesterday.
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrnormalize
+Status:        Success
index dfc5d26..eb15e21 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrremovechild1   
-Status:        failure
-Detail:        attrChildNotNull: assertNotNull failed
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrremovechild1
+Status:        Success
index 5f8b5e6..c76d0a5 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrreplacechild1  
-Status:        failure
-Detail:        attrChildNotNull: assertNotNull failed
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrreplacechild1
+Status:        Success
index 68b0f83..798bea3 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrreplacechild2  
-Status:        failure
-Detail:        attrChildNotNull: assertNotNull failed
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrreplacechild2
+Status:        Success
index b8017a2..edfe74b 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrsetvalue1      
-Status:        failure
-Detail:        attrChildNotNull: assertNotNull failed
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrsetvalue1
+Status:        Success
index 59e8e06..34743da 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrsetvalue2      
-Status:        failure
-Detail:        attrValue: assertEquals failed, actual Yes, expected Tomorrow.
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_attrsetvalue2
+Status:        Success
index 84641bc..8c46839 100644 (file)
@@ -1,3 +1,2 @@
-Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_elementnormalize2  
-Status:        failure
-Detail:        firstChild: assertEquals failed, actual , expected Yes.
+Test:  http://www.w3.org/2001/DOM-Test-Suite/level1/core/hc_elementnormalize2
+Status:        Success
index 15be399..05b2995 100644 (file)
@@ -1,3 +1,67 @@
+2005-08-19  Anders Carlsson  <andersca@mac.com>
+
+        Reviewed by Darin.
+        Landed by David Harrison.
+
+        Test cases added: None.  Fixes existing tests.
+
+        * khtml/ecma/kjs_dom.cpp:
+        Attribute values are writable
+        
+        * khtml/xml/dom_docimpl.cpp:
+        (DocumentImpl::createAttributeNS):
+        Update for new AttrImpl constructor.
+        
+        * khtml/xml/dom_elementimpl.cpp:
+        (AttributeImpl::allocateImpl):
+        Update for new AttrImpl constructor.
+        
+        (AttrImpl::AttrImpl):
+        Initialize m_ignoreChildCount to 0. If createTextChild.
+        is true, create a child text node with the contents
+        of the attribute value.
+        
+        (AttrImpl::setValue):
+        Remove all children and create a new text node with the contents
+        of the attribute value.
+        
+        (AttrImpl::cloneNode):
+        Make sure to clone any children.
+        
+        (AttrImpl::childrenChanged):
+        If m_ignoreChildrenChanged is 0, update the attribute value.
+        
+        * khtml/xml/dom_elementimpl.h:
+        Add childrenChanged, update AttrImpl constructor and
+        add m_ignoreChildrenChanged to AttrImpl.
+
+        * khtml/xml/dom_nodeimpl.cpp:
+        (DOM::NodeImpl::normalize):
+        If an element has attributes, make sure to normalize them.
+
+        * layout-tests/dom/html/level1/core/hc_attrappendchild1-expected.txt:
+        * layout-tests/dom/html/level1/core/hc_attrappendchild3-expected.txt:
+        * layout-tests/dom/html/level1/core/hc_attrappendchild6-expected.txt:
+        * layout-tests/dom/html/level1/core/hc_attrchildnodes1-expected.txt:
+        * layout-tests/dom/html/level1/core/hc_attrchildnodes2-expected.txt:
+        * layout-tests/dom/html/level1/core/hc_attrclonenode1-expected.txt:
+        * layout-tests/dom/html/level1/core/hc_attrcreatetextnode-expected.txt:
+        * layout-tests/dom/html/level1/core/hc_attrfirstchild-expected.txt:
+        * layout-tests/dom/html/level1/core/hc_attrhaschildnodes-expected.txt:
+        * layout-tests/dom/html/level1/core/hc_attrinsertbefore1-expected.txt:
+        * layout-tests/dom/html/level1/core/hc_attrinsertbefore2-expected.txt:
+        * layout-tests/dom/html/level1/core/hc_attrinsertbefore3-expected.txt:
+        * layout-tests/dom/html/level1/core/hc_attrinsertbefore4-expected.txt:
+        * layout-tests/dom/html/level1/core/hc_attrlastchild-expected.txt:
+        * layout-tests/dom/html/level1/core/hc_attrnormalize-expected.txt:
+        * layout-tests/dom/html/level1/core/hc_attrremovechild1-expected.txt:
+        * layout-tests/dom/html/level1/core/hc_attrreplacechild1-expected.txt:
+        * layout-tests/dom/html/level1/core/hc_attrreplacechild2-expected.txt:
+        * layout-tests/dom/html/level1/core/hc_attrsetvalue1-expected.txt:
+        * layout-tests/dom/html/level1/core/hc_attrsetvalue2-expected.txt:
+        * layout-tests/dom/html/level1/core/hc_elementnormalize2-expected.txt:
+        These tests pass now.
+
 2005-08-19  Mitz Pettel  <opendarwin.org@mitzpettel.com>
 
         Reviewed by Darin.
index b98ddef..8f0594d 100644 (file)
@@ -810,7 +810,7 @@ const ClassInfo DOMAttr::info = { "Attr", &DOMNode::info, &DOMAttrTable, 0 };
 @begin DOMAttrTable 5
   name         DOMAttr::Name           DontDelete|ReadOnly
   specified    DOMAttr::Specified      DontDelete|ReadOnly
-  value                DOMAttr::ValueProperty  DontDelete|ReadOnly
+  value                DOMAttr::ValueProperty  DontDelete
   ownerElement DOMAttr::OwnerElement   DontDelete|ReadOnly
 @end
 */
index 2286543..32a80aa 100644 (file)
@@ -3030,7 +3030,7 @@ AttrImpl *DocumentImpl::createAttributeNS(const DOMString &namespaceURI, const D
     // documents if we're wrong.
     return new AttrImpl(0, docPtr(), new MappedAttributeImpl(QualifiedName(prefix.implementation(), 
                                                                            localName.implementation(),
-                                                                           namespaceURI.implementation()), DOMString("").implementation()));
+                                                                           namespaceURI.implementation()), DOMString("").implementation()), false);
 }
 
 SharedPtr<HTMLCollectionImpl> DocumentImpl::images()
index a70ff9b..179b00b 100644 (file)
@@ -57,18 +57,26 @@ AttributeImpl* AttributeImpl::clone(bool) const
 }
 
 void AttributeImpl::allocateImpl(ElementImpl* e) {
-    m_impl = new AttrImpl(e, e->docPtr(), this);
+    m_impl = new AttrImpl(e, e->docPtr(), this, true);
 }
 
-AttrImpl::AttrImpl(ElementImpl* element, DocumentPtr* docPtr, AttributeImpl* a)
+AttrImpl::AttrImpl(ElementImpl* element, DocumentPtr* docPtr, AttributeImpl* a, bool createTextChild)
     : ContainerNodeImpl(docPtr),
       m_element(element),
-      m_attribute(a)
+      m_attribute(a),
+      m_ignoreChildrenChanged(0)
 {
     assert(!m_attribute->m_impl);
     m_attribute->m_impl = this;
     m_attribute->ref();
     m_specified = true;
+    
+    if (createTextChild && !m_attribute->value().isEmpty()) {
+        int exceptioncode = 0;
+        m_ignoreChildrenChanged++;
+        appendChild(getDocument()->createTextNode(m_attribute->value().implementation()), exceptioncode);
+        m_ignoreChildrenChanged--;
+    }
 }
 
 AttrImpl::~AttrImpl()
@@ -113,8 +121,6 @@ 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
@@ -129,6 +135,12 @@ void AttrImpl::setValue( const DOMString &v, int &exceptioncode )
         return;
     }
 
+    int e = 0;
+    m_ignoreChildrenChanged++;
+    removeChildren();
+    appendChild(getDocument()->createTextNode(v.implementation()), e);
+    m_ignoreChildrenChanged--;
+    
     m_attribute->setValue(v.implementation());
     if (m_element)
         m_element->attributeChanged(m_attribute);
@@ -143,7 +155,10 @@ void AttrImpl::setNodeValue( const DOMString &v, int &exceptioncode )
 
 NodeImpl *AttrImpl::cloneNode ( bool /*deep*/)
 {
-    return new AttrImpl(0, docPtr(), m_attribute->clone());
+    AttrImpl *clone = new AttrImpl(0, docPtr(), m_attribute->clone(), false);
+    
+    cloneChildNodes(clone);
+    return clone;
 }
 
 // DOM Section 1.1.1
@@ -167,6 +182,26 @@ bool AttrImpl::childTypeAllowed( unsigned short type )
     }
 }
 
+void AttrImpl::childrenChanged()
+{
+    NodeImpl::childrenChanged();
+    
+    if (m_ignoreChildrenChanged > 0)
+        return;
+    
+    // FIXME: We should include entity references in the value
+    
+    DOMString val = "";
+    for (NodeImpl *n = firstChild(); n; n = n->nextSibling()) {
+        if (n->isTextNode())
+            val += static_cast<TextImpl *>(n)->data();
+    }
+    
+    m_attribute->setValue(val.implementation());
+    if (m_element)
+        m_element->attributeChanged(m_attribute);
+}
+
 DOMString AttrImpl::toString() const
 {
     DOMString result;
index b35de4a..94c513a 100644 (file)
@@ -115,7 +115,7 @@ class AttrImpl : public ContainerNodeImpl
     friend class NamedAttrMapImpl;
 
 public:
-    AttrImpl(ElementImpl* element, DocumentPtr* docPtr, AttributeImpl* a);
+    AttrImpl(ElementImpl* element, DocumentPtr* docPtr, AttributeImpl* a, bool createTextChild);
     ~AttrImpl();
 
 private:
@@ -147,11 +147,13 @@ public:
     virtual bool childAllowed( NodeImpl *newChild );
     virtual bool childTypeAllowed( unsigned short type );
 
+    virtual void childrenChanged();
     virtual DOMString toString() const;
 
 protected:
     ElementImpl* m_element;
     AttributeImpl* m_attribute;
+    int m_ignoreChildrenChanged;
 };
 
 
index c8fa003..a22ec07 100644 (file)
@@ -233,10 +233,27 @@ bool NodeImpl::hasChildNodes(  ) const
 
 void NodeImpl::normalize ()
 {
-    // ### normalize attributes? (when we store attributes using child nodes)
     int exceptioncode = 0;
     NodeImpl *child = firstChild();
 
+    if (isElementNode()) {
+        // Normalize any attribute children we might have 
+        ElementImpl *element = static_cast<ElementImpl *>(this);
+        NamedAttrMapImpl *attrMap = element->attributes();
+        
+        if (attrMap) {
+            unsigned long numAttrs = attrMap->length();
+            
+            for (unsigned long i = 0; i < numAttrs; i++) {
+                AttributeImpl *attribute = attrMap->attributeItem(i);
+                AttrImpl *attr = attribute->attrImpl();
+                
+                if (attr)
+                    attr->normalize();
+            }
+        }
+    }
+    
     // Recursively go through the subtree beneath us, normalizing all nodes. In the case
     // where there are two adjacent text nodes, they are merged together
     while (child) {