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

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

Issue 974823002: Add [TypeChecking=Interface] to Range interface (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: add FIXME comments Created 5 years, 9 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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 Node* startRootContainer = start.container(); 150 Node* startRootContainer = start.container();
151 while (startRootContainer->parentNode()) 151 while (startRootContainer->parentNode())
152 startRootContainer = startRootContainer->parentNode(); 152 startRootContainer = startRootContainer->parentNode();
153 153
154 return startRootContainer != endRootContainer || (Range::compareBoundaryPoin ts(start, end, ASSERT_NO_EXCEPTION) > 0); 154 return startRootContainer != endRootContainer || (Range::compareBoundaryPoin ts(start, end, ASSERT_NO_EXCEPTION) > 0);
155 } 155 }
156 156
157 void Range::setStart(PassRefPtrWillBeRawPtr<Node> refNode, int offset, Exception State& exceptionState) 157 void Range::setStart(PassRefPtrWillBeRawPtr<Node> refNode, int offset, Exception State& exceptionState)
158 { 158 {
159 if (!refNode) { 159 if (!refNode) {
160 exceptionState.throwDOMException(NotFoundError, "The node provided was n ull."); 160 // FIXME: Generated bindings code never calls with null, and neither sho uld other callers!
161 exceptionState.throwTypeError("The node provided is null.");
161 return; 162 return;
162 } 163 }
163 164
164 bool didMoveDocument = false; 165 bool didMoveDocument = false;
165 if (refNode->document() != m_ownerDocument) { 166 if (refNode->document() != m_ownerDocument) {
166 setDocument(refNode->document()); 167 setDocument(refNode->document());
167 didMoveDocument = true; 168 didMoveDocument = true;
168 } 169 }
169 170
170 Node* childNode = checkNodeWOffset(refNode.get(), offset, exceptionState); 171 Node* childNode = checkNodeWOffset(refNode.get(), offset, exceptionState);
171 if (exceptionState.hadException()) 172 if (exceptionState.hadException())
172 return; 173 return;
173 174
174 m_start.set(refNode, offset, childNode); 175 m_start.set(refNode, offset, childNode);
175 176
176 if (didMoveDocument || checkForDifferentRootContainer(m_start, m_end)) 177 if (didMoveDocument || checkForDifferentRootContainer(m_start, m_end))
177 collapse(true); 178 collapse(true);
178 } 179 }
179 180
180 void Range::setEnd(PassRefPtrWillBeRawPtr<Node> refNode, int offset, ExceptionSt ate& exceptionState) 181 void Range::setEnd(PassRefPtrWillBeRawPtr<Node> refNode, int offset, ExceptionSt ate& exceptionState)
181 { 182 {
182 if (!refNode) { 183 if (!refNode) {
183 exceptionState.throwDOMException(NotFoundError, "The node provided was n ull."); 184 // FIXME: Generated bindings code never calls with null, and neither sho uld other callers!
185 exceptionState.throwTypeError("The node provided is null.");
184 return; 186 return;
185 } 187 }
186 188
187 bool didMoveDocument = false; 189 bool didMoveDocument = false;
188 if (refNode->document() != m_ownerDocument) { 190 if (refNode->document() != m_ownerDocument) {
189 setDocument(refNode->document()); 191 setDocument(refNode->document());
190 didMoveDocument = true; 192 didMoveDocument = true;
191 } 193 }
192 194
193 Node* childNode = checkNodeWOffset(refNode.get(), offset, exceptionState); 195 Node* childNode = checkNodeWOffset(refNode.get(), offset, exceptionState);
(...skipping 22 matching lines...) Expand all
216 { 218 {
217 if (toStart) 219 if (toStart)
218 m_end = m_start; 220 m_end = m_start;
219 else 221 else
220 m_start = m_end; 222 m_start = m_end;
221 } 223 }
222 224
223 bool Range::isPointInRange(Node* refNode, int offset, ExceptionState& exceptionS tate) 225 bool Range::isPointInRange(Node* refNode, int offset, ExceptionState& exceptionS tate)
224 { 226 {
225 if (!refNode) { 227 if (!refNode) {
226 exceptionState.throwDOMException(HierarchyRequestError, "The node provid ed was null."); 228 // FIXME: Generated bindings code never calls with null, and neither sho uld other callers!
229 exceptionState.throwTypeError("The node provided is null.");
227 return false; 230 return false;
228 } 231 }
229 232
230 if (!refNode->inActiveDocument() || refNode->document() != m_ownerDocument) { 233 if (!refNode->inActiveDocument() || refNode->document() != m_ownerDocument) {
231 return false; 234 return false;
232 } 235 }
233 236
234 checkNodeWOffset(refNode, offset, exceptionState); 237 checkNodeWOffset(refNode, offset, exceptionState);
235 if (exceptionState.hadException()) 238 if (exceptionState.hadException())
236 return false; 239 return false;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 return 0; 277 return 0;
275 } 278 }
276 279
277 Range::CompareResults Range::compareNode(Node* refNode, ExceptionState& exceptio nState) const 280 Range::CompareResults Range::compareNode(Node* refNode, ExceptionState& exceptio nState) const
278 { 281 {
279 // http://developer.mozilla.org/en/docs/DOM:range.compareNode 282 // http://developer.mozilla.org/en/docs/DOM:range.compareNode
280 // This method returns 0, 1, 2, or 3 based on if the node is before, after, 283 // This method returns 0, 1, 2, or 3 based on if the node is before, after,
281 // before and after(surrounds), or inside the range, respectively 284 // before and after(surrounds), or inside the range, respectively
282 285
283 if (!refNode) { 286 if (!refNode) {
284 exceptionState.throwDOMException(NotFoundError, "The node provided was n ull."); 287 // FIXME: Generated bindings code never calls with null, and neither sho uld other callers!
288 exceptionState.throwTypeError("The node provided is null.");
285 return NODE_BEFORE; 289 return NODE_BEFORE;
286 } 290 }
287 291
288 if (!refNode->inActiveDocument()) { 292 if (!refNode->inActiveDocument()) {
289 // Firefox doesn't throw an exception for this case; it returns 0. 293 // Firefox doesn't throw an exception for this case; it returns 0.
290 return NODE_BEFORE; 294 return NODE_BEFORE;
291 } 295 }
292 296
293 if (refNode->document() != m_ownerDocument) { 297 if (refNode->document() != m_ownerDocument) {
294 // Firefox doesn't throw an exception for this case; it returns 0. 298 // Firefox doesn't throw an exception for this case; it returns 0.
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 470
467 { 471 {
468 EventQueueScope eventQueueScope; 472 EventQueueScope eventQueueScope;
469 processContents(DELETE_CONTENTS, exceptionState); 473 processContents(DELETE_CONTENTS, exceptionState);
470 } 474 }
471 } 475 }
472 476
473 static bool nodeValidForIntersects(Node* refNode, Document* expectedDocument, Ex ceptionState& exceptionState) 477 static bool nodeValidForIntersects(Node* refNode, Document* expectedDocument, Ex ceptionState& exceptionState)
474 { 478 {
475 if (!refNode) { 479 if (!refNode) {
476 exceptionState.throwDOMException(NotFoundError, "The node provided is nu ll."); 480 // FIXME: Generated bindings code never calls with null, and neither sho uld other callers!
481 exceptionState.throwTypeError("The node provided is null.");
477 return false; 482 return false;
478 } 483 }
479 484
480 if (!refNode->inActiveDocument() || refNode->document() != expectedDocument) { 485 if (!refNode->inActiveDocument() || refNode->document() != expectedDocument) {
481 // Firefox doesn't throw an exception for these cases; it returns false. 486 // Firefox doesn't throw an exception for these cases; it returns false.
482 return false; 487 return false;
483 } 488 }
484 489
485 return true; 490 return true;
486 } 491 }
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 PassRefPtrWillBeRawPtr<DocumentFragment> Range::cloneContents(ExceptionState& ex ceptionState) 858 PassRefPtrWillBeRawPtr<DocumentFragment> Range::cloneContents(ExceptionState& ex ceptionState)
854 { 859 {
855 return processContents(CLONE_CONTENTS, exceptionState); 860 return processContents(CLONE_CONTENTS, exceptionState);
856 } 861 }
857 862
858 void Range::insertNode(PassRefPtrWillBeRawPtr<Node> prpNewNode, ExceptionState& exceptionState) 863 void Range::insertNode(PassRefPtrWillBeRawPtr<Node> prpNewNode, ExceptionState& exceptionState)
859 { 864 {
860 RefPtrWillBeRawPtr<Node> newNode = prpNewNode; 865 RefPtrWillBeRawPtr<Node> newNode = prpNewNode;
861 866
862 if (!newNode) { 867 if (!newNode) {
863 exceptionState.throwDOMException(NotFoundError, "The node provided is nu ll."); 868 // FIXME: Generated bindings code never calls with null, and neither sho uld other callers!
869 exceptionState.throwTypeError("The node provided is null.");
864 return; 870 return;
865 } 871 }
866 872
867 // HierarchyRequestError: Raised if the container of the start of the Range is of a type that 873 // HierarchyRequestError: Raised if the container of the start of the Range is of a type that
868 // does not allow children of the type of newNode or if newNode is an ancest or of the container. 874 // does not allow children of the type of newNode or if newNode is an ancest or of the container.
869 875
870 // an extra one here - if a text node is going to split, it must have a pare nt to insert into 876 // an extra one here - if a text node is going to split, it must have a pare nt to insert into
871 bool startIsText = m_start.container()->isTextNode(); 877 bool startIsText = m_start.container()->isTextNode();
872 if (startIsText && !m_start.container()->parentNode()) { 878 if (startIsText && !m_start.container()->parentNode()) {
873 exceptionState.throwDOMException(HierarchyRequestError, "This operation would split a text node, but there's no parent into which to insert."); 879 exceptionState.throwDOMException(HierarchyRequestError, "This operation would split a text node, but there's no parent into which to insert.");
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 return childBefore; 1078 return childBefore;
1073 } 1079 }
1074 } 1080 }
1075 ASSERT_NOT_REACHED(); 1081 ASSERT_NOT_REACHED();
1076 return nullptr; 1082 return nullptr;
1077 } 1083 }
1078 1084
1079 void Range::checkNodeBA(Node* n, ExceptionState& exceptionState) const 1085 void Range::checkNodeBA(Node* n, ExceptionState& exceptionState) const
1080 { 1086 {
1081 if (!n) { 1087 if (!n) {
1082 exceptionState.throwDOMException(NotFoundError, "The node provided is nu ll."); 1088 // FIXME: Generated bindings code never calls with null, and neither sho uld other callers!
1089 exceptionState.throwTypeError("The node provided is null.");
1083 return; 1090 return;
1084 } 1091 }
1085 1092
1086 // InvalidNodeTypeError: Raised if the root container of refNode is not an 1093 // InvalidNodeTypeError: Raised if the root container of refNode is not an
1087 // Attr, Document, DocumentFragment or ShadowRoot node, or part of a SVG sha dow DOM tree, 1094 // Attr, Document, DocumentFragment or ShadowRoot node, or part of a SVG sha dow DOM tree,
1088 // or if refNode is a Document, DocumentFragment, ShadowRoot, Attr, Entity, or Notation node. 1095 // or if refNode is a Document, DocumentFragment, ShadowRoot, Attr, Entity, or Notation node.
1089 1096
1090 if (!n->parentNode()) { 1097 if (!n->parentNode()) {
1091 exceptionState.throwDOMException(InvalidNodeTypeError, "the given Node h as no parent."); 1098 exceptionState.throwDOMException(InvalidNodeTypeError, "the given Node h as no parent.");
1092 return; 1099 return;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 checkNodeBA(refNode, exceptionState); 1162 checkNodeBA(refNode, exceptionState);
1156 if (exceptionState.hadException()) 1163 if (exceptionState.hadException())
1157 return; 1164 return;
1158 1165
1159 setEnd(refNode->parentNode(), refNode->nodeIndex() + 1, exceptionState); 1166 setEnd(refNode->parentNode(), refNode->nodeIndex() + 1, exceptionState);
1160 } 1167 }
1161 1168
1162 void Range::selectNode(Node* refNode, ExceptionState& exceptionState) 1169 void Range::selectNode(Node* refNode, ExceptionState& exceptionState)
1163 { 1170 {
1164 if (!refNode) { 1171 if (!refNode) {
1165 exceptionState.throwDOMException(NotFoundError, "The node provided is nu ll."); 1172 // FIXME: Generated bindings code never calls with null, and neither sho uld other callers!
1173 exceptionState.throwTypeError("The node provided is null.");
1166 return; 1174 return;
1167 } 1175 }
1168 1176
1169 if (!refNode->parentNode()) { 1177 if (!refNode->parentNode()) {
1170 exceptionState.throwDOMException(InvalidNodeTypeError, "the given Node h as no parent."); 1178 exceptionState.throwDOMException(InvalidNodeTypeError, "the given Node h as no parent.");
1171 return; 1179 return;
1172 } 1180 }
1173 1181
1174 // InvalidNodeTypeError: Raised if an ancestor of refNode is an Entity, Nota tion or 1182 // InvalidNodeTypeError: Raised if an ancestor of refNode is an Entity, Nota tion or
1175 // DocumentType node or if refNode is a Document, DocumentFragment, ShadowRo ot, Attr, Entity, or Notation 1183 // DocumentType node or if refNode is a Document, DocumentFragment, ShadowRo ot, Attr, Entity, or Notation
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1209 if (m_ownerDocument != refNode->document()) 1217 if (m_ownerDocument != refNode->document())
1210 setDocument(refNode->document()); 1218 setDocument(refNode->document());
1211 1219
1212 setStartBefore(refNode); 1220 setStartBefore(refNode);
1213 setEndAfter(refNode); 1221 setEndAfter(refNode);
1214 } 1222 }
1215 1223
1216 void Range::selectNodeContents(Node* refNode, ExceptionState& exceptionState) 1224 void Range::selectNodeContents(Node* refNode, ExceptionState& exceptionState)
1217 { 1225 {
1218 if (!refNode) { 1226 if (!refNode) {
1219 exceptionState.throwDOMException(NotFoundError, "The node provided is nu ll."); 1227 // FIXME: Generated bindings code never calls with null, and neither sho uld other callers!
1228 exceptionState.throwTypeError("The node provided is null.");
1220 return; 1229 return;
1221 } 1230 }
1222 1231
1223 // InvalidNodeTypeError: Raised if refNode or an ancestor of refNode is an E ntity, Notation 1232 // InvalidNodeTypeError: Raised if refNode or an ancestor of refNode is an E ntity, Notation
1224 // or DocumentType node. 1233 // or DocumentType node.
1225 for (Node* n = refNode; n; n = n->parentNode()) { 1234 for (Node* n = refNode; n; n = n->parentNode()) {
1226 switch (n->nodeType()) { 1235 switch (n->nodeType()) {
1227 case Node::ATTRIBUTE_NODE: 1236 case Node::ATTRIBUTE_NODE:
1228 case Node::CDATA_SECTION_NODE: 1237 case Node::CDATA_SECTION_NODE:
1229 case Node::COMMENT_NODE: 1238 case Node::COMMENT_NODE:
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1274 RangeBoundaryPoint endBoundaryPoint(refNode); 1283 RangeBoundaryPoint endBoundaryPoint(refNode);
1275 endBoundaryPoint.setToEndOfNode(*refNode); 1284 endBoundaryPoint.setToEndOfNode(*refNode);
1276 end = endBoundaryPoint.toPosition(); 1285 end = endBoundaryPoint.toPosition();
1277 return true; 1286 return true;
1278 } 1287 }
1279 1288
1280 void Range::surroundContents(PassRefPtrWillBeRawPtr<Node> passNewParent, Excepti onState& exceptionState) 1289 void Range::surroundContents(PassRefPtrWillBeRawPtr<Node> passNewParent, Excepti onState& exceptionState)
1281 { 1290 {
1282 RefPtrWillBeRawPtr<Node> newParent = passNewParent; 1291 RefPtrWillBeRawPtr<Node> newParent = passNewParent;
1283 if (!newParent) { 1292 if (!newParent) {
1284 exceptionState.throwDOMException(NotFoundError, "The node provided is nu ll."); 1293 // FIXME: Generated bindings code never calls with null, and neither sho uld other callers!
1294 exceptionState.throwTypeError("The node provided is null.");
1285 return; 1295 return;
1286 } 1296 }
1287 1297
1288 // InvalidStateError: Raised if the Range partially selects a non-Text node. 1298 // InvalidStateError: Raised if the Range partially selects a non-Text node.
1289 Node* startNonTextContainer = m_start.container(); 1299 Node* startNonTextContainer = m_start.container();
1290 if (startNonTextContainer->nodeType() == Node::TEXT_NODE) 1300 if (startNonTextContainer->nodeType() == Node::TEXT_NODE)
1291 startNonTextContainer = startNonTextContainer->parentNode(); 1301 startNonTextContainer = startNonTextContainer->parentNode();
1292 Node* endNonTextContainer = m_end.container(); 1302 Node* endNonTextContainer = m_end.container();
1293 if (endNonTextContainer->nodeType() == Node::TEXT_NODE) 1303 if (endNonTextContainer->nodeType() == Node::TEXT_NODE)
1294 endNonTextContainer = endNonTextContainer->parentNode(); 1304 endNonTextContainer = endNonTextContainer->parentNode();
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
1776 1786
1777 void showTree(const blink::Range* range) 1787 void showTree(const blink::Range* range)
1778 { 1788 {
1779 if (range && range->boundaryPointsValid()) { 1789 if (range && range->boundaryPointsValid()) {
1780 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E"); 1790 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E");
1781 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset()); 1791 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset());
1782 } 1792 }
1783 } 1793 }
1784 1794
1785 #endif 1795 #endif
OLDNEW
« no previous file with comments | « LayoutTests/fast/text/first-letter-bad-line-boxes-crash-expected.txt ('k') | Source/core/dom/Range.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698