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

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

Issue 674553002: Move parts of core/dom to C++11 (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Make Windows shut up when I just try following the style guide Created 6 years, 2 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/dom/PresentationAttributeStyle.cpp ('k') | no next file » | 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 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 } else { 579 } else {
580 while (container->parentNode() != commonRoot) 580 while (container->parentNode() != commonRoot)
581 container = container->parentNode(); 581 container = container->parentNode();
582 } 582 }
583 583
584 return container; 584 return container;
585 } 585 }
586 586
587 PassRefPtrWillBeRawPtr<DocumentFragment> Range::processContents(ActionType actio n, ExceptionState& exceptionState) 587 PassRefPtrWillBeRawPtr<DocumentFragment> Range::processContents(ActionType actio n, ExceptionState& exceptionState)
588 { 588 {
589 typedef WillBeHeapVector<RefPtrWillBeMember<Node> > NodeVector; 589 typedef WillBeHeapVector<RefPtrWillBeMember<Node>> NodeVector;
590 590
591 RefPtrWillBeRawPtr<DocumentFragment> fragment = nullptr; 591 RefPtrWillBeRawPtr<DocumentFragment> fragment = nullptr;
592 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) 592 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS)
593 fragment = DocumentFragment::create(*m_ownerDocument.get()); 593 fragment = DocumentFragment::create(*m_ownerDocument.get());
594 594
595 if (collapsed()) 595 if (collapsed())
596 return fragment.release(); 596 return fragment.release();
597 597
598 RefPtrWillBeRawPtr<Node> commonRoot = commonAncestorContainer(); 598 RefPtrWillBeRawPtr<Node> commonRoot = commonAncestorContainer();
599 ASSERT(commonRoot); 599 ASSERT(commonRoot);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 case Node::DOCUMENT_FRAGMENT_NODE: 745 case Node::DOCUMENT_FRAGMENT_NODE:
746 // FIXME: Should we assert that some nodes never appear here? 746 // FIXME: Should we assert that some nodes never appear here?
747 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) { 747 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) {
748 if (fragment) 748 if (fragment)
749 result = fragment; 749 result = fragment;
750 else 750 else
751 result = container->cloneNode(false); 751 result = container->cloneNode(false);
752 } 752 }
753 753
754 Node* n = container->firstChild(); 754 Node* n = container->firstChild();
755 WillBeHeapVector<RefPtrWillBeMember<Node> > nodes; 755 WillBeHeapVector<RefPtrWillBeMember<Node>> nodes;
756 for (unsigned i = startOffset; n && i; i--) 756 for (unsigned i = startOffset; n && i; i--)
757 n = n->nextSibling(); 757 n = n->nextSibling();
758 for (unsigned i = startOffset; n && i < endOffset; i++, n = n->nextSibli ng()) 758 for (unsigned i = startOffset; n && i < endOffset; i++, n = n->nextSibli ng())
759 nodes.append(n); 759 nodes.append(n);
760 760
761 processNodes(action, nodes, container, result, exceptionState); 761 processNodes(action, nodes, container, result, exceptionState);
762 break; 762 break;
763 } 763 }
764 764
765 return result.release(); 765 return result.release();
766 } 766 }
767 767
768 void Range::processNodes(ActionType action, WillBeHeapVector<RefPtrWillBeMember< Node> >& nodes, PassRefPtrWillBeRawPtr<Node> oldContainer, PassRefPtrWillBeRawPt r<Node> newContainer, ExceptionState& exceptionState) 768 void Range::processNodes(ActionType action, WillBeHeapVector<RefPtrWillBeMember< Node>>& nodes, PassRefPtrWillBeRawPtr<Node> oldContainer, PassRefPtrWillBeRawPtr <Node> newContainer, ExceptionState& exceptionState)
769 { 769 {
770 for (unsigned i = 0; i < nodes.size(); i++) { 770 for (auto& node : nodes) {
771 switch (action) { 771 switch (action) {
772 case DELETE_CONTENTS: 772 case DELETE_CONTENTS:
773 oldContainer->removeChild(nodes[i].get(), exceptionState); 773 oldContainer->removeChild(node.get(), exceptionState);
774 break; 774 break;
775 case EXTRACT_CONTENTS: 775 case EXTRACT_CONTENTS:
776 newContainer->appendChild(nodes[i].release(), exceptionState); // wi ll remove n from its parent 776 newContainer->appendChild(node.release(), exceptionState); // Will r emove n from its parent.
777 break; 777 break;
778 case CLONE_CONTENTS: 778 case CLONE_CONTENTS:
779 newContainer->appendChild(nodes[i]->cloneNode(true), exceptionState) ; 779 newContainer->appendChild(node->cloneNode(true), exceptionState);
780 break; 780 break;
781 } 781 }
782 } 782 }
783 } 783 }
784 784
785 PassRefPtrWillBeRawPtr<Node> Range::processAncestorsAndTheirSiblings(ActionType action, Node* container, ContentsProcessDirection direction, PassRefPtrWillBeRaw Ptr<Node> passedClonedContainer, Node* commonRoot, ExceptionState& exceptionStat e) 785 PassRefPtrWillBeRawPtr<Node> Range::processAncestorsAndTheirSiblings(ActionType action, Node* container, ContentsProcessDirection direction, PassRefPtrWillBeRaw Ptr<Node> passedClonedContainer, Node* commonRoot, ExceptionState& exceptionStat e)
786 { 786 {
787 typedef WillBeHeapVector<RefPtrWillBeMember<Node> > NodeVector; 787 typedef WillBeHeapVector<RefPtrWillBeMember<Node>> NodeVector;
788 788
789 RefPtrWillBeRawPtr<Node> clonedContainer = passedClonedContainer; 789 RefPtrWillBeRawPtr<Node> clonedContainer = passedClonedContainer;
790 NodeVector ancestors; 790 NodeVector ancestors;
791 for (ContainerNode* n = container->parentNode(); n && n != commonRoot; n = n ->parentNode()) 791 for (ContainerNode* n = container->parentNode(); n && n != commonRoot; n = n ->parentNode())
792 ancestors.append(n); 792 ancestors.append(n);
793 793
794 RefPtrWillBeRawPtr<Node> firstChildInAncestorToProcess = direction == Proces sContentsForward ? container->nextSibling() : container->previousSibling(); 794 RefPtrWillBeRawPtr<Node> firstChildInAncestorToProcess = direction == Proces sContentsForward ? container->nextSibling() : container->previousSibling();
795 for (NodeVector::const_iterator it = ancestors.begin(); it != ancestors.end( ); ++it) { 795 for (const RefPtrWillBeRawPtr<Node>& ancestor : ancestors) {
796 RefPtrWillBeRawPtr<Node> ancestor = *it;
797 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) { 796 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) {
798 if (RefPtrWillBeRawPtr<Node> clonedAncestor = ancestor->cloneNode(fa lse)) { // Might have been removed already during mutation event. 797 if (RefPtrWillBeRawPtr<Node> clonedAncestor = ancestor->cloneNode(fa lse)) { // Might have been removed already during mutation event.
799 clonedAncestor->appendChild(clonedContainer, exceptionState); 798 clonedAncestor->appendChild(clonedContainer, exceptionState);
800 clonedContainer = clonedAncestor; 799 clonedContainer = clonedAncestor;
801 } 800 }
802 } 801 }
803 802
804 // Copy siblings of an ancestor of start/end containers 803 // Copy siblings of an ancestor of start/end containers
805 // FIXME: This assertion may fail if DOM is modified during mutation eve nt 804 // FIXME: This assertion may fail if DOM is modified during mutation eve nt
806 // FIXME: Share code with Range::processNodes 805 // FIXME: Share code with Range::processNodes
807 ASSERT(!firstChildInAncestorToProcess || firstChildInAncestorToProcess-> parentNode() == ancestor); 806 ASSERT(!firstChildInAncestorToProcess || firstChildInAncestorToProcess-> parentNode() == ancestor);
808 807
809 NodeVector nodes; 808 NodeVector nodes;
810 for (Node* child = firstChildInAncestorToProcess.get(); child; 809 for (Node* child = firstChildInAncestorToProcess.get(); child;
811 child = (direction == ProcessContentsForward) ? child->nextSibling() : child->previousSibling()) 810 child = (direction == ProcessContentsForward) ? child->nextSibling() : child->previousSibling())
812 nodes.append(child); 811 nodes.append(child);
813 812
814 for (NodeVector::const_iterator it = nodes.begin(); it != nodes.end(); + +it) { 813 for (const RefPtrWillBeRawPtr<Node>& node : nodes) {
815 Node* child = it->get(); 814 Node* child = node.get();
816 switch (action) { 815 switch (action) {
817 case DELETE_CONTENTS: 816 case DELETE_CONTENTS:
818 // Prior call of ancestor->removeChild() may cause a tree change due to DOMSubtreeModified event. 817 // Prior call of ancestor->removeChild() may cause a tree change due to DOMSubtreeModified event.
819 // Therefore, we need to make sure |ancestor| is still |child|'s parent. 818 // Therefore, we need to make sure |ancestor| is still |child|'s parent.
820 if (ancestor == child->parentNode()) 819 if (ancestor == child->parentNode())
821 ancestor->removeChild(child, exceptionState); 820 ancestor->removeChild(child, exceptionState);
822 break; 821 break;
823 case EXTRACT_CONTENTS: // will remove child from ancestor 822 case EXTRACT_CONTENTS: // will remove child from ancestor
824 if (direction == ProcessContentsForward) 823 if (direction == ProcessContentsForward)
825 clonedContainer->appendChild(child, exceptionState); 824 clonedContainer->appendChild(child, exceptionState);
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 void Range::detach() 1045 void Range::detach()
1047 { 1046 {
1048 // This is now a no-op as per the DOM specification. 1047 // This is now a no-op as per the DOM specification.
1049 } 1048 }
1050 1049
1051 Node* Range::checkNodeWOffset(Node* n, int offset, ExceptionState& exceptionStat e) const 1050 Node* Range::checkNodeWOffset(Node* n, int offset, ExceptionState& exceptionStat e) const
1052 { 1051 {
1053 switch (n->nodeType()) { 1052 switch (n->nodeType()) {
1054 case Node::DOCUMENT_TYPE_NODE: 1053 case Node::DOCUMENT_TYPE_NODE:
1055 exceptionState.throwDOMException(InvalidNodeTypeError, "The node pro vided is of type '" + n->nodeName() + "'."); 1054 exceptionState.throwDOMException(InvalidNodeTypeError, "The node pro vided is of type '" + n->nodeName() + "'.");
1056 return 0; 1055 return nullptr;
1057 case Node::CDATA_SECTION_NODE: 1056 case Node::CDATA_SECTION_NODE:
1058 case Node::COMMENT_NODE: 1057 case Node::COMMENT_NODE:
1059 case Node::TEXT_NODE: 1058 case Node::TEXT_NODE:
1060 if (static_cast<unsigned>(offset) > toCharacterData(n)->length()) 1059 if (static_cast<unsigned>(offset) > toCharacterData(n)->length())
1061 exceptionState.throwDOMException(IndexSizeError, "The offset " + String::number(offset) + " is larger than or equal to the node's length (" + St ring::number(toCharacterData(n)->length()) + ")."); 1060 exceptionState.throwDOMException(IndexSizeError, "The offset " + String::number(offset) + " is larger than or equal to the node's length (" + St ring::number(toCharacterData(n)->length()) + ").");
1062 return 0; 1061 return nullptr;
1063 case Node::PROCESSING_INSTRUCTION_NODE: 1062 case Node::PROCESSING_INSTRUCTION_NODE:
1064 if (static_cast<unsigned>(offset) > toProcessingInstruction(n)->data ().length()) 1063 if (static_cast<unsigned>(offset) > toProcessingInstruction(n)->data ().length())
1065 exceptionState.throwDOMException(IndexSizeError, "The offset " + String::number(offset) + " is larger than or equal to than the node's length (" + String::number(toProcessingInstruction(n)->data().length()) + ")."); 1064 exceptionState.throwDOMException(IndexSizeError, "The offset " + String::number(offset) + " is larger than or equal to than the node's length (" + String::number(toProcessingInstruction(n)->data().length()) + ").");
1066 return 0; 1065 return nullptr;
1067 case Node::ATTRIBUTE_NODE: 1066 case Node::ATTRIBUTE_NODE:
1068 case Node::DOCUMENT_FRAGMENT_NODE: 1067 case Node::DOCUMENT_FRAGMENT_NODE:
1069 case Node::DOCUMENT_NODE: 1068 case Node::DOCUMENT_NODE:
1070 case Node::ELEMENT_NODE: { 1069 case Node::ELEMENT_NODE: {
1071 if (!offset) 1070 if (!offset)
1072 return 0; 1071 return nullptr;
1073 Node* childBefore = NodeTraversal::childAt(*n, offset - 1); 1072 Node* childBefore = NodeTraversal::childAt(*n, offset - 1);
1074 if (!childBefore) 1073 if (!childBefore)
1075 exceptionState.throwDOMException(IndexSizeError, "There is no ch ild at offset " + String::number(offset) + "."); 1074 exceptionState.throwDOMException(IndexSizeError, "There is no ch ild at offset " + String::number(offset) + ".");
1076 return childBefore; 1075 return childBefore;
1077 } 1076 }
1078 } 1077 }
1079 ASSERT_NOT_REACHED(); 1078 ASSERT_NOT_REACHED();
1080 return 0; 1079 return nullptr;
1081 } 1080 }
1082 1081
1083 void Range::checkNodeBA(Node* n, ExceptionState& exceptionState) const 1082 void Range::checkNodeBA(Node* n, ExceptionState& exceptionState) const
1084 { 1083 {
1085 if (!n) { 1084 if (!n) {
1086 exceptionState.throwDOMException(NotFoundError, "The node provided is nu ll."); 1085 exceptionState.throwDOMException(NotFoundError, "The node provided is nu ll.");
1087 return; 1086 return;
1088 } 1087 }
1089 1088
1090 // InvalidNodeTypeError: Raised if the root container of refNode is not an 1089 // InvalidNodeTypeError: Raised if the root container of refNode is not an
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1393 return m_start.container(); 1392 return m_start.container();
1394 if (Node* child = NodeTraversal::childAt(*m_start.container(), m_start.offse t())) 1393 if (Node* child = NodeTraversal::childAt(*m_start.container(), m_start.offse t()))
1395 return child; 1394 return child;
1396 if (!m_start.offset()) 1395 if (!m_start.offset())
1397 return m_start.container(); 1396 return m_start.container();
1398 return NodeTraversal::nextSkippingChildren(*m_start.container()); 1397 return NodeTraversal::nextSkippingChildren(*m_start.container());
1399 } 1398 }
1400 1399
1401 ShadowRoot* Range::shadowRoot() const 1400 ShadowRoot* Range::shadowRoot() const
1402 { 1401 {
1403 return startContainer() ? startContainer()->containingShadowRoot() : 0; 1402 return startContainer() ? startContainer()->containingShadowRoot() : nullptr ;
1404 } 1403 }
1405 1404
1406 Node* Range::pastLastNode() const 1405 Node* Range::pastLastNode() const
1407 { 1406 {
1408 if (m_end.container()->offsetInCharacters()) 1407 if (m_end.container()->offsetInCharacters())
1409 return NodeTraversal::nextSkippingChildren(*m_end.container()); 1408 return NodeTraversal::nextSkippingChildren(*m_end.container());
1410 if (Node* child = NodeTraversal::childAt(*m_end.container(), m_end.offset()) ) 1409 if (Node* child = NodeTraversal::childAt(*m_end.container(), m_end.offset()) )
1411 return child; 1410 return child;
1412 return NodeTraversal::nextSkippingChildren(*m_end.container()); 1411 return NodeTraversal::nextSkippingChildren(*m_end.container());
1413 } 1412 }
1414 1413
1415 IntRect Range::boundingBox() const 1414 IntRect Range::boundingBox() const
1416 { 1415 {
1417 IntRect result; 1416 IntRect result;
1418 Vector<IntRect> rects; 1417 Vector<IntRect> rects;
1419 textRects(rects); 1418 textRects(rects);
1420 const size_t n = rects.size(); 1419 for (const IntRect& rect : rects)
1421 for (size_t i = 0; i < n; ++i) 1420 result.unite(rect);
1422 result.unite(rects[i]);
1423 return result; 1421 return result;
1424 } 1422 }
1425 1423
1426 void Range::textRects(Vector<IntRect>& rects, bool useSelectionHeight, RangeInFi xedPosition* inFixed) const 1424 void Range::textRects(Vector<IntRect>& rects, bool useSelectionHeight, RangeInFi xedPosition* inFixed) const
1427 { 1425 {
1428 Node* startContainer = m_start.container(); 1426 Node* startContainer = m_start.container();
1429 ASSERT(startContainer); 1427 ASSERT(startContainer);
1430 Node* endContainer = m_end.container(); 1428 Node* endContainer = m_end.container();
1431 ASSERT(endContainer); 1429 ASSERT(endContainer);
1432 1430
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1715 { 1713 {
1716 return ClientRect::create(boundingRect()); 1714 return ClientRect::create(boundingRect());
1717 } 1715 }
1718 1716
1719 void Range::getBorderAndTextQuads(Vector<FloatQuad>& quads) const 1717 void Range::getBorderAndTextQuads(Vector<FloatQuad>& quads) const
1720 { 1718 {
1721 Node* startContainer = m_start.container(); 1719 Node* startContainer = m_start.container();
1722 Node* endContainer = m_end.container(); 1720 Node* endContainer = m_end.container();
1723 Node* stopNode = pastLastNode(); 1721 Node* stopNode = pastLastNode();
1724 1722
1725 WillBeHeapHashSet<RawPtrWillBeMember<Node> > nodeSet; 1723 WillBeHeapHashSet<RawPtrWillBeMember<Node>> nodeSet;
1726 for (Node* node = firstNode(); node != stopNode; node = NodeTraversal::next( *node)) { 1724 for (Node* node = firstNode(); node != stopNode; node = NodeTraversal::next( *node)) {
1727 if (node->isElementNode()) 1725 if (node->isElementNode())
1728 nodeSet.add(node); 1726 nodeSet.add(node);
1729 } 1727 }
1730 1728
1731 for (Node* node = firstNode(); node != stopNode; node = NodeTraversal::next( *node)) { 1729 for (Node* node = firstNode(); node != stopNode; node = NodeTraversal::next( *node)) {
1732 if (node->isElementNode()) { 1730 if (node->isElementNode()) {
1733 if (!nodeSet.contains(node->parentNode())) { 1731 if (!nodeSet.contains(node->parentNode())) {
1734 if (RenderBoxModelObject* renderBoxModelObject = toElement(node) ->renderBoxModelObject()) { 1732 if (RenderBoxModelObject* renderBoxModelObject = toElement(node) ->renderBoxModelObject()) {
1735 Vector<FloatQuad> elementQuads; 1733 Vector<FloatQuad> elementQuads;
(...skipping 17 matching lines...) Expand all
1753 } 1751 }
1754 } 1752 }
1755 } 1753 }
1756 1754
1757 FloatRect Range::boundingRect() const 1755 FloatRect Range::boundingRect() const
1758 { 1756 {
1759 m_ownerDocument->updateLayoutIgnorePendingStylesheets(); 1757 m_ownerDocument->updateLayoutIgnorePendingStylesheets();
1760 1758
1761 Vector<FloatQuad> quads; 1759 Vector<FloatQuad> quads;
1762 getBorderAndTextQuads(quads); 1760 getBorderAndTextQuads(quads);
1763 if (quads.isEmpty())
1764 return FloatRect();
1765 1761
1766 FloatRect result; 1762 FloatRect result;
1767 for (size_t i = 0; i < quads.size(); ++i) 1763 for (const FloatQuad& quad : quads)
1768 result.unite(quads[i].boundingBox()); 1764 result.unite(quad.boundingBox());
1769 1765
1770 return result; 1766 return result;
1771 } 1767 }
1772 1768
1773 void Range::trace(Visitor* visitor) 1769 void Range::trace(Visitor* visitor)
1774 { 1770 {
1775 visitor->trace(m_ownerDocument); 1771 visitor->trace(m_ownerDocument);
1776 visitor->trace(m_start); 1772 visitor->trace(m_start);
1777 visitor->trace(m_end); 1773 visitor->trace(m_end);
1778 } 1774 }
1779 1775
1780 } // namespace blink 1776 } // namespace blink
1781 1777
1782 #ifndef NDEBUG 1778 #ifndef NDEBUG
1783 1779
1784 void showTree(const blink::Range* range) 1780 void showTree(const blink::Range* range)
1785 { 1781 {
1786 if (range && range->boundaryPointsValid()) { 1782 if (range && range->boundaryPointsValid()) {
1787 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E"); 1783 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E");
1788 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset()); 1784 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset());
1789 } 1785 }
1790 } 1786 }
1791 1787
1792 #endif 1788 #endif
OLDNEW
« no previous file with comments | « Source/core/dom/PresentationAttributeStyle.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698