Changeset 20997 in webkit


Ignore:
Timestamp:
Apr 21, 2007 2:38:59 AM (17 years ago)
Author:
ap
Message:

2007-04-21 Lamar Goddard <lamargoddard@gmail.com>

Reviewed by Darin.

Fix for http://bugs.webkit.org/show_bug.cgi?id=5262
<rdar://problem/5018778>
XMLSerializer drops Namespace information

WebCore:

Updated WebCore::markup to output namespace information for elements/attributes whose namespace information
doesn't appear in its scope in the output.

  • WebCore/editing/markup.cpp: (WebCore::createMarkup(const Node*, ...)): Changed call to WebCore::markup to match parameters (WebCore::markup): Changed recursive call to match tree structure, removed ASSERT and no longer needed includeSiblings parameter. (WebCore::startMarkup): Added optional parameter to track namespaces in the current scope. (WebCore::addNamespace): Function to add namespace information to markup. (WebCore::shouldAddNamespaceAttr): (WebCore::shouldAddNamespaceElem): Functions that test whether namespace information should be added for a given node.
  • WebCore/dom/Document.idl: (createElementNS): (createAttributeNS): (getElementsByTagNameNS): Added [ConvertNullToNullString] to namespaceURI parameter.
  • WebCore/dom/Node.cpp: (Node::getElementsByTagNameNS): removed test for namespaceURI being null as null can be a valid namespace.

LayoutTests:

  • fast/dom/serialize-nodes-expected.txt: Added.
  • fast/dom/serialize-nodes.xhtml: Added.
  • dom/xhtml/level3/core/nodeisequalnode14-expected.txt: This test fails because createAttribute is supposed to create an Attr with localName of null.
  • dom/xhtml/level3/core/nodeisequalnode15-expected.txt: Now succeeds.
  • fast/innerHTML/004-expected.txt: Added namespace information to head and body nodes as xhtml nodes now serialize with namespace information.
Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r20996 r20997  
     12007-04-21  Lamar Goddard  <lamargoddard@gmail.com>
     2
     3        Reviewed by Darin.
     4
     5        http://bugs.webkit.org/show_bug.cgi?id=5262
     6        <rdar://problem/5018778>
     7        XMLSerializer drops Namespace information
     8
     9        * fast/dom/serialize-nodes-expected.txt: Added.
     10        * fast/dom/serialize-nodes.xhtml: Added.
     11        * dom/xhtml/level3/core/nodeisequalnode14-expected.txt: This test fails because
     12        createAttribute is supposed to create an Attr with localName of null.
     13        * dom/xhtml/level3/core/nodeisequalnode15-expected.txt: Now succeeds.
     14        * fast/innerHTML/004-expected.txt: Added namespace information to head and body nodes
     15        as xhtml nodes now serialize with namespace information.
     16
    1172007-04-21  Alexey Proskuryakov  <ap@webkit.org>
    218
  • trunk/LayoutTests/dom/xhtml/level3/core/nodeisequalnode14-expected.txt

    r11962 r20997  
    11Test    http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodeisequalnode14
    2 Status  Success
     2Status  failure
     3Message nodeisequalnode14: assertTrue failed
  • trunk/LayoutTests/dom/xhtml/level3/core/nodeisequalnode15-expected.txt

    r13297 r20997  
    11Test    http://www.w3.org/2001/DOM-Test-Suite/level3/core/nodeisequalnode15
    2 Status  failure
    3 Message nodeisequalnode15: assertTrue failed
     2Status  Success
  • trunk/LayoutTests/fast/innerHTML/004-expected.txt

    r14948 r20997  
    11Content:
    22
    3 <head>
     3<head xmlns="http://www.w3.org/1999/xhtml">
    44<meta name="description" content="This tests singular elements too" />
    55<title>xhtml innerHTML test</title>
    66</head>
    7 <body>
     7<body xmlns="http://www.w3.org/1999/xhtml">
    88<span>Content:</span>
    99<pre id="content">placeholder</pre>
  • trunk/WebCore/ChangeLog

    r20996 r20997  
     12007-04-21  Lamar Goddard <lamargoddard@gmail.com>
     2
     3        Reviewed by Darin.
     4
     5        Fix for http://bugs.webkit.org/show_bug.cgi?id=5262
     6        <rdar://problem/5018778>
     7        XMLSerializer drops Namespace information
     8
     9        Updated WebCore::markup to output namespace information for elements/attributes whose namespace information
     10        doesn't appear in its scope in the output.
     11
     12        Added test case: fast/dom/serialize-nodes.xhtml
     13
     14        * WebCore/editing/markup.cpp:
     15        (WebCore::createMarkup(const Node*, ...)): Changed call to WebCore::markup to match parameters
     16        (WebCore::markup): Changed recursive call to match tree structure, removed ASSERT and no longer needed includeSiblings parameter.
     17        (WebCore::startMarkup): Added optional parameter to track namespaces in the current scope.
     18        (WebCore::addNamespace): Function to add namespace information to markup.
     19        (WebCore::shouldAddNamespaceAttr):
     20        (WebCore::shouldAddNamespaceElem): Functions that test whether namespace information should be added for a given node.
     21        * WebCore/dom/Document.idl:
     22        (createElementNS):
     23        (createAttributeNS):
     24        (getElementsByTagNameNS): Added [ConvertNullToNullString] to namespaceURI parameter.
     25        * WebCore/dom/Node.cpp:
     26        (Node::getElementsByTagNameNS): removed test for namespaceURI being null as null can be a valid namespace.
     27
    1282007-04-21  Alexey Proskuryakov  <ap@webkit.org>
    229
  • trunk/WebCore/dom/Document.idl

    r20948 r20997  
    5050                                       in boolean deep)
    5151            raises (DOMException);
    52         [OldStyleObjC] Element createElementNS(in DOMString namespaceURI,
     52        [OldStyleObjC] Element createElementNS(in [ConvertNullToNullString] DOMString namespaceURI,
    5353                                               in DOMString qualifiedName)
    5454            raises (DOMException);
    55         [OldStyleObjC] Attr createAttributeNS(in DOMString namespaceURI,
     55        [OldStyleObjC] Attr createAttributeNS(in [ConvertNullToNullString] DOMString namespaceURI,
    5656                                              in DOMString qualifiedName)
    5757            raises (DOMException);
    58         [OldStyleObjC] NodeList getElementsByTagNameNS(in DOMString namespaceURI,
     58        [OldStyleObjC] NodeList getElementsByTagNameNS(in [ConvertNullToNullString] DOMString namespaceURI,
    5959                                                       in DOMString localName);
    6060        Element            getElementById(in DOMString elementId);
  • trunk/WebCore/dom/Node.cpp

    r20495 r20997  
    11951195PassRefPtr<NodeList> Node::getElementsByTagNameNS(const String &namespaceURI, const String &localName)
    11961196{
    1197     if (namespaceURI.isNull() || localName.isNull())
     1197    if (localName.isNull())
    11981198        return 0; // FIXME: Who relies on getting 0 instead of a node list in this case?
    11991199   
  • trunk/WebCore/editing/markup.cpp

    r20912 r20997  
    4949#include "Logging.h"
    5050#include "ProcessingInstruction.h"
     51#include "QualifiedName.h"
    5152#include "Range.h"
    5253#include "Selection.h"
     
    155156}
    156157
    157 static DeprecatedString startMarkup(const Node *node, const Range *range, EAnnotateForInterchange annotate, bool convertBlocksToInlines = false)
     158static bool shouldAddNamespaceElem(const Element* elem)
     159{
     160    // Don't add namespace attribute if it is already defined for this elem.
     161    const AtomicString& prefix = elem->prefix();
     162    AtomicString attr = !prefix.isEmpty() ? "xmlns:" + prefix : "xmlns";
     163    return !elem->hasAttribute(attr);
     164}
     165
     166static bool shouldAddNamespaceAttr(const Attribute* attr, HashMap<AtomicStringImpl*, AtomicStringImpl*>& namespaces)
     167{
     168    // Don't add namespace attributes twice
     169    static const AtomicString xmlnsURI = "http://www.w3.org/2000/xmlns/";
     170    static const QualifiedName xmlnsAttr(nullAtom, "xmlns", xmlnsURI);
     171    if (attr->name() == xmlnsAttr) {
     172        namespaces.set(emptyAtom.impl(), attr->value().impl());
     173        return false;
     174    }
     175   
     176    QualifiedName xmlnsPrefixAttr("xmlns", attr->localName(), xmlnsURI);
     177    if (attr->name() == xmlnsPrefixAttr) {
     178        namespaces.set(attr->localName().impl(), attr->value().impl());
     179        return false;
     180    }
     181   
     182    return true;
     183}
     184
     185static String addNamespace(const AtomicString& prefix, const AtomicString& ns, HashMap<AtomicStringImpl*, AtomicStringImpl*>& namespaces)
     186{
     187    if (ns.isEmpty())
     188        return "";
     189   
     190    // Use emptyAtoms's impl() for both null and empty strings since the HashMap can't handle 0 as a key
     191    AtomicStringImpl* pre = prefix.isEmpty() ? emptyAtom.impl() : prefix.impl();
     192    AtomicStringImpl* foundNS = namespaces.get(pre);
     193    if (foundNS != ns.impl()) {
     194        namespaces.set(pre, ns.impl());
     195        return " xmlns" + (!prefix.isEmpty() ? ":" + prefix : "") + "=\"" + escapeTextForMarkup(ns.deprecatedString(), true) + "\"";
     196    }
     197   
     198    return "";
     199}
     200
     201static DeprecatedString startMarkup(const Node *node, const Range *range, EAnnotateForInterchange annotate, bool convertBlocksToInlines = false, HashMap<AtomicStringImpl*, AtomicStringImpl*>* namespaces = 0)
    158202{
    159203    bool documentIsHTML = node->document()->isHTMLDocument();
     
    194238            NamedAttrMap *attrs = el->attributes();
    195239            unsigned length = attrs->length();
     240            if (!documentIsHTML && namespaces && shouldAddNamespaceElem(el))
     241                markup += addNamespace(el->prefix(), el->namespaceURI(), *namespaces).deprecatedString();
    196242
    197243            for (unsigned int i = 0; i < length; i++) {
     
    207253                    markup += " " + attr->name().toString().deprecatedString();
    208254                markup += "=\"" + escapeTextForMarkup(value.deprecatedString(), true) + "\"";
     255
     256                if (!documentIsHTML && namespaces && shouldAddNamespaceAttr(attr, *namespaces))
     257                    markup += addNamespace(attr->prefix(), attr->namespaceURI(), *namespaces).deprecatedString();
    209258            }
    210259           
     
    275324}
    276325
    277 static DeprecatedString markup(Node* startNode, bool onlyIncludeChildren, bool includeSiblings, Vector<Node*> *nodes)
    278 {
    279     // Doesn't make sense to only include children and include siblings.
    280     ASSERT(!(onlyIncludeChildren && includeSiblings));
     326static DeprecatedString markup(Node* startNode, bool onlyIncludeChildren, Vector<Node*>* nodes, const HashMap<AtomicStringImpl*, AtomicStringImpl*>* namespaces = 0)
     327{
     328    HashMap<AtomicStringImpl*, AtomicStringImpl*> namespaceHash;
     329    if (namespaces)
     330        namespaceHash = *namespaces;
     331   
    281332    DeprecatedString me = "";
    282     for (Node* current = startNode; current != NULL; current = includeSiblings ? current->nextSibling() : NULL) {
    283         if (!onlyIncludeChildren) {
    284             if (nodes)
    285                 nodes->append(current);
    286             me += startMarkup(current, 0, DoNotAnnotateForInterchange);
    287         }
    288         // print children
    289         if (Node *n = current->firstChild())
    290             if (!(n->document()->isHTMLDocument() && doesHTMLForbidEndTag(current)))
    291                 me += markup(n, false, true, nodes);
    292        
    293         // Print my ending tag
    294         if (!onlyIncludeChildren)
    295             me += endMarkup(current);
    296     }
     333    if (!onlyIncludeChildren) {
     334        if (nodes)
     335            nodes->append(startNode);
     336        me += startMarkup(startNode, 0, DoNotAnnotateForInterchange, false, &namespaceHash);
     337    }
     338    // print children
     339    if (!(startNode->document()->isHTMLDocument() && doesHTMLForbidEndTag(startNode)))
     340        for (Node* current = startNode->firstChild(); current; current = current->nextSibling())
     341            me += markup(current, false, nodes, &namespaceHash);
     342   
     343    // Print my ending tag
     344    if (!onlyIncludeChildren)
     345        me += endMarkup(startNode);
     346   
    297347    return me;
    298348}
     
    586636        node->document()->frame()->editor()->deleteButtonController()->disable();
    587637    node->document()->updateLayoutIgnorePendingStylesheets();
    588     DeprecatedString result(markup(const_cast<Node*>(node), includeChildren, false, nodes));
     638    DeprecatedString result(markup(const_cast<Node*>(node), includeChildren, nodes));
    589639    if (node->document()->frame())
    590640        node->document()->frame()->editor()->deleteButtonController()->enable();
Note: See TracChangeset for help on using the changeset viewer.