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

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

Issue 2068053002: Rename Blink constants generated from IDL files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 4 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
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 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 // compare to end, and point comes after 282 // compare to end, and point comes after
283 if (compareBoundaryPoints(refNode, offset, m_end.container(), m_end.offset() , exceptionState) > 0 && !exceptionState.hadException()) 283 if (compareBoundaryPoints(refNode, offset, m_end.container(), m_end.offset() , exceptionState) > 0 && !exceptionState.hadException())
284 return 1; 284 return 1;
285 285
286 // point is in the middle of this range, or on the boundary points 286 // point is in the middle of this range, or on the boundary points
287 return 0; 287 return 0;
288 } 288 }
289 289
290 short Range::compareBoundaryPoints(unsigned how, const Range* sourceRange, Excep tionState& exceptionState) const 290 short Range::compareBoundaryPoints(unsigned how, const Range* sourceRange, Excep tionState& exceptionState) const
291 { 291 {
292 if (!(how == START_TO_START || how == START_TO_END || how == END_TO_END || h ow == END_TO_START)) { 292 if (!(how == kStartToStart || how == kStartToEnd || how == kEndToEnd || how == kEndToStart)) {
293 exceptionState.throwDOMException(NotSupportedError, "The comparison meth od provided must be one of 'START_TO_START', 'START_TO_END', 'END_TO_END', or 'E ND_TO_START'."); 293 exceptionState.throwDOMException(NotSupportedError, "The comparison meth od provided must be one of 'START_TO_START', 'START_TO_END', 'END_TO_END', or 'E ND_TO_START'.");
294 return 0; 294 return 0;
295 } 295 }
296 296
297 Node* thisCont = commonAncestorContainer(); 297 Node* thisCont = commonAncestorContainer();
298 Node* sourceCont = sourceRange->commonAncestorContainer(); 298 Node* sourceCont = sourceRange->commonAncestorContainer();
299 if (thisCont->document() != sourceCont->document()) { 299 if (thisCont->document() != sourceCont->document()) {
300 exceptionState.throwDOMException(WrongDocumentError, "The source range i s in a different document than this range."); 300 exceptionState.throwDOMException(WrongDocumentError, "The source range i s in a different document than this range.");
301 return 0; 301 return 0;
302 } 302 }
303 303
304 Node* thisTop = thisCont; 304 Node* thisTop = thisCont;
305 Node* sourceTop = sourceCont; 305 Node* sourceTop = sourceCont;
306 while (thisTop->parentNode()) 306 while (thisTop->parentNode())
307 thisTop = thisTop->parentNode(); 307 thisTop = thisTop->parentNode();
308 while (sourceTop->parentNode()) 308 while (sourceTop->parentNode())
309 sourceTop = sourceTop->parentNode(); 309 sourceTop = sourceTop->parentNode();
310 if (thisTop != sourceTop) { // in different DocumentFragments 310 if (thisTop != sourceTop) { // in different DocumentFragments
311 exceptionState.throwDOMException(WrongDocumentError, "The source range i s in a different document than this range."); 311 exceptionState.throwDOMException(WrongDocumentError, "The source range i s in a different document than this range.");
312 return 0; 312 return 0;
313 } 313 }
314 314
315 switch (how) { 315 switch (how) {
316 case START_TO_START: 316 case kStartToStart:
317 return compareBoundaryPoints(m_start, sourceRange->m_start, exceptionSta te); 317 return compareBoundaryPoints(m_start, sourceRange->m_start, exceptionSta te);
318 case START_TO_END: 318 case kStartToEnd:
319 return compareBoundaryPoints(m_end, sourceRange->m_start, exceptionState ); 319 return compareBoundaryPoints(m_end, sourceRange->m_start, exceptionState );
320 case END_TO_END: 320 case kEndToEnd:
321 return compareBoundaryPoints(m_end, sourceRange->m_end, exceptionState); 321 return compareBoundaryPoints(m_end, sourceRange->m_end, exceptionState);
322 case END_TO_START: 322 case kEndToStart:
323 return compareBoundaryPoints(m_start, sourceRange->m_end, exceptionState ); 323 return compareBoundaryPoints(m_start, sourceRange->m_end, exceptionState );
324 } 324 }
325 325
326 ASSERT_NOT_REACHED(); 326 ASSERT_NOT_REACHED();
327 return 0; 327 return 0;
328 } 328 }
329 329
330 short Range::compareBoundaryPoints(Node* containerA, int offsetA, Node* containe rB, int offsetB, ExceptionState& exceptionState) 330 short Range::compareBoundaryPoints(Node* containerA, int offsetA, Node* containe rB, int offsetB, ExceptionState& exceptionState)
331 { 331 {
332 bool disconnected = false; 332 bool disconnected = false;
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 581
582 Node* Range::processContentsBetweenOffsets(ActionType action, DocumentFragment* fragment, 582 Node* Range::processContentsBetweenOffsets(ActionType action, DocumentFragment* fragment,
583 Node* container, unsigned startOffset, unsigned endOffset, ExceptionState& e xceptionState) 583 Node* container, unsigned startOffset, unsigned endOffset, ExceptionState& e xceptionState)
584 { 584 {
585 DCHECK(container); 585 DCHECK(container);
586 DCHECK_LE(startOffset, endOffset); 586 DCHECK_LE(startOffset, endOffset);
587 587
588 // This switch statement must be consistent with that of Node::lengthOfConte nts. 588 // This switch statement must be consistent with that of Node::lengthOfConte nts.
589 Node* result = nullptr; 589 Node* result = nullptr;
590 switch (container->getNodeType()) { 590 switch (container->getNodeType()) {
591 case Node::TEXT_NODE: 591 case Node::kTextNode:
592 case Node::CDATA_SECTION_NODE: 592 case Node::kCdataSectionNode:
593 case Node::COMMENT_NODE: 593 case Node::kCommentNode:
594 case Node::PROCESSING_INSTRUCTION_NODE: 594 case Node::kProcessingInstructionNode:
595 endOffset = std::min(endOffset, toCharacterData(container)->length()); 595 endOffset = std::min(endOffset, toCharacterData(container)->length());
596 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) { 596 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) {
597 CharacterData* c = static_cast<CharacterData*>(container->cloneNode( true)); 597 CharacterData* c = static_cast<CharacterData*>(container->cloneNode( true));
598 deleteCharacterData(c, startOffset, endOffset, exceptionState); 598 deleteCharacterData(c, startOffset, endOffset, exceptionState);
599 if (fragment) { 599 if (fragment) {
600 result = fragment; 600 result = fragment;
601 result->appendChild(c, exceptionState); 601 result->appendChild(c, exceptionState);
602 } else { 602 } else {
603 result = c; 603 result = c;
604 } 604 }
605 } 605 }
606 if (action == EXTRACT_CONTENTS || action == DELETE_CONTENTS) 606 if (action == EXTRACT_CONTENTS || action == DELETE_CONTENTS)
607 toCharacterData(container)->deleteData(startOffset, endOffset - star tOffset, exceptionState); 607 toCharacterData(container)->deleteData(startOffset, endOffset - star tOffset, exceptionState);
608 break; 608 break;
609 case Node::ELEMENT_NODE: 609 case Node::kElementNode:
610 case Node::ATTRIBUTE_NODE: 610 case Node::kAttributeNode:
611 case Node::DOCUMENT_NODE: 611 case Node::kDocumentNode:
612 case Node::DOCUMENT_TYPE_NODE: 612 case Node::kDocumentTypeNode:
613 case Node::DOCUMENT_FRAGMENT_NODE: 613 case Node::kDocumentFragmentNode:
614 // FIXME: Should we assert that some nodes never appear here? 614 // FIXME: Should we assert that some nodes never appear here?
615 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) { 615 if (action == EXTRACT_CONTENTS || action == CLONE_CONTENTS) {
616 if (fragment) 616 if (fragment)
617 result = fragment; 617 result = fragment;
618 else 618 else
619 result = container->cloneNode(false); 619 result = container->cloneNode(false);
620 } 620 }
621 621
622 Node* n = container->firstChild(); 622 Node* n = container->firstChild();
623 HeapVector<Member<Node>> nodes; 623 HeapVector<Member<Node>> nodes;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 // In the case where the container is a text node, we check against the cont ainer's parent, because 744 // In the case where the container is a text node, we check against the cont ainer's parent, because
745 // text nodes get split up upon insertion. 745 // text nodes get split up upon insertion.
746 Node* checkAgainst; 746 Node* checkAgainst;
747 if (startIsText) 747 if (startIsText)
748 checkAgainst = m_start.container()->parentNode(); 748 checkAgainst = m_start.container()->parentNode();
749 else 749 else
750 checkAgainst = m_start.container(); 750 checkAgainst = m_start.container();
751 751
752 Node::NodeType newNodeType = newNode->getNodeType(); 752 Node::NodeType newNodeType = newNode->getNodeType();
753 int numNewChildren; 753 int numNewChildren;
754 if (newNodeType == Node::DOCUMENT_FRAGMENT_NODE && !newNode->isShadowRoot()) { 754 if (newNodeType == Node::kDocumentFragmentNode && !newNode->isShadowRoot()) {
755 // check each child node, not the DocumentFragment itself 755 // check each child node, not the DocumentFragment itself
756 numNewChildren = 0; 756 numNewChildren = 0;
757 for (Node* c = toDocumentFragment(newNode)->firstChild(); c; c = c->next Sibling()) { 757 for (Node* c = toDocumentFragment(newNode)->firstChild(); c; c = c->next Sibling()) {
758 if (!checkAgainst->childTypeAllowed(c->getNodeType())) { 758 if (!checkAgainst->childTypeAllowed(c->getNodeType())) {
759 exceptionState.throwDOMException(HierarchyRequestError, "The nod e to be inserted contains a '" + c->nodeName() + "' node, which may not be inser ted here."); 759 exceptionState.throwDOMException(HierarchyRequestError, "The nod e to be inserted contains a '" + c->nodeName() + "' node, which may not be inser ted here.");
760 return; 760 return;
761 } 761 }
762 ++numNewChildren; 762 ++numNewChildren;
763 } 763 }
764 } else { 764 } else {
765 numNewChildren = 1; 765 numNewChildren = 1;
766 if (!checkAgainst->childTypeAllowed(newNodeType)) { 766 if (!checkAgainst->childTypeAllowed(newNodeType)) {
767 exceptionState.throwDOMException(HierarchyRequestError, "The node to be inserted is a '" + newNode->nodeName() + "' node, which may not be inserted here."); 767 exceptionState.throwDOMException(HierarchyRequestError, "The node to be inserted is a '" + newNode->nodeName() + "' node, which may not be inserted here.");
768 return; 768 return;
769 } 769 }
770 } 770 }
771 771
772 for (Node& node : NodeTraversal::inclusiveAncestorsOf(*m_start.container())) { 772 for (Node& node : NodeTraversal::inclusiveAncestorsOf(*m_start.container())) {
773 if (node == newNode) { 773 if (node == newNode) {
774 exceptionState.throwDOMException(HierarchyRequestError, "The node to be inserted contains the insertion point; it may not be inserted into itself.") ; 774 exceptionState.throwDOMException(HierarchyRequestError, "The node to be inserted contains the insertion point; it may not be inserted into itself.") ;
775 return; 775 return;
776 } 776 }
777 } 777 }
778 778
779 // InvalidNodeTypeError: Raised if newNode is an Attr, Entity, Notation, Sha dowRoot or Document node. 779 // InvalidNodeTypeError: Raised if newNode is an Attr, Entity, Notation, Sha dowRoot or Document node.
780 switch (newNodeType) { 780 switch (newNodeType) {
781 case Node::ATTRIBUTE_NODE: 781 case Node::kAttributeNode:
782 case Node::DOCUMENT_NODE: 782 case Node::kDocumentNode:
783 exceptionState.throwDOMException(InvalidNodeTypeError, "The node to be i nserted is a '" + newNode->nodeName() + "' node, which may not be inserted here. "); 783 exceptionState.throwDOMException(InvalidNodeTypeError, "The node to be i nserted is a '" + newNode->nodeName() + "' node, which may not be inserted here. ");
784 return; 784 return;
785 default: 785 default:
786 if (newNode->isShadowRoot()) { 786 if (newNode->isShadowRoot()) {
787 exceptionState.throwDOMException(InvalidNodeTypeError, "The node to be inserted is a shadow root, which may not be inserted here."); 787 exceptionState.throwDOMException(InvalidNodeTypeError, "The node to be inserted is a shadow root, which may not be inserted here.");
788 return; 788 return;
789 } 789 }
790 break; 790 break;
791 } 791 }
792 792
(...skipping 15 matching lines...) Expand all
808 // Some types of events don't support EventQueueScope. Given 808 // Some types of events don't support EventQueueScope. Given
809 // circumstance may mutate the tree so newText->parentNode() may 809 // circumstance may mutate the tree so newText->parentNode() may
810 // become null. 810 // become null.
811 if (!newText->parentNode()) { 811 if (!newText->parentNode()) {
812 exceptionState.throwDOMException(HierarchyRequestError, "This op eration would set range's end to parent with new offset, but there's no parent i nto which to continue."); 812 exceptionState.throwDOMException(HierarchyRequestError, "This op eration would set range's end to parent with new offset, but there's no parent i nto which to continue.");
813 return; 813 return;
814 } 814 }
815 m_end.setToBeforeChild(*newText); 815 m_end.setToBeforeChild(*newText);
816 } 816 }
817 } else { 817 } else {
818 Node* lastChild = (newNodeType == Node::DOCUMENT_FRAGMENT_NODE) ? toDocu mentFragment(newNode)->lastChild() : newNode; 818 Node* lastChild = (newNodeType == Node::kDocumentFragmentNode) ? toDocum entFragment(newNode)->lastChild() : newNode;
819 if (lastChild && lastChild == m_start.childBefore()) { 819 if (lastChild && lastChild == m_start.childBefore()) {
820 // The insertion will do nothing, but we need to extend the range to include 820 // The insertion will do nothing, but we need to extend the range to include
821 // the inserted nodes. 821 // the inserted nodes.
822 Node* firstChild = (newNodeType == Node::DOCUMENT_FRAGMENT_NODE) ? t oDocumentFragment(newNode)->firstChild() : newNode; 822 Node* firstChild = (newNodeType == Node::kDocumentFragmentNode) ? to DocumentFragment(newNode)->firstChild() : newNode;
823 DCHECK(firstChild); 823 DCHECK(firstChild);
824 m_start.setToBeforeChild(*firstChild); 824 m_start.setToBeforeChild(*firstChild);
825 return; 825 return;
826 } 826 }
827 827
828 container = m_start.container(); 828 container = m_start.container();
829 container->insertBefore(newNode, NodeTraversal::childAt(*container, m_st art.offset()), exceptionState); 829 container->insertBefore(newNode, NodeTraversal::childAt(*container, m_st art.offset()), exceptionState);
830 if (exceptionState.hadException()) 830 if (exceptionState.hadException())
831 return; 831 return;
832 832
833 // Note that m_start.offset() may have changed as a result of container- >insertBefore, 833 // Note that m_start.offset() may have changed as a result of container- >insertBefore,
834 // when the node we are inserting comes before the range in the same con tainer. 834 // when the node we are inserting comes before the range in the same con tainer.
835 if (collapsed && numNewChildren) 835 if (collapsed && numNewChildren)
836 m_end.set(m_start.container(), m_start.offset() + numNewChildren, la stChild); 836 m_end.set(m_start.container(), m_start.offset() + numNewChildren, la stChild);
837 } 837 }
838 } 838 }
839 839
840 String Range::toString() const 840 String Range::toString() const
841 { 841 {
842 StringBuilder builder; 842 StringBuilder builder;
843 843
844 Node* pastLast = pastLastNode(); 844 Node* pastLast = pastLastNode();
845 for (Node* n = firstNode(); n != pastLast; n = NodeTraversal::next(*n)) { 845 for (Node* n = firstNode(); n != pastLast; n = NodeTraversal::next(*n)) {
846 Node::NodeType type = n->getNodeType(); 846 Node::NodeType type = n->getNodeType();
847 if (type == Node::TEXT_NODE || type == Node::CDATA_SECTION_NODE) { 847 if (type == Node::kTextNode || type == Node::kCdataSectionNode) {
848 String data = toCharacterData(n)->data(); 848 String data = toCharacterData(n)->data();
849 int length = data.length(); 849 int length = data.length();
850 int start = (n == m_start.container()) ? std::min(std::max(0, m_star t.offset()), length) : 0; 850 int start = (n == m_start.container()) ? std::min(std::max(0, m_star t.offset()), length) : 0;
851 int end = (n == m_end.container()) ? std::min(std::max(start, m_end. offset()), length) : length; 851 int end = (n == m_end.container()) ? std::min(std::max(start, m_end. offset()), length) : length;
852 builder.append(data, start, end - start); 852 builder.append(data, start, end - start);
853 } 853 }
854 } 854 }
855 855
856 return builder.toString(); 856 return builder.toString();
857 } 857 }
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 907
908 908
909 void Range::detach() 909 void Range::detach()
910 { 910 {
911 // This is now a no-op as per the DOM specification. 911 // This is now a no-op as per the DOM specification.
912 } 912 }
913 913
914 Node* Range::checkNodeWOffset(Node* n, int offset, ExceptionState& exceptionStat e) const 914 Node* Range::checkNodeWOffset(Node* n, int offset, ExceptionState& exceptionStat e) const
915 { 915 {
916 switch (n->getNodeType()) { 916 switch (n->getNodeType()) {
917 case Node::DOCUMENT_TYPE_NODE: 917 case Node::kDocumentTypeNode:
918 exceptionState.throwDOMException(InvalidNodeTypeError, "The node provide d is of type '" + n->nodeName() + "'."); 918 exceptionState.throwDOMException(InvalidNodeTypeError, "The node provide d is of type '" + n->nodeName() + "'.");
919 return nullptr; 919 return nullptr;
920 case Node::CDATA_SECTION_NODE: 920 case Node::kCdataSectionNode:
921 case Node::COMMENT_NODE: 921 case Node::kCommentNode:
922 case Node::TEXT_NODE: 922 case Node::kTextNode:
923 if (static_cast<unsigned>(offset) > toCharacterData(n)->length()) 923 if (static_cast<unsigned>(offset) > toCharacterData(n)->length())
924 exceptionState.throwDOMException(IndexSizeError, "The offset " + Str ing::number(offset) + " is larger than or equal to the node's length (" + String ::number(toCharacterData(n)->length()) + ")."); 924 exceptionState.throwDOMException(IndexSizeError, "The offset " + Str ing::number(offset) + " is larger than or equal to the node's length (" + String ::number(toCharacterData(n)->length()) + ").");
925 return nullptr; 925 return nullptr;
926 case Node::PROCESSING_INSTRUCTION_NODE: 926 case Node::kProcessingInstructionNode:
927 if (static_cast<unsigned>(offset) > toProcessingInstruction(n)->data().l ength()) 927 if (static_cast<unsigned>(offset) > toProcessingInstruction(n)->data().l ength())
928 exceptionState.throwDOMException(IndexSizeError, "The offset " + Str ing::number(offset) + " is larger than or equal to than the node's length (" + S tring::number(toProcessingInstruction(n)->data().length()) + ")."); 928 exceptionState.throwDOMException(IndexSizeError, "The offset " + Str ing::number(offset) + " is larger than or equal to than the node's length (" + S tring::number(toProcessingInstruction(n)->data().length()) + ").");
929 return nullptr; 929 return nullptr;
930 case Node::ATTRIBUTE_NODE: 930 case Node::kAttributeNode:
931 case Node::DOCUMENT_FRAGMENT_NODE: 931 case Node::kDocumentFragmentNode:
932 case Node::DOCUMENT_NODE: 932 case Node::kDocumentNode:
933 case Node::ELEMENT_NODE: { 933 case Node::kElementNode: {
934 if (!offset) 934 if (!offset)
935 return nullptr; 935 return nullptr;
936 Node* childBefore = NodeTraversal::childAt(*n, offset - 1); 936 Node* childBefore = NodeTraversal::childAt(*n, offset - 1);
937 if (!childBefore) 937 if (!childBefore)
938 exceptionState.throwDOMException(IndexSizeError, "There is no child at offset " + String::number(offset) + "."); 938 exceptionState.throwDOMException(IndexSizeError, "There is no child at offset " + String::number(offset) + ".");
939 return childBefore; 939 return childBefore;
940 } 940 }
941 } 941 }
942 ASSERT_NOT_REACHED(); 942 ASSERT_NOT_REACHED();
943 return nullptr; 943 return nullptr;
(...skipping 10 matching lines...) Expand all
954 // InvalidNodeTypeError: Raised if the root container of refNode is not an 954 // InvalidNodeTypeError: Raised if the root container of refNode is not an
955 // Attr, Document, DocumentFragment or ShadowRoot node, or part of a SVG sha dow DOM tree, 955 // Attr, Document, DocumentFragment or ShadowRoot node, or part of a SVG sha dow DOM tree,
956 // or if refNode is a Document, DocumentFragment, ShadowRoot, Attr, Entity, or Notation node. 956 // or if refNode is a Document, DocumentFragment, ShadowRoot, Attr, Entity, or Notation node.
957 957
958 if (!n->parentNode()) { 958 if (!n->parentNode()) {
959 exceptionState.throwDOMException(InvalidNodeTypeError, "the given Node h as no parent."); 959 exceptionState.throwDOMException(InvalidNodeTypeError, "the given Node h as no parent.");
960 return; 960 return;
961 } 961 }
962 962
963 switch (n->getNodeType()) { 963 switch (n->getNodeType()) {
964 case Node::ATTRIBUTE_NODE: 964 case Node::kAttributeNode:
965 case Node::DOCUMENT_FRAGMENT_NODE: 965 case Node::kDocumentFragmentNode:
966 case Node::DOCUMENT_NODE: 966 case Node::kDocumentNode:
967 exceptionState.throwDOMException(InvalidNodeTypeError, "The node provide d is of type '" + n->nodeName() + "'."); 967 exceptionState.throwDOMException(InvalidNodeTypeError, "The node provide d is of type '" + n->nodeName() + "'.");
968 return; 968 return;
969 case Node::CDATA_SECTION_NODE: 969 case Node::kCdataSectionNode:
970 case Node::COMMENT_NODE: 970 case Node::kCommentNode:
971 case Node::DOCUMENT_TYPE_NODE: 971 case Node::kDocumentTypeNode:
972 case Node::ELEMENT_NODE: 972 case Node::kElementNode:
973 case Node::PROCESSING_INSTRUCTION_NODE: 973 case Node::kProcessingInstructionNode:
974 case Node::TEXT_NODE: 974 case Node::kTextNode:
975 break; 975 break;
976 } 976 }
977 977
978 Node* root = n; 978 Node* root = n;
979 while (ContainerNode* parent = root->parentNode()) 979 while (ContainerNode* parent = root->parentNode())
980 root = parent; 980 root = parent;
981 981
982 switch (root->getNodeType()) { 982 switch (root->getNodeType()) {
983 case Node::ATTRIBUTE_NODE: 983 case Node::kAttributeNode:
984 case Node::DOCUMENT_NODE: 984 case Node::kDocumentNode:
985 case Node::DOCUMENT_FRAGMENT_NODE: 985 case Node::kDocumentFragmentNode:
986 case Node::ELEMENT_NODE: 986 case Node::kElementNode:
987 break; 987 break;
988 case Node::CDATA_SECTION_NODE: 988 case Node::kCdataSectionNode:
989 case Node::COMMENT_NODE: 989 case Node::kCommentNode:
990 case Node::DOCUMENT_TYPE_NODE: 990 case Node::kDocumentTypeNode:
991 case Node::PROCESSING_INSTRUCTION_NODE: 991 case Node::kProcessingInstructionNode:
992 case Node::TEXT_NODE: 992 case Node::kTextNode:
993 exceptionState.throwDOMException(InvalidNodeTypeError, "The node provide d is of type '" + n->nodeName() + "'."); 993 exceptionState.throwDOMException(InvalidNodeTypeError, "The node provide d is of type '" + n->nodeName() + "'.");
994 return; 994 return;
995 } 995 }
996 } 996 }
997 997
998 Range* Range::cloneRange() const 998 Range* Range::cloneRange() const
999 { 999 {
1000 return Range::create(*m_ownerDocument.get(), m_start.container(), m_start.of fset(), m_end.container(), m_end.offset()); 1000 return Range::create(*m_ownerDocument.get(), m_start.container(), m_start.of fset(), m_end.container(), m_end.offset());
1001 } 1001 }
1002 1002
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 exceptionState.throwTypeError("The node provided is null."); 1034 exceptionState.throwTypeError("The node provided is null.");
1035 return; 1035 return;
1036 } 1036 }
1037 1037
1038 if (!refNode->parentNode()) { 1038 if (!refNode->parentNode()) {
1039 exceptionState.throwDOMException(InvalidNodeTypeError, "the given Node h as no parent."); 1039 exceptionState.throwDOMException(InvalidNodeTypeError, "the given Node h as no parent.");
1040 return; 1040 return;
1041 } 1041 }
1042 1042
1043 switch (refNode->getNodeType()) { 1043 switch (refNode->getNodeType()) {
1044 case Node::CDATA_SECTION_NODE: 1044 case Node::kCdataSectionNode:
1045 case Node::COMMENT_NODE: 1045 case Node::kCommentNode:
1046 case Node::DOCUMENT_TYPE_NODE: 1046 case Node::kDocumentTypeNode:
1047 case Node::ELEMENT_NODE: 1047 case Node::kElementNode:
1048 case Node::PROCESSING_INSTRUCTION_NODE: 1048 case Node::kProcessingInstructionNode:
1049 case Node::TEXT_NODE: 1049 case Node::kTextNode:
1050 break; 1050 break;
1051 case Node::ATTRIBUTE_NODE: 1051 case Node::kAttributeNode:
1052 case Node::DOCUMENT_FRAGMENT_NODE: 1052 case Node::kDocumentFragmentNode:
1053 case Node::DOCUMENT_NODE: 1053 case Node::kDocumentNode:
1054 exceptionState.throwDOMException(InvalidNodeTypeError, "The node provide d is of type '" + refNode->nodeName() + "'."); 1054 exceptionState.throwDOMException(InvalidNodeTypeError, "The node provide d is of type '" + refNode->nodeName() + "'.");
1055 return; 1055 return;
1056 } 1056 }
1057 1057
1058 if (m_ownerDocument != refNode->document()) 1058 if (m_ownerDocument != refNode->document())
1059 setDocument(refNode->document()); 1059 setDocument(refNode->document());
1060 1060
1061 setStartBefore(refNode); 1061 setStartBefore(refNode);
1062 setEndAfter(refNode); 1062 setEndAfter(refNode);
1063 } 1063 }
1064 1064
1065 void Range::selectNodeContents(Node* refNode, ExceptionState& exceptionState) 1065 void Range::selectNodeContents(Node* refNode, ExceptionState& exceptionState)
1066 { 1066 {
1067 if (!refNode) { 1067 if (!refNode) {
1068 // FIXME: Generated bindings code never calls with null, and neither sho uld other callers! 1068 // FIXME: Generated bindings code never calls with null, and neither sho uld other callers!
1069 exceptionState.throwTypeError("The node provided is null."); 1069 exceptionState.throwTypeError("The node provided is null.");
1070 return; 1070 return;
1071 } 1071 }
1072 1072
1073 // InvalidNodeTypeError: Raised if refNode or an ancestor of refNode is an E ntity, Notation 1073 // InvalidNodeTypeError: Raised if refNode or an ancestor of refNode is an E ntity, Notation
1074 // or DocumentType node. 1074 // or DocumentType node.
1075 for (Node* n = refNode; n; n = n->parentNode()) { 1075 for (Node* n = refNode; n; n = n->parentNode()) {
1076 switch (n->getNodeType()) { 1076 switch (n->getNodeType()) {
1077 case Node::ATTRIBUTE_NODE: 1077 case Node::kAttributeNode:
1078 case Node::CDATA_SECTION_NODE: 1078 case Node::kCdataSectionNode:
1079 case Node::COMMENT_NODE: 1079 case Node::kCommentNode:
1080 case Node::DOCUMENT_FRAGMENT_NODE: 1080 case Node::kDocumentFragmentNode:
1081 case Node::DOCUMENT_NODE: 1081 case Node::kDocumentNode:
1082 case Node::ELEMENT_NODE: 1082 case Node::kElementNode:
1083 case Node::PROCESSING_INSTRUCTION_NODE: 1083 case Node::kProcessingInstructionNode:
1084 case Node::TEXT_NODE: 1084 case Node::kTextNode:
1085 break; 1085 break;
1086 case Node::DOCUMENT_TYPE_NODE: 1086 case Node::kDocumentTypeNode:
1087 exceptionState.throwDOMException(InvalidNodeTypeError, "The node pro vided is of type '" + refNode->nodeName() + "'."); 1087 exceptionState.throwDOMException(InvalidNodeTypeError, "The node pro vided is of type '" + refNode->nodeName() + "'.");
1088 return; 1088 return;
1089 } 1089 }
1090 } 1090 }
1091 1091
1092 if (m_ownerDocument != refNode->document()) 1092 if (m_ownerDocument != refNode->document())
1093 setDocument(refNode->document()); 1093 setDocument(refNode->document());
1094 1094
1095 m_start.setToStartOfNode(*refNode); 1095 m_start.setToStartOfNode(*refNode);
1096 m_end.setToEndOfNode(*refNode); 1096 m_end.setToEndOfNode(*refNode);
1097 } 1097 }
1098 1098
1099 bool Range::selectNodeContents(Node* refNode, Position& start, Position& end) 1099 bool Range::selectNodeContents(Node* refNode, Position& start, Position& end)
1100 { 1100 {
1101 if (!refNode) { 1101 if (!refNode) {
1102 return false; 1102 return false;
1103 } 1103 }
1104 1104
1105 for (Node* n = refNode; n; n = n->parentNode()) { 1105 for (Node* n = refNode; n; n = n->parentNode()) {
1106 switch (n->getNodeType()) { 1106 switch (n->getNodeType()) {
1107 case Node::ATTRIBUTE_NODE: 1107 case Node::kAttributeNode:
1108 case Node::CDATA_SECTION_NODE: 1108 case Node::kCdataSectionNode:
1109 case Node::COMMENT_NODE: 1109 case Node::kCommentNode:
1110 case Node::DOCUMENT_FRAGMENT_NODE: 1110 case Node::kDocumentFragmentNode:
1111 case Node::DOCUMENT_NODE: 1111 case Node::kDocumentNode:
1112 case Node::ELEMENT_NODE: 1112 case Node::kElementNode:
1113 case Node::PROCESSING_INSTRUCTION_NODE: 1113 case Node::kProcessingInstructionNode:
1114 case Node::TEXT_NODE: 1114 case Node::kTextNode:
1115 break; 1115 break;
1116 case Node::DOCUMENT_TYPE_NODE: 1116 case Node::kDocumentTypeNode:
1117 return false; 1117 return false;
1118 } 1118 }
1119 } 1119 }
1120 1120
1121 RangeBoundaryPoint startBoundaryPoint(refNode); 1121 RangeBoundaryPoint startBoundaryPoint(refNode);
1122 startBoundaryPoint.setToStartOfNode(*refNode); 1122 startBoundaryPoint.setToStartOfNode(*refNode);
1123 start = startBoundaryPoint.toPosition(); 1123 start = startBoundaryPoint.toPosition();
1124 RangeBoundaryPoint endBoundaryPoint(refNode); 1124 RangeBoundaryPoint endBoundaryPoint(refNode);
1125 endBoundaryPoint.setToEndOfNode(*refNode); 1125 endBoundaryPoint.setToEndOfNode(*refNode);
1126 end = endBoundaryPoint.toPosition(); 1126 end = endBoundaryPoint.toPosition();
1127 return true; 1127 return true;
1128 } 1128 }
1129 1129
1130 void Range::surroundContents(Node* newParent, ExceptionState& exceptionState) 1130 void Range::surroundContents(Node* newParent, ExceptionState& exceptionState)
1131 { 1131 {
1132 if (!newParent) { 1132 if (!newParent) {
1133 // FIXME: Generated bindings code never calls with null, and neither sho uld other callers! 1133 // FIXME: Generated bindings code never calls with null, and neither sho uld other callers!
1134 exceptionState.throwTypeError("The node provided is null."); 1134 exceptionState.throwTypeError("The node provided is null.");
1135 return; 1135 return;
1136 } 1136 }
1137 1137
1138 // InvalidStateError: Raised if the Range partially selects a non-Text node. 1138 // InvalidStateError: Raised if the Range partially selects a non-Text node.
1139 Node* startNonTextContainer = m_start.container(); 1139 Node* startNonTextContainer = m_start.container();
1140 if (startNonTextContainer->getNodeType() == Node::TEXT_NODE) 1140 if (startNonTextContainer->getNodeType() == Node::kTextNode)
1141 startNonTextContainer = startNonTextContainer->parentNode(); 1141 startNonTextContainer = startNonTextContainer->parentNode();
1142 Node* endNonTextContainer = m_end.container(); 1142 Node* endNonTextContainer = m_end.container();
1143 if (endNonTextContainer->getNodeType() == Node::TEXT_NODE) 1143 if (endNonTextContainer->getNodeType() == Node::kTextNode)
1144 endNonTextContainer = endNonTextContainer->parentNode(); 1144 endNonTextContainer = endNonTextContainer->parentNode();
1145 if (startNonTextContainer != endNonTextContainer) { 1145 if (startNonTextContainer != endNonTextContainer) {
1146 exceptionState.throwDOMException(InvalidStateError, "The Range has parti ally selected a non-Text node."); 1146 exceptionState.throwDOMException(InvalidStateError, "The Range has parti ally selected a non-Text node.");
1147 return; 1147 return;
1148 } 1148 }
1149 1149
1150 // InvalidNodeTypeError: Raised if node is an Attr, Entity, DocumentType, No tation, 1150 // InvalidNodeTypeError: Raised if node is an Attr, Entity, DocumentType, No tation,
1151 // Document, or DocumentFragment node. 1151 // Document, or DocumentFragment node.
1152 switch (newParent->getNodeType()) { 1152 switch (newParent->getNodeType()) {
1153 case Node::ATTRIBUTE_NODE: 1153 case Node::kAttributeNode:
1154 case Node::DOCUMENT_FRAGMENT_NODE: 1154 case Node::kDocumentFragmentNode:
1155 case Node::DOCUMENT_NODE: 1155 case Node::kDocumentNode:
1156 case Node::DOCUMENT_TYPE_NODE: 1156 case Node::kDocumentTypeNode:
1157 exceptionState.throwDOMException(InvalidNodeTypeError, "The node provide d is of type '" + newParent->nodeName() + "'."); 1157 exceptionState.throwDOMException(InvalidNodeTypeError, "The node provide d is of type '" + newParent->nodeName() + "'.");
1158 return; 1158 return;
1159 case Node::CDATA_SECTION_NODE: 1159 case Node::kCdataSectionNode:
1160 case Node::COMMENT_NODE: 1160 case Node::kCommentNode:
1161 case Node::ELEMENT_NODE: 1161 case Node::kElementNode:
1162 case Node::PROCESSING_INSTRUCTION_NODE: 1162 case Node::kProcessingInstructionNode:
1163 case Node::TEXT_NODE: 1163 case Node::kTextNode:
1164 break; 1164 break;
1165 } 1165 }
1166 1166
1167 // Raise a HierarchyRequestError if m_start.container() doesn't accept child ren like newParent. 1167 // Raise a HierarchyRequestError if m_start.container() doesn't accept child ren like newParent.
1168 Node* parentOfNewParent = m_start.container(); 1168 Node* parentOfNewParent = m_start.container();
1169 1169
1170 // If m_start.container() is a character data node, it will be split and it will be its parent that will 1170 // If m_start.container() is a character data node, it will be split and it will be its parent that will
1171 // need to accept newParent (or in the case of a comment, it logically "woul d" be inserted into the parent, 1171 // need to accept newParent (or in the case of a comment, it logically "woul d" be inserted into the parent,
1172 // although this will fail below for another reason). 1172 // although this will fail below for another reason).
1173 if (parentOfNewParent->isCharacterDataNode()) 1173 if (parentOfNewParent->isCharacterDataNode())
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
1587 { 1587 {
1588 if (range && range->boundaryPointsValid()) { 1588 if (range && range->boundaryPointsValid()) {
1589 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E"); 1589 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E");
1590 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset()); 1590 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset());
1591 } else { 1591 } else {
1592 fprintf(stderr, "Cannot show tree if range is null, or if boundary point s are invalid.\n"); 1592 fprintf(stderr, "Cannot show tree if range is null, or if boundary point s are invalid.\n");
1593 } 1593 }
1594 } 1594 }
1595 1595
1596 #endif 1596 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/Range.h ('k') | third_party/WebKit/Source/core/dom/StyleSheetCandidate.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698