[webkit-changes] cvs commit: WebCore/khtml/xml dom_docimpl.cpp dom_elementimpl.cpp dom_elementimpl.h dom_nodeimpl.cpp dom_nodeimpl.h

Adele adele at opensource.apple.com
Tue Jul 12 14:16:39 PDT 2005


adele       05/07/12 14:16:39

  Modified:    .        Tag: Safari-2-0-branch ChangeLog
               khtml/html Tag: Safari-2-0-branch html_elementimpl.cpp
               khtml/xml Tag: Safari-2-0-branch dom_docimpl.cpp
                        dom_elementimpl.cpp dom_elementimpl.h
                        dom_nodeimpl.cpp dom_nodeimpl.h
  Log:
          Merged for from TOT to Safari-2-0-branch
          <rdar://problem/4164960>
  
      2005-04-29  Darin Adler  <darin at apple.com>
  
          Reviewed by Chris Blumenberg.
          Added two layout tests for regression testing.
  
          - fixed <rdar://problem/4097849> REGRESSION (162-163): importNode creates non-HTML elements, thus style attributes (and some others) don't work
  
          * khtml/xml/dom_docimpl.cpp:
          (DocumentImpl::importNode): Reorganized and partly rewrote this. The change that fixes the bug at
          hand is to explicitly use XHTML_NAMESPACE for HTML elements, since the old way of getting the namespace
          will return the null string for HTML elements, and createElementNS will not create an HTML element
          if passed a null string for the namespace.
          (DocumentImpl::processHttpEquiv): Removed some bogus getDocument() calls -- no need to call getDocument()
          in a document object.
          (DocumentImpl::attrName): Ditto.
          (DocumentImpl::tagName): Ditto.
          (DocumentImpl::setFocusNode): Ditto.
  
          * khtml/html/html_elementimpl.cpp: (HTMLElementImpl::cloneNode): Moved the actual cloning here
          from ElementImpl::cloneNode, because XMLElementImpl already had its own version, and in here
          we can use createHTMLElement, which will work properly even in an XML document, and is also slightly
          more efficient.
  
          * khtml/xml/dom_nodeimpl.h: Added a namespaceURI method function to go along with localName.
          * khtml/xml/dom_nodeimpl.cpp: (NodeImpl::namespaceURI): Added. Returns null string to be consistent
          with localName (only works on certain types of elements as documented).
          * khtml/xml/dom_elementimpl.h: Removed ElementImpl::cloneNode (see above). Added an override of
          namespaceURI for XMLElementImpl.
          * khtml/xml/dom_elementimpl.cpp: (XMLElementImpl::namespaceURI): Added. Returns the namespace
          (consistent with localName).
  
          * layout-tests/fast/dom/importNodeHTML.html: Added. Tests both importNode and cloneNode (for comparison).
          * layout-tests/fast/dom/importNodeHTML-expected.txt: Added.
          * layout-tests/fast/dom/importNodeXML.xhtml: Added. XML version of the same test as above. Tests a different
          code path, so useful to have.
          * layout-tests/fast/dom/importNodeXML-expected.txt: Added.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.4104.2.56 +42 -0     WebCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebCore/ChangeLog,v
  retrieving revision 1.4104.2.55
  retrieving revision 1.4104.2.56
  diff -u -r1.4104.2.55 -r1.4104.2.56
  --- ChangeLog	12 Jul 2005 21:10:30 -0000	1.4104.2.55
  +++ ChangeLog	12 Jul 2005 21:16:15 -0000	1.4104.2.56
  @@ -1,3 +1,45 @@
  +2005-07-12  Adele Peterson  <adele at apple.com>
  +
  +        Merged for from TOT to Safari-2-0-branch
  +        <rdar://problem/4164960>
  +
  +    2005-04-29  Darin Adler  <darin at apple.com>
  +
  +        Reviewed by Chris Blumenberg.
  +        Added two layout tests for regression testing.
  +
  +        - fixed <rdar://problem/4097849> REGRESSION (162-163): importNode creates non-HTML elements, thus style attributes (and some others) don't work
  +
  +        * khtml/xml/dom_docimpl.cpp:
  +        (DocumentImpl::importNode): Reorganized and partly rewrote this. The change that fixes the bug at
  +        hand is to explicitly use XHTML_NAMESPACE for HTML elements, since the old way of getting the namespace
  +        will return the null string for HTML elements, and createElementNS will not create an HTML element
  +        if passed a null string for the namespace.
  +        (DocumentImpl::processHttpEquiv): Removed some bogus getDocument() calls -- no need to call getDocument()
  +        in a document object.
  +        (DocumentImpl::attrName): Ditto.
  +        (DocumentImpl::tagName): Ditto.
  +        (DocumentImpl::setFocusNode): Ditto.
  +
  +        * khtml/html/html_elementimpl.cpp: (HTMLElementImpl::cloneNode): Moved the actual cloning here
  +        from ElementImpl::cloneNode, because XMLElementImpl already had its own version, and in here
  +        we can use createHTMLElement, which will work properly even in an XML document, and is also slightly
  +        more efficient.
  +
  +        * khtml/xml/dom_nodeimpl.h: Added a namespaceURI method function to go along with localName.
  +        * khtml/xml/dom_nodeimpl.cpp: (NodeImpl::namespaceURI): Added. Returns null string to be consistent
  +        with localName (only works on certain types of elements as documented).
  +        * khtml/xml/dom_elementimpl.h: Removed ElementImpl::cloneNode (see above). Added an override of
  +        namespaceURI for XMLElementImpl.
  +        * khtml/xml/dom_elementimpl.cpp: (XMLElementImpl::namespaceURI): Added. Returns the namespace
  +        (consistent with localName).
  +
  +        * layout-tests/fast/dom/importNodeHTML.html: Added. Tests both importNode and cloneNode (for comparison).
  +        * layout-tests/fast/dom/importNodeHTML-expected.txt: Added.
  +        * layout-tests/fast/dom/importNodeXML.xhtml: Added. XML version of the same test as above. Tests a different
  +        code path, so useful to have.
  +        * layout-tests/fast/dom/importNodeXML-expected.txt: Added.
  +
   2005-07-12  Vicki Murley  <vicki at apple.com>
   
   	- merge this fix from HEAD
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.76.8.3  +14 -5     WebCore/khtml/html/html_elementimpl.cpp
  
  Index: html_elementimpl.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/html/html_elementimpl.cpp,v
  retrieving revision 1.76.8.2
  retrieving revision 1.76.8.3
  diff -u -r1.76.8.2 -r1.76.8.3
  --- html_elementimpl.cpp	1 Jul 2005 23:02:42 -0000	1.76.8.2
  +++ html_elementimpl.cpp	12 Jul 2005 21:16:34 -0000	1.76.8.3
  @@ -302,11 +302,20 @@
   
   NodeImpl *HTMLElementImpl::cloneNode(bool deep)
   {
  -    HTMLElementImpl *n = static_cast<HTMLElementImpl *>(ElementImpl::cloneNode(deep));
  -    if (n && m_inlineStyleDecl) {
  -        *n->getInlineStyleDecl() = *m_inlineStyleDecl;
  -    }
  -    return n;
  +    HTMLElementImpl *clone = static_cast<HTMLElementImpl *>(getDocument()->createHTMLElement(localNamePart(id())));
  +    if (!clone)
  +        return 0;
  +
  +    if (namedAttrMap)
  +        *clone->attributes() = *namedAttrMap;
  +
  +    if (m_inlineStyleDecl)
  +        *clone->getInlineStyleDecl() = *m_inlineStyleDecl;
  +
  +    if (deep)
  +        cloneChildNodes(clone);
  +
  +    return clone;
   }
   
   void HTMLElementImpl::attributeChanged(AttributeImpl* attr, bool preserveDecls)
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.211.6.7 +83 -78    WebCore/khtml/xml/dom_docimpl.cpp
  
  Index: dom_docimpl.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xml/dom_docimpl.cpp,v
  retrieving revision 1.211.6.6
  retrieving revision 1.211.6.7
  diff -u -r1.211.6.6 -r1.211.6.7
  --- dom_docimpl.cpp	12 Jul 2005 20:50:36 -0000	1.211.6.6
  +++ dom_docimpl.cpp	12 Jul 2005 21:16:35 -0000	1.211.6.7
  @@ -538,72 +538,80 @@
   
   NodeImpl *DocumentImpl::importNode(NodeImpl *importedNode, bool deep, int &exceptioncode)
   {
  -	NodeImpl *result = 0;
  +    exceptioncode = 0;
   
  -	if(importedNode->nodeType() == Node::ELEMENT_NODE)
  -	{
  -		ElementImpl *tempElementImpl = createElementNS(getDocument()->namespaceURI(id()), importedNode->nodeName(), exceptioncode);
  -                if (exceptioncode)
  -                    return 0;
  -		result = tempElementImpl;
  -
  -		if(static_cast<ElementImpl *>(importedNode)->attributes(true) && static_cast<ElementImpl *>(importedNode)->attributes(true)->length())
  -		{
  -			NamedNodeMapImpl *attr = static_cast<ElementImpl *>(importedNode)->attributes();
  -
  -			for(unsigned int i = 0; i < attr->length(); i++)
  -			{
  -				DOMString qualifiedName = attr->item(i)->nodeName();
  -				DOMString value = attr->item(i)->nodeValue();
  -
  -				int colonpos = qualifiedName.find(':');
  -				DOMString localName = qualifiedName;
  -				if(colonpos >= 0)
  -				{
  -					localName.remove(0, colonpos + 1);
  -					// ### extract and set new prefix
  -				}
  -
  -				NodeImpl::Id nodeId = getDocument()->attrId(getDocument()->namespaceURI(id()), localName.implementation(), false /* allocate */);
  -				tempElementImpl->setAttribute(nodeId, value.implementation(), exceptioncode);
  -
  -				if(exceptioncode != 0)
  -					break;
  -			}
  -		}
  -	}
  -	else if(importedNode->nodeType() == Node::TEXT_NODE)
  -	{
  -		result = createTextNode(importedNode->nodeValue());
  -		deep = false;
  -	}
  -	else if(importedNode->nodeType() == Node::CDATA_SECTION_NODE)
  -	{
  -		result = createCDATASection(importedNode->nodeValue());
  -		deep = false;
  -	}
  -	else if(importedNode->nodeType() == Node::ENTITY_REFERENCE_NODE)
  -		result = createEntityReference(importedNode->nodeName());
  -	else if(importedNode->nodeType() == Node::PROCESSING_INSTRUCTION_NODE)
  -	{
  -		result = createProcessingInstruction(importedNode->nodeName(), importedNode->nodeValue());
  -		deep = false;
  -	}
  -	else if(importedNode->nodeType() == Node::COMMENT_NODE)
  -	{
  -		result = createComment(importedNode->nodeValue());
  -		deep = false;
  -	}
  -	else
  -		exceptioncode = DOMException::NOT_SUPPORTED_ERR;
  +    switch (importedNode->nodeType()) {
  +        case Node::TEXT_NODE:
  +            return createTextNode(importedNode->nodeValue());
  +        case Node::CDATA_SECTION_NODE:
  +            return createCDATASection(importedNode->nodeValue());
  +        case Node::ENTITY_REFERENCE_NODE:
  +            return createEntityReference(importedNode->nodeName());
  +        case Node::PROCESSING_INSTRUCTION_NODE:
  +            return createProcessingInstruction(importedNode->nodeName(), importedNode->nodeValue());
  +        case Node::COMMENT_NODE:
  +            return createComment(importedNode->nodeValue());
  +        case Node::ELEMENT_NODE: {
  +            ElementImpl *oldElement = static_cast<ElementImpl *>(importedNode);
  +            DocumentImpl *oldDoc = oldElement->getDocument();
  +            static DOMString HTMLNamespace(XHTML_NAMESPACE);
  +            DOMString elementNamespace = oldElement->isHTMLElement() ? HTMLNamespace : oldElement->namespaceURI();
  +            ElementImpl *newElement = createElementNS(elementNamespace.implementation(), oldElement->tagName(), exceptioncode);
  +            if (exceptioncode != 0)
  +                return 0;
   
  -	if(deep)
  -	{
  -		for(Node n = importedNode->firstChild(); !n.isNull(); n = n.nextSibling())
  -			result->appendChild(importNode(n.handle(), true, exceptioncode), exceptioncode);
  -	}
  +            newElement->ref();
  +
  +            NamedAttrMapImpl *attrs = oldElement->attributes(true);
  +            if (attrs) {
  +                unsigned length = attrs->length();
  +                for (unsigned i = 0; i < length; i++) {
  +                    AttrImpl *attr = attrs->item(i);
  +                    DOMString qualifiedName = attr->nodeName();
  +                    DOMString value = attr->nodeValue();
  +
  +                    int colonpos = qualifiedName.find(':');
  +                    DOMString localName = qualifiedName;
  +                    if (colonpos >= 0) {
  +                        localName.remove(0, colonpos + 1);
  +                        // ### extract and set new prefix
  +                    }
   
  -	return result;
  +                    NodeImpl::Id nodeId = attrId(oldDoc->namespaceURI(attr->attrImpl()->id()), localName.implementation(), false /* allocate */);
  +                    newElement->setAttribute(nodeId, value.implementation(), exceptioncode);
  +                    if (exceptioncode != 0) {
  +                        newElement->deref();
  +                        return 0;
  +                    }
  +                }
  +            }
  +
  +            if (deep) {
  +                for (NodeImpl *oldChild = oldElement->firstChild(); oldChild; oldChild = oldChild->nextSibling()) {
  +                    NodeImpl *newChild = importNode(oldChild, true, exceptioncode);
  +                    if (exceptioncode != 0) {
  +                        newElement->deref();
  +                        return 0;
  +                    }
  +                    newElement->appendChild(newChild, exceptioncode);
  +                    if (exceptioncode != 0) {
  +                        newElement->deref();
  +                        return 0;
  +                    }
  +                }
  +            }
  +
  +            // Trick to get the result back to the floating state, with 0 refs but not destroyed.
  +            newElement->setParent(this);
  +            newElement->deref();
  +            newElement->setParent(0);
  +
  +            return newElement;
  +        }
  +    }
  +
  +    exceptioncode = DOMException::NOT_SUPPORTED_ERR;
  +    return 0;
   }
   
   ElementImpl *DocumentImpl::createElementNS( const DOMString &_namespaceURI, const DOMString &_qualifiedName, int &exceptioncode)
  @@ -1949,7 +1957,7 @@
   {
       assert(!equiv.isNull() && !content.isNull());
   
  -    KHTMLPart *part = getDocument()->part();
  +    KHTMLPart *part = this->part();
   
       if (strcasecmp(equiv, "default-style") == 0) {
           // The preferred style set has been overridden as per section 
  @@ -1996,9 +2004,9 @@
               if ( ok && part )
   #if APPLE_CHANGES
                   // We want a new history item if the refresh timeout > 1 second
  -                part->scheduleRedirection(delay, getDocument()->completeURL( str ), delay <= 1);
  +                part->scheduleRedirection(delay, completeURL( str ), delay <= 1);
   #else
  -                part->scheduleRedirection(delay, getDocument()->completeURL( str ));
  +                part->scheduleRedirection(delay, completeURL( str ));
   #endif
           }
       }
  @@ -2177,8 +2185,7 @@
   
       // Attribute names are always lowercase in the DOM for both
       // HTML and XHTML.
  -    if (getDocument()->isHTMLDocument() ||
  -        getDocument()->htmlMode() == DocumentImpl::XHtml)
  +    if (isHTMLDocument() || htmlMode() == XHtml)
           return result.lower();
   
       return result;
  @@ -2253,7 +2260,7 @@
           return m_elementNames[localNamePart(_id) - (ID_LAST_TAG + 1)];
       else {
           // ### put them in a cache
  -        if (getDocument()->htmlMode() == DocumentImpl::XHtml)
  +        if (htmlMode() == XHtml)
               return getTagName(_id).lower();
           else
               return getTagName(_id);
  @@ -2278,14 +2285,12 @@
       return m_styleSheets;
   }
   
  -DOMString 
  -DocumentImpl::preferredStylesheetSet()
  +DOMString DocumentImpl::preferredStylesheetSet()
   {
     return m_preferredStylesheetSet;
   }
   
  -DOMString 
  -DocumentImpl::selectedStylesheetSet()
  +DOMString DocumentImpl::selectedStylesheetSet()
   {
     return view() ? view()->part()->d->m_sheetUsed : DOMString();
   }
  @@ -2554,8 +2559,8 @@
       // Remove focus from the existing focus node (if any)
       if (oldFocusNode) {
           // This goes hand in hand with the Qt focus setting below.
  -        if (!newFocusNode && getDocument()->view()) {
  -            getDocument()->view()->setFocus();
  +        if (!newFocusNode && view()) {
  +            view()->setFocus();
           }
   
           if (oldFocusNode->active())
  @@ -2617,20 +2622,20 @@
           m_focusNode->setFocus();
           // eww, I suck. set the qt focus correctly
           // ### find a better place in the code for this
  -        if (getDocument()->view()) {
  +        if (view()) {
               QWidget *focusWidget = widgetForNode(m_focusNode);
               if (focusWidget) {
                   // Make sure a widget has the right size before giving it focus.
                   // Otherwise, we are testing edge cases of the QWidget code.
                   // Specifically, in WebCore this does not work well for text fields.
  -                getDocument()->updateLayout();
  +                updateLayout();
                   // Re-get the widget in case updating the layout changed things.
                   focusWidget = widgetForNode(m_focusNode);
               }
               if (focusWidget)
                   focusWidget->setFocus();
               else
  -                getDocument()->view()->setFocus();
  +                view()->setFocus();
           }
      }
   
  
  
  
  1.61.6.1  +4 -16     WebCore/khtml/xml/dom_elementimpl.cpp
  
  Index: dom_elementimpl.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xml/dom_elementimpl.cpp,v
  retrieving revision 1.61
  retrieving revision 1.61.6.1
  diff -u -r1.61 -r1.61.6.1
  --- dom_elementimpl.cpp	1 Mar 2005 01:58:34 -0000	1.61
  +++ dom_elementimpl.cpp	12 Jul 2005 21:16:36 -0000	1.61.6.1
  @@ -336,22 +336,6 @@
       return namedAttrMap && namedAttrMap->length() > 0;
   }
   
  -NodeImpl *ElementImpl::cloneNode(bool deep)
  -{
  -    // ### we lose the namespace here ... FIXME
  -    int exceptioncode;
  -    ElementImpl *clone = getDocument()->createElement(tagName(), exceptioncode);
  -    if (!clone) return 0;
  -
  -    // clone attributes
  -    if (namedAttrMap)
  -        *clone->attributes() = *namedAttrMap;
  -
  -    if (deep)
  -        cloneChildNodes(clone);
  -    return clone;
  -}
  -
   DOMString ElementImpl::nodeName() const
   {
       return tagName();
  @@ -724,6 +708,10 @@
       return getDocument()->tagName(m_id);
   }
   
  +DOMString XMLElementImpl::namespaceURI() const
  +{
  +    return getDocument()->namespaceURI(m_id);
  +}
   
   NodeImpl *XMLElementImpl::cloneNode ( bool deep )
   {
  
  
  
  1.35.8.1  +2 -2      WebCore/khtml/xml/dom_elementimpl.h
  
  Index: dom_elementimpl.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xml/dom_elementimpl.h,v
  retrieving revision 1.35
  retrieving revision 1.35.8.1
  diff -u -r1.35 -r1.35.8.1
  --- dom_elementimpl.h	19 Mar 2005 00:34:07 -0000	1.35
  +++ dom_elementimpl.h	12 Jul 2005 21:16:36 -0000	1.35.8.1
  @@ -174,7 +174,7 @@
       // DOM methods overridden from  parent classes
       virtual DOMString tagName() const;
       virtual unsigned short nodeType() const;
  -    virtual NodeImpl *cloneNode ( bool deep );
  +    virtual NodeImpl *cloneNode ( bool deep ) = 0;
       virtual DOMString nodeName() const;
       virtual bool isElementNode() const { return true; }
       virtual void insertedIntoDocument();
  @@ -250,7 +250,7 @@
       ~XMLElementImpl();
   
       // DOM methods overridden from  parent classes
  -
  +    virtual DOMString namespaceURI() const;
       virtual DOMString localName() const;
       virtual NodeImpl *cloneNode ( bool deep );
   
  
  
  
  1.140.8.3 +5 -0      WebCore/khtml/xml/dom_nodeimpl.cpp
  
  Index: dom_nodeimpl.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xml/dom_nodeimpl.cpp,v
  retrieving revision 1.140.8.2
  retrieving revision 1.140.8.3
  diff -u -r1.140.8.2 -r1.140.8.3
  --- dom_nodeimpl.cpp	31 May 2005 19:37:41 -0000	1.140.8.2
  +++ dom_nodeimpl.cpp	12 Jul 2005 21:16:36 -0000	1.140.8.3
  @@ -267,6 +267,11 @@
       return DOMString();
   }
   
  +DOMString NodeImpl::namespaceURI() const
  +{
  +    return DOMString();
  +}
  +
   void NodeImpl::setFirstChild(NodeImpl *)
   {
   }
  
  
  
  1.75.8.3  +1 -0      WebCore/khtml/xml/dom_nodeimpl.h
  
  Index: dom_nodeimpl.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xml/dom_nodeimpl.h,v
  retrieving revision 1.75.8.2
  retrieving revision 1.75.8.3
  diff -u -r1.75.8.2 -r1.75.8.3
  --- dom_nodeimpl.h	12 Jul 2005 16:32:11 -0000	1.75.8.2
  +++ dom_nodeimpl.h	12 Jul 2005 21:16:37 -0000	1.75.8.3
  @@ -114,6 +114,7 @@
       virtual bool hasChildNodes (  ) const;
       virtual NodeImpl *cloneNode ( bool deep ) = 0;
       virtual DOMString localName() const;
  +    virtual DOMString namespaceURI() const;
       virtual DOMString prefix() const;
       virtual void setPrefix(const DOMString &_prefix, int &exceptioncode );
       void normalize ();
  
  
  



More information about the webkit-changes mailing list