[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

rniwa at webkit.org rniwa at webkit.org
Wed Dec 22 13:13:44 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 7a7907c60943564bcb29515b28bc1ebd5d31e6a8
Author: rniwa at webkit.org <rniwa at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Thu Sep 9 06:32:24 2010 +0000

    2010-09-08  Ryosuke Niwa  <rniwa at webkit.org>
    
            Reviewed by Tony Chang.
    
            MarkupAccumulator should be broken down into two classes
            https://bugs.webkit.org/show_bug.cgi?id=44854
    
            Extracted wrapWithNode, wrapWithStyleNode, stringValueForRange, renderedText, removeExteriorStyles,
            shouldAnnotate, m_shouldAnnotate, and m_reversedPrecedingMarkup from MarkupAccumulator to create
            StyledMarkupAccumulator in order to isolate annotation related code and prepending of text.
    
            Isolating MarkupAccumulator as a separate class has two advantages:
            1. Isolated serialization code is easier to understand and easier to security-review.
            2. Embedder can use MarkupAccumulator to implement "Save as" feature.
    
            Also made takeResults, appendText, and appendElement in MarkupAccumulator virtual to override in
            StyledMarkupAccumulator because prepending text requires overriding takeResults, appendText needs
            to append only rendered text when shouldAnnotate() is true, and appendElement requires a different
            behavior when shouldAnnotate() is true or when called inside wrapWithNode with convertBlocksToInlines = true.
    
            No new tests are added since this is a cleanup.
    
            * editing/markup.cpp:
            (WebCore::MarkupAccumulator::MarkupAccumulator): Removed shouldAnnotate from argument.
            (WebCore::MarkupAccumulator::~MarkupAccumulator): Added.
            (WebCore::StyledMarkupAccumulator::): Added.
            (WebCore::StyledMarkupAccumulator::StyledMarkupAccumulator): Added.
            (WebCore::StyledMarkupAccumulator::appendElement): Added to support annotation.
            (WebCore::StyledMarkupAccumulator::shouldAnnotate): Moved from MarkupAccumulator.
            (WebCore::MarkupAccumulator::appendStartTag): No longer takes convertBlocksToInlines and RangeFullySelectsNode.
            (WebCore::StyledMarkupAccumulator::wrapWithStyleNode): Moved from MarkupAccumulator.
            (WebCore::MarkupAccumulator::takeResults): No longer accumulates prepended text, and made virtual.
            (WebCore::StyledMarkupAccumulator::takeResults): Added to support prepended text.
            (WebCore::MarkupAccumulator::shouldAddNamespaceAttribute): Takes a reference to Attribute instead of a pointer.
            (WebCore::MarkupAccumulator::entityMaskForText): Extracted from appendText.
            (WebCore::MarkupAccumulator::appendText): No longer deals with annotation.
            (WebCore::StyledMarkupAccumulator::appendText): Added to support annotation.
            (WebCore::StyledMarkupAccumulator::stringValueForRange): Moved from MarkupAccumulator.
            (WebCore::StyledMarkupAccumulator::renderedText): Moved from MarkupAccumulator.
            (WebCore::MarkupAccumulator::appendElement): No longer deals with annotation.
            (WebCore::StyledMarkupAccumulator::wrapWithNode): Moved from MarkupAccumulator.
            (WebCore::StyledMarkupAccumulator::removeExteriorStyles): Moved from MarkupAccumulator.
            (WebCore::MarkupAccumulator::appendOpenTag): Added.
            (WebCore::MarkupAccumulator::appendCloseTag): Added.
            (WebCore::MarkupAccumulator::appendAttribute): Added.
            (WebCore::MarkupAccumulator::appendStartMarkup): No longer takes convertBlocksToInlines and RangeFullySelectsNode.
            (WebCore::serializeNodes): Takes StyledMarkupAccumulator.
            (WebCore::createMarkup): Range version uses StyledMarkupAccumulator and node version uses MarkupAccumulator.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@67064 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 72da6f1..6fa3632 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,52 @@
+2010-09-08  Ryosuke Niwa  <rniwa at webkit.org>
+
+        Reviewed by Tony Chang.
+
+        MarkupAccumulator should be broken down into two classes
+        https://bugs.webkit.org/show_bug.cgi?id=44854
+
+        Extracted wrapWithNode, wrapWithStyleNode, stringValueForRange, renderedText, removeExteriorStyles,
+        shouldAnnotate, m_shouldAnnotate, and m_reversedPrecedingMarkup from MarkupAccumulator to create
+        StyledMarkupAccumulator in order to isolate annotation related code and prepending of text.
+
+        Isolating MarkupAccumulator as a separate class has two advantages:
+        1. Isolated serialization code is easier to understand and easier to security-review.
+        2. Embedder can use MarkupAccumulator to implement "Save as" feature.
+
+        Also made takeResults, appendText, and appendElement in MarkupAccumulator virtual to override in
+        StyledMarkupAccumulator because prepending text requires overriding takeResults, appendText needs
+        to append only rendered text when shouldAnnotate() is true, and appendElement requires a different
+        behavior when shouldAnnotate() is true or when called inside wrapWithNode with convertBlocksToInlines = true.
+
+        No new tests are added since this is a cleanup.
+
+        * editing/markup.cpp:
+        (WebCore::MarkupAccumulator::MarkupAccumulator): Removed shouldAnnotate from argument.
+        (WebCore::MarkupAccumulator::~MarkupAccumulator): Added.
+        (WebCore::StyledMarkupAccumulator::): Added.
+        (WebCore::StyledMarkupAccumulator::StyledMarkupAccumulator): Added.
+        (WebCore::StyledMarkupAccumulator::appendElement): Added to support annotation.
+        (WebCore::StyledMarkupAccumulator::shouldAnnotate): Moved from MarkupAccumulator.
+        (WebCore::MarkupAccumulator::appendStartTag): No longer takes convertBlocksToInlines and RangeFullySelectsNode.
+        (WebCore::StyledMarkupAccumulator::wrapWithStyleNode): Moved from MarkupAccumulator.
+        (WebCore::MarkupAccumulator::takeResults): No longer accumulates prepended text, and made virtual.
+        (WebCore::StyledMarkupAccumulator::takeResults): Added to support prepended text.
+        (WebCore::MarkupAccumulator::shouldAddNamespaceAttribute): Takes a reference to Attribute instead of a pointer.
+        (WebCore::MarkupAccumulator::entityMaskForText): Extracted from appendText.
+        (WebCore::MarkupAccumulator::appendText): No longer deals with annotation.
+        (WebCore::StyledMarkupAccumulator::appendText): Added to support annotation.
+        (WebCore::StyledMarkupAccumulator::stringValueForRange): Moved from MarkupAccumulator.
+        (WebCore::StyledMarkupAccumulator::renderedText): Moved from MarkupAccumulator.
+        (WebCore::MarkupAccumulator::appendElement): No longer deals with annotation.
+        (WebCore::StyledMarkupAccumulator::wrapWithNode): Moved from MarkupAccumulator.
+        (WebCore::StyledMarkupAccumulator::removeExteriorStyles): Moved from MarkupAccumulator.
+        (WebCore::MarkupAccumulator::appendOpenTag): Added.
+        (WebCore::MarkupAccumulator::appendCloseTag): Added.
+        (WebCore::MarkupAccumulator::appendAttribute): Added.
+        (WebCore::MarkupAccumulator::appendStartMarkup): No longer takes convertBlocksToInlines and RangeFullySelectsNode.
+        (WebCore::serializeNodes): Takes StyledMarkupAccumulator.
+        (WebCore::createMarkup): Range version uses StyledMarkupAccumulator and node version uses MarkupAccumulator.
+
 2010-09-08  Peter Kasting  <pkasting at google.com>
 
         Not reviewed, layout test fix.
diff --git a/WebCore/editing/markup.cpp b/WebCore/editing/markup.cpp
index 7bf85a4..180d03b 100644
--- a/WebCore/editing/markup.cpp
+++ b/WebCore/editing/markup.cpp
@@ -147,51 +147,75 @@ typedef HashMap<AtomicStringImpl*, AtomicStringImpl*> Namespaces;
 
 class MarkupAccumulator {
 public:
-    enum RangeFullySelectsNode { DoesFullySelectNode, DoesNotFullySelectNode };
-
-    MarkupAccumulator(Vector<Node*>* nodes, EAbsoluteURLs shouldResolveURLs, EAnnotateForInterchange shouldAnnotate, const Range* range = 0)
+    MarkupAccumulator(Vector<Node*>* nodes, EAbsoluteURLs shouldResolveURLs, const Range* range = 0)
         : m_nodes(nodes)
-        , m_shouldResolveURLs(shouldResolveURLs)
-        , m_shouldAnnotate(shouldAnnotate)
         , m_range(range)
+        , m_shouldResolveURLs(shouldResolveURLs)
     {
     }
+    virtual ~MarkupAccumulator() {}
     void appendString(const String&);
     void appendStartTag(Node*, Namespaces* = 0);
     void appendEndTag(Node*);
-    void wrapWithNode(Node*, bool convertBlocksToInlines = false, RangeFullySelectsNode = DoesFullySelectNode);
-    void wrapWithStyleNode(CSSStyleDeclaration*, Document*, bool isBlock = false);
-    String takeResults();
+    virtual String takeResults();
 
-private:
+protected:
     void appendAttributeValue(Vector<UChar>& result, const String& attribute, bool documentIsHTML);
     void appendQuotedURLAttributeValue(Vector<UChar>& result, const String& urlString);
-    String stringValueForRange(const Node*, const Range*);
     void appendNodeValue(Vector<UChar>& out, const Node*, const Range*, EntityMask);
-    String renderedText(const Node*, const Range*);
     bool shouldAddNamespaceElement(const Element*);
-    bool shouldAddNamespaceAttribute(const Attribute*, Namespaces&);
+    bool shouldAddNamespaceAttribute(const Attribute&, Namespaces&);
     void appendNamespace(Vector<UChar>& result, const AtomicString& prefix, const AtomicString& namespaceURI, Namespaces&);
-    void appendText(Vector<UChar>& out, Text*);
+    EntityMask entityMaskForText(Text* text) const;
+    virtual void appendText(Vector<UChar>& out, Text*);
     void appendComment(Vector<UChar>& out, const String& comment);
     void appendDocumentType(Vector<UChar>& result, const DocumentType*);
     void appendProcessingInstruction(Vector<UChar>& out, const String& target, const String& data);
-    void removeExteriorStyles(CSSMutableStyleDeclaration*);
-    void appendElement(Vector<UChar>& out, Element* element, bool addDisplayInline, Namespaces*, RangeFullySelectsNode);
+    virtual void appendElement(Vector<UChar>& out, Element*, Namespaces*);
+    void appendOpenTag(Vector<UChar>& out, Element* element, Namespaces*);
+    void appendCloseTag(Vector<UChar>& out, Element* element);
+    void appendAttribute(Vector<UChar>& out, Element* element, const Attribute&, Namespaces*);
     void appendCDATASection(Vector<UChar>& out, const String& section);
-    void appendStartMarkup(Vector<UChar>& result, const Node*, bool convertBlocksToInlines, Namespaces*, RangeFullySelectsNode);
+    void appendStartMarkup(Vector<UChar>& result, const Node*, Namespaces*);
     bool shouldSelfClose(const Node*);
     void appendEndMarkup(Vector<UChar>& result, const Node*);
 
     bool shouldResolveURLs() { return m_shouldResolveURLs == AbsoluteURLs; }
-    bool shouldAnnotate() { return m_shouldAnnotate == AnnotateForInterchange; }
 
     Vector<Node*>* const m_nodes;
-    const bool m_shouldResolveURLs;
-    const EAnnotateForInterchange m_shouldAnnotate;
     const Range* const m_range;
-    Vector<String> m_reversedPrecedingMarkup;
     Vector<String> m_succeedingMarkup;
+
+private:
+    const bool m_shouldResolveURLs;
+};
+
+class StyledMarkupAccumulator : public MarkupAccumulator {
+public:
+    enum RangeFullySelectsNode { DoesFullySelectNode, DoesNotFullySelectNode };
+
+    StyledMarkupAccumulator(Vector<Node*>* nodes, EAbsoluteURLs shouldResolveURLs, EAnnotateForInterchange shouldAnnotate, const Range* range)
+        : MarkupAccumulator(nodes, shouldResolveURLs, range)
+        , m_shouldAnnotate(shouldAnnotate)
+    {
+    }
+    void wrapWithNode(Node*, bool convertBlocksToInlines = false, RangeFullySelectsNode = DoesFullySelectNode);
+    void wrapWithStyleNode(CSSStyleDeclaration*, Document*, bool isBlock = false);
+    String takeResults();
+
+protected:
+    virtual void appendText(Vector<UChar>& out, Text*);
+    String renderedText(const Node*, const Range*);
+    String stringValueForRange(const Node*, const Range*);
+    void removeExteriorStyles(CSSMutableStyleDeclaration*);
+    void appendElement(Vector<UChar>& out, Element* element, bool addDisplayInline, RangeFullySelectsNode);
+    void appendElement(Vector<UChar>& out, Element* element, Namespaces*) { appendElement(out, element, false, DoesFullySelectNode); }
+
+    bool shouldAnnotate() { return m_shouldAnnotate == AnnotateForInterchange; }
+
+private:
+    Vector<String> m_reversedPrecedingMarkup;
+    const EAnnotateForInterchange m_shouldAnnotate;
 };
 
 void MarkupAccumulator::appendString(const String& string)
@@ -202,7 +226,7 @@ void MarkupAccumulator::appendString(const String& string)
 void MarkupAccumulator::appendStartTag(Node* node, Namespaces* namespaces)
 {
     Vector<UChar> markup;
-    appendStartMarkup(markup, node, false, namespaces, DoesFullySelectNode);
+    appendStartMarkup(markup, node, namespaces);
     m_succeedingMarkup.append(String::adopt(markup));
     if (m_nodes)
         m_nodes->append(node);
@@ -215,17 +239,20 @@ void MarkupAccumulator::appendEndTag(Node* node)
     m_succeedingMarkup.append(String::adopt(markup));
 }
 
-void MarkupAccumulator::wrapWithNode(Node* node, bool convertBlocksToInlines, RangeFullySelectsNode rangeFullySelectsNode)
+void StyledMarkupAccumulator::wrapWithNode(Node* node, bool convertBlocksToInlines, RangeFullySelectsNode rangeFullySelectsNode)
 {
     Vector<UChar> markup;
-    appendStartMarkup(markup, node, convertBlocksToInlines, 0, rangeFullySelectsNode);
+    if (node->isElementNode())
+        appendElement(markup, static_cast<Element*>(node), convertBlocksToInlines && isBlock(const_cast<Node*>(node)), rangeFullySelectsNode);
+    else
+        appendStartMarkup(markup, node, 0);
     m_reversedPrecedingMarkup.append(String::adopt(markup));
     appendEndTag(node);
     if (m_nodes)
         m_nodes->append(node);
 }
-    
-void MarkupAccumulator::wrapWithStyleNode(CSSStyleDeclaration* style, Document* document, bool isBlock)
+
+void StyledMarkupAccumulator::wrapWithStyleNode(CSSStyleDeclaration* style, Document* document, bool isBlock)
 {
     // All text-decoration-related elements should have been treated as special ancestors
     // If we ever hit this ASSERT, we should export StyleChange in ApplyStyleCommand and use it here
@@ -250,6 +277,23 @@ String MarkupAccumulator::takeResults()
 {
     size_t length = 0;
 
+    size_t postCount = m_succeedingMarkup.size();
+    for (size_t i = 0; i < postCount; ++i)
+        length += m_succeedingMarkup[i].length();
+
+    Vector<UChar> result;
+    result.reserveInitialCapacity(length);
+
+    for (size_t i = 0; i < postCount; ++i)
+        append(result, m_succeedingMarkup[i]);
+
+    return String::adopt(result);
+}
+
+String StyledMarkupAccumulator::takeResults()
+{
+    size_t length = 0;
+
     size_t preCount = m_reversedPrecedingMarkup.size();
     for (size_t i = 0; i < preCount; ++i)
         length += m_reversedPrecedingMarkup[i].length();
@@ -297,10 +341,10 @@ void MarkupAccumulator::appendQuotedURLAttributeValue(Vector<UChar>& result, con
     // FIXME: This does not fully match other browsers. Firefox percent-escapes non-ASCII characters for innerHTML.
     result.append(quoteChar);
     appendAttributeValue(result, urlString, false);
-    result.append(quoteChar);    
+    result.append(quoteChar);
 }
 
-String MarkupAccumulator::stringValueForRange(const Node* node, const Range* range)
+String StyledMarkupAccumulator::stringValueForRange(const Node* node, const Range* range)
 {
     if (!range)
         return node->nodeValue();
@@ -330,11 +374,11 @@ void MarkupAccumulator::appendNodeValue(Vector<UChar>& out, const Node* node, co
             length -= start;
         }
     }
-    
+
     appendCharactersReplacingEntities(out, characters, length, entityMask);
 }
 
-String MarkupAccumulator::renderedText(const Node* node, const Range* range)
+String StyledMarkupAccumulator::renderedText(const Node* node, const Range* range)
 {
     if (!node->isTextNode())
         return String();
@@ -348,7 +392,7 @@ String MarkupAccumulator::renderedText(const Node* node, const Range* range)
         startOffset = range->startOffset(ec);
     if (range && node == range->endContainer(ec))
         endOffset = range->endOffset(ec);
-    
+
     Position start(const_cast<Node*>(node), startOffset);
     Position end(const_cast<Node*>(node), endOffset);
     return plainText(Range::create(node->document(), start, end).get());
@@ -395,19 +439,19 @@ bool MarkupAccumulator::shouldAddNamespaceElement(const Element* element)
     return !element->hasAttribute(attr);
 }
 
-bool MarkupAccumulator::shouldAddNamespaceAttribute(const Attribute* attribute, Namespaces& namespaces)
+bool MarkupAccumulator::shouldAddNamespaceAttribute(const Attribute& attribute, Namespaces& namespaces)
 {
     namespaces.checkConsistency();
 
     // Don't add namespace attributes twice
-    if (attribute->name() == XMLNSNames::xmlnsAttr) {
-        namespaces.set(emptyAtom.impl(), attribute->value().impl());
+    if (attribute.name() == XMLNSNames::xmlnsAttr) {
+        namespaces.set(emptyAtom.impl(), attribute.value().impl());
         return false;
     }
     
-    QualifiedName xmlnsPrefixAttr(xmlnsAtom, attribute->localName(), XMLNSNames::xmlnsNamespaceURI);
-    if (attribute->name() == xmlnsPrefixAttr) {
-        namespaces.set(attribute->localName().impl(), attribute->value().impl());
+    QualifiedName xmlnsPrefixAttr(xmlnsAtom, attribute.localName(), XMLNSNames::xmlnsNamespaceURI);
+    if (attribute.name() == xmlnsPrefixAttr) {
+        namespaces.set(attribute.localName().impl(), attribute.value().impl());
         return false;
     }
     
@@ -439,19 +483,27 @@ void MarkupAccumulator::appendNamespace(Vector<UChar>& result, const AtomicStrin
     }
 }
 
-void MarkupAccumulator::appendText(Vector<UChar>& out, Text* text)
+EntityMask MarkupAccumulator::entityMaskForText(Text* text) const
 {
     const QualifiedName* parentName = 0;
     if (text->parentElement())
         parentName = &static_cast<Element*>(text->parentElement())->tagQName();
+    
+    if (parentName && (*parentName == scriptTag || *parentName == styleTag || *parentName == xmpTag))
+        return EntityMaskInCDATA;
 
-    if (parentName && (*parentName == scriptTag || *parentName == styleTag || *parentName == xmpTag)) {
-        appendNodeValue(out, text, m_range, EntityMaskInCDATA);
-        return;
-    }
+    return text->document()->isHTMLDocument() ? EntityMaskInHTMLPCDATA : EntityMaskInPCDATA;
+}
+
+void MarkupAccumulator::appendText(Vector<UChar>& out, Text* text)
+{
+    appendNodeValue(out, text, m_range, entityMaskForText(text));
+}
 
-    if (!shouldAnnotate() || (parentName && *parentName == textareaTag)) {
-        appendNodeValue(out, text, m_range, text->document()->isHTMLDocument() ? EntityMaskInHTMLPCDATA : EntityMaskInPCDATA);
+void StyledMarkupAccumulator::appendText(Vector<UChar>& out, Text* text)
+{
+    if (!shouldAnnotate() || (text->parentElement() && text->parentElement()->tagQName() == textareaTag)) {
+        MarkupAccumulator::appendText(out, text);
         return;
     }
 
@@ -509,18 +561,27 @@ void MarkupAccumulator::appendProcessingInstruction(Vector<UChar>& out, const St
     append(out, "?>");
 }
 
-void MarkupAccumulator::removeExteriorStyles(CSSMutableStyleDeclaration* style)
+void StyledMarkupAccumulator::removeExteriorStyles(CSSMutableStyleDeclaration* style)
 {
     style->removeProperty(CSSPropertyFloat);
 }
 
-void MarkupAccumulator::appendElement(Vector<UChar>& out, Element* element, bool addDisplayInline, Namespaces* namespaces, RangeFullySelectsNode rangeFullySelectsNode)
+void MarkupAccumulator::appendElement(Vector<UChar>& out, Element* element, Namespaces* namespaces)
+{
+    appendOpenTag(out, element, namespaces);
+
+    NamedNodeMap* attributes = element->attributes();
+    unsigned length = attributes->length();
+    for (unsigned int i = 0; i < length; i++)
+        appendAttribute(out, element, *attributes->attributeItem(i), namespaces);
+
+    appendCloseTag(out, element);
+}
+
+void StyledMarkupAccumulator::appendElement(Vector<UChar>& out, Element* element, bool addDisplayInline, RangeFullySelectsNode rangeFullySelectsNode)
 {
     bool documentIsHTML = element->document()->isHTMLDocument();
-    out.append('<');
-    append(out, element->nodeNamePreservingCase());
-    if (!documentIsHTML && namespaces && shouldAddNamespaceElement(element))
-        appendNamespace(out, element->prefix(), element->namespaceURI(), *namespaces);
+    appendOpenTag(out, element, 0);
 
     NamedNodeMap* attributes = element->attributes();
     unsigned length = attributes->length();
@@ -529,30 +590,7 @@ void MarkupAccumulator::appendElement(Vector<UChar>& out, Element* element, bool
         // We'll handle the style attribute separately, below.
         if (attribute->name() == styleAttr && element->isHTMLElement() && (shouldAnnotate() || addDisplayInline))
             continue;
-        out.append(' ');
-        
-        if (documentIsHTML)
-            append(out, attribute->name().localName());
-        else
-            append(out, attribute->name().toString());
-
-        out.append('=');
-
-        if (element->isURLAttribute(attribute)) {
-            // We don't want to complete file:/// URLs because it may contain sensitive information
-            // about the user's system.
-            if (shouldResolveURLs() && !element->document()->url().isLocalFile())
-                appendQuotedURLAttributeValue(out, element->document()->completeURL(attribute->value()).string());
-            else
-                appendQuotedURLAttributeValue(out, attribute->value().string());
-        } else {
-            out.append('\"');
-            appendAttributeValue(out, attribute->value(), documentIsHTML);
-            out.append('\"');
-        }
-
-        if (!documentIsHTML && namespaces && shouldAddNamespaceAttribute(attribute, *namespaces))
-            appendNamespace(out, attribute->prefix(), attribute->namespaceURI(), *namespaces);
+        appendAttribute(out, element, *attribute, 0);
     }
 
     if (element->isHTMLElement() && (shouldAnnotate() || addDisplayInline)) {
@@ -597,6 +635,19 @@ void MarkupAccumulator::appendElement(Vector<UChar>& out, Element* element, bool
         }
     }
 
+    appendCloseTag(out, element);
+}
+    
+void MarkupAccumulator::appendOpenTag(Vector<UChar>& out, Element* element, Namespaces* namespaces)
+{
+    out.append('<');
+    append(out, element->nodeNamePreservingCase());
+    if (!element->document()->isHTMLDocument() && namespaces && shouldAddNamespaceElement(element))
+        appendNamespace(out, element->prefix(), element->namespaceURI(), *namespaces);    
+}
+
+void MarkupAccumulator::appendCloseTag(Vector<UChar>& out, Element* element)
+{
     if (shouldSelfClose(element)) {
         if (element->isHTMLElement())
             out.append(' '); // XHTML 1.0 <-> HTML compatibility.
@@ -605,6 +656,36 @@ void MarkupAccumulator::appendElement(Vector<UChar>& out, Element* element, bool
     out.append('>');
 }
 
+void MarkupAccumulator::appendAttribute(Vector<UChar>& out, Element* element, const Attribute& attribute, Namespaces* namespaces)
+{
+    bool documentIsHTML = element->document()->isHTMLDocument();
+
+    out.append(' ');
+
+    if (documentIsHTML)
+        append(out, attribute.name().localName());
+    else
+        append(out, attribute.name().toString());
+
+    out.append('=');
+
+    if (element->isURLAttribute(const_cast<Attribute*>(&attribute))) {
+        // We don't want to complete file:/// URLs because it may contain sensitive information
+        // about the user's system.
+        if (shouldResolveURLs() && !element->document()->url().isLocalFile())
+            appendQuotedURLAttributeValue(out, element->document()->completeURL(attribute.value()).string());
+        else
+            appendQuotedURLAttributeValue(out, attribute.value()); 
+    } else {
+        out.append('\"');
+        appendAttributeValue(out, attribute.value(), documentIsHTML);
+        out.append('\"');
+    }
+
+    if (!documentIsHTML && namespaces && shouldAddNamespaceAttribute(attribute, *namespaces))
+        appendNamespace(out, attribute.prefix(), attribute.namespaceURI(), *namespaces);
+}
+
 void MarkupAccumulator::appendCDATASection(Vector<UChar>& out, const String& section)
 {
     // FIXME: CDATA content is not escaped, but XMLSerializer (and possibly other callers) should raise an exception if it includes "]]>".
@@ -613,7 +694,7 @@ void MarkupAccumulator::appendCDATASection(Vector<UChar>& out, const String& sec
     append(out, "]]>");
 }
 
-void MarkupAccumulator::appendStartMarkup(Vector<UChar>& result, const Node* node, bool convertBlocksToInlines, Namespaces* namespaces, RangeFullySelectsNode rangeFullySelectsNode)
+void MarkupAccumulator::appendStartMarkup(Vector<UChar>& result, const Node* node, Namespaces* namespaces)
 {
     if (namespaces)
         namespaces->checkConsistency();
@@ -635,7 +716,7 @@ void MarkupAccumulator::appendStartMarkup(Vector<UChar>& result, const Node* nod
         appendProcessingInstruction(result, static_cast<const ProcessingInstruction*>(node)->target(), static_cast<const ProcessingInstruction*>(node)->data());
         break;
     case Node::ELEMENT_NODE:
-        appendElement(result, static_cast<Element*>(const_cast<Node*>(node)), convertBlocksToInlines && isBlock(const_cast<Node*>(node)), namespaces, rangeFullySelectsNode);
+        appendElement(result, static_cast<Element*>(const_cast<Node*>(node)), namespaces);
         break;
     case Node::CDATA_SECTION_NODE:
         appendCDATASection(result, static_cast<const CDATASection*>(node)->data());
@@ -786,7 +867,7 @@ static bool shouldIncludeWrapperForFullySelectedRoot(Node* fullySelectedRoot, CS
     return style->getPropertyCSSValue(CSSPropertyBackgroundImage) || style->getPropertyCSSValue(CSSPropertyBackgroundColor);
 }
 
-static Node* serializeNodes(MarkupAccumulator& accumulator, Node* startNode, Node* pastEnd)
+static Node* serializeNodes(StyledMarkupAccumulator& accumulator, Node* startNode, Node* pastEnd)
 {
     Vector<Node*> ancestorsToClose;
     Node* next;
@@ -896,7 +977,7 @@ String createMarkup(const Range* range, Vector<Node*>* nodes, EAnnotateForInterc
 
     document->updateLayoutIgnorePendingStylesheets();
 
-    MarkupAccumulator accumulator(nodes, shouldResolveURLs, shouldAnnotate, updatedRange.get());
+    StyledMarkupAccumulator accumulator(nodes, shouldResolveURLs, shouldAnnotate, updatedRange.get());
     Node* pastEnd = updatedRange->pastLastNode();
 
     Node* startNode = updatedRange->firstNode();
@@ -994,7 +1075,7 @@ String createMarkup(const Range* range, Vector<Node*>* nodes, EAnnotateForInterc
             } else {
                 // Since this node and all the other ancestors are not in the selection we want to set RangeFullySelectsNode to DoesNotFullySelectNode
                 // so that styles that affect the exterior of the node are not included.
-                accumulator.wrapWithNode(ancestor, convertBlocksToInlines, MarkupAccumulator::DoesNotFullySelectNode);
+                accumulator.wrapWithNode(ancestor, convertBlocksToInlines, StyledMarkupAccumulator::DoesNotFullySelectNode);
             }
             if (nodes)
                 nodes->append(ancestor);
@@ -1097,7 +1178,7 @@ String createMarkup(const Node* node, EChildrenOnly childrenOnly, Vector<Node*>*
             return "";
     }
 
-    MarkupAccumulator accumulator(nodes, shouldResolveURLs, DoNotAnnotateForInterchange);
+    MarkupAccumulator accumulator(nodes, shouldResolveURLs);
     serializeNodesWithNamespaces(accumulator, const_cast<Node*>(node), deleteButtonContainerElement, childrenOnly, 0);
     return accumulator.takeResults();
 }

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list