Changeset 64477 in webkit


Ignore:
Timestamp:
Aug 2, 2010 11:13:59 AM (14 years ago)
Author:
rniwa@webkit.org
Message:

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

Reviewed by Kent Tamura.

Group functions used in createMarkup (range version) into a class so they are easier to understand
https://bugs.webkit.org/show_bug.cgi?id=43227

Added MarkupAccumulatorWrapper to group getStartMarkup, getEndMarkup, joinMarkups, and addStyleMarkup.
MarkupAccumulatorWrapper is intended to be merged with MarkupAccumulator in the future.

No new tests added since this is a clean up.

  • editing/markup.cpp: (WebCore::MarkupAccumulatorWrapper::MarkupAccumulatorWrapper): Added. (WebCore::MarkupAccumulatorWrapper::insertString): Added. (WebCore::MarkupAccumulatorWrapper::insertOpenTag): Added. (WebCore::MarkupAccumulatorWrapper::insertEndTag): Added. (WebCore::MarkupAccumulatorWrapper::wrapWithNode): Added. (WebCore::MarkupAccumulatorWrapper::wrapWithStyleNode): Added. (WebCore::MarkupAccumulatorWrapper::takeResults): Added. (WebCore::createMarkup): Uses MarkupAccumulatorWrapper.
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r64476 r64477  
     12010-08-02  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        Reviewed by Kent Tamura.
     4
     5        Group functions used in createMarkup (range version) into a class so they are easier to understand
     6        https://bugs.webkit.org/show_bug.cgi?id=43227
     7
     8        Added MarkupAccumulatorWrapper to group getStartMarkup, getEndMarkup, joinMarkups, and addStyleMarkup.
     9        MarkupAccumulatorWrapper is intended to be merged with MarkupAccumulator in the future.
     10
     11        No new tests added since this is a clean up.
     12
     13        * editing/markup.cpp:
     14        (WebCore::MarkupAccumulatorWrapper::MarkupAccumulatorWrapper): Added.
     15        (WebCore::MarkupAccumulatorWrapper::insertString): Added.
     16        (WebCore::MarkupAccumulatorWrapper::insertOpenTag): Added.
     17        (WebCore::MarkupAccumulatorWrapper::insertEndTag): Added.
     18        (WebCore::MarkupAccumulatorWrapper::wrapWithNode): Added.
     19        (WebCore::MarkupAccumulatorWrapper::wrapWithStyleNode): Added.
     20        (WebCore::MarkupAccumulatorWrapper::takeResults): Added.
     21        (WebCore::createMarkup): Uses MarkupAccumulatorWrapper.
     22
    1232010-08-02  Brian Weinstein  <bweinstein@apple.com>
    224
  • trunk/WebCore/editing/markup.cpp

    r61178 r64477  
    556556}
    557557
    558 static String getStartMarkup(const Node* node, const Range* range, EAnnotateForInterchange annotate, EAbsoluteURLs absoluteURLs, bool convertBlocksToInlines = false, HashMap<AtomicStringImpl*, AtomicStringImpl*>* namespaces = 0, RangeFullySelectsNode rangeFullySelectsNode = DoesFullySelectNode)
    559 {
    560     Vector<UChar> result;
    561     appendStartMarkup(result, node, range, annotate, absoluteURLs, convertBlocksToInlines, namespaces, rangeFullySelectsNode);
    562     return String::adopt(result);
    563 }
    564 
    565558static inline bool doesHTMLForbidEndTag(const Node *node)
    566559{
     
    597590    append(result, static_cast<const Element*>(node)->nodeNamePreservingCase());
    598591    result.append('>');
    599 }
    600 
    601 static String getEndMarkup(const Node *node)
    602 {
    603     Vector<UChar> result;
    604     appendEndMarkup(result, node);
    605     return String::adopt(result);
    606592}
    607593
     
    723709}
    724710
    725 static String joinMarkups(const Vector<String>& preMarkups, const Vector<String>& postMarkups)
    726 {
    727     size_t length = 0;
    728 
    729     size_t preCount = preMarkups.size();
    730     for (size_t i = 0; i < preCount; ++i)
    731         length += preMarkups[i].length();
    732 
    733     size_t postCount = postMarkups.size();
    734     for (size_t i = 0; i < postCount; ++i)
    735         length += postMarkups[i].length();
    736 
    737     Vector<UChar> result;
    738     result.reserveInitialCapacity(length);
    739 
    740     for (size_t i = preCount; i > 0; --i)
    741         append(result, preMarkups[i - 1]);
    742 
    743     for (size_t i = 0; i < postCount; ++i)
    744         append(result, postMarkups[i]);
    745 
    746     return String::adopt(result);
    747 }
    748 
    749711static bool isSpecialAncestorBlock(Node* node)
    750712{
     
    774736}
    775737
    776 static void addStyleMarkup(Vector<String>& preMarkups, Vector<String>& postMarkups, CSSStyleDeclaration* style, Document* document, bool isBlock = false)
    777 {
    778     // All text-decoration-related elements should have been treated as special ancestors
    779     // If we ever hit this ASSERT, we should export StyleChange in ApplyStyleCommand and use it here
    780     ASSERT(propertyMissingOrEqualToNone(style, CSSPropertyTextDecoration) && propertyMissingOrEqualToNone(style, CSSPropertyWebkitTextDecorationsInEffect));
    781     DEFINE_STATIC_LOCAL(const String, divStyle, ("<div style=\""));
    782     DEFINE_STATIC_LOCAL(const String, divClose, ("</div>"));
    783     DEFINE_STATIC_LOCAL(const String, styleSpanOpen, ("<span class=\"" AppleStyleSpanClass "\" style=\""));
    784     DEFINE_STATIC_LOCAL(const String, styleSpanClose, ("</span>"));
    785     Vector<UChar> openTag;
    786     append(openTag, isBlock ? divStyle : styleSpanOpen);
    787     appendAttributeValue(openTag, style->cssText(), document->isHTMLDocument());
    788     openTag.append('\"');
    789     openTag.append('>');
    790     preMarkups.append(String::adopt(openTag));
    791 
    792     postMarkups.append(isBlock ? divClose : styleSpanClose);
    793 }
     738class MarkupAccumulatorWrapper {
     739public:
     740    MarkupAccumulatorWrapper()
     741    {
     742    }
     743
     744    void insertString(const String& s)
     745    {
     746        postMarkups.append(s);
     747    }
     748
     749    void insertOpenTag(const Node* node, const Range* range, EAnnotateForInterchange annotate, EAbsoluteURLs absoluteURLs, bool convertBlocksToInlines = false, RangeFullySelectsNode rangeFullySelectsNode = DoesFullySelectNode)
     750    {
     751        Vector<UChar> result;
     752        appendStartMarkup(result, node, range, annotate, absoluteURLs, convertBlocksToInlines, 0, rangeFullySelectsNode);
     753        postMarkups.append(String::adopt(result));
     754    }
     755
     756    void insertEndTag(const Node* node)
     757    {
     758        Vector<UChar> result;
     759        appendEndMarkup(result, node);
     760        postMarkups.append(String::adopt(result));
     761    }
     762
     763    void wrapWithNode(const Node* node, const Range* range, EAnnotateForInterchange annotate, EAbsoluteURLs absoluteURLs, bool convertBlocksToInlines = false, RangeFullySelectsNode rangeFullySelectsNode = DoesFullySelectNode)
     764    {
     765        Vector<UChar> result;
     766        appendStartMarkup(result, node, range, annotate, absoluteURLs, convertBlocksToInlines, 0, rangeFullySelectsNode);
     767        preMarkups.append(String::adopt(result));
     768        insertEndTag(node);
     769    }
     770
     771    void wrapWithStyleNode(CSSStyleDeclaration* style, Document* document, bool isBlock = false)
     772    {
     773        // All text-decoration-related elements should have been treated as special ancestors
     774        // If we ever hit this ASSERT, we should export StyleChange in ApplyStyleCommand and use it here
     775        ASSERT(propertyMissingOrEqualToNone(style, CSSPropertyTextDecoration) && propertyMissingOrEqualToNone(style, CSSPropertyWebkitTextDecorationsInEffect));
     776        DEFINE_STATIC_LOCAL(const String, divStyle, ("<div style=\""));
     777        DEFINE_STATIC_LOCAL(const String, divClose, ("</div>"));
     778        DEFINE_STATIC_LOCAL(const String, styleSpanOpen, ("<span class=\"" AppleStyleSpanClass "\" style=\""));
     779        DEFINE_STATIC_LOCAL(const String, styleSpanClose, ("</span>"));
     780        Vector<UChar> openTag;
     781        WebCore::append(openTag, isBlock ? divStyle : styleSpanOpen);
     782        appendAttributeValue(openTag, style->cssText(), document->isHTMLDocument());
     783        openTag.append('\"');
     784        openTag.append('>');
     785        preMarkups.append(String::adopt(openTag));
     786        postMarkups.append(isBlock ? divClose : styleSpanClose);
     787    }
     788
     789    // FIXME: This is a very inefficient way of accumulating the markup.
     790    // We're converting results of appendStartMarkup and appendEndMarkup from Vector<UChar> to String
     791    // and then back to Vector<UChar> and again to String here.
     792    String takeResults()
     793    {
     794        size_t length = 0;
     795
     796        size_t preCount = preMarkups.size();
     797        for (size_t i = 0; i < preCount; ++i)
     798            length += preMarkups[i].length();
     799
     800        size_t postCount = postMarkups.size();
     801        for (size_t i = 0; i < postCount; ++i)
     802            length += postMarkups[i].length();
     803
     804        Vector<UChar> result;
     805        result.reserveInitialCapacity(length);
     806
     807        for (size_t i = preCount; i > 0; --i)
     808            WebCore::append(result, preMarkups[i - 1]);
     809
     810        for (size_t i = 0; i < postCount; ++i)
     811            WebCore::append(result, postMarkups[i]);
     812
     813        return String::adopt(result);
     814    }
     815
     816private:
     817    Vector<String> preMarkups;
     818    Vector<String> postMarkups;
     819};
    794820
    795821// FIXME: Shouldn't we omit style info when annotate == DoNotAnnotateForInterchange?
     
    829855    document->updateLayoutIgnorePendingStylesheets();
    830856
    831     Vector<String> markups;
    832     Vector<String> preMarkups;
     857    MarkupAccumulatorWrapper accumulator;
    833858    Node* pastEnd = updatedRange->pastLastNode();
    834859    Node* lastClosed = 0;
     
    845870        }
    846871
    847         markups.append(interchangeNewlineString);
     872        accumulator.insertString(interchangeNewlineString);
    848873        startNode = visibleStart.next().deepEquivalent().node();
    849874
     
    884909        // Add the node to the markup.
    885910        if (addMarkupForNode) {
    886             markups.append(getStartMarkup(n, updatedRange.get(), annotate, absoluteURLs));
     911
     912            accumulator.insertOpenTag(n, updatedRange.get(), annotate, absoluteURLs);
    887913            if (nodes)
    888914                nodes->append(n);
     
    892918            // Node has no children, or we are skipping it's descendants, add its close tag now.
    893919            if (addMarkupForNode) {
    894                 markups.append(getEndMarkup(n));
     920                accumulator.insertEndTag(n);
    895921                lastClosed = n;
    896922            }
     
    905931                            break;
    906932                        // Not at the end of the range, close ancestors up to sibling of next node.
    907                         markups.append(getEndMarkup(ancestor));
     933                        accumulator.insertEndTag(ancestor);
    908934                        lastClosed = ancestor;
    909935                        ancestorsToClose.removeLast();
     
    921947                        // or b) ancestors that we never encountered during a pre-order traversal starting at startNode:
    922948                        ASSERT(startNode->isDescendantOf(parent));
    923                         preMarkups.append(getStartMarkup(parent, updatedRange.get(), annotate, absoluteURLs));
    924                         markups.append(getEndMarkup(parent));
     949                        accumulator.wrapWithNode(parent, updatedRange.get(), annotate, absoluteURLs);
    925950                        if (nodes)
    926951                            nodes->append(parent);
     
    10021027                    if (!propertyMissingOrEqualToNone(fullySelectedRootStyle.get(), CSSPropertyWebkitTextDecorationsInEffect))
    10031028                        fullySelectedRootStyle->setProperty(CSSPropertyWebkitTextDecorationsInEffect, CSSValueNone);
    1004                     addStyleMarkup(preMarkups, markups, fullySelectedRootStyle.get(), document, true);
     1029                    accumulator.wrapWithStyleNode(fullySelectedRootStyle.get(), document, true);
    10051030                }
    10061031            } else {
    10071032                // Since this node and all the other ancestors are not in the selection we want to set RangeFullySelectsNode to DoesNotFullySelectNode
    10081033                // so that styles that affect the exterior of the node are not included.
    1009                 preMarkups.append(getStartMarkup(ancestor, updatedRange.get(), annotate, absoluteURLs, convertBlocksToInlines, 0, DoesNotFullySelectNode));
    1010                 markups.append(getEndMarkup(ancestor));
     1034                accumulator.wrapWithNode(ancestor, updatedRange.get(), annotate, absoluteURLs, convertBlocksToInlines, DoesNotFullySelectNode);
    10111035            }
    10121036            if (nodes)
     
    10401064
    10411065        if (style->length() > 0)
    1042             addStyleMarkup(preMarkups, markups, style.get(), document);
     1066            accumulator.wrapWithStyleNode(style.get(), document);
    10431067    }
    10441068   
     
    10501074
    10511075        if (defaultStyle->length() > 0)
    1052             addStyleMarkup(preMarkups, markups, defaultStyle.get(), document);
     1076            accumulator.wrapWithStyleNode(defaultStyle.get(), document);
    10531077    }
    10541078
    10551079    // FIXME: The interchange newline should be placed in the block that it's in, not after all of the content, unconditionally.
    10561080    if (annotate && needInterchangeNewlineAfter(visibleEnd.previous()))
    1057         markups.append(interchangeNewlineString);
    1058    
     1081        accumulator.insertString(interchangeNewlineString);
     1082
    10591083    if (deleteButton)
    10601084        deleteButton->enable();
    10611085
    1062     return joinMarkups(preMarkups, markups);
     1086    return accumulator.takeResults();
    10631087}
    10641088
Note: See TracChangeset for help on using the changeset viewer.