[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 14:41:41 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 72da002f159cc53a183041c9952f8af7df9b2f89
Author: rniwa at webkit.org <rniwa at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Sat Oct 16 03:16:18 2010 +0000

    2010-10-15  Ryosuke Niwa  <rniwa at webkit.org>
    
            Reviewed by Tony Chang.
    
            serializeNodesWithNamespaces should be in MarkupAccumulator
            https://bugs.webkit.org/show_bug.cgi?id=47749
    
            Moved serializeNodesWithNamespaces to MarkupAccumulator, and renamed it to serializeNodes.
            MarkupAccumulator::serializeNode now returns the resultant string instead of having a separate takeResults().
            Added several helper functions to MarkupAccumulator.
    
            No new tests are added since this is a cleanup.
    
            * editing/MarkupAccumulator.cpp:
            (WebCore::MarkupAccumulator::serializeNodes): Wrapper for serializeNodes and concatenateMarkup.
            (WebCore::MarkupAccumulator::serializeNodesWithNamespaces): Moved from markup.cpp
            (WebCore::MarkupAccumulator::appendStartTag): Calls appendString instead of appending into m_succeedingMarkup directly.
            (WebCore::MarkupAccumulator::appendEndTag): Ditto.
            (WebCore::MarkupAccumulator::totalLength): Added; extracted from takeResults.
            (WebCore::MarkupAccumulator::concatenateMarkup): Ditto.
            * editing/MarkupAccumulator.h:
            (WebCore::MarkupAccumulator::length): Added; calls totalLength.
            * editing/markup.cpp:
            (WebCore::StyledMarkupAccumulator::appendString): Added; calls MarkupAccumulator's appendString.
            (WebCore::StyledMarkupAccumulator::wrapWithStyleNode): Calls appendString.
            (WebCore::StyledMarkupAccumulator::takeResults): Calls length, totalLength, and concatenateMarkup.
            (WebCore::StyledMarkupAccumulator::serializeNodes): Became a member function.
            (WebCore::createMarkup): Uses MarkupAccumulator.
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@69909 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 006a078..cd6452f 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,32 @@
+2010-10-15  Ryosuke Niwa  <rniwa at webkit.org>
+
+        Reviewed by Tony Chang.
+
+        serializeNodesWithNamespaces should be in MarkupAccumulator
+        https://bugs.webkit.org/show_bug.cgi?id=47749
+
+        Moved serializeNodesWithNamespaces to MarkupAccumulator, and renamed it to serializeNodes.
+        MarkupAccumulator::serializeNode now returns the resultant string instead of having a separate takeResults().
+        Added several helper functions to MarkupAccumulator.
+
+        No new tests are added since this is a cleanup.
+
+        * editing/MarkupAccumulator.cpp:
+        (WebCore::MarkupAccumulator::serializeNodes): Wrapper for serializeNodes and concatenateMarkup.
+        (WebCore::MarkupAccumulator::serializeNodesWithNamespaces): Moved from markup.cpp
+        (WebCore::MarkupAccumulator::appendStartTag): Calls appendString instead of appending into m_succeedingMarkup directly.
+        (WebCore::MarkupAccumulator::appendEndTag): Ditto.
+        (WebCore::MarkupAccumulator::totalLength): Added; extracted from takeResults.
+        (WebCore::MarkupAccumulator::concatenateMarkup): Ditto.
+        * editing/MarkupAccumulator.h:
+        (WebCore::MarkupAccumulator::length): Added; calls totalLength.
+        * editing/markup.cpp:
+        (WebCore::StyledMarkupAccumulator::appendString): Added; calls MarkupAccumulator's appendString.
+        (WebCore::StyledMarkupAccumulator::wrapWithStyleNode): Calls appendString.
+        (WebCore::StyledMarkupAccumulator::takeResults): Calls length, totalLength, and concatenateMarkup.
+        (WebCore::StyledMarkupAccumulator::serializeNodes): Became a member function.
+        (WebCore::createMarkup): Uses MarkupAccumulator.
+
 2010-10-15  Kinuko Yasuda  <kinuko at google.com>
 
         Reviewed by Jian Li.
diff --git a/WebCore/editing/MarkupAccumulator.cpp b/WebCore/editing/MarkupAccumulator.cpp
index aa6e5cf..91a74c8 100644
--- a/WebCore/editing/MarkupAccumulator.cpp
+++ b/WebCore/editing/MarkupAccumulator.cpp
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2009, 2010 Google Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -10,17 +11,17 @@
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
  *
- * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #include "config.h"
@@ -83,6 +84,36 @@ MarkupAccumulator::~MarkupAccumulator()
 {
 }
 
+String MarkupAccumulator::serializeNodes(Node* node, Node* nodeToSkip, EChildrenOnly childrenOnly)
+{
+    Vector<UChar> out;
+    serializeNodesWithNamespaces(node, nodeToSkip, childrenOnly, 0);
+    out.reserveInitialCapacity(length());
+    concatenateMarkup(out);
+    return String::adopt(out);
+}
+
+void MarkupAccumulator::serializeNodesWithNamespaces(Node* node, Node* nodeToSkip, EChildrenOnly childrenOnly, const Namespaces* namespaces)
+{
+    if (node == nodeToSkip)
+        return;
+
+    Namespaces namespaceHash;
+    if (namespaces)
+        namespaceHash = *namespaces;
+
+    if (!childrenOnly)
+        appendStartTag(node, &namespaceHash);
+
+    if (!(node->document()->isHTMLDocument() && elementCannotHaveEndTag(node))) {
+        for (Node* current = node->firstChild(); current; current = current->nextSibling())
+            serializeNodesWithNamespaces(current, nodeToSkip, IncludeNode, &namespaceHash);
+    }
+
+    if (!childrenOnly)
+        appendEndTag(node);
+}
+
 void MarkupAccumulator::appendString(const String& string)
 {
     m_succeedingMarkup.append(string);
@@ -92,7 +123,7 @@ void MarkupAccumulator::appendStartTag(Node* node, Namespaces* namespaces)
 {
     Vector<UChar> markup;
     appendStartMarkup(markup, node, namespaces);
-    m_succeedingMarkup.append(String::adopt(markup));
+    appendString(String::adopt(markup));
     if (m_nodes)
         m_nodes->append(node);
 }
@@ -101,27 +132,24 @@ void MarkupAccumulator::appendEndTag(Node* node)
 {
     Vector<UChar> markup;
     appendEndMarkup(markup, node);
-    m_succeedingMarkup.append(String::adopt(markup));
+    appendString(String::adopt(markup));
+}
+
+size_t MarkupAccumulator::totalLength(const Vector<String>& strings)
+{
+    size_t length = 0;
+    for (size_t i = 0; i < strings.size(); ++i)
+        length += strings[i].length();
+    return length;
 }
 
 // FIXME: This is a very inefficient way of accumulating the markup.
 // We're converting results of appendStartMarkup and appendEndMarkup from Vector<UChar> to String
 // and then back to Vector<UChar> and again to String here.
-String MarkupAccumulator::takeResults()
+void MarkupAccumulator::concatenateMarkup(Vector<UChar>& out)
 {
-    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);
+    for (size_t i = 0; i < m_succeedingMarkup.size(); ++i)
+        append(out, m_succeedingMarkup[i]);
 }
 
 void MarkupAccumulator::appendAttributeValue(Vector<UChar>& result, const String& attribute, bool documentIsHTML)
diff --git a/WebCore/editing/MarkupAccumulator.h b/WebCore/editing/MarkupAccumulator.h
index 3741259..b35d230 100644
--- a/WebCore/editing/MarkupAccumulator.h
+++ b/WebCore/editing/MarkupAccumulator.h
@@ -69,12 +69,15 @@ public:
     MarkupAccumulator(Vector<Node*>* nodes, EAbsoluteURLs shouldResolveURLs, const Range* range = 0);
     virtual ~MarkupAccumulator();
 
+    String serializeNodes(Node* node, Node* nodeToSkip, EChildrenOnly childrenOnly);
+
+protected:
     void appendString(const String&);
     void appendStartTag(Node*, Namespaces* = 0);
     void appendEndTag(Node*);
-    virtual String takeResults();
-
-protected:
+    static size_t totalLength(const Vector<String>&);
+    size_t length() const { return totalLength(m_succeedingMarkup); }
+    void concatenateMarkup(Vector<UChar>& out);
     void appendAttributeValue(Vector<UChar>& result, const String& attribute, bool documentIsHTML);
     void appendQuotedURLAttributeValue(Vector<UChar>& result, const String& urlString);
     void appendNodeValue(Vector<UChar>& out, const Node*, const Range*, EntityMask);
@@ -99,9 +102,11 @@ protected:
 
     Vector<Node*>* const m_nodes;
     const Range* const m_range;
-    Vector<String> m_succeedingMarkup;
 
 private:
+    void serializeNodesWithNamespaces(Node*, Node* nodeToSkip, EChildrenOnly, const Namespaces*);
+
+    Vector<String> m_succeedingMarkup;
     const bool m_shouldResolveURLs;
 };
 
diff --git a/WebCore/editing/markup.cpp b/WebCore/editing/markup.cpp
index bf5bbdb..2219996 100644
--- a/WebCore/editing/markup.cpp
+++ b/WebCore/editing/markup.cpp
@@ -139,11 +139,14 @@ public:
     , m_shouldAnnotate(shouldAnnotate)
     {
     }
+
+    Node* serializeNodes(Node* startNode, Node* pastEnd);
+    void appendString(const String& s) { return MarkupAccumulator::appendString(s); }
     void wrapWithNode(Node*, bool convertBlocksToInlines = false, RangeFullySelectsNode = DoesFullySelectNode);
     void wrapWithStyleNode(CSSStyleDeclaration*, Document*, bool isBlock = false);
     String takeResults();
 
-protected:
+private:
     virtual void appendText(Vector<UChar>& out, Text*);
     String renderedText(const Node*, const Range*);
     String stringValueForRange(const Node*, const Range*);
@@ -153,7 +156,6 @@ protected:
 
     bool shouldAnnotate() { return m_shouldAnnotate == AnnotateForInterchange; }
 
-private:
     Vector<String> m_reversedPrecedingMarkup;
     const EAnnotateForInterchange m_shouldAnnotate;
 };
@@ -186,29 +188,18 @@ void StyledMarkupAccumulator::wrapWithStyleNode(CSSStyleDeclaration* style, Docu
     openTag.append('\"');
     openTag.append('>');
     m_reversedPrecedingMarkup.append(String::adopt(openTag));
-    m_succeedingMarkup.append(isBlock ? divClose : styleSpanClose);
+    appendString(isBlock ? divClose : styleSpanClose);
 }
 
 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();
-
-    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);
+    result.reserveInitialCapacity(totalLength(m_reversedPrecedingMarkup) + length());
 
-    for (size_t i = preCount; i > 0; --i)
+    for (size_t i = m_reversedPrecedingMarkup.size(); i > 0; --i)
         append(result, m_reversedPrecedingMarkup[i - 1]);
 
-    for (size_t i = 0; i < postCount; ++i)
-        append(result, m_succeedingMarkup[i]);
+    concatenateMarkup(result);
 
     return String::adopt(result);
 }
@@ -342,7 +333,7 @@ void StyledMarkupAccumulator::removeExteriorStyles(CSSMutableStyleDeclaration* s
     style->removeProperty(CSSPropertyFloat);
 }
 
-static Node* serializeNodes(StyledMarkupAccumulator& accumulator, Node* startNode, Node* pastEnd)
+Node* StyledMarkupAccumulator::serializeNodes(Node* startNode, Node* pastEnd)
 {
     Vector<Node*> ancestorsToClose;
     Node* next;
@@ -370,11 +361,11 @@ static Node* serializeNodes(StyledMarkupAccumulator& accumulator, Node* startNod
                 next = pastEnd;
         } else {
             // Add the node to the markup if we're not skipping the descendants
-            accumulator.appendStartTag(n);
+            appendStartTag(n);
 
             // If node has no children, close the tag now.
             if (!n->childNodeCount()) {
-                accumulator.appendEndTag(n);
+                appendEndTag(n);
                 lastClosed = n;
             } else {
                 openedTag = true;
@@ -391,7 +382,7 @@ static Node* serializeNodes(StyledMarkupAccumulator& accumulator, Node* startNod
                 if (next != pastEnd && next->isDescendantOf(ancestor))
                     break;
                 // Not at the end of the range, close ancestors up to sibling of next node.
-                accumulator.appendEndTag(ancestor);
+                appendEndTag(ancestor);
                 lastClosed = ancestor;
                 ancestorsToClose.removeLast();
             }
@@ -406,7 +397,7 @@ static Node* serializeNodes(StyledMarkupAccumulator& accumulator, Node* startNod
                         continue;
                     // or b) ancestors that we never encountered during a pre-order traversal starting at startNode:
                     ASSERT(startNode->isDescendantOf(parent));
-                    accumulator.wrapWithNode(parent);
+                    wrapWithNode(parent);
                     lastClosed = parent;
                 }
             }
@@ -630,7 +621,7 @@ String createMarkup(const Range* range, Vector<Node*>* nodes, EAnnotateForInterc
 
     Node* specialCommonAncestor = highestAncestorToWrapMarkup(updatedRange.get(), fullySelectedRoot, shouldAnnotate);
 
-    Node* lastClosed = serializeNodes(accumulator, startNode, pastEnd);
+    Node* lastClosed = accumulator.serializeNodes(startNode, pastEnd);
 
     if (specialCommonAncestor && lastClosed) {
         // Also include all of the ancestors of lastClosed up to this special ancestor.
@@ -726,27 +717,6 @@ PassRefPtr<DocumentFragment> createFragmentFromMarkup(Document* document, const
     return fragment.release();
 }
 
-static void serializeNodesWithNamespaces(MarkupAccumulator& accumulator, Node* node, Node* nodeToSkip, EChildrenOnly childrenOnly, const Namespaces* namespaces)
-{
-    if (node == nodeToSkip)
-        return;
-
-    Namespaces namespaceHash;
-    if (namespaces)
-        namespaceHash = *namespaces;
-
-    if (!childrenOnly)
-        accumulator.appendStartTag(node, &namespaceHash);
-
-    if (!(node->document()->isHTMLDocument() && elementCannotHaveEndTag(node))) {
-        for (Node* current = node->firstChild(); current; current = current->nextSibling())
-            serializeNodesWithNamespaces(accumulator, current, nodeToSkip, IncludeNode, &namespaceHash);
-    }
-
-    if (!childrenOnly)
-        accumulator.appendEndTag(node);
-}
-
 String createMarkup(const Node* node, EChildrenOnly childrenOnly, Vector<Node*>* nodes, EAbsoluteURLs shouldResolveURLs)
 {
     if (!node)
@@ -760,8 +730,7 @@ String createMarkup(const Node* node, EChildrenOnly childrenOnly, Vector<Node*>*
     }
 
     MarkupAccumulator accumulator(nodes, shouldResolveURLs);
-    serializeNodesWithNamespaces(accumulator, const_cast<Node*>(node), deleteButtonContainerElement, childrenOnly, 0);
-    return accumulator.takeResults();
+    return accumulator.serializeNodes(const_cast<Node*>(node), deleteButtonContainerElement, childrenOnly);
 }
 
 static void fillContainerFromString(ContainerNode* paragraph, const String& string)

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list