| 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 478 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 489 } | 489 } | 
| 490 | 490 | 
| 491 static bool isElementPresentational(const Node* node) | 491 static bool isElementPresentational(const Node* node) | 
| 492 { | 492 { | 
| 493     return node->hasTagName(uTag) || node->hasTagName(sTag) || node->hasTagName(
      strikeTag) | 493     return node->hasTagName(uTag) || node->hasTagName(sTag) || node->hasTagName(
      strikeTag) | 
| 494         || node->hasTagName(iTag) || node->hasTagName(emTag) || node->hasTagName
      (bTag) || node->hasTagName(strongTag); | 494         || node->hasTagName(iTag) || node->hasTagName(emTag) || node->hasTagName
      (bTag) || node->hasTagName(strongTag); | 
| 495 } | 495 } | 
| 496 | 496 | 
| 497 static Node* highestAncestorToWrapMarkup(const Range* range, EAnnotateForInterch
      ange shouldAnnotate, Node* constrainingAncestor) | 497 static Node* highestAncestorToWrapMarkup(const Range* range, EAnnotateForInterch
      ange shouldAnnotate, Node* constrainingAncestor) | 
| 498 { | 498 { | 
| 499     Node* commonAncestor = range->commonAncestorContainer(IGNORE_EXCEPTION_STATE
      ); | 499     Node* commonAncestor = range->commonAncestorContainer(IGNORE_EXCEPTION); | 
| 500     ASSERT(commonAncestor); | 500     ASSERT(commonAncestor); | 
| 501     Node* specialCommonAncestor = 0; | 501     Node* specialCommonAncestor = 0; | 
| 502     if (shouldAnnotate == AnnotateForInterchange) { | 502     if (shouldAnnotate == AnnotateForInterchange) { | 
| 503         // Include ancestors that aren't completely inside the range but are req
      uired to retain | 503         // Include ancestors that aren't completely inside the range but are req
      uired to retain | 
| 504         // the structure and appearance of the copied markup. | 504         // the structure and appearance of the copied markup. | 
| 505         specialCommonAncestor = ancestorToRetainStructureAndAppearance(commonAnc
      estor); | 505         specialCommonAncestor = ancestorToRetainStructureAndAppearance(commonAnc
      estor); | 
| 506 | 506 | 
| 507         if (Node* parentListNode = enclosingNodeOfType(firstPositionInOrBeforeNo
      de(range->firstNode()), isListItem)) { | 507         if (Node* parentListNode = enclosingNodeOfType(firstPositionInOrBeforeNo
      de(range->firstNode()), isListItem)) { | 
| 508             if (WebCore::areRangesEqual(VisibleSelection::selectionFromContentsO
      fNode(parentListNode).toNormalizedRange().get(), range)) { | 508             if (WebCore::areRangesEqual(VisibleSelection::selectionFromContentsO
      fNode(parentListNode).toNormalizedRange().get(), range)) { | 
| 509                 specialCommonAncestor = parentListNode->parentNode(); | 509                 specialCommonAncestor = parentListNode->parentNode(); | 
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 542 // FIXME: Shouldn't we omit style info when annotate == DoNotAnnotateForIntercha
      nge? | 542 // FIXME: Shouldn't we omit style info when annotate == DoNotAnnotateForIntercha
      nge? | 
| 543 // FIXME: At least, annotation and style info should probably not be included in
       range.markupString() | 543 // FIXME: At least, annotation and style info should probably not be included in
       range.markupString() | 
| 544 static String createMarkupInternal(Document* document, const Range* range, const
       Range* updatedRange, Vector<Node*>* nodes, | 544 static String createMarkupInternal(Document* document, const Range* range, const
       Range* updatedRange, Vector<Node*>* nodes, | 
| 545     EAnnotateForInterchange shouldAnnotate, bool convertBlocksToInlines, EAbsolu
      teURLs shouldResolveURLs, Node* constrainingAncestor) | 545     EAnnotateForInterchange shouldAnnotate, bool convertBlocksToInlines, EAbsolu
      teURLs shouldResolveURLs, Node* constrainingAncestor) | 
| 546 { | 546 { | 
| 547     ASSERT(document); | 547     ASSERT(document); | 
| 548     ASSERT(range); | 548     ASSERT(range); | 
| 549     ASSERT(updatedRange); | 549     ASSERT(updatedRange); | 
| 550     DEFINE_STATIC_LOCAL(const String, interchangeNewlineString, (ASCIILiteral("<
      br class=\"" AppleInterchangeNewline "\">"))); | 550     DEFINE_STATIC_LOCAL(const String, interchangeNewlineString, (ASCIILiteral("<
      br class=\"" AppleInterchangeNewline "\">"))); | 
| 551 | 551 | 
| 552     bool collapsed = updatedRange->collapsed(ASSERT_NO_EXCEPTION_STATE); | 552     bool collapsed = updatedRange->collapsed(ASSERT_NO_EXCEPTION); | 
| 553     if (collapsed) | 553     if (collapsed) | 
| 554         return emptyString(); | 554         return emptyString(); | 
| 555     Node* commonAncestor = updatedRange->commonAncestorContainer(ASSERT_NO_EXCEP
      TION_STATE); | 555     Node* commonAncestor = updatedRange->commonAncestorContainer(ASSERT_NO_EXCEP
      TION); | 
| 556     if (!commonAncestor) | 556     if (!commonAncestor) | 
| 557         return emptyString(); | 557         return emptyString(); | 
| 558 | 558 | 
| 559     document->updateLayoutIgnorePendingStylesheets(); | 559     document->updateLayoutIgnorePendingStylesheets(); | 
| 560 | 560 | 
| 561     Node* body = enclosingNodeWithTag(firstPositionInNode(commonAncestor), bodyT
      ag); | 561     Node* body = enclosingNodeWithTag(firstPositionInNode(commonAncestor), bodyT
      ag); | 
| 562     Node* fullySelectedRoot = 0; | 562     Node* fullySelectedRoot = 0; | 
| 563     // FIXME: Do this for all fully selected blocks, not just the body. | 563     // FIXME: Do this for all fully selected blocks, not just the body. | 
| 564     if (body && areRangesEqual(VisibleSelection::selectionFromContentsOfNode(bod
      y).toNormalizedRange().get(), range)) | 564     if (body && areRangesEqual(VisibleSelection::selectionFromContentsOfNode(bod
      y).toNormalizedRange().get(), range)) | 
| 565         fullySelectedRoot = body; | 565         fullySelectedRoot = body; | 
| 566     Node* specialCommonAncestor = highestAncestorToWrapMarkup(updatedRange, shou
      ldAnnotate, constrainingAncestor); | 566     Node* specialCommonAncestor = highestAncestorToWrapMarkup(updatedRange, shou
      ldAnnotate, constrainingAncestor); | 
| 567     StyledMarkupAccumulator accumulator(nodes, shouldResolveURLs, shouldAnnotate
      , updatedRange, specialCommonAncestor); | 567     StyledMarkupAccumulator accumulator(nodes, shouldResolveURLs, shouldAnnotate
      , updatedRange, specialCommonAncestor); | 
| 568     Node* pastEnd = updatedRange->pastLastNode(); | 568     Node* pastEnd = updatedRange->pastLastNode(); | 
| 569 | 569 | 
| 570     Node* startNode = updatedRange->firstNode(); | 570     Node* startNode = updatedRange->firstNode(); | 
| 571     VisiblePosition visibleStart(updatedRange->startPosition(), VP_DEFAULT_AFFIN
      ITY); | 571     VisiblePosition visibleStart(updatedRange->startPosition(), VP_DEFAULT_AFFIN
      ITY); | 
| 572     VisiblePosition visibleEnd(updatedRange->endPosition(), VP_DEFAULT_AFFINITY)
      ; | 572     VisiblePosition visibleEnd(updatedRange->endPosition(), VP_DEFAULT_AFFINITY)
      ; | 
| 573     if (shouldAnnotate == AnnotateForInterchange && needInterchangeNewlineAfter(
      visibleStart)) { | 573     if (shouldAnnotate == AnnotateForInterchange && needInterchangeNewlineAfter(
      visibleStart)) { | 
| 574         if (visibleStart == visibleEnd.previous()) | 574         if (visibleStart == visibleEnd.previous()) | 
| 575             return interchangeNewlineString; | 575             return interchangeNewlineString; | 
| 576 | 576 | 
| 577         accumulator.appendString(interchangeNewlineString); | 577         accumulator.appendString(interchangeNewlineString); | 
| 578         startNode = visibleStart.next().deepEquivalent().deprecatedNode(); | 578         startNode = visibleStart.next().deepEquivalent().deprecatedNode(); | 
| 579 | 579 | 
| 580         if (pastEnd && Range::compareBoundaryPoints(startNode, 0, pastEnd, 0, AS
      SERT_NO_EXCEPTION_STATE) >= 0) | 580         if (pastEnd && Range::compareBoundaryPoints(startNode, 0, pastEnd, 0, AS
      SERT_NO_EXCEPTION) >= 0) | 
| 581             return interchangeNewlineString; | 581             return interchangeNewlineString; | 
| 582     } | 582     } | 
| 583 | 583 | 
| 584     Node* lastClosed = accumulator.serializeNodes(startNode, pastEnd); | 584     Node* lastClosed = accumulator.serializeNodes(startNode, pastEnd); | 
| 585 | 585 | 
| 586     if (specialCommonAncestor && lastClosed) { | 586     if (specialCommonAncestor && lastClosed) { | 
| 587         // Also include all of the ancestors of lastClosed up to this special an
      cestor. | 587         // Also include all of the ancestors of lastClosed up to this special an
      cestor. | 
| 588         for (ContainerNode* ancestor = lastClosed->parentNode(); ancestor; ances
      tor = ancestor->parentNode()) { | 588         for (ContainerNode* ancestor = lastClosed->parentNode(); ancestor; ances
      tor = ancestor->parentNode()) { | 
| 589             if (ancestor == fullySelectedRoot && !convertBlocksToInlines) { | 589             if (ancestor == fullySelectedRoot && !convertBlocksToInlines) { | 
| 590                 RefPtr<EditingStyle> fullySelectedRootStyle = styleFromMatchedRu
      lesAndInlineDecl(fullySelectedRoot); | 590                 RefPtr<EditingStyle> fullySelectedRootStyle = styleFromMatchedRu
      lesAndInlineDecl(fullySelectedRoot); | 
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 675 static void trimFragment(DocumentFragment* fragment, Node* nodeBeforeContext, No
      de* nodeAfterContext) | 675 static void trimFragment(DocumentFragment* fragment, Node* nodeBeforeContext, No
      de* nodeAfterContext) | 
| 676 { | 676 { | 
| 677     RefPtr<Node> next; | 677     RefPtr<Node> next; | 
| 678     for (RefPtr<Node> node = fragment->firstChild(); node; node = next) { | 678     for (RefPtr<Node> node = fragment->firstChild(); node; node = next) { | 
| 679         if (nodeBeforeContext->isDescendantOf(node.get())) { | 679         if (nodeBeforeContext->isDescendantOf(node.get())) { | 
| 680             next = NodeTraversal::next(node.get()); | 680             next = NodeTraversal::next(node.get()); | 
| 681             continue; | 681             continue; | 
| 682         } | 682         } | 
| 683         next = NodeTraversal::nextSkippingChildren(node.get()); | 683         next = NodeTraversal::nextSkippingChildren(node.get()); | 
| 684         ASSERT(!node->contains(nodeAfterContext)); | 684         ASSERT(!node->contains(nodeAfterContext)); | 
| 685         node->parentNode()->removeChild(node.get(), ASSERT_NO_EXCEPTION_STATE); | 685         node->parentNode()->removeChild(node.get(), ASSERT_NO_EXCEPTION); | 
| 686         if (nodeBeforeContext == node) | 686         if (nodeBeforeContext == node) | 
| 687             break; | 687             break; | 
| 688     } | 688     } | 
| 689 | 689 | 
| 690     ASSERT(nodeAfterContext->parentNode()); | 690     ASSERT(nodeAfterContext->parentNode()); | 
| 691     for (RefPtr<Node> node = nodeAfterContext; node; node = next) { | 691     for (RefPtr<Node> node = nodeAfterContext; node; node = next) { | 
| 692         next = NodeTraversal::nextSkippingChildren(node.get()); | 692         next = NodeTraversal::nextSkippingChildren(node.get()); | 
| 693         node->parentNode()->removeChild(node.get(), ASSERT_NO_EXCEPTION_STATE); | 693         node->parentNode()->removeChild(node.get(), ASSERT_NO_EXCEPTION); | 
| 694     } | 694     } | 
| 695 } | 695 } | 
| 696 | 696 | 
| 697 PassRefPtr<DocumentFragment> createFragmentFromMarkupWithContext(Document* docum
      ent, const String& markup, unsigned fragmentStart, unsigned fragmentEnd, | 697 PassRefPtr<DocumentFragment> createFragmentFromMarkupWithContext(Document* docum
      ent, const String& markup, unsigned fragmentStart, unsigned fragmentEnd, | 
| 698     const String& baseURL, ParserContentPolicy parserContentPolicy) | 698     const String& baseURL, ParserContentPolicy parserContentPolicy) | 
| 699 { | 699 { | 
| 700     // FIXME: Need to handle the case where the markup already contains these ma
      rkers. | 700     // FIXME: Need to handle the case where the markup already contains these ma
      rkers. | 
| 701 | 701 | 
| 702     StringBuilder taggedMarkup; | 702     StringBuilder taggedMarkup; | 
| 703     taggedMarkup.append(markup.left(fragmentStart)); | 703     taggedMarkup.append(markup.left(fragmentStart)); | 
| 704     MarkupAccumulator::appendComment(taggedMarkup, fragmentMarkerTag); | 704     MarkupAccumulator::appendComment(taggedMarkup, fragmentMarkerTag); | 
| 705     taggedMarkup.append(markup.substring(fragmentStart, fragmentEnd - fragmentSt
      art)); | 705     taggedMarkup.append(markup.substring(fragmentStart, fragmentEnd - fragmentSt
      art)); | 
| 706     MarkupAccumulator::appendComment(taggedMarkup, fragmentMarkerTag); | 706     MarkupAccumulator::appendComment(taggedMarkup, fragmentMarkerTag); | 
| 707     taggedMarkup.append(markup.substring(fragmentEnd)); | 707     taggedMarkup.append(markup.substring(fragmentEnd)); | 
| 708 | 708 | 
| 709     RefPtr<DocumentFragment> taggedFragment = createFragmentFromMarkup(document,
       taggedMarkup.toString(), baseURL, parserContentPolicy); | 709     RefPtr<DocumentFragment> taggedFragment = createFragmentFromMarkup(document,
       taggedMarkup.toString(), baseURL, parserContentPolicy); | 
| 710     RefPtr<Document> taggedDocument = Document::create(); | 710     RefPtr<Document> taggedDocument = Document::create(); | 
| 711     taggedDocument->setContextFeatures(document->contextFeatures()); | 711     taggedDocument->setContextFeatures(document->contextFeatures()); | 
| 712     taggedDocument->takeAllChildrenFrom(taggedFragment.get()); | 712     taggedDocument->takeAllChildrenFrom(taggedFragment.get()); | 
| 713 | 713 | 
| 714     RefPtr<Node> nodeBeforeContext; | 714     RefPtr<Node> nodeBeforeContext; | 
| 715     RefPtr<Node> nodeAfterContext; | 715     RefPtr<Node> nodeAfterContext; | 
| 716     if (!findNodesSurroundingContext(taggedDocument.get(), nodeBeforeContext, no
      deAfterContext)) | 716     if (!findNodesSurroundingContext(taggedDocument.get(), nodeBeforeContext, no
      deAfterContext)) | 
| 717         return 0; | 717         return 0; | 
| 718 | 718 | 
| 719     RefPtr<Range> range = Range::create(taggedDocument.get(), | 719     RefPtr<Range> range = Range::create(taggedDocument.get(), | 
| 720         positionAfterNode(nodeBeforeContext.get()).parentAnchoredEquivalent(), | 720         positionAfterNode(nodeBeforeContext.get()).parentAnchoredEquivalent(), | 
| 721         positionBeforeNode(nodeAfterContext.get()).parentAnchoredEquivalent()); | 721         positionBeforeNode(nodeAfterContext.get()).parentAnchoredEquivalent()); | 
| 722 | 722 | 
| 723     Node* commonAncestor = range->commonAncestorContainer(ASSERT_NO_EXCEPTION_ST
      ATE); | 723     Node* commonAncestor = range->commonAncestorContainer(ASSERT_NO_EXCEPTION); | 
| 724     Node* specialCommonAncestor = ancestorToRetainStructureAndAppearanceWithNoRe
      nderer(commonAncestor); | 724     Node* specialCommonAncestor = ancestorToRetainStructureAndAppearanceWithNoRe
      nderer(commonAncestor); | 
| 725 | 725 | 
| 726     // When there's a special common ancestor outside of the fragment, we must i
      nclude it as well to | 726     // When there's a special common ancestor outside of the fragment, we must i
      nclude it as well to | 
| 727     // preserve the structure and appearance of the fragment. For example, if th
      e fragment contains | 727     // preserve the structure and appearance of the fragment. For example, if th
      e fragment contains | 
| 728     // TD, we need to include the enclosing TABLE tag as well. | 728     // TD, we need to include the enclosing TABLE tag as well. | 
| 729     RefPtr<DocumentFragment> fragment = DocumentFragment::create(document); | 729     RefPtr<DocumentFragment> fragment = DocumentFragment::create(document); | 
| 730     if (specialCommonAncestor) | 730     if (specialCommonAncestor) | 
| 731         fragment->appendChild(specialCommonAncestor, ASSERT_NO_EXCEPTION_STATE); | 731         fragment->appendChild(specialCommonAncestor, ASSERT_NO_EXCEPTION); | 
| 732     else | 732     else | 
| 733         fragment->takeAllChildrenFrom(toContainerNode(commonAncestor)); | 733         fragment->takeAllChildrenFrom(toContainerNode(commonAncestor)); | 
| 734 | 734 | 
| 735     trimFragment(fragment.get(), nodeBeforeContext.get(), nodeAfterContext.get()
      ); | 735     trimFragment(fragment.get(), nodeBeforeContext.get(), nodeAfterContext.get()
      ); | 
| 736 | 736 | 
| 737     return fragment; | 737     return fragment; | 
| 738 } | 738 } | 
| 739 | 739 | 
| 740 String createMarkup(const Node* node, EChildrenOnly childrenOnly, Vector<Node*>*
       nodes, EAbsoluteURLs shouldResolveURLs, Vector<QualifiedName>* tagNamesToSkip) | 740 String createMarkup(const Node* node, EChildrenOnly childrenOnly, Vector<Node*>*
       nodes, EAbsoluteURLs shouldResolveURLs, Vector<QualifiedName>* tagNamesToSkip) | 
| 741 { | 741 { | 
| 742     if (!node) | 742     if (!node) | 
| 743         return ""; | 743         return ""; | 
| 744 | 744 | 
| 745     MarkupAccumulator accumulator(nodes, shouldResolveURLs); | 745     MarkupAccumulator accumulator(nodes, shouldResolveURLs); | 
| 746     return accumulator.serializeNodes(const_cast<Node*>(node), childrenOnly, tag
      NamesToSkip); | 746     return accumulator.serializeNodes(const_cast<Node*>(node), childrenOnly, tag
      NamesToSkip); | 
| 747 } | 747 } | 
| 748 | 748 | 
| 749 static void fillContainerFromString(ContainerNode* paragraph, const String& stri
      ng) | 749 static void fillContainerFromString(ContainerNode* paragraph, const String& stri
      ng) | 
| 750 { | 750 { | 
| 751     Document* document = paragraph->document(); | 751     Document* document = paragraph->document(); | 
| 752 | 752 | 
| 753     if (string.isEmpty()) { | 753     if (string.isEmpty()) { | 
| 754         paragraph->appendChild(createBlockPlaceholderElement(document), ASSERT_N
      O_EXCEPTION_STATE); | 754         paragraph->appendChild(createBlockPlaceholderElement(document), ASSERT_N
      O_EXCEPTION); | 
| 755         return; | 755         return; | 
| 756     } | 756     } | 
| 757 | 757 | 
| 758     ASSERT(string.find('\n') == notFound); | 758     ASSERT(string.find('\n') == notFound); | 
| 759 | 759 | 
| 760     Vector<String> tabList; | 760     Vector<String> tabList; | 
| 761     string.split('\t', true, tabList); | 761     string.split('\t', true, tabList); | 
| 762     String tabText = emptyString(); | 762     String tabText = emptyString(); | 
| 763     bool first = true; | 763     bool first = true; | 
| 764     size_t numEntries = tabList.size(); | 764     size_t numEntries = tabList.size(); | 
| 765     for (size_t i = 0; i < numEntries; ++i) { | 765     for (size_t i = 0; i < numEntries; ++i) { | 
| 766         const String& s = tabList[i]; | 766         const String& s = tabList[i]; | 
| 767 | 767 | 
| 768         // append the non-tab textual part | 768         // append the non-tab textual part | 
| 769         if (!s.isEmpty()) { | 769         if (!s.isEmpty()) { | 
| 770             if (!tabText.isEmpty()) { | 770             if (!tabText.isEmpty()) { | 
| 771                 paragraph->appendChild(createTabSpanElement(document, tabText), 
      ASSERT_NO_EXCEPTION_STATE); | 771                 paragraph->appendChild(createTabSpanElement(document, tabText), 
      ASSERT_NO_EXCEPTION); | 
| 772                 tabText = emptyString(); | 772                 tabText = emptyString(); | 
| 773             } | 773             } | 
| 774             RefPtr<Node> textNode = document->createTextNode(stringWithRebalance
      dWhitespace(s, first, i + 1 == numEntries)); | 774             RefPtr<Node> textNode = document->createTextNode(stringWithRebalance
      dWhitespace(s, first, i + 1 == numEntries)); | 
| 775             paragraph->appendChild(textNode.release(), ASSERT_NO_EXCEPTION_STATE
      ); | 775             paragraph->appendChild(textNode.release(), ASSERT_NO_EXCEPTION); | 
| 776         } | 776         } | 
| 777 | 777 | 
| 778         // there is a tab after every entry, except the last entry | 778         // there is a tab after every entry, except the last entry | 
| 779         // (if the last character is a tab, the list gets an extra empty entry) | 779         // (if the last character is a tab, the list gets an extra empty entry) | 
| 780         if (i + 1 != numEntries) | 780         if (i + 1 != numEntries) | 
| 781             tabText.append('\t'); | 781             tabText.append('\t'); | 
| 782         else if (!tabText.isEmpty()) | 782         else if (!tabText.isEmpty()) | 
| 783             paragraph->appendChild(createTabSpanElement(document, tabText), ASSE
      RT_NO_EXCEPTION_STATE); | 783             paragraph->appendChild(createTabSpanElement(document, tabText), ASSE
      RT_NO_EXCEPTION); | 
| 784 | 784 | 
| 785         first = false; | 785         first = false; | 
| 786     } | 786     } | 
| 787 } | 787 } | 
| 788 | 788 | 
| 789 bool isPlainTextMarkup(Node *node) | 789 bool isPlainTextMarkup(Node *node) | 
| 790 { | 790 { | 
| 791     if (!node->isElementNode() || !node->hasTagName(divTag) || toElement(node)->
      hasAttributes()) | 791     if (!node->isElementNode() || !node->hasTagName(divTag) || toElement(node)->
      hasAttributes()) | 
| 792         return false; | 792         return false; | 
| 793 | 793 | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
| 814 | 814 | 
| 815     if (text.isEmpty()) | 815     if (text.isEmpty()) | 
| 816         return fragment.release(); | 816         return fragment.release(); | 
| 817 | 817 | 
| 818     String string = text; | 818     String string = text; | 
| 819     string.replace("\r\n", "\n"); | 819     string.replace("\r\n", "\n"); | 
| 820     string.replace('\r', '\n'); | 820     string.replace('\r', '\n'); | 
| 821 | 821 | 
| 822     RenderObject* renderer = styleNode->renderer(); | 822     RenderObject* renderer = styleNode->renderer(); | 
| 823     if (renderer && renderer->style()->preserveNewline()) { | 823     if (renderer && renderer->style()->preserveNewline()) { | 
| 824         fragment->appendChild(document->createTextNode(string), ASSERT_NO_EXCEPT
      ION_STATE); | 824         fragment->appendChild(document->createTextNode(string), ASSERT_NO_EXCEPT
      ION); | 
| 825         if (string.endsWith('\n')) { | 825         if (string.endsWith('\n')) { | 
| 826             RefPtr<Element> element = createBreakElement(document); | 826             RefPtr<Element> element = createBreakElement(document); | 
| 827             element->setAttribute(classAttr, AppleInterchangeNewline); | 827             element->setAttribute(classAttr, AppleInterchangeNewline); | 
| 828             fragment->appendChild(element.release(), ASSERT_NO_EXCEPTION_STATE); | 828             fragment->appendChild(element.release(), ASSERT_NO_EXCEPTION); | 
| 829         } | 829         } | 
| 830         return fragment.release(); | 830         return fragment.release(); | 
| 831     } | 831     } | 
| 832 | 832 | 
| 833     // A string with no newlines gets added inline, rather than being put into a
       paragraph. | 833     // A string with no newlines gets added inline, rather than being put into a
       paragraph. | 
| 834     if (string.find('\n') == notFound) { | 834     if (string.find('\n') == notFound) { | 
| 835         fillContainerFromString(fragment.get(), string); | 835         fillContainerFromString(fragment.get(), string); | 
| 836         return fragment.release(); | 836         return fragment.release(); | 
| 837     } | 837     } | 
| 838 | 838 | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
| 860         } else if (useLineBreak) { | 860         } else if (useLineBreak) { | 
| 861             element = createBreakElement(document); | 861             element = createBreakElement(document); | 
| 862             fillContainerFromString(fragment.get(), s); | 862             fillContainerFromString(fragment.get(), s); | 
| 863         } else { | 863         } else { | 
| 864             if (useClonesOfEnclosingBlock) | 864             if (useClonesOfEnclosingBlock) | 
| 865                 element = block->cloneElementWithoutChildren(); | 865                 element = block->cloneElementWithoutChildren(); | 
| 866             else | 866             else | 
| 867                 element = createDefaultParagraphElement(document); | 867                 element = createDefaultParagraphElement(document); | 
| 868             fillContainerFromString(element.get(), s); | 868             fillContainerFromString(element.get(), s); | 
| 869         } | 869         } | 
| 870         fragment->appendChild(element.release(), ASSERT_NO_EXCEPTION_STATE); | 870         fragment->appendChild(element.release(), ASSERT_NO_EXCEPTION); | 
| 871     } | 871     } | 
| 872     return fragment.release(); | 872     return fragment.release(); | 
| 873 } | 873 } | 
| 874 | 874 | 
| 875 PassRefPtr<DocumentFragment> createFragmentFromNodes(Document *document, const V
      ector<Node*>& nodes) | 875 PassRefPtr<DocumentFragment> createFragmentFromNodes(Document *document, const V
      ector<Node*>& nodes) | 
| 876 { | 876 { | 
| 877     if (!document) | 877     if (!document) | 
| 878         return 0; | 878         return 0; | 
| 879 | 879 | 
| 880     RefPtr<DocumentFragment> fragment = document->createDocumentFragment(); | 880     RefPtr<DocumentFragment> fragment = document->createDocumentFragment(); | 
| 881 | 881 | 
| 882     size_t size = nodes.size(); | 882     size_t size = nodes.size(); | 
| 883     for (size_t i = 0; i < size; ++i) { | 883     for (size_t i = 0; i < size; ++i) { | 
| 884         RefPtr<Element> element = createDefaultParagraphElement(document); | 884         RefPtr<Element> element = createDefaultParagraphElement(document); | 
| 885         element->appendChild(nodes[i], ASSERT_NO_EXCEPTION_STATE); | 885         element->appendChild(nodes[i], ASSERT_NO_EXCEPTION); | 
| 886         fragment->appendChild(element.release(), ASSERT_NO_EXCEPTION_STATE); | 886         fragment->appendChild(element.release(), ASSERT_NO_EXCEPTION); | 
| 887     } | 887     } | 
| 888 | 888 | 
| 889     return fragment.release(); | 889     return fragment.release(); | 
| 890 } | 890 } | 
| 891 | 891 | 
| 892 String createFullMarkup(const Node* node) | 892 String createFullMarkup(const Node* node) | 
| 893 { | 893 { | 
| 894     if (!node) | 894     if (!node) | 
| 895         return String(); | 895         return String(); | 
| 896 | 896 | 
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 983     // FIXME: Do we need to mess with URLs here? | 983     // FIXME: Do we need to mess with URLs here? | 
| 984 | 984 | 
| 985     return fragment.release(); | 985     return fragment.release(); | 
| 986 } | 986 } | 
| 987 | 987 | 
| 988 static inline void removeElementPreservingChildren(PassRefPtr<DocumentFragment> 
      fragment, HTMLElement* element) | 988 static inline void removeElementPreservingChildren(PassRefPtr<DocumentFragment> 
      fragment, HTMLElement* element) | 
| 989 { | 989 { | 
| 990     RefPtr<Node> nextChild; | 990     RefPtr<Node> nextChild; | 
| 991     for (RefPtr<Node> child = element->firstChild(); child; child = nextChild) { | 991     for (RefPtr<Node> child = element->firstChild(); child; child = nextChild) { | 
| 992         nextChild = child->nextSibling(); | 992         nextChild = child->nextSibling(); | 
| 993         element->removeChild(child.get(), ASSERT_NO_EXCEPTION_STATE); | 993         element->removeChild(child.get(), ASSERT_NO_EXCEPTION); | 
| 994         fragment->insertBefore(child, element, ASSERT_NO_EXCEPTION_STATE); | 994         fragment->insertBefore(child, element, ASSERT_NO_EXCEPTION); | 
| 995     } | 995     } | 
| 996     fragment->removeChild(element, ASSERT_NO_EXCEPTION_STATE); | 996     fragment->removeChild(element, ASSERT_NO_EXCEPTION); | 
| 997 } | 997 } | 
| 998 | 998 | 
| 999 PassRefPtr<DocumentFragment> createContextualFragment(const String& markup, HTML
      Element* element, ParserContentPolicy parserContentPolicy, ExceptionState& es) | 999 PassRefPtr<DocumentFragment> createContextualFragment(const String& markup, HTML
      Element* element, ParserContentPolicy parserContentPolicy, ExceptionState& es) | 
| 1000 { | 1000 { | 
| 1001     ASSERT(element); | 1001     ASSERT(element); | 
| 1002     if (element->ieForbidsInsertHTML()) { | 1002     if (element->ieForbidsInsertHTML()) { | 
| 1003         es.throwDOMException(NotSupportedError); | 1003         es.throwDOMException(NotSupportedError); | 
| 1004         return 0; | 1004         return 0; | 
| 1005     } | 1005     } | 
| 1006 | 1006 | 
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1083     if (hasOneChild(containerNode.get())) { | 1083     if (hasOneChild(containerNode.get())) { | 
| 1084         containerNode->replaceChild(textNode.release(), containerNode->firstChil
      d(), es); | 1084         containerNode->replaceChild(textNode.release(), containerNode->firstChil
      d(), es); | 
| 1085         return; | 1085         return; | 
| 1086     } | 1086     } | 
| 1087 | 1087 | 
| 1088     containerNode->removeChildren(); | 1088     containerNode->removeChildren(); | 
| 1089     containerNode->appendChild(textNode.release(), es); | 1089     containerNode->appendChild(textNode.release(), es); | 
| 1090 } | 1090 } | 
| 1091 | 1091 | 
| 1092 } | 1092 } | 
| OLD | NEW | 
|---|