Changeset 64477 in webkit
- Timestamp:
- Aug 2, 2010 11:13:59 AM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r64476 r64477 1 2010-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 1 23 2010-08-02 Brian Weinstein <bweinstein@apple.com> 2 24 -
trunk/WebCore/editing/markup.cpp
r61178 r64477 556 556 } 557 557 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 565 558 static inline bool doesHTMLForbidEndTag(const Node *node) 566 559 { … … 597 590 append(result, static_cast<const Element*>(node)->nodeNamePreservingCase()); 598 591 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);606 592 } 607 593 … … 723 709 } 724 710 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 749 711 static bool isSpecialAncestorBlock(Node* node) 750 712 { … … 774 736 } 775 737 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 } 738 class MarkupAccumulatorWrapper { 739 public: 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 816 private: 817 Vector<String> preMarkups; 818 Vector<String> postMarkups; 819 }; 794 820 795 821 // FIXME: Shouldn't we omit style info when annotate == DoNotAnnotateForInterchange? … … 829 855 document->updateLayoutIgnorePendingStylesheets(); 830 856 831 Vector<String> markups; 832 Vector<String> preMarkups; 857 MarkupAccumulatorWrapper accumulator; 833 858 Node* pastEnd = updatedRange->pastLastNode(); 834 859 Node* lastClosed = 0; … … 845 870 } 846 871 847 markups.append(interchangeNewlineString);872 accumulator.insertString(interchangeNewlineString); 848 873 startNode = visibleStart.next().deepEquivalent().node(); 849 874 … … 884 909 // Add the node to the markup. 885 910 if (addMarkupForNode) { 886 markups.append(getStartMarkup(n, updatedRange.get(), annotate, absoluteURLs)); 911 912 accumulator.insertOpenTag(n, updatedRange.get(), annotate, absoluteURLs); 887 913 if (nodes) 888 914 nodes->append(n); … … 892 918 // Node has no children, or we are skipping it's descendants, add its close tag now. 893 919 if (addMarkupForNode) { 894 markups.append(getEndMarkup(n));920 accumulator.insertEndTag(n); 895 921 lastClosed = n; 896 922 } … … 905 931 break; 906 932 // Not at the end of the range, close ancestors up to sibling of next node. 907 markups.append(getEndMarkup(ancestor));933 accumulator.insertEndTag(ancestor); 908 934 lastClosed = ancestor; 909 935 ancestorsToClose.removeLast(); … … 921 947 // or b) ancestors that we never encountered during a pre-order traversal starting at startNode: 922 948 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); 925 950 if (nodes) 926 951 nodes->append(parent); … … 1002 1027 if (!propertyMissingOrEqualToNone(fullySelectedRootStyle.get(), CSSPropertyWebkitTextDecorationsInEffect)) 1003 1028 fullySelectedRootStyle->setProperty(CSSPropertyWebkitTextDecorationsInEffect, CSSValueNone); 1004 a ddStyleMarkup(preMarkups, markups,fullySelectedRootStyle.get(), document, true);1029 accumulator.wrapWithStyleNode(fullySelectedRootStyle.get(), document, true); 1005 1030 } 1006 1031 } else { 1007 1032 // Since this node and all the other ancestors are not in the selection we want to set RangeFullySelectsNode to DoesNotFullySelectNode 1008 1033 // 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); 1011 1035 } 1012 1036 if (nodes) … … 1040 1064 1041 1065 if (style->length() > 0) 1042 a ddStyleMarkup(preMarkups, markups,style.get(), document);1066 accumulator.wrapWithStyleNode(style.get(), document); 1043 1067 } 1044 1068 … … 1050 1074 1051 1075 if (defaultStyle->length() > 0) 1052 a ddStyleMarkup(preMarkups, markups,defaultStyle.get(), document);1076 accumulator.wrapWithStyleNode(defaultStyle.get(), document); 1053 1077 } 1054 1078 1055 1079 // FIXME: The interchange newline should be placed in the block that it's in, not after all of the content, unconditionally. 1056 1080 if (annotate && needInterchangeNewlineAfter(visibleEnd.previous())) 1057 markups.append(interchangeNewlineString);1058 1081 accumulator.insertString(interchangeNewlineString); 1082 1059 1083 if (deleteButton) 1060 1084 deleteButton->enable(); 1061 1085 1062 return joinMarkups(preMarkups, markups);1086 return accumulator.takeResults(); 1063 1087 } 1064 1088
Note: See TracChangeset
for help on using the changeset viewer.