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

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

Issue 48803004: Have Document::nodeWillBeRemoved() take a reference (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 1 month 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/RangeBoundaryPoint.h » ('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 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 RefPtr<Text> newText = toText(container)->splitText(m_start.offset(), es ); 1028 RefPtr<Text> newText = toText(container)->splitText(m_start.offset(), es );
1029 if (es.hadException()) 1029 if (es.hadException())
1030 return; 1030 return;
1031 1031
1032 container = m_start.container(); 1032 container = m_start.container();
1033 container->parentNode()->insertBefore(newNode.release(), newText.get(), es); 1033 container->parentNode()->insertBefore(newNode.release(), newText.get(), es);
1034 if (es.hadException()) 1034 if (es.hadException())
1035 return; 1035 return;
1036 1036
1037 if (collapsed) 1037 if (collapsed)
1038 m_end.setToBeforeChild(newText.get()); 1038 m_end.setToBeforeChild(*newText);
1039 } else { 1039 } else {
1040 RefPtr<Node> lastChild = (newNodeType == Node::DOCUMENT_FRAGMENT_NODE) ? newNode->lastChild() : newNode; 1040 RefPtr<Node> lastChild = (newNodeType == Node::DOCUMENT_FRAGMENT_NODE) ? newNode->lastChild() : newNode;
1041 if (lastChild && lastChild == m_start.childBefore()) { 1041 if (lastChild && lastChild == m_start.childBefore()) {
1042 // The insertion will do nothing, but we need to extend the range to include 1042 // The insertion will do nothing, but we need to extend the range to include
1043 // the inserted nodes. 1043 // the inserted nodes.
1044 Node* firstChild = (newNodeType == Node::DOCUMENT_FRAGMENT_NODE) ? n ewNode->firstChild() : newNode.get(); 1044 Node* firstChild = (newNodeType == Node::DOCUMENT_FRAGMENT_NODE) ? n ewNode->firstChild() : newNode.get();
1045 ASSERT(firstChild); 1045 ASSERT(firstChild);
1046 m_start.setToBeforeChild(firstChild); 1046 m_start.setToBeforeChild(*firstChild);
1047 return; 1047 return;
1048 } 1048 }
1049 1049
1050 container = m_start.container(); 1050 container = m_start.container();
1051 container->insertBefore(newNode.release(), container->childNode(m_start. offset()), es); 1051 container->insertBefore(newNode.release(), container->childNode(m_start. offset()), es);
1052 if (es.hadException()) 1052 if (es.hadException())
1053 return; 1053 return;
1054 1054
1055 // Note that m_start.offset() may have changed as a result of container- >insertBefore, 1055 // Note that m_start.offset() may have changed as a result of container- >insertBefore,
1056 // when the node we are inserting comes before the range in the same con tainer. 1056 // when the node we are inserting comes before the range in the same con tainer.
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
1687 } 1687 }
1688 1688
1689 void Range::nodeChildrenWillBeRemoved(ContainerNode* container) 1689 void Range::nodeChildrenWillBeRemoved(ContainerNode* container)
1690 { 1690 {
1691 ASSERT(container); 1691 ASSERT(container);
1692 ASSERT(container->document() == m_ownerDocument); 1692 ASSERT(container->document() == m_ownerDocument);
1693 boundaryNodeChildrenWillBeRemoved(m_start, container); 1693 boundaryNodeChildrenWillBeRemoved(m_start, container);
1694 boundaryNodeChildrenWillBeRemoved(m_end, container); 1694 boundaryNodeChildrenWillBeRemoved(m_end, container);
1695 } 1695 }
1696 1696
1697 static inline void boundaryNodeWillBeRemoved(RangeBoundaryPoint& boundary, Node* nodeToBeRemoved) 1697 static inline void boundaryNodeWillBeRemoved(RangeBoundaryPoint& boundary, Node& nodeToBeRemoved)
1698 { 1698 {
1699 if (boundary.childBefore() == nodeToBeRemoved) { 1699 if (boundary.childBefore() == nodeToBeRemoved) {
1700 boundary.childBeforeWillBeRemoved(); 1700 boundary.childBeforeWillBeRemoved();
1701 return; 1701 return;
1702 } 1702 }
1703 1703
1704 for (Node* n = boundary.container(); n; n = n->parentNode()) { 1704 for (Node* n = boundary.container(); n; n = n->parentNode()) {
1705 if (n == nodeToBeRemoved) { 1705 if (n == nodeToBeRemoved) {
1706 boundary.setToBeforeChild(nodeToBeRemoved); 1706 boundary.setToBeforeChild(nodeToBeRemoved);
1707 return; 1707 return;
1708 } 1708 }
1709 } 1709 }
1710 } 1710 }
1711 1711
1712 void Range::nodeWillBeRemoved(Node* node) 1712 void Range::nodeWillBeRemoved(Node& node)
1713 { 1713 {
1714 ASSERT(node); 1714 ASSERT(node.document() == m_ownerDocument);
1715 ASSERT(node->document() == m_ownerDocument);
1716 ASSERT(node != m_ownerDocument); 1715 ASSERT(node != m_ownerDocument);
1717 1716
1718 // FIXME: Once DOMNodeRemovedFromDocument mutation event removed, we 1717 // FIXME: Once DOMNodeRemovedFromDocument mutation event removed, we
1719 // should change following if-statement to ASSERT(!node->parentNode). 1718 // should change following if-statement to ASSERT(!node->parentNode).
1720 if (!node->parentNode()) 1719 if (!node.parentNode())
1721 return; 1720 return;
1722 boundaryNodeWillBeRemoved(m_start, node); 1721 boundaryNodeWillBeRemoved(m_start, node);
1723 boundaryNodeWillBeRemoved(m_end, node); 1722 boundaryNodeWillBeRemoved(m_end, node);
1724 } 1723 }
1725 1724
1726 static inline void boundaryTextInserted(RangeBoundaryPoint& boundary, Node* text , unsigned offset, unsigned length) 1725 static inline void boundaryTextInserted(RangeBoundaryPoint& boundary, Node* text , unsigned offset, unsigned length)
1727 { 1726 {
1728 if (boundary.container() != text) 1727 if (boundary.container() != text)
1729 return; 1728 return;
1730 unsigned boundaryOffset = boundary.offset(); 1729 unsigned boundaryOffset = boundary.offset();
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1908 1907
1909 void showTree(const WebCore::Range* range) 1908 void showTree(const WebCore::Range* range)
1910 { 1909 {
1911 if (range && range->boundaryPointsValid()) { 1910 if (range && range->boundaryPointsValid()) {
1912 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E"); 1911 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E");
1913 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset()); 1912 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset());
1914 } 1913 }
1915 } 1914 }
1916 1915
1917 #endif 1916 #endif
OLDNEW
« no previous file with comments | « Source/core/dom/Range.h ('k') | Source/core/dom/RangeBoundaryPoint.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698