Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: Source/core/editing/markup.cpp

Issue 23453033: Have DOMPatchSupport and DocumentFragment deal with Document references (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/editing/markup.h ('k') | Source/core/html/HTMLElement.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 620 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 { 631 {
632 if (!range) 632 if (!range)
633 return emptyString(); 633 return emptyString();
634 634
635 Document& document = range->ownerDocument(); 635 Document& document = range->ownerDocument();
636 const Range* updatedRange = range; 636 const Range* updatedRange = range;
637 637
638 return createMarkupInternal(document, range, updatedRange, nodes, shouldAnno tate, convertBlocksToInlines, shouldResolveURLs, constrainingAncestor); 638 return createMarkupInternal(document, range, updatedRange, nodes, shouldAnno tate, convertBlocksToInlines, shouldResolveURLs, constrainingAncestor);
639 } 639 }
640 640
641 PassRefPtr<DocumentFragment> createFragmentFromMarkup(Document* document, const String& markup, const String& baseURL, ParserContentPolicy parserContentPolicy) 641 PassRefPtr<DocumentFragment> createFragmentFromMarkup(Document& document, const String& markup, const String& baseURL, ParserContentPolicy parserContentPolicy)
642 { 642 {
643 ASSERT(document);
644 // We use a fake body element here to trick the HTML parser to using the InB ody insertion mode. 643 // We use a fake body element here to trick the HTML parser to using the InB ody insertion mode.
645 RefPtr<HTMLBodyElement> fakeBody = HTMLBodyElement::create(*document); 644 RefPtr<HTMLBodyElement> fakeBody = HTMLBodyElement::create(document);
646 RefPtr<DocumentFragment> fragment = DocumentFragment::create(document); 645 RefPtr<DocumentFragment> fragment = DocumentFragment::create(document);
647 646
648 fragment->parseHTML(markup, fakeBody.get(), parserContentPolicy); 647 fragment->parseHTML(markup, fakeBody.get(), parserContentPolicy);
649 648
650 if (!baseURL.isEmpty() && baseURL != blankURL() && baseURL != document->base URL()) 649 if (!baseURL.isEmpty() && baseURL != blankURL() && baseURL != document.baseU RL())
651 completeURLs(fragment.get(), baseURL); 650 completeURLs(fragment.get(), baseURL);
652 651
653 return fragment.release(); 652 return fragment.release();
654 } 653 }
655 654
656 static const char fragmentMarkerTag[] = "webkit-fragment-marker"; 655 static const char fragmentMarkerTag[] = "webkit-fragment-marker";
657 656
658 static bool findNodesSurroundingContext(Document* document, RefPtr<Node>& nodeBe foreContext, RefPtr<Node>& nodeAfterContext) 657 static bool findNodesSurroundingContext(Document* document, RefPtr<Node>& nodeBe foreContext, RefPtr<Node>& nodeAfterContext)
659 { 658 {
660 for (Node* node = document->firstChild(); node; node = NodeTraversal::next(n ode)) { 659 for (Node* node = document->firstChild(); node; node = NodeTraversal::next(n ode)) {
(...skipping 24 matching lines...) Expand all
685 break; 684 break;
686 } 685 }
687 686
688 ASSERT(nodeAfterContext->parentNode()); 687 ASSERT(nodeAfterContext->parentNode());
689 for (RefPtr<Node> node = nodeAfterContext; node; node = next) { 688 for (RefPtr<Node> node = nodeAfterContext; node; node = next) {
690 next = NodeTraversal::nextSkippingChildren(node.get()); 689 next = NodeTraversal::nextSkippingChildren(node.get());
691 node->parentNode()->removeChild(node.get(), ASSERT_NO_EXCEPTION); 690 node->parentNode()->removeChild(node.get(), ASSERT_NO_EXCEPTION);
692 } 691 }
693 } 692 }
694 693
695 PassRefPtr<DocumentFragment> createFragmentFromMarkupWithContext(Document* docum ent, const String& markup, unsigned fragmentStart, unsigned fragmentEnd, 694 PassRefPtr<DocumentFragment> createFragmentFromMarkupWithContext(Document& docum ent, const String& markup, unsigned fragmentStart, unsigned fragmentEnd,
696 const String& baseURL, ParserContentPolicy parserContentPolicy) 695 const String& baseURL, ParserContentPolicy parserContentPolicy)
697 { 696 {
698 // FIXME: Need to handle the case where the markup already contains these ma rkers. 697 // FIXME: Need to handle the case where the markup already contains these ma rkers.
699 698
700 StringBuilder taggedMarkup; 699 StringBuilder taggedMarkup;
701 taggedMarkup.append(markup.left(fragmentStart)); 700 taggedMarkup.append(markup.left(fragmentStart));
702 MarkupAccumulator::appendComment(taggedMarkup, fragmentMarkerTag); 701 MarkupAccumulator::appendComment(taggedMarkup, fragmentMarkerTag);
703 taggedMarkup.append(markup.substring(fragmentStart, fragmentEnd - fragmentSt art)); 702 taggedMarkup.append(markup.substring(fragmentStart, fragmentEnd - fragmentSt art));
704 MarkupAccumulator::appendComment(taggedMarkup, fragmentMarkerTag); 703 MarkupAccumulator::appendComment(taggedMarkup, fragmentMarkerTag);
705 taggedMarkup.append(markup.substring(fragmentEnd)); 704 taggedMarkup.append(markup.substring(fragmentEnd));
706 705
707 RefPtr<DocumentFragment> taggedFragment = createFragmentFromMarkup(document, taggedMarkup.toString(), baseURL, parserContentPolicy); 706 RefPtr<DocumentFragment> taggedFragment = createFragmentFromMarkup(document, taggedMarkup.toString(), baseURL, parserContentPolicy);
708 RefPtr<Document> taggedDocument = Document::create(); 707 RefPtr<Document> taggedDocument = Document::create();
709 taggedDocument->setContextFeatures(document->contextFeatures()); 708 taggedDocument->setContextFeatures(document.contextFeatures());
710 taggedDocument->takeAllChildrenFrom(taggedFragment.get()); 709 taggedDocument->takeAllChildrenFrom(taggedFragment.get());
711 710
712 RefPtr<Node> nodeBeforeContext; 711 RefPtr<Node> nodeBeforeContext;
713 RefPtr<Node> nodeAfterContext; 712 RefPtr<Node> nodeAfterContext;
714 if (!findNodesSurroundingContext(taggedDocument.get(), nodeBeforeContext, no deAfterContext)) 713 if (!findNodesSurroundingContext(taggedDocument.get(), nodeBeforeContext, no deAfterContext))
715 return 0; 714 return 0;
716 715
717 RefPtr<Range> range = Range::create(*taggedDocument.get(), 716 RefPtr<Range> range = Range::create(*taggedDocument.get(),
718 positionAfterNode(nodeBeforeContext.get()).parentAnchoredEquivalent(), 717 positionAfterNode(nodeBeforeContext.get()).parentAnchoredEquivalent(),
719 positionBeforeNode(nodeAfterContext.get()).parentAnchoredEquivalent()); 718 positionBeforeNode(nodeAfterContext.get()).parentAnchoredEquivalent());
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 markup.append("<a href=\""); 934 markup.append("<a href=\"");
936 markup.append(url.string()); 935 markup.append(url.string());
937 markup.append("\">"); 936 markup.append("\">");
938 MarkupAccumulator::appendCharactersReplacingEntities(markup, title, 0, title .length(), EntityMaskInPCDATA); 937 MarkupAccumulator::appendCharactersReplacingEntities(markup, title, 0, title .length(), EntityMaskInPCDATA);
939 markup.append("</a>"); 938 markup.append("</a>");
940 return markup.toString(); 939 return markup.toString();
941 } 940 }
942 941
943 PassRefPtr<DocumentFragment> createFragmentForInnerOuterHTML(const String& marku p, Element* contextElement, ParserContentPolicy parserContentPolicy, ExceptionSt ate& es) 942 PassRefPtr<DocumentFragment> createFragmentForInnerOuterHTML(const String& marku p, Element* contextElement, ParserContentPolicy parserContentPolicy, ExceptionSt ate& es)
944 { 943 {
945 Document* document = contextElement->hasTagName(templateTag) ? contextElemen t->document().ensureTemplateDocument() : &contextElement->document(); 944 Document& document = contextElement->hasTagName(templateTag) ? contextElemen t->document().ensureTemplateDocument() : contextElement->document();
946 RefPtr<DocumentFragment> fragment = DocumentFragment::create(document); 945 RefPtr<DocumentFragment> fragment = DocumentFragment::create(document);
947 946
948 if (document->isHTMLDocument()) { 947 if (document.isHTMLDocument()) {
949 fragment->parseHTML(markup, contextElement, parserContentPolicy); 948 fragment->parseHTML(markup, contextElement, parserContentPolicy);
950 return fragment; 949 return fragment;
951 } 950 }
952 951
953 bool wasValid = fragment->parseXML(markup, contextElement, parserContentPoli cy); 952 bool wasValid = fragment->parseXML(markup, contextElement, parserContentPoli cy);
954 if (!wasValid) { 953 if (!wasValid) {
955 es.throwDOMException(SyntaxError); 954 es.throwDOMException(SyntaxError);
956 return 0; 955 return 0;
957 } 956 }
958 return fragment.release(); 957 return fragment.release();
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1069 if (containerNode->hasOneChild()) { 1068 if (containerNode->hasOneChild()) {
1070 containerNode->replaceChild(textNode.release(), containerNode->firstChil d(), es); 1069 containerNode->replaceChild(textNode.release(), containerNode->firstChil d(), es);
1071 return; 1070 return;
1072 } 1071 }
1073 1072
1074 containerNode->removeChildren(); 1073 containerNode->removeChildren();
1075 containerNode->appendChild(textNode.release(), es); 1074 containerNode->appendChild(textNode.release(), es);
1076 } 1075 }
1077 1076
1078 } 1077 }
OLDNEW
« no previous file with comments | « Source/core/editing/markup.h ('k') | Source/core/html/HTMLElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698