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

Side by Side Diff: Source/core/dom/Range.cpp

Issue 289273002: Oilpan: make DocumentFragment a heap allocated object. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebased + add WillBeGarbageCollected FIXME. Created 6 years, 7 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
« no previous file with comments | « Source/core/dom/Range.h ('k') | Source/core/dom/shadow/ShadowRoot.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 * (C) 1999 Lars Knoll (knoll@kde.org) 2 * (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Gunnstein Lye (gunnstein@netcom.no) 3 * (C) 2000 Gunnstein Lye (gunnstein@netcom.no)
4 * (C) 2000 Frederik Holljen (frederik.holljen@hig.no) 4 * (C) 2000 Frederik Holljen (frederik.holljen@hig.no)
5 * (C) 2001 Peter Kelly (pmk@post.com) 5 * (C) 2001 Peter Kelly (pmk@post.com)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved.
7 * Copyright (C) 2011 Motorola Mobility. All rights reserved. 7 * Copyright (C) 2011 Motorola Mobility. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 case Node::DOCUMENT_NODE: 558 case Node::DOCUMENT_NODE:
559 case Node::DOCUMENT_FRAGMENT_NODE: 559 case Node::DOCUMENT_FRAGMENT_NODE:
560 return toContainerNode(node)->countChildren(); 560 return toContainerNode(node)->countChildren();
561 case Node::DOCUMENT_TYPE_NODE: 561 case Node::DOCUMENT_TYPE_NODE:
562 return 0; 562 return 0;
563 } 563 }
564 ASSERT_NOT_REACHED(); 564 ASSERT_NOT_REACHED();
565 return 0; 565 return 0;
566 } 566 }
567 567
568 PassRefPtr<DocumentFragment> Range::processContents(ActionType action, Exception State& exceptionState) 568 PassRefPtrWillBeRawPtr<DocumentFragment> Range::processContents(ActionType actio n, ExceptionState& exceptionState)
569 { 569 {
570 typedef Vector<RefPtr<Node> > NodeVector; 570 typedef Vector<RefPtr<Node> > NodeVector;
571 571
572 RefPtr<DocumentFragment> fragment; 572 RefPtrWillBeRawPtr<DocumentFragment> fragment = nullptr;
573 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) 573 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS)
574 fragment = DocumentFragment::create(*m_ownerDocument.get()); 574 fragment = DocumentFragment::create(*m_ownerDocument.get());
575 575
576 if (collapsed()) 576 if (collapsed())
577 return fragment.release(); 577 return fragment.release();
578 578
579 RefPtr<Node> commonRoot = commonAncestorContainer(); 579 RefPtr<Node> commonRoot = commonAncestorContainer();
580 ASSERT(commonRoot); 580 ASSERT(commonRoot);
581 581
582 if (m_start.container() == m_end.container()) { 582 if (m_start.container() == m_end.container()) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 } 669 }
670 670
671 static inline void deleteCharacterData(PassRefPtrWillBeRawPtr<CharacterData> dat a, unsigned startOffset, unsigned endOffset, ExceptionState& exceptionState) 671 static inline void deleteCharacterData(PassRefPtrWillBeRawPtr<CharacterData> dat a, unsigned startOffset, unsigned endOffset, ExceptionState& exceptionState)
672 { 672 {
673 if (data->length() - endOffset) 673 if (data->length() - endOffset)
674 data->deleteData(endOffset, data->length() - endOffset, exceptionState); 674 data->deleteData(endOffset, data->length() - endOffset, exceptionState);
675 if (startOffset) 675 if (startOffset)
676 data->deleteData(0, startOffset, exceptionState); 676 data->deleteData(0, startOffset, exceptionState);
677 } 677 }
678 678
679 PassRefPtr<Node> Range::processContentsBetweenOffsets(ActionType action, PassRef Ptr<DocumentFragment> fragment, 679 PassRefPtr<Node> Range::processContentsBetweenOffsets(ActionType action, PassRef PtrWillBeRawPtr<DocumentFragment> fragment,
680 Node* container, unsigned startOffset, unsigned endOffset, ExceptionState& e xceptionState) 680 Node* container, unsigned startOffset, unsigned endOffset, ExceptionState& e xceptionState)
681 { 681 {
682 ASSERT(container); 682 ASSERT(container);
683 ASSERT(startOffset <= endOffset); 683 ASSERT(startOffset <= endOffset);
684 684
685 // This switch statement must be consistent with that of lengthOfContentsInN ode. 685 // This switch statement must be consistent with that of lengthOfContentsInN ode.
686 RefPtr<Node> result; 686 RefPtr<Node> result;
687 switch (container->nodeType()) { 687 switch (container->nodeType()) {
688 case Node::TEXT_NODE: 688 case Node::TEXT_NODE:
689 case Node::CDATA_SECTION_NODE: 689 case Node::CDATA_SECTION_NODE:
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 clonedContainer->insertBefore(child->cloneNode(true), cloned Container->firstChild(), exceptionState); 814 clonedContainer->insertBefore(child->cloneNode(true), cloned Container->firstChild(), exceptionState);
815 break; 815 break;
816 } 816 }
817 } 817 }
818 firstChildInAncestorToProcess = direction == ProcessContentsForward ? an cestor->nextSibling() : ancestor->previousSibling(); 818 firstChildInAncestorToProcess = direction == ProcessContentsForward ? an cestor->nextSibling() : ancestor->previousSibling();
819 } 819 }
820 820
821 return clonedContainer.release(); 821 return clonedContainer.release();
822 } 822 }
823 823
824 PassRefPtr<DocumentFragment> Range::extractContents(ExceptionState& exceptionSta te) 824 PassRefPtrWillBeRawPtr<DocumentFragment> Range::extractContents(ExceptionState& exceptionState)
825 { 825 {
826 checkDeleteExtract(exceptionState); 826 checkDeleteExtract(exceptionState);
827 if (exceptionState.hadException()) 827 if (exceptionState.hadException())
828 return nullptr; 828 return nullptr;
829 829
830 return processContents(EXTRACT_CONTENTS, exceptionState); 830 return processContents(EXTRACT_CONTENTS, exceptionState);
831 } 831 }
832 832
833 PassRefPtr<DocumentFragment> Range::cloneContents(ExceptionState& exceptionState ) 833 PassRefPtrWillBeRawPtr<DocumentFragment> Range::cloneContents(ExceptionState& ex ceptionState)
834 { 834 {
835 return processContents(CLONE_CONTENTS, exceptionState); 835 return processContents(CLONE_CONTENTS, exceptionState);
836 } 836 }
837 837
838 void Range::insertNode(PassRefPtr<Node> prpNewNode, ExceptionState& exceptionSta te) 838 void Range::insertNode(PassRefPtr<Node> prpNewNode, ExceptionState& exceptionSta te)
839 { 839 {
840 RefPtr<Node> newNode = prpNewNode; 840 RefPtr<Node> newNode = prpNewNode;
841 841
842 if (!newNode) { 842 if (!newNode) {
843 exceptionState.throwDOMException(NotFoundError, "The node provided is nu ll."); 843 exceptionState.throwDOMException(NotFoundError, "The node provided is nu ll.");
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 967
968 String Range::text() const 968 String Range::text() const
969 { 969 {
970 // We need to update layout, since plainText uses line boxes in the render t ree. 970 // We need to update layout, since plainText uses line boxes in the render t ree.
971 // FIXME: As with innerText, we'd like this to work even if there are no ren der objects. 971 // FIXME: As with innerText, we'd like this to work even if there are no ren der objects.
972 m_start.container()->document().updateLayout(); 972 m_start.container()->document().updateLayout();
973 973
974 return plainText(this); 974 return plainText(this);
975 } 975 }
976 976
977 PassRefPtr<DocumentFragment> Range::createContextualFragment(const String& marku p, ExceptionState& exceptionState) 977 PassRefPtrWillBeRawPtr<DocumentFragment> Range::createContextualFragment(const S tring& markup, ExceptionState& exceptionState)
978 { 978 {
979 Node* element = m_start.container()->isElementNode() ? m_start.container() : m_start.container()->parentNode(); 979 Node* element = m_start.container()->isElementNode() ? m_start.container() : m_start.container()->parentNode();
980 if (!element || !element->isHTMLElement()) { 980 if (!element || !element->isHTMLElement()) {
981 exceptionState.throwDOMException(NotSupportedError, "The range's contain er must be an HTML element."); 981 exceptionState.throwDOMException(NotSupportedError, "The range's contain er must be an HTML element.");
982 return nullptr; 982 return nullptr;
983 } 983 }
984 984
985 RefPtr<DocumentFragment> fragment = WebCore::createContextualFragment(markup , toHTMLElement(element), AllowScriptingContentAndDoNotMarkAlreadyStarted, excep tionState); 985 RefPtrWillBeRawPtr<DocumentFragment> fragment = WebCore::createContextualFra gment(markup, toHTMLElement(element), AllowScriptingContentAndDoNotMarkAlreadySt arted, exceptionState);
986 if (!fragment) 986 if (!fragment)
987 return nullptr; 987 return nullptr;
988 988
989 return fragment.release(); 989 return fragment.release();
990 } 990 }
991 991
992 992
993 void Range::detach() 993 void Range::detach()
994 { 994 {
995 // This is now a no-op as per the DOM specification. 995 // This is now a no-op as per the DOM specification.
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 if (startNonTextContainer != endNonTextContainer) { 1259 if (startNonTextContainer != endNonTextContainer) {
1260 exceptionState.throwDOMException(InvalidStateError, "The Range has parti ally selected a non-Text node."); 1260 exceptionState.throwDOMException(InvalidStateError, "The Range has parti ally selected a non-Text node.");
1261 return; 1261 return;
1262 } 1262 }
1263 1263
1264 while (Node* n = newParent->firstChild()) { 1264 while (Node* n = newParent->firstChild()) {
1265 toContainerNode(newParent)->removeChild(n, exceptionState); 1265 toContainerNode(newParent)->removeChild(n, exceptionState);
1266 if (exceptionState.hadException()) 1266 if (exceptionState.hadException())
1267 return; 1267 return;
1268 } 1268 }
1269 RefPtr<DocumentFragment> fragment = extractContents(exceptionState); 1269 RefPtrWillBeRawPtr<DocumentFragment> fragment = extractContents(exceptionSta te);
1270 if (exceptionState.hadException()) 1270 if (exceptionState.hadException())
1271 return; 1271 return;
1272 insertNode(newParent, exceptionState); 1272 insertNode(newParent, exceptionState);
1273 if (exceptionState.hadException()) 1273 if (exceptionState.hadException())
1274 return; 1274 return;
1275 newParent->appendChild(fragment.release(), exceptionState); 1275 newParent->appendChild(fragment.release(), exceptionState);
1276 if (exceptionState.hadException()) 1276 if (exceptionState.hadException())
1277 return; 1277 return;
1278 selectNode(newParent.get(), exceptionState); 1278 selectNode(newParent.get(), exceptionState);
1279 } 1279 }
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
1685 1685
1686 void showTree(const WebCore::Range* range) 1686 void showTree(const WebCore::Range* range)
1687 { 1687 {
1688 if (range && range->boundaryPointsValid()) { 1688 if (range && range->boundaryPointsValid()) {
1689 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E"); 1689 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E");
1690 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset()); 1690 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset());
1691 } 1691 }
1692 } 1692 }
1693 1693
1694 #endif 1694 #endif
OLDNEW
« no previous file with comments | « Source/core/dom/Range.h ('k') | Source/core/dom/shadow/ShadowRoot.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698