[webkit-changes] cvs commit: WebCore/khtml/xml dom_xmlimpl.cpp dom_xmlimpl.h

Eric eseidel at opensource.apple.com
Wed Oct 26 23:03:34 PDT 2005


eseidel     05/10/26 23:03:33

  Modified:    .        ChangeLog
               khtml/editing markup.cpp
               khtml/html html_elementimpl.cpp htmltokenizer.cpp
                        htmltokenizer.h
               khtml/xml dom_xmlimpl.cpp dom_xmlimpl.h
  Log:
  Bug #: 5404
  Submitted by: eseidel
  Reviewed by: mjs & darin
          Various fixes to createMarkup and toString code to properly
          support serialization of XML.
          http://bugzilla.opendarwin.org/show_bug.cgi?id=5404
  
          * khtml/editing/markup.cpp:
          (khtml::startMarkup):
          (khtml::doesHTMLForbidEndTag):
          (khtml::shouldSelfClose):
          (khtml::endMarkup):
          (khtml::markup):
          (khtml::createFragmentFromMarkup):
          (khtml::createMarkup):
          * khtml/html/html_elementimpl.cpp:
          (HTMLElementImpl::createContextualFragment):
          (HTMLElementImpl::toString):
          * khtml/html/htmltokenizer.cpp:
          (khtml::parseHTMLDocumentFragment):
          * khtml/html/htmltokenizer.h:
          * khtml/xml/dom_xmlimpl.cpp:
          (DOM::ProcessingInstructionImpl::ProcessingInstructionImpl):
          (DOM::ProcessingInstructionImpl::~ProcessingInstructionImpl):
          (DOM::ProcessingInstructionImpl::toString):
          * khtml/xml/dom_xmlimpl.h:
          (DOM::ProcessingInstructionImpl::sheet):
          (DOM::ProcessingInstructionImpl::setStyleSheet):
  
  Revision  Changes    Path
  1.298     +30 -0     WebCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebCore/ChangeLog,v
  retrieving revision 1.297
  retrieving revision 1.298
  diff -u -r1.297 -r1.298
  --- ChangeLog	26 Oct 2005 22:13:26 -0000	1.297
  +++ ChangeLog	27 Oct 2005 06:03:25 -0000	1.298
  @@ -1,3 +1,33 @@
  +2005-10-26  Eric Seidel  <eseidel at apple.com>
  +
  +        Reviewed by mjs & darin.
  +
  +        Various fixes to createMarkup and toString code to properly
  +        support serialization of XML.
  +        http://bugzilla.opendarwin.org/show_bug.cgi?id=5404
  +
  +        * khtml/editing/markup.cpp:
  +        (khtml::startMarkup):
  +        (khtml::doesHTMLForbidEndTag):
  +        (khtml::shouldSelfClose):
  +        (khtml::endMarkup):
  +        (khtml::markup):
  +        (khtml::createFragmentFromMarkup):
  +        (khtml::createMarkup):
  +        * khtml/html/html_elementimpl.cpp:
  +        (HTMLElementImpl::createContextualFragment):
  +        (HTMLElementImpl::toString):
  +        * khtml/html/htmltokenizer.cpp:
  +        (khtml::parseHTMLDocumentFragment):
  +        * khtml/html/htmltokenizer.h:
  +        * khtml/xml/dom_xmlimpl.cpp:
  +        (DOM::ProcessingInstructionImpl::ProcessingInstructionImpl):
  +        (DOM::ProcessingInstructionImpl::~ProcessingInstructionImpl):
  +        (DOM::ProcessingInstructionImpl::toString):
  +        * khtml/xml/dom_xmlimpl.h:
  +        (DOM::ProcessingInstructionImpl::sheet):
  +        (DOM::ProcessingInstructionImpl::setStyleSheet):
  +
   2005-10-26  David Hyatt  <hyatt at apple.com>
   
   	Don't allow position:relative to apply to table sections.  Fixes the crash described in
  
  
  
  1.38      +63 -47    WebCore/khtml/editing/markup.cpp
  
  Index: markup.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/editing/markup.cpp,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- markup.cpp	3 Oct 2005 21:12:20 -0000	1.37
  +++ markup.cpp	27 Oct 2005 06:03:29 -0000	1.38
  @@ -34,6 +34,7 @@
   #include "editing/visible_units.h"
   #include "html/html_elementimpl.h"
   #include "xml/dom_position.h"
  +#include "xml/dom_xmlimpl.h"
   #include "xml/dom2_rangeimpl.h"
   #include "rendering/render_text.h"
   #include "htmlnames.h"
  @@ -42,6 +43,7 @@
   
   using DOM::AttributeImpl;
   using DOM::CommentImpl;
  +using DOM::ProcessingInstructionImpl;
   using DOM::CSSComputedStyleDeclarationImpl;
   using DOM::CSSMutableStyleDeclarationImpl;
   using DOM::DocumentFragmentImpl;
  @@ -71,6 +73,9 @@
   
   namespace khtml {
   
  +static inline bool doesHTMLForbidEndTag(const NodeImpl *node);
  +static inline bool shouldSelfClose(const NodeImpl *node);
  +
   static QString escapeHTML(const QString &in)
   {
       QString s = "";
  @@ -173,6 +178,7 @@
   
   static QString startMarkup(const NodeImpl *node, const RangeImpl *range, EAnnotateForInterchange annotate, CSSMutableStyleDeclarationImpl *defaultStyle)
   {
  +    bool documentIsHTML = node->getDocument()->isHTMLDocument();
       unsigned short type = node->nodeType();
       switch (type) {
           case Node::TEXT_NODE: {
  @@ -187,18 +193,14 @@
               if (defaultStyle) {
                   NodeImpl *element = node->parentNode();
                   if (element) {
  -                    CSSComputedStyleDeclarationImpl *computedStyle = Position(element, 0).computedStyle();
  -                    computedStyle->ref();
  -                    CSSMutableStyleDeclarationImpl *style = computedStyle->copyInheritableProperties();
  -                    computedStyle->deref();
  -                    style->ref();
  -                    defaultStyle->diff(style);
  +                    SharedPtr<CSSComputedStyleDeclarationImpl> computedStyle = Position(element, 0).computedStyle();
  +                    SharedPtr<CSSMutableStyleDeclarationImpl> style = computedStyle->copyInheritableProperties();
  +                    defaultStyle->diff(style.get());
                       if (style->length() > 0) {
                           // FIXME: Handle case where style->cssText() has illegal characters in it, like "
                           QString openTag = QString("<span class=\"") + AppleStyleSpanClass + "\" style=\"" + style->cssText().qstring() + "\">";
                           markup = openTag + markup + "</span>";
                       }
  -                    style->deref();
                   }            
               }
               return annotate ? convertHTMLTextToInterchangeFormat(markup) : markup;
  @@ -207,25 +209,23 @@
               return static_cast<const CommentImpl *>(node)->toString().qstring();
           case Node::DOCUMENT_NODE:
               return "";
  +        case Node::PROCESSING_INSTRUCTION_NODE:
  +            return static_cast<const ProcessingInstructionImpl *>(node)->toString().qstring();
           default: {
               QString markup = QChar('<') + node->nodeName().qstring();
               if (type == Node::ELEMENT_NODE) {
                   const ElementImpl *el = static_cast<const ElementImpl *>(node);
                   DOMString additionalStyle;
                   if (defaultStyle && el->isHTMLElement()) {
  -                    CSSComputedStyleDeclarationImpl *computedStyle = Position(const_cast<ElementImpl *>(el), 0).computedStyle();
  -                    computedStyle->ref();
  -                    CSSMutableStyleDeclarationImpl *style = computedStyle->copyInheritableProperties();
  -                    computedStyle->deref();
  -                    style->ref();
  -                    defaultStyle->diff(style);
  +                    SharedPtr<CSSComputedStyleDeclarationImpl> computedStyle = Position(const_cast<ElementImpl *>(el), 0).computedStyle();
  +                    SharedPtr<CSSMutableStyleDeclarationImpl> style = computedStyle->copyInheritableProperties();
  +                    defaultStyle->diff(style.get());
                       if (style->length() > 0) {
                           CSSMutableStyleDeclarationImpl *inlineStyleDecl = static_cast<const HTMLElementImpl *>(el)->inlineStyleDecl();
                           if (inlineStyleDecl)
  -                            inlineStyleDecl->diff(style);
  +                            inlineStyleDecl->diff(style.get());
                           additionalStyle = style->cssText();
                       }
  -                    style->deref();
                   }
                   NamedAttrMapImpl *attrs = el->attributes();
                   unsigned length = attrs->length();
  @@ -240,25 +240,56 @@
                           if (attr->name() == styleAttr && additionalStyle.length() > 0)
                               value += "; " + additionalStyle;
                           // FIXME: Handle case where value has illegal characters in it, like "
  -                        // FIXME: Namespaces! XML! Ack!
  -                        markup += " " + attr->name().localName().qstring() + "=\"" + value.qstring() + "\"";
  +                        if (documentIsHTML)
  +                            markup += " " + attr->name().localName().qstring();
  +                        else
  +                            markup += " " + attr->name().toString().qstring();
  +                        markup += "=\"" + value.qstring() + "\"";
                       }
                   }
               }
  -            markup += node->isHTMLElement() ? ">" : "/>";
  +            
  +            if (shouldSelfClose(node)) {
  +                if (node->isHTMLElement())
  +                    markup += " "; // XHTML 1.0 <-> HTML compatibility.
  +                markup += "/>";
  +            } else
  +                markup += ">";
  +            
               return markup;
           }
       }
   }
   
  -static QString endMarkup(const NodeImpl *node)
  +static inline bool doesHTMLForbidEndTag(const NodeImpl *node)
   {
  -    bool hasEndTag = node->isElementNode();
       if (node->isHTMLElement()) {
           const HTMLElementImpl* htmlElt = static_cast<const HTMLElementImpl*>(node);
  -        hasEndTag = (htmlElt->endTagRequirement() != TagStatusForbidden);
  +        return (htmlElt->endTagRequirement() == TagStatusForbidden);
       }
  -    if (hasEndTag)
  +    return false;
  +}
  +
  +// Rules of self-closure
  +// 1. all html elements in html documents close with >
  +// 2. all elements w/ children close with >
  +// 3. all non-html elements w/o children close with />
  +// 4. all html elements with a FORBIDDEN close tag, self close in XML docs
  +static inline bool shouldSelfClose(const NodeImpl *node)
  +{
  +    bool htmlForbidsEndTag = doesHTMLForbidEndTag(node);
  +    bool documentIsHTML = node->getDocument()->isHTMLDocument();
  +    
  +    if (node->isHTMLElement() && (documentIsHTML || !htmlForbidsEndTag))
  +        return false;
  +    else if (!node->hasChildNodes() || htmlForbidsEndTag)
  +        return true;
  +    return false;
  +}
  +
  +static QString endMarkup(const NodeImpl *node)
  +{
  +    if (node->isElementNode() && !shouldSelfClose(node) && !doesHTMLForbidEndTag(node))
           return "</" + node->nodeName().qstring() + ">";
       return "";
   }
  @@ -270,27 +301,18 @@
       QString me = "";
       for (const NodeImpl *current = startNode; current != NULL; current = includeSiblings ? current->nextSibling() : NULL) {
           if (!onlyIncludeChildren) {
  -            if (nodes) {
  +            if (nodes)
                   nodes->append(current);
  -            }
               me += startMarkup(current, 0, DoNotAnnotateForInterchange, 0);
           }
  -        
  -        bool container = true;
  -        if (current->isHTMLElement()) {
  -            const HTMLElementImpl* h = static_cast<const HTMLElementImpl*>(current);
  -            container = h->endTagRequirement() != TagStatusForbidden;
  -        }
  -        if (container) {
  -            // print children
  -            if (NodeImpl *n = current->firstChild()) {
  +        // print children
  +        if (NodeImpl *n = current->firstChild())
  +            if (!(n->getDocument()->isHTMLDocument() && doesHTMLForbidEndTag(current)))
                   me += markup(n, false, true, nodes);
  -            }
  -            // Print my ending tag
  -            if (!onlyIncludeChildren) {
  -                me += endMarkup(current);
  -            }
  -        }
  +        
  +        // Print my ending tag
  +        if (!onlyIncludeChildren)
  +            me += endMarkup(current);
       }
       return me;
   }
  @@ -477,6 +499,7 @@
   
   DocumentFragmentImpl *createFragmentFromMarkup(DocumentImpl *document, const QString &markup, const QString &baseURL)
   {
  +    ASSERT(document->documentElement()->isHTMLElement());
       // FIXME: What if the document element is not an HTML element?
       HTMLElementImpl *element = static_cast<HTMLElementImpl *>(document->documentElement());
   
  @@ -493,14 +516,7 @@
       QPtrList<DOM::NodeImpl> *nodes, EAnnotateForInterchange annotate)
   {
       ASSERT(annotate == DoNotAnnotateForInterchange); // annotation not yet implemented for this code path
  -
  -    // FIXME: We could take out this if statement if we had more time to test.
  -    // I'm concerned that making this crash when the document is nil might be too risky a change at the moment.
  -    DocumentImpl *doc = node->getDocument();
  -    assert(doc);
  -    if (doc)
  -        doc->updateLayout();
  -
  +    node->getDocument()->updateLayout();
       return markup(node, includeChildren, false, nodes);
   }
   
  
  
  
  1.109     +5 -13     WebCore/khtml/html/html_elementimpl.cpp
  
  Index: html_elementimpl.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/html/html_elementimpl.cpp,v
  retrieving revision 1.108
  retrieving revision 1.109
  diff -u -r1.108 -r1.109
  --- html_elementimpl.cpp	9 Oct 2005 02:14:05 -0000	1.108
  +++ html_elementimpl.cpp	27 Oct 2005 06:03:29 -0000	1.109
  @@ -286,23 +286,15 @@
       DocumentFragmentImpl *fragment = new DocumentFragmentImpl(docPtr());
       fragment->ref();
       
  -    if (!getDocument()->isHTMLDocument()) {
  -        bool ret = parseXMLDocumentFragment(html, fragment, this);
  -        
  -        if (!ret) {
  +    if (getDocument()->isHTMLDocument())
  +         parseHTMLDocumentFragment(html, fragment);
  +    else {
  +        if (!parseXMLDocumentFragment(html, fragment, this)) {
               // FIXME: We should propagate a syntax error exception out here.
               fragment->deref();
               return 0;
           }
       }
  -    else
  -    {
  -        HTMLTokenizer tok(docPtr(), fragment);
  -        tok.setForceSynchronous(true);            // disable asynchronous parsing
  -        tok.write( html.qstring(), true );
  -        tok.finish();
  -        assert(!tok.processingData());            // make sure we're done (see 3963151)
  -    }
   
       // Exceptions are ignored because none ought to happen here.
       int ignoredExceptionCode;
  @@ -603,7 +595,7 @@
   
   DOMString HTMLElementImpl::toString() const
   {
  -    if (!hasChildNodes()) {
  +    if (!hasChildNodes() && getDocument()->isHTMLDocument()) {
   	DOMString result = openTagStartToString();
   	result += ">";
   
  
  
  
  1.124     +9 -0      WebCore/khtml/html/htmltokenizer.cpp
  
  Index: htmltokenizer.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/html/htmltokenizer.cpp,v
  retrieving revision 1.123
  retrieving revision 1.124
  diff -u -r1.123 -r1.124
  --- htmltokenizer.cpp	25 Oct 2005 22:32:54 -0000	1.123
  +++ htmltokenizer.cpp	27 Oct 2005 06:03:31 -0000	1.124
  @@ -1836,4 +1836,13 @@
       onHold = _onHold;
   }
   
  +void parseHTMLDocumentFragment(const DOM::DOMString &source, DOM::DocumentFragmentImpl *fragment)
  +{
  +    HTMLTokenizer tok(fragment->docPtr(), fragment);
  +    tok.setForceSynchronous(true);
  +    tok.write(source.qstring(), true);
  +    tok.finish();
  +    assert(!tok.processingData());      // make sure we're done (see 3963151)
  +}
  +
   }
  
  
  
  1.45      +2 -0      WebCore/khtml/html/htmltokenizer.h
  
  Index: htmltokenizer.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/html/htmltokenizer.h,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- htmltokenizer.h	25 Oct 2005 22:32:54 -0000	1.44
  +++ htmltokenizer.h	27 Oct 2005 06:03:31 -0000	1.45
  @@ -381,6 +381,8 @@
       bool inWrite;
   };
   
  +void parseHTMLDocumentFragment(const DOM::DOMString &, DOM::DocumentFragmentImpl *);
  +
   }
   
   #if APPLE_CHANGES
  
  
  
  1.17      +1 -19     WebCore/khtml/xml/dom_xmlimpl.cpp
  
  Index: dom_xmlimpl.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xml/dom_xmlimpl.cpp,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- dom_xmlimpl.cpp	3 Oct 2005 21:12:54 -0000	1.16
  +++ dom_xmlimpl.cpp	27 Oct 2005 06:03:32 -0000	1.17
  @@ -303,7 +303,6 @@
       m_target = 0;
       m_data = 0;
       m_localHref = 0;
  -    m_sheet = 0;
       m_cachedSheet = 0;
       m_loading = false;
   #ifdef KHTML_XSLT
  @@ -319,7 +318,6 @@
       m_data = _data.impl();
       if (m_data)
           m_data->ref();
  -    m_sheet = 0;
       m_cachedSheet = 0;
       m_localHref = 0;
   #ifdef KHTML_XSLT
  @@ -335,8 +333,6 @@
           m_data->deref();
       if (m_cachedSheet)
   	m_cachedSheet->deref(this);
  -    if (m_sheet)
  -	m_sheet->deref();
   }
   
   DOMString ProcessingInstructionImpl::target() const
  @@ -492,11 +488,6 @@
       return true;
   }
   
  -StyleSheetImpl* ProcessingInstructionImpl::sheet() const
  -{
  -    return m_sheet;
  -}
  -
   bool ProcessingInstructionImpl::isLoading() const
   {
       if (m_loading)
  @@ -535,22 +526,13 @@
           getDocument()->stylesheetLoaded();
   }
   
  -void ProcessingInstructionImpl::setStyleSheet(CSSStyleSheetImpl* sheet)
  -{
  -    if (m_sheet)
  -        m_sheet->deref();
  -    m_sheet = sheet;
  -    if (m_sheet)
  -        m_sheet->ref();
  -}
  -
   DOMString ProcessingInstructionImpl::toString() const
   {
       DOMString result = "<?";
       result += m_target;
       result += " ";
       result += m_data;
  -    result += ">";
  +    result += "?>";
       return result;
   }
   
  
  
  
  1.14      +4 -5      WebCore/khtml/xml/dom_xmlimpl.h
  
  Index: dom_xmlimpl.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xml/dom_xmlimpl.h,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- dom_xmlimpl.h	10 May 2005 21:59:15 -0000	1.13
  +++ dom_xmlimpl.h	27 Oct 2005 06:03:33 -0000	1.14
  @@ -23,6 +23,7 @@
   #ifndef _DOM_XmlImpl_h_
   #define _DOM_XmlImpl_h_
   
  +#include "css_stylesheetimpl.h"
   #include "xml/dom_nodeimpl.h"
   #include "misc/loader_client.h"
   
  @@ -33,8 +34,6 @@
   namespace DOM {
   
   class DocumentImpl;
  -class CSSStyleSheetImpl;
  -class StyleSheetImpl;
   class DOMString;
   #if APPLE_CHANGES
   class ProcessingInstruction;
  @@ -150,10 +149,10 @@
   
       virtual DOMString localHref() const;
       virtual bool childTypeAllowed( unsigned short type );
  -    StyleSheetImpl *sheet() const;
  +    StyleSheetImpl *sheet() const { return m_sheet.get(); }
       bool checkStyleSheet();
       virtual void setStyleSheet(const DOMString &url, const DOMString &sheet);
  -    virtual void setStyleSheet(CSSStyleSheetImpl* sheet);
  +    virtual void setStyleSheet(CSSStyleSheetImpl *sheet) { m_sheet = sheet; }
       bool isLoading() const;
       void sheetLoaded();
   
  @@ -168,7 +167,7 @@
       DOMStringImpl *m_data;
       DOMStringImpl *m_localHref;
       khtml::CachedObject *m_cachedSheet;
  -    StyleSheetImpl *m_sheet;
  +    SharedPtr<StyleSheetImpl> m_sheet;
       bool m_loading;
   #ifdef KHTML_XSLT
       bool m_isXSL;
  
  
  



More information about the webkit-changes mailing list