Changeset 65265 in webkit


Ignore:
Timestamp:
Aug 12, 2010 2:06:42 PM (14 years ago)
Author:
rniwa@webkit.org
Message:

2010-08-11 Ryosuke Niwa <rniwa@webkit.org>

Reviewed by Kent Tamura.

merge MarkupAccumulator and MarkupAccumulatorWrapper
https://bugs.webkit.org/show_bug.cgi?id=43834

Removed MarkupAccumulator and added serializeNodesWithNamespaces to use MarkupAccumulatorWrapper
in both versions of createMarkup. Accumulation of nodes done manually in serializeNodes is
now done by MarkupAccumulatorWrapper as done in the original MarkupAccumulator.

No new tests added since this is a cleanup.

  • editing/markup.cpp: (WebCore::MarkupAccumulatorWrapper::MarkupAccumulatorWrapper): Takes vector of nodes and set it to m_nodes. (WebCore::MarkupAccumulatorWrapper::insertOpenTag): Adds node to m_nodes. (WebCore::MarkupAccumulatorWrapper::wrapWithNode): Adds node to m_nodes. (WebCore::serializeNodes): Adding node to nodes is moved into MarkupAccumulatorWrapper. (WebCore::createMarkup): Instantiates MarkupAccumulatorWrapper. (WebCore::serializeNodesWithNamespaces): Renamed from MarkupAccumulator::appendMarkup.
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r65261 r65265  
     12010-08-11  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Reviewed by Kent Tamura.
     4
     5        merge MarkupAccumulator and MarkupAccumulatorWrapper
     6        https://bugs.webkit.org/show_bug.cgi?id=43834
     7
     8        Removed MarkupAccumulator and added serializeNodesWithNamespaces to use MarkupAccumulatorWrapper
     9        in both versions of createMarkup.  Accumulation of nodes done manually in serializeNodes is
     10        now done by MarkupAccumulatorWrapper as done in the original MarkupAccumulator.
     11
     12        No new tests added since this is a cleanup.
     13
     14        * editing/markup.cpp:
     15        (WebCore::MarkupAccumulatorWrapper::MarkupAccumulatorWrapper): Takes vector of nodes and set it to m_nodes.
     16        (WebCore::MarkupAccumulatorWrapper::insertOpenTag): Adds node to m_nodes.
     17        (WebCore::MarkupAccumulatorWrapper::wrapWithNode): Adds node to m_nodes.
     18        (WebCore::serializeNodes): Adding node to nodes is moved into MarkupAccumulatorWrapper.
     19        (WebCore::createMarkup): Instantiates MarkupAccumulatorWrapper.
     20        (WebCore::serializeNodesWithNamespaces): Renamed from MarkupAccumulator::appendMarkup.
     21
    1222010-08-12  Dirk Schulze  <krit@webkit.org>
    223
  • trunk/WebCore/editing/markup.cpp

    r65021 r65265  
    592592}
    593593
    594 class MarkupAccumulator {
    595 public:
    596     MarkupAccumulator(Node* nodeToSkip, Vector<Node*>* nodes)
    597         : m_nodeToSkip(nodeToSkip)
    598         , m_nodes(nodes)
    599     {
    600     }
    601 
    602     void appendMarkup(Node* startNode, EChildrenOnly, EAbsoluteURLs, const HashMap<AtomicStringImpl*, AtomicStringImpl*>* namespaces = 0);
    603 
    604     String takeResult() { return String::adopt(m_result); }
    605 
    606 private:
    607     Vector<UChar> m_result;
    608     Node* m_nodeToSkip;
    609     Vector<Node*>* m_nodes;
    610 };
    611 
    612 // FIXME: Would be nice to do this in a non-recursive way.
    613 void MarkupAccumulator::appendMarkup(Node* startNode, EChildrenOnly childrenOnly, EAbsoluteURLs absoluteURLs, const HashMap<AtomicStringImpl*, AtomicStringImpl*>* namespaces)
    614 {
    615     if (startNode == m_nodeToSkip)
    616         return;
    617 
    618     HashMap<AtomicStringImpl*, AtomicStringImpl*> namespaceHash;
    619     if (namespaces)
    620         namespaceHash = *namespaces;
    621 
    622     // start tag
    623     if (!childrenOnly) {
    624         if (m_nodes)
    625             m_nodes->append(startNode);
    626         appendStartMarkup(m_result, startNode, 0, DoNotAnnotateForInterchange, absoluteURLs, false, &namespaceHash);
    627     }
    628 
    629     // children
    630     if (!(startNode->document()->isHTMLDocument() && doesHTMLForbidEndTag(startNode))) {
    631         for (Node* current = startNode->firstChild(); current; current = current->nextSibling())
    632             appendMarkup(current, IncludeNode, absoluteURLs, &namespaceHash);
    633     }
    634 
    635     // end tag
    636     if (!childrenOnly)
    637         appendEndMarkup(m_result, startNode);
    638 }
    639 
    640594static void completeURLs(Node* node, const String& baseURL)
    641595{
     
    738692class MarkupAccumulatorWrapper {
    739693public:
    740     MarkupAccumulatorWrapper()
     694    MarkupAccumulatorWrapper(Vector<Node*>* nodes)
     695    : m_nodes(nodes)
    741696    {
    742697    }
     
    747702    }
    748703
    749     void insertOpenTag(const Node* node, const Range* range, EAnnotateForInterchange annotate, EAbsoluteURLs absoluteURLs, bool convertBlocksToInlines = false, RangeFullySelectsNode rangeFullySelectsNode = DoesFullySelectNode)
     704    void insertOpenTag(const Node* node, const Range* range, EAnnotateForInterchange annotate, EAbsoluteURLs absoluteURLs, bool convertBlocksToInlines = false, HashMap<AtomicStringImpl*, AtomicStringImpl*>* namespaces = 0, RangeFullySelectsNode rangeFullySelectsNode = DoesFullySelectNode)
    750705    {
    751706        Vector<UChar> result;
    752         appendStartMarkup(result, node, range, annotate, absoluteURLs, convertBlocksToInlines, 0, rangeFullySelectsNode);
     707        appendStartMarkup(result, node, range, annotate, absoluteURLs, convertBlocksToInlines, namespaces, rangeFullySelectsNode);
    753708        postMarkups.append(String::adopt(result));
     709        if (m_nodes)
     710            m_nodes->append(const_cast<Node*>(node));
    754711    }
    755712
     
    761718    }
    762719
    763     void wrapWithNode(const Node* node, const Range* range, EAnnotateForInterchange annotate, EAbsoluteURLs absoluteURLs, bool convertBlocksToInlines = false, RangeFullySelectsNode rangeFullySelectsNode = DoesFullySelectNode)
     720    void wrapWithNode(const Node* node, const Range* range, EAnnotateForInterchange annotate, EAbsoluteURLs absoluteURLs, bool convertBlocksToInlines = false, HashMap<AtomicStringImpl*, AtomicStringImpl*>* namespaces = 0, RangeFullySelectsNode rangeFullySelectsNode = DoesFullySelectNode)
    764721    {
    765722        Vector<UChar> result;
    766         appendStartMarkup(result, node, range, annotate, absoluteURLs, convertBlocksToInlines, 0, rangeFullySelectsNode);
     723        appendStartMarkup(result, node, range, annotate, absoluteURLs, convertBlocksToInlines, namespaces, rangeFullySelectsNode);
    767724        preMarkups.append(String::adopt(result));
    768725        insertEndTag(node);
     726        if (m_nodes)
     727            m_nodes->append(const_cast<Node*>(node));
    769728    }
    770729
     
    815774
    816775private:
     776    Vector<Node*>* m_nodes;
    817777    Vector<String> preMarkups;
    818778    Vector<String> postMarkups;
    819779};
    820780
    821 static Node* serializeNodes(MarkupAccumulatorWrapper& accumulator, Node* startNode, Node* pastEnd, Vector<Node*>* nodes, const Range* range, EAnnotateForInterchange annotate, EAbsoluteURLs absoluteURLs)
     781static Node* serializeNodes(MarkupAccumulatorWrapper& accumulator, Node* startNode, Node* pastEnd, const Range* range, EAnnotateForInterchange annotate, EAbsoluteURLs absoluteURLs)
    822782{
    823783    Vector<Node*> ancestorsToClose;
     
    848808            // Add the node to the markup if we're not skipping the descendants
    849809            accumulator.insertOpenTag(n, range, annotate, absoluteURLs);
    850             if (nodes)
    851                 nodes->append(n);
    852810
    853811            // If node has no children, close the tag now.
     
    886844                    ASSERT(startNode->isDescendantOf(parent));
    887845                    accumulator.wrapWithNode(parent, range, annotate, absoluteURLs);
    888                     if (nodes)
    889                         nodes->append(parent);
    890846                    lastClosed = parent;
    891847                }
     
    933889    document->updateLayoutIgnorePendingStylesheets();
    934890
    935     MarkupAccumulatorWrapper accumulator;
     891    MarkupAccumulatorWrapper accumulator(nodes);
    936892    Node* pastEnd = updatedRange->pastLastNode();
    937893
     
    956912    }
    957913
    958     Node* lastClosed = serializeNodes(accumulator, startNode, pastEnd, nodes, range, annotate, absoluteURLs);
     914    Node* lastClosed = serializeNodes(accumulator, startNode, pastEnd, range, annotate, absoluteURLs);
    959915
    960916    // Include ancestors that aren't completely inside the range but are required to retain
     
    1031987                // Since this node and all the other ancestors are not in the selection we want to set RangeFullySelectsNode to DoesNotFullySelectNode
    1032988                // so that styles that affect the exterior of the node are not included.
    1033                 accumulator.wrapWithNode(ancestor, updatedRange.get(), annotate, absoluteURLs, convertBlocksToInlines, DoesNotFullySelectNode);
     989                accumulator.wrapWithNode(ancestor, updatedRange.get(), annotate, absoluteURLs, convertBlocksToInlines, 0, DoesNotFullySelectNode);
    1034990            }
    1035991            if (nodes)
     
    10961052}
    10971053
     1054static void serializeNodesWithNamespaces(MarkupAccumulatorWrapper& accumulator, const Node* node, Node* nodeToSkip, EChildrenOnly childrenOnly, EAbsoluteURLs absoluteURLs, const HashMap<AtomicStringImpl*, AtomicStringImpl*>* namespaces)
     1055{
     1056    if (node == nodeToSkip)
     1057        return;
     1058
     1059    HashMap<AtomicStringImpl*, AtomicStringImpl*> namespaceHash;
     1060    if (namespaces)
     1061        namespaceHash = *namespaces;
     1062
     1063    if (!childrenOnly)
     1064        accumulator.insertOpenTag(node, 0, DoNotAnnotateForInterchange, absoluteURLs, false, &namespaceHash);
     1065
     1066    if (!(node->document()->isHTMLDocument() && doesHTMLForbidEndTag(node))) {
     1067        for (Node* current = node->firstChild(); current; current = current->nextSibling())
     1068            serializeNodesWithNamespaces(accumulator, current, nodeToSkip, IncludeNode, absoluteURLs, &namespaceHash);
     1069    }
     1070
     1071    if (!childrenOnly)
     1072        accumulator.insertEndTag(node);
     1073}
     1074
    10981075String createMarkup(const Node* node, EChildrenOnly childrenOnly, Vector<Node*>* nodes, EAbsoluteURLs absoluteURLs)
    10991076{
     
    11081085    }
    11091086
    1110     MarkupAccumulator accumulator(deleteButtonContainerElement, nodes);
    1111     accumulator.appendMarkup(const_cast<Node*>(node), childrenOnly, absoluteURLs);
    1112     return accumulator.takeResult();
     1087    MarkupAccumulatorWrapper accumulator(nodes);
     1088    serializeNodesWithNamespaces(accumulator, node, deleteButtonContainerElement, childrenOnly, absoluteURLs, 0);
     1089    return accumulator.takeResults();
    11131090}
    11141091
Note: See TracChangeset for help on using the changeset viewer.