| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. |
| 3 * Copyright (C) 2008, 2009, 2010, 2011 Google Inc. All rights reserved. | 3 * Copyright (C) 2008, 2009, 2010, 2011 Google Inc. All rights reserved. |
| 4 * Copyright (C) 2011 Igalia S.L. | 4 * Copyright (C) 2011 Igalia S.L. |
| 5 * Copyright (C) 2011 Motorola Mobility. All rights reserved. | 5 * Copyright (C) 2011 Motorola Mobility. All rights reserved. |
| 6 * | 6 * |
| 7 * Redistribution and use in source and binary forms, with or without | 7 * Redistribution and use in source and binary forms, with or without |
| 8 * modification, are permitted provided that the following conditions | 8 * modification, are permitted provided that the following conditions |
| 9 * are met: | 9 * are met: |
| 10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
| (...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 745 | 745 |
| 746 MarkupAccumulator accumulator(nodes, shouldResolveURLs); | 746 MarkupAccumulator accumulator(nodes, shouldResolveURLs); |
| 747 return accumulator.serializeNodes(const_cast<Node*>(node), childrenOnly, tag
NamesToSkip); | 747 return accumulator.serializeNodes(const_cast<Node*>(node), childrenOnly, tag
NamesToSkip); |
| 748 } | 748 } |
| 749 | 749 |
| 750 static void fillContainerFromString(ContainerNode* paragraph, const String& stri
ng) | 750 static void fillContainerFromString(ContainerNode* paragraph, const String& stri
ng) |
| 751 { | 751 { |
| 752 Document& document = paragraph->document(); | 752 Document& document = paragraph->document(); |
| 753 | 753 |
| 754 if (string.isEmpty()) { | 754 if (string.isEmpty()) { |
| 755 paragraph->appendChild(createBlockPlaceholderElement(&document)); | 755 paragraph->appendChild(createBlockPlaceholderElement(document)); |
| 756 return; | 756 return; |
| 757 } | 757 } |
| 758 | 758 |
| 759 ASSERT(string.find('\n') == notFound); | 759 ASSERT(string.find('\n') == notFound); |
| 760 | 760 |
| 761 Vector<String> tabList; | 761 Vector<String> tabList; |
| 762 string.split('\t', true, tabList); | 762 string.split('\t', true, tabList); |
| 763 String tabText = emptyString(); | 763 String tabText = emptyString(); |
| 764 bool first = true; | 764 bool first = true; |
| 765 size_t numEntries = tabList.size(); | 765 size_t numEntries = tabList.size(); |
| 766 for (size_t i = 0; i < numEntries; ++i) { | 766 for (size_t i = 0; i < numEntries; ++i) { |
| 767 const String& s = tabList[i]; | 767 const String& s = tabList[i]; |
| 768 | 768 |
| 769 // append the non-tab textual part | 769 // append the non-tab textual part |
| 770 if (!s.isEmpty()) { | 770 if (!s.isEmpty()) { |
| 771 if (!tabText.isEmpty()) { | 771 if (!tabText.isEmpty()) { |
| 772 paragraph->appendChild(createTabSpanElement(&document, tabText))
; | 772 paragraph->appendChild(createTabSpanElement(document, tabText)); |
| 773 tabText = emptyString(); | 773 tabText = emptyString(); |
| 774 } | 774 } |
| 775 RefPtr<Node> textNode = document.createTextNode(stringWithRebalanced
Whitespace(s, first, i + 1 == numEntries)); | 775 RefPtr<Node> textNode = document.createTextNode(stringWithRebalanced
Whitespace(s, first, i + 1 == numEntries)); |
| 776 paragraph->appendChild(textNode.release()); | 776 paragraph->appendChild(textNode.release()); |
| 777 } | 777 } |
| 778 | 778 |
| 779 // there is a tab after every entry, except the last entry | 779 // there is a tab after every entry, except the last entry |
| 780 // (if the last character is a tab, the list gets an extra empty entry) | 780 // (if the last character is a tab, the list gets an extra empty entry) |
| 781 if (i + 1 != numEntries) | 781 if (i + 1 != numEntries) |
| 782 tabText.append('\t'); | 782 tabText.append('\t'); |
| 783 else if (!tabText.isEmpty()) | 783 else if (!tabText.isEmpty()) |
| 784 paragraph->appendChild(createTabSpanElement(&document, tabText)); | 784 paragraph->appendChild(createTabSpanElement(document, tabText)); |
| 785 | 785 |
| 786 first = false; | 786 first = false; |
| 787 } | 787 } |
| 788 } | 788 } |
| 789 | 789 |
| 790 bool isPlainTextMarkup(Node *node) | 790 bool isPlainTextMarkup(Node *node) |
| 791 { | 791 { |
| 792 if (!node->isElementNode() || !node->hasTagName(divTag) || toElement(node)->
hasAttributes()) | 792 if (!node->isElementNode() || !node->hasTagName(divTag) || toElement(node)->
hasAttributes()) |
| 793 return false; | 793 return false; |
| 794 | 794 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 811 } | 811 } |
| 812 | 812 |
| 813 return false; | 813 return false; |
| 814 } | 814 } |
| 815 | 815 |
| 816 PassRefPtr<DocumentFragment> createFragmentFromText(Range* context, const String
& text) | 816 PassRefPtr<DocumentFragment> createFragmentFromText(Range* context, const String
& text) |
| 817 { | 817 { |
| 818 if (!context) | 818 if (!context) |
| 819 return 0; | 819 return 0; |
| 820 | 820 |
| 821 Document* document = context->ownerDocument(); | 821 Document& document = *context->ownerDocument(); |
| 822 RefPtr<DocumentFragment> fragment = document->createDocumentFragment(); | 822 RefPtr<DocumentFragment> fragment = document.createDocumentFragment(); |
| 823 | 823 |
| 824 if (text.isEmpty()) | 824 if (text.isEmpty()) |
| 825 return fragment.release(); | 825 return fragment.release(); |
| 826 | 826 |
| 827 String string = text; | 827 String string = text; |
| 828 string.replace("\r\n", "\n"); | 828 string.replace("\r\n", "\n"); |
| 829 string.replace('\r', '\n'); | 829 string.replace('\r', '\n'); |
| 830 | 830 |
| 831 if (shouldPreserveNewline(*context)) { | 831 if (shouldPreserveNewline(*context)) { |
| 832 fragment->appendChild(document->createTextNode(string)); | 832 fragment->appendChild(document.createTextNode(string)); |
| 833 if (string.endsWith('\n')) { | 833 if (string.endsWith('\n')) { |
| 834 RefPtr<Element> element = createBreakElement(document); | 834 RefPtr<Element> element = createBreakElement(document); |
| 835 element->setAttribute(classAttr, AppleInterchangeNewline); | 835 element->setAttribute(classAttr, AppleInterchangeNewline); |
| 836 fragment->appendChild(element.release()); | 836 fragment->appendChild(element.release()); |
| 837 } | 837 } |
| 838 return fragment.release(); | 838 return fragment.release(); |
| 839 } | 839 } |
| 840 | 840 |
| 841 // A string with no newlines gets added inline, rather than being put into a
paragraph. | 841 // A string with no newlines gets added inline, rather than being put into a
paragraph. |
| 842 if (string.find('\n') == notFound) { | 842 if (string.find('\n') == notFound) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 882 | 882 |
| 883 PassRefPtr<DocumentFragment> createFragmentFromNodes(Document *document, const V
ector<Node*>& nodes) | 883 PassRefPtr<DocumentFragment> createFragmentFromNodes(Document *document, const V
ector<Node*>& nodes) |
| 884 { | 884 { |
| 885 if (!document) | 885 if (!document) |
| 886 return 0; | 886 return 0; |
| 887 | 887 |
| 888 RefPtr<DocumentFragment> fragment = document->createDocumentFragment(); | 888 RefPtr<DocumentFragment> fragment = document->createDocumentFragment(); |
| 889 | 889 |
| 890 size_t size = nodes.size(); | 890 size_t size = nodes.size(); |
| 891 for (size_t i = 0; i < size; ++i) { | 891 for (size_t i = 0; i < size; ++i) { |
| 892 RefPtr<Element> element = createDefaultParagraphElement(document); | 892 RefPtr<Element> element = createDefaultParagraphElement(*document); |
| 893 element->appendChild(nodes[i]); | 893 element->appendChild(nodes[i]); |
| 894 fragment->appendChild(element.release()); | 894 fragment->appendChild(element.release()); |
| 895 } | 895 } |
| 896 | 896 |
| 897 return fragment.release(); | 897 return fragment.release(); |
| 898 } | 898 } |
| 899 | 899 |
| 900 String createFullMarkup(const Node* node) | 900 String createFullMarkup(const Node* node) |
| 901 { | 901 { |
| 902 if (!node) | 902 if (!node) |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1072 if (containerNode->hasOneChild()) { | 1072 if (containerNode->hasOneChild()) { |
| 1073 containerNode->replaceChild(textNode.release(), containerNode->firstChil
d(), es); | 1073 containerNode->replaceChild(textNode.release(), containerNode->firstChil
d(), es); |
| 1074 return; | 1074 return; |
| 1075 } | 1075 } |
| 1076 | 1076 |
| 1077 containerNode->removeChildren(); | 1077 containerNode->removeChildren(); |
| 1078 containerNode->appendChild(textNode.release(), es); | 1078 containerNode->appendChild(textNode.release(), es); |
| 1079 } | 1079 } |
| 1080 | 1080 |
| 1081 } | 1081 } |
| OLD | NEW |