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

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

Issue 24469004: Amusingly deprecate the generic version of 'ExceptionState::throwDOMException'. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 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/Node.cpp ('k') | Source/core/editing/markup.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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 } 212 }
213 213
214 void Range::setStart(PassRefPtr<Node> refNode, int offset, ExceptionState& es) 214 void Range::setStart(PassRefPtr<Node> refNode, int offset, ExceptionState& es)
215 { 215 {
216 if (!m_start.container()) { 216 if (!m_start.container()) {
217 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("setStart", "Range", "The range has no container. Perhaps 'detatch()' has bee n invoked on this object?")); 217 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("setStart", "Range", "The range has no container. Perhaps 'detatch()' has bee n invoked on this object?"));
218 return; 218 return;
219 } 219 }
220 220
221 if (!refNode) { 221 if (!refNode) {
222 es.throwDOMException(NotFoundError); 222 es.throwUninformativeAndGenericDOMException(NotFoundError);
223 return; 223 return;
224 } 224 }
225 225
226 bool didMoveDocument = false; 226 bool didMoveDocument = false;
227 if (&refNode->document() != m_ownerDocument) { 227 if (&refNode->document() != m_ownerDocument) {
228 setDocument(refNode->document()); 228 setDocument(refNode->document());
229 didMoveDocument = true; 229 didMoveDocument = true;
230 } 230 }
231 231
232 Node* childNode = checkNodeWOffset(refNode.get(), offset, es); 232 Node* childNode = checkNodeWOffset(refNode.get(), offset, es);
233 if (es.hadException()) 233 if (es.hadException())
234 return; 234 return;
235 235
236 m_start.set(refNode, offset, childNode); 236 m_start.set(refNode, offset, childNode);
237 237
238 if (didMoveDocument || checkForDifferentRootContainer(m_start, m_end)) 238 if (didMoveDocument || checkForDifferentRootContainer(m_start, m_end))
239 collapse(true, es); 239 collapse(true, es);
240 } 240 }
241 241
242 void Range::setEnd(PassRefPtr<Node> refNode, int offset, ExceptionState& es) 242 void Range::setEnd(PassRefPtr<Node> refNode, int offset, ExceptionState& es)
243 { 243 {
244 if (!m_start.container()) { 244 if (!m_start.container()) {
245 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("setEnd", "Range", "The range has no container. Perhaps 'detatch()' has been invoked on this object?")); 245 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("setEnd", "Range", "The range has no container. Perhaps 'detatch()' has been invoked on this object?"));
246 return; 246 return;
247 } 247 }
248 248
249 if (!refNode) { 249 if (!refNode) {
250 es.throwDOMException(NotFoundError); 250 es.throwUninformativeAndGenericDOMException(NotFoundError);
251 return; 251 return;
252 } 252 }
253 253
254 bool didMoveDocument = false; 254 bool didMoveDocument = false;
255 if (&refNode->document() != m_ownerDocument) { 255 if (&refNode->document() != m_ownerDocument) {
256 setDocument(refNode->document()); 256 setDocument(refNode->document());
257 didMoveDocument = true; 257 didMoveDocument = true;
258 } 258 }
259 259
260 Node* childNode = checkNodeWOffset(refNode.get(), offset, es); 260 Node* childNode = checkNodeWOffset(refNode.get(), offset, es);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 } 293 }
294 294
295 bool Range::isPointInRange(Node* refNode, int offset, ExceptionState& es) 295 bool Range::isPointInRange(Node* refNode, int offset, ExceptionState& es)
296 { 296 {
297 if (!m_start.container()) { 297 if (!m_start.container()) {
298 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("isPointInRange", "Range", "The range has no container. Perhaps 'detatch()' h as been invoked on this object?")); 298 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("isPointInRange", "Range", "The range has no container. Perhaps 'detatch()' h as been invoked on this object?"));
299 return false; 299 return false;
300 } 300 }
301 301
302 if (!refNode) { 302 if (!refNode) {
303 es.throwDOMException(HierarchyRequestError); 303 es.throwUninformativeAndGenericDOMException(HierarchyRequestError);
304 return false; 304 return false;
305 } 305 }
306 306
307 if (!refNode->attached() || &refNode->document() != m_ownerDocument) { 307 if (!refNode->attached() || &refNode->document() != m_ownerDocument) {
308 return false; 308 return false;
309 } 309 }
310 310
311 checkNodeWOffset(refNode, offset, es); 311 checkNodeWOffset(refNode, offset, es);
312 if (es.hadException()) 312 if (es.hadException())
313 return false; 313 return false;
314 314
315 return compareBoundaryPoints(refNode, offset, m_start.container(), m_start.o ffset(), es) >= 0 && !es.hadException() 315 return compareBoundaryPoints(refNode, offset, m_start.container(), m_start.o ffset(), es) >= 0 && !es.hadException()
316 && compareBoundaryPoints(refNode, offset, m_end.container(), m_end.offse t(), es) <= 0 && !es.hadException(); 316 && compareBoundaryPoints(refNode, offset, m_end.container(), m_end.offse t(), es) <= 0 && !es.hadException();
317 } 317 }
318 318
319 short Range::comparePoint(Node* refNode, int offset, ExceptionState& es) const 319 short Range::comparePoint(Node* refNode, int offset, ExceptionState& es) const
320 { 320 {
321 // http://developer.mozilla.org/en/docs/DOM:range.comparePoint 321 // http://developer.mozilla.org/en/docs/DOM:range.comparePoint
322 // This method returns -1, 0 or 1 depending on if the point described by the 322 // This method returns -1, 0 or 1 depending on if the point described by the
323 // refNode node and an offset within the node is before, same as, or after t he range respectively. 323 // refNode node and an offset within the node is before, same as, or after t he range respectively.
324 324
325 if (!m_start.container()) { 325 if (!m_start.container()) {
326 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("comparePoint", "Range", "The range has no container. Perhaps 'detatch()' has been invoked on this object?")); 326 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("comparePoint", "Range", "The range has no container. Perhaps 'detatch()' has been invoked on this object?"));
327 return 0; 327 return 0;
328 } 328 }
329 329
330 if (!refNode) { 330 if (!refNode) {
331 es.throwDOMException(HierarchyRequestError); 331 es.throwUninformativeAndGenericDOMException(HierarchyRequestError);
332 return 0; 332 return 0;
333 } 333 }
334 334
335 if (!refNode->attached() || &refNode->document() != m_ownerDocument) { 335 if (!refNode->attached() || &refNode->document() != m_ownerDocument) {
336 es.throwDOMException(WrongDocumentError); 336 es.throwUninformativeAndGenericDOMException(WrongDocumentError);
337 return 0; 337 return 0;
338 } 338 }
339 339
340 checkNodeWOffset(refNode, offset, es); 340 checkNodeWOffset(refNode, offset, es);
341 if (es.hadException()) 341 if (es.hadException())
342 return 0; 342 return 0;
343 343
344 // compare to start, and point comes before 344 // compare to start, and point comes before
345 if (compareBoundaryPoints(refNode, offset, m_start.container(), m_start.offs et(), es) < 0) 345 if (compareBoundaryPoints(refNode, offset, m_start.container(), m_start.offs et(), es) < 0)
346 return -1; 346 return -1;
347 347
348 if (es.hadException()) 348 if (es.hadException())
349 return 0; 349 return 0;
350 350
351 // compare to end, and point comes after 351 // compare to end, and point comes after
352 if (compareBoundaryPoints(refNode, offset, m_end.container(), m_end.offset() , es) > 0 && !es.hadException()) 352 if (compareBoundaryPoints(refNode, offset, m_end.container(), m_end.offset() , es) > 0 && !es.hadException())
353 return 1; 353 return 1;
354 354
355 // point is in the middle of this range, or on the boundary points 355 // point is in the middle of this range, or on the boundary points
356 return 0; 356 return 0;
357 } 357 }
358 358
359 Range::CompareResults Range::compareNode(Node* refNode, ExceptionState& es) cons t 359 Range::CompareResults Range::compareNode(Node* refNode, ExceptionState& es) cons t
360 { 360 {
361 // http://developer.mozilla.org/en/docs/DOM:range.compareNode 361 // http://developer.mozilla.org/en/docs/DOM:range.compareNode
362 // This method returns 0, 1, 2, or 3 based on if the node is before, after, 362 // This method returns 0, 1, 2, or 3 based on if the node is before, after,
363 // before and after(surrounds), or inside the range, respectively 363 // before and after(surrounds), or inside the range, respectively
364 364
365 if (!refNode) { 365 if (!refNode) {
366 es.throwDOMException(NotFoundError); 366 es.throwUninformativeAndGenericDOMException(NotFoundError);
367 return NODE_BEFORE; 367 return NODE_BEFORE;
368 } 368 }
369 369
370 if (!m_start.container() && refNode->attached()) { 370 if (!m_start.container() && refNode->attached()) {
371 es.throwDOMException(InvalidStateError); 371 es.throwUninformativeAndGenericDOMException(InvalidStateError);
372 return NODE_BEFORE; 372 return NODE_BEFORE;
373 } 373 }
374 374
375 if (m_start.container() && !refNode->attached()) { 375 if (m_start.container() && !refNode->attached()) {
376 // Firefox doesn't throw an exception for this case; it returns 0. 376 // Firefox doesn't throw an exception for this case; it returns 0.
377 return NODE_BEFORE; 377 return NODE_BEFORE;
378 } 378 }
379 379
380 if (&refNode->document() != m_ownerDocument) { 380 if (&refNode->document() != m_ownerDocument) {
381 // Firefox doesn't throw an exception for this case; it returns 0. 381 // Firefox doesn't throw an exception for this case; it returns 0.
382 return NODE_BEFORE; 382 return NODE_BEFORE;
383 } 383 }
384 384
385 ContainerNode* parentNode = refNode->parentNode(); 385 ContainerNode* parentNode = refNode->parentNode();
386 int nodeIndex = refNode->nodeIndex(); 386 int nodeIndex = refNode->nodeIndex();
387 387
388 if (!parentNode) { 388 if (!parentNode) {
389 // if the node is the top document we should return NODE_BEFORE_AND_AFTE R 389 // if the node is the top document we should return NODE_BEFORE_AND_AFTE R
390 // but we throw to match firefox behavior 390 // but we throw to match firefox behavior
391 es.throwDOMException(NotFoundError); 391 es.throwUninformativeAndGenericDOMException(NotFoundError);
392 return NODE_BEFORE; 392 return NODE_BEFORE;
393 } 393 }
394 394
395 if (comparePoint(parentNode, nodeIndex, es) < 0) { // starts before 395 if (comparePoint(parentNode, nodeIndex, es) < 0) { // starts before
396 if (comparePoint(parentNode, nodeIndex + 1, es) > 0) // ends after the r ange 396 if (comparePoint(parentNode, nodeIndex + 1, es) > 0) // ends after the r ange
397 return NODE_BEFORE_AND_AFTER; 397 return NODE_BEFORE_AND_AFTER;
398 return NODE_BEFORE; // ends before or in the range 398 return NODE_BEFORE; // ends before or in the range
399 } 399 }
400 // starts at or after the range start 400 // starts at or after the range start
401 if (comparePoint(parentNode, nodeIndex + 1, es) > 0) // ends after the range 401 if (comparePoint(parentNode, nodeIndex + 1, es) > 0) // ends after the range
402 return NODE_AFTER; 402 return NODE_AFTER;
403 return NODE_INSIDE; // ends inside the range 403 return NODE_INSIDE; // ends inside the range
404 } 404 }
405 405
406 short Range::compareBoundaryPoints(CompareHow how, const Range* sourceRange, Exc eptionState& es) const 406 short Range::compareBoundaryPoints(CompareHow how, const Range* sourceRange, Exc eptionState& es) const
407 { 407 {
408 if (!m_start.container()) { 408 if (!m_start.container()) {
409 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("compareBoundaryPoints", "Range", "The range has no container. Perhaps 'detat ch()' has been invoked on this object?")); 409 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("compareBoundaryPoints", "Range", "The range has no container. Perhaps 'detat ch()' has been invoked on this object?"));
410 return 0; 410 return 0;
411 } 411 }
412 412
413 if (!sourceRange) { 413 if (!sourceRange) {
414 es.throwDOMException(NotFoundError); 414 es.throwUninformativeAndGenericDOMException(NotFoundError);
415 return 0; 415 return 0;
416 } 416 }
417 417
418 Node* thisCont = commonAncestorContainer(es); 418 Node* thisCont = commonAncestorContainer(es);
419 if (es.hadException()) 419 if (es.hadException())
420 return 0; 420 return 0;
421 Node* sourceCont = sourceRange->commonAncestorContainer(es); 421 Node* sourceCont = sourceRange->commonAncestorContainer(es);
422 if (es.hadException()) 422 if (es.hadException())
423 return 0; 423 return 0;
424 424
425 if (&thisCont->document() != &sourceCont->document()) { 425 if (&thisCont->document() != &sourceCont->document()) {
426 es.throwDOMException(WrongDocumentError); 426 es.throwUninformativeAndGenericDOMException(WrongDocumentError);
427 return 0; 427 return 0;
428 } 428 }
429 429
430 Node* thisTop = thisCont; 430 Node* thisTop = thisCont;
431 Node* sourceTop = sourceCont; 431 Node* sourceTop = sourceCont;
432 while (thisTop->parentNode()) 432 while (thisTop->parentNode())
433 thisTop = thisTop->parentNode(); 433 thisTop = thisTop->parentNode();
434 while (sourceTop->parentNode()) 434 while (sourceTop->parentNode())
435 sourceTop = sourceTop->parentNode(); 435 sourceTop = sourceTop->parentNode();
436 if (thisTop != sourceTop) { // in different DocumentFragments 436 if (thisTop != sourceTop) { // in different DocumentFragments
437 es.throwDOMException(WrongDocumentError); 437 es.throwUninformativeAndGenericDOMException(WrongDocumentError);
438 return 0; 438 return 0;
439 } 439 }
440 440
441 switch (how) { 441 switch (how) {
442 case START_TO_START: 442 case START_TO_START:
443 return compareBoundaryPoints(m_start, sourceRange->m_start, es); 443 return compareBoundaryPoints(m_start, sourceRange->m_start, es);
444 case START_TO_END: 444 case START_TO_END:
445 return compareBoundaryPoints(m_end, sourceRange->m_start, es); 445 return compareBoundaryPoints(m_end, sourceRange->m_start, es);
446 case END_TO_END: 446 case END_TO_END:
447 return compareBoundaryPoints(m_end, sourceRange->m_end, es); 447 return compareBoundaryPoints(m_end, sourceRange->m_end, es);
448 case END_TO_START: 448 case END_TO_START:
449 return compareBoundaryPoints(m_start, sourceRange->m_end, es); 449 return compareBoundaryPoints(m_start, sourceRange->m_end, es);
450 } 450 }
451 451
452 es.throwDOMException(SyntaxError); 452 es.throwUninformativeAndGenericDOMException(SyntaxError);
453 return 0; 453 return 0;
454 } 454 }
455 455
456 short Range::compareBoundaryPoints(Node* containerA, int offsetA, Node* containe rB, int offsetB, ExceptionState& es) 456 short Range::compareBoundaryPoints(Node* containerA, int offsetA, Node* containe rB, int offsetB, ExceptionState& es)
457 { 457 {
458 ASSERT(containerA); 458 ASSERT(containerA);
459 ASSERT(containerB); 459 ASSERT(containerB);
460 460
461 if (!containerA) 461 if (!containerA)
462 return -1; 462 return -1;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 if (offsetC < offsetB) 508 if (offsetC < offsetB)
509 return -1; // A is before B 509 return -1; // A is before B
510 else 510 else
511 return 1; // A is after B 511 return 1; // A is after B
512 } 512 }
513 513
514 // case 4: containers A & B are siblings, or children of siblings 514 // case 4: containers A & B are siblings, or children of siblings
515 // ### we need to do a traversal here instead 515 // ### we need to do a traversal here instead
516 Node* commonAncestor = commonAncestorContainer(containerA, containerB); 516 Node* commonAncestor = commonAncestorContainer(containerA, containerB);
517 if (!commonAncestor) { 517 if (!commonAncestor) {
518 es.throwDOMException(WrongDocumentError); 518 es.throwUninformativeAndGenericDOMException(WrongDocumentError);
519 return 0; 519 return 0;
520 } 520 }
521 Node* childA = containerA; 521 Node* childA = containerA;
522 while (childA && childA->parentNode() != commonAncestor) 522 while (childA && childA->parentNode() != commonAncestor)
523 childA = childA->parentNode(); 523 childA = childA->parentNode();
524 if (!childA) 524 if (!childA)
525 childA = commonAncestor; 525 childA = commonAncestor;
526 Node* childB = containerB; 526 Node* childB = containerB;
527 while (childB && childB->parentNode() != commonAncestor) 527 while (childB && childB->parentNode() != commonAncestor)
528 childB = childB->parentNode(); 528 childB = childB->parentNode();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 { 570 {
571 // http://developer.mozilla.org/en/docs/DOM:range.intersectsNode 571 // http://developer.mozilla.org/en/docs/DOM:range.intersectsNode
572 // Returns a bool if the node intersects the range. 572 // Returns a bool if the node intersects the range.
573 573
574 // Throw exception if the range is already detached. 574 // Throw exception if the range is already detached.
575 if (!m_start.container()) { 575 if (!m_start.container()) {
576 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("intersectsNode", "Range", "The range has no container. Perhaps 'detatch()' h as been invoked on this object?")); 576 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("intersectsNode", "Range", "The range has no container. Perhaps 'detatch()' h as been invoked on this object?"));
577 return false; 577 return false;
578 } 578 }
579 if (!refNode) { 579 if (!refNode) {
580 es.throwDOMException(NotFoundError); 580 es.throwUninformativeAndGenericDOMException(NotFoundError);
581 return false; 581 return false;
582 } 582 }
583 583
584 if (!refNode->attached() || &refNode->document() != m_ownerDocument) { 584 if (!refNode->attached() || &refNode->document() != m_ownerDocument) {
585 // Firefox doesn't throw an exception for these cases; it returns false. 585 // Firefox doesn't throw an exception for these cases; it returns false.
586 return false; 586 return false;
587 } 587 }
588 588
589 ContainerNode* parentNode = refNode->parentNode(); 589 ContainerNode* parentNode = refNode->parentNode();
590 int nodeIndex = refNode->nodeIndex(); 590 int nodeIndex = refNode->nodeIndex();
591 591
592 if (!parentNode) { 592 if (!parentNode) {
593 // if the node is the top document we should return NODE_BEFORE_AND_AFTE R 593 // if the node is the top document we should return NODE_BEFORE_AND_AFTE R
594 // but we throw to match firefox behavior 594 // but we throw to match firefox behavior
595 es.throwDOMException(NotFoundError); 595 es.throwUninformativeAndGenericDOMException(NotFoundError);
596 return false; 596 return false;
597 } 597 }
598 598
599 if (comparePoint(parentNode, nodeIndex, es) < 0 // starts before start 599 if (comparePoint(parentNode, nodeIndex, es) < 0 // starts before start
600 && comparePoint(parentNode, nodeIndex + 1, es) < 0) { // ends before sta rt 600 && comparePoint(parentNode, nodeIndex + 1, es) < 0) { // ends before sta rt
601 return false; 601 return false;
602 } 602 }
603 603
604 if (comparePoint(parentNode, nodeIndex, es) > 0 // starts after end 604 if (comparePoint(parentNode, nodeIndex, es) > 0 // starts after end
605 && comparePoint(parentNode, nodeIndex + 1, es) > 0) { // ends after end 605 && comparePoint(parentNode, nodeIndex + 1, es) > 0) { // ends after end
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 void Range::insertNode(PassRefPtr<Node> prpNewNode, ExceptionState& es) 948 void Range::insertNode(PassRefPtr<Node> prpNewNode, ExceptionState& es)
949 { 949 {
950 RefPtr<Node> newNode = prpNewNode; 950 RefPtr<Node> newNode = prpNewNode;
951 951
952 if (!m_start.container()) { 952 if (!m_start.container()) {
953 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("insertNode", "Range", "The range has no container. Perhaps 'detatch()' has b een invoked on this object?")); 953 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("insertNode", "Range", "The range has no container. Perhaps 'detatch()' has b een invoked on this object?"));
954 return; 954 return;
955 } 955 }
956 956
957 if (!newNode) { 957 if (!newNode) {
958 es.throwDOMException(NotFoundError); 958 es.throwUninformativeAndGenericDOMException(NotFoundError);
959 return; 959 return;
960 } 960 }
961 961
962 // HierarchyRequestError: Raised if the container of the start of the Range is of a type that 962 // HierarchyRequestError: Raised if the container of the start of the Range is of a type that
963 // does not allow children of the type of newNode or if newNode is an ancest or of the container. 963 // does not allow children of the type of newNode or if newNode is an ancest or of the container.
964 964
965 // an extra one here - if a text node is going to split, it must have a pare nt to insert into 965 // an extra one here - if a text node is going to split, it must have a pare nt to insert into
966 bool startIsText = m_start.container()->isTextNode(); 966 bool startIsText = m_start.container()->isTextNode();
967 if (startIsText && !m_start.container()->parentNode()) { 967 if (startIsText && !m_start.container()->parentNode()) {
968 es.throwDOMException(HierarchyRequestError); 968 es.throwUninformativeAndGenericDOMException(HierarchyRequestError);
969 return; 969 return;
970 } 970 }
971 971
972 // In the case where the container is a text node, we check against the cont ainer's parent, because 972 // In the case where the container is a text node, we check against the cont ainer's parent, because
973 // text nodes get split up upon insertion. 973 // text nodes get split up upon insertion.
974 Node* checkAgainst; 974 Node* checkAgainst;
975 if (startIsText) 975 if (startIsText)
976 checkAgainst = m_start.container()->parentNode(); 976 checkAgainst = m_start.container()->parentNode();
977 else 977 else
978 checkAgainst = m_start.container(); 978 checkAgainst = m_start.container();
979 979
980 Node::NodeType newNodeType = newNode->nodeType(); 980 Node::NodeType newNodeType = newNode->nodeType();
981 int numNewChildren; 981 int numNewChildren;
982 if (newNodeType == Node::DOCUMENT_FRAGMENT_NODE && !newNode->isShadowRoot()) { 982 if (newNodeType == Node::DOCUMENT_FRAGMENT_NODE && !newNode->isShadowRoot()) {
983 // check each child node, not the DocumentFragment itself 983 // check each child node, not the DocumentFragment itself
984 numNewChildren = 0; 984 numNewChildren = 0;
985 for (Node* c = newNode->firstChild(); c; c = c->nextSibling()) { 985 for (Node* c = newNode->firstChild(); c; c = c->nextSibling()) {
986 if (!checkAgainst->childTypeAllowed(c->nodeType())) { 986 if (!checkAgainst->childTypeAllowed(c->nodeType())) {
987 es.throwDOMException(HierarchyRequestError); 987 es.throwUninformativeAndGenericDOMException(HierarchyRequestErro r);
988 return; 988 return;
989 } 989 }
990 ++numNewChildren; 990 ++numNewChildren;
991 } 991 }
992 } else { 992 } else {
993 numNewChildren = 1; 993 numNewChildren = 1;
994 if (!checkAgainst->childTypeAllowed(newNodeType)) { 994 if (!checkAgainst->childTypeAllowed(newNodeType)) {
995 es.throwDOMException(HierarchyRequestError); 995 es.throwUninformativeAndGenericDOMException(HierarchyRequestError);
996 return; 996 return;
997 } 997 }
998 } 998 }
999 999
1000 for (Node* n = m_start.container(); n; n = n->parentNode()) { 1000 for (Node* n = m_start.container(); n; n = n->parentNode()) {
1001 if (n == newNode) { 1001 if (n == newNode) {
1002 es.throwDOMException(HierarchyRequestError); 1002 es.throwUninformativeAndGenericDOMException(HierarchyRequestError);
1003 return; 1003 return;
1004 } 1004 }
1005 } 1005 }
1006 1006
1007 // InvalidNodeTypeError: Raised if newNode is an Attr, Entity, Notation, Sha dowRoot or Document node. 1007 // InvalidNodeTypeError: Raised if newNode is an Attr, Entity, Notation, Sha dowRoot or Document node.
1008 switch (newNodeType) { 1008 switch (newNodeType) {
1009 case Node::ATTRIBUTE_NODE: 1009 case Node::ATTRIBUTE_NODE:
1010 case Node::ENTITY_NODE: 1010 case Node::ENTITY_NODE:
1011 case Node::NOTATION_NODE: 1011 case Node::NOTATION_NODE:
1012 case Node::DOCUMENT_NODE: 1012 case Node::DOCUMENT_NODE:
1013 es.throwDOMException(InvalidNodeTypeError); 1013 es.throwUninformativeAndGenericDOMException(InvalidNodeTypeError);
1014 return; 1014 return;
1015 default: 1015 default:
1016 if (newNode->isShadowRoot()) { 1016 if (newNode->isShadowRoot()) {
1017 es.throwDOMException(InvalidNodeTypeError); 1017 es.throwUninformativeAndGenericDOMException(InvalidNodeTypeError);
1018 return; 1018 return;
1019 } 1019 }
1020 break; 1020 break;
1021 } 1021 }
1022 1022
1023 EventQueueScope scope; 1023 EventQueueScope scope;
1024 bool collapsed = m_start == m_end; 1024 bool collapsed = m_start == m_end;
1025 RefPtr<Node> container; 1025 RefPtr<Node> container;
1026 if (startIsText) { 1026 if (startIsText) {
1027 container = m_start.container(); 1027 container = m_start.container();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 1094
1095 PassRefPtr<DocumentFragment> Range::createContextualFragment(const String& marku p, ExceptionState& es) 1095 PassRefPtr<DocumentFragment> Range::createContextualFragment(const String& marku p, ExceptionState& es)
1096 { 1096 {
1097 if (!m_start.container()) { 1097 if (!m_start.container()) {
1098 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("createContextualFragment", "Range", "The range has no container. Perhaps 'de tatch()' has been invoked on this object?")); 1098 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("createContextualFragment", "Range", "The range has no container. Perhaps 'de tatch()' has been invoked on this object?"));
1099 return 0; 1099 return 0;
1100 } 1100 }
1101 1101
1102 Node* element = m_start.container()->isElementNode() ? m_start.container() : m_start.container()->parentNode(); 1102 Node* element = m_start.container()->isElementNode() ? m_start.container() : m_start.container()->parentNode();
1103 if (!element || !element->isHTMLElement()) { 1103 if (!element || !element->isHTMLElement()) {
1104 es.throwDOMException(NotSupportedError); 1104 es.throwUninformativeAndGenericDOMException(NotSupportedError);
1105 return 0; 1105 return 0;
1106 } 1106 }
1107 1107
1108 RefPtr<DocumentFragment> fragment = WebCore::createContextualFragment(markup , toHTMLElement(element), AllowScriptingContentAndDoNotMarkAlreadyStarted, es); 1108 RefPtr<DocumentFragment> fragment = WebCore::createContextualFragment(markup , toHTMLElement(element), AllowScriptingContentAndDoNotMarkAlreadyStarted, es);
1109 if (!fragment) 1109 if (!fragment)
1110 return 0; 1110 return 0;
1111 1111
1112 return fragment.release(); 1112 return fragment.release();
1113 } 1113 }
1114 1114
(...skipping 11 matching lines...) Expand all
1126 m_start.clear(); 1126 m_start.clear();
1127 m_end.clear(); 1127 m_end.clear();
1128 } 1128 }
1129 1129
1130 Node* Range::checkNodeWOffset(Node* n, int offset, ExceptionState& es) const 1130 Node* Range::checkNodeWOffset(Node* n, int offset, ExceptionState& es) const
1131 { 1131 {
1132 switch (n->nodeType()) { 1132 switch (n->nodeType()) {
1133 case Node::DOCUMENT_TYPE_NODE: 1133 case Node::DOCUMENT_TYPE_NODE:
1134 case Node::ENTITY_NODE: 1134 case Node::ENTITY_NODE:
1135 case Node::NOTATION_NODE: 1135 case Node::NOTATION_NODE:
1136 es.throwDOMException(InvalidNodeTypeError); 1136 es.throwUninformativeAndGenericDOMException(InvalidNodeTypeError);
1137 return 0; 1137 return 0;
1138 case Node::CDATA_SECTION_NODE: 1138 case Node::CDATA_SECTION_NODE:
1139 case Node::COMMENT_NODE: 1139 case Node::COMMENT_NODE:
1140 case Node::TEXT_NODE: 1140 case Node::TEXT_NODE:
1141 if (static_cast<unsigned>(offset) > toCharacterData(n)->length()) 1141 if (static_cast<unsigned>(offset) > toCharacterData(n)->length())
1142 es.throwDOMException(IndexSizeError); 1142 es.throwUninformativeAndGenericDOMException(IndexSizeError);
1143 return 0; 1143 return 0;
1144 case Node::PROCESSING_INSTRUCTION_NODE: 1144 case Node::PROCESSING_INSTRUCTION_NODE:
1145 if (static_cast<unsigned>(offset) > toProcessingInstruction(n)->data ().length()) 1145 if (static_cast<unsigned>(offset) > toProcessingInstruction(n)->data ().length())
1146 es.throwDOMException(IndexSizeError); 1146 es.throwUninformativeAndGenericDOMException(IndexSizeError);
1147 return 0; 1147 return 0;
1148 case Node::ATTRIBUTE_NODE: 1148 case Node::ATTRIBUTE_NODE:
1149 case Node::DOCUMENT_FRAGMENT_NODE: 1149 case Node::DOCUMENT_FRAGMENT_NODE:
1150 case Node::DOCUMENT_NODE: 1150 case Node::DOCUMENT_NODE:
1151 case Node::ELEMENT_NODE: 1151 case Node::ELEMENT_NODE:
1152 case Node::XPATH_NAMESPACE_NODE: { 1152 case Node::XPATH_NAMESPACE_NODE: {
1153 if (!offset) 1153 if (!offset)
1154 return 0; 1154 return 0;
1155 Node* childBefore = n->childNode(offset - 1); 1155 Node* childBefore = n->childNode(offset - 1);
1156 if (!childBefore) 1156 if (!childBefore)
1157 es.throwDOMException(IndexSizeError); 1157 es.throwUninformativeAndGenericDOMException(IndexSizeError);
1158 return childBefore; 1158 return childBefore;
1159 } 1159 }
1160 } 1160 }
1161 ASSERT_NOT_REACHED(); 1161 ASSERT_NOT_REACHED();
1162 return 0; 1162 return 0;
1163 } 1163 }
1164 1164
1165 void Range::checkNodeBA(Node* n, const String& methodName, ExceptionState& es) c onst 1165 void Range::checkNodeBA(Node* n, const String& methodName, ExceptionState& es) c onst
1166 { 1166 {
1167 if (!m_start.container()) { 1167 if (!m_start.container()) {
1168 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te(methodName, "Range", "The range has no container. Perhaps 'detatch()' has bee n invoked on this object?")); 1168 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te(methodName, "Range", "The range has no container. Perhaps 'detatch()' has bee n invoked on this object?"));
1169 return; 1169 return;
1170 } 1170 }
1171 1171
1172 if (!n) { 1172 if (!n) {
1173 es.throwDOMException(NotFoundError); 1173 es.throwUninformativeAndGenericDOMException(NotFoundError);
1174 return; 1174 return;
1175 } 1175 }
1176 1176
1177 // InvalidNodeTypeError: Raised if the root container of refNode is not an 1177 // InvalidNodeTypeError: Raised if the root container of refNode is not an
1178 // Attr, Document, DocumentFragment or ShadowRoot node, or part of a SVG sha dow DOM tree, 1178 // Attr, Document, DocumentFragment or ShadowRoot node, or part of a SVG sha dow DOM tree,
1179 // or if refNode is a Document, DocumentFragment, ShadowRoot, Attr, Entity, or Notation node. 1179 // or if refNode is a Document, DocumentFragment, ShadowRoot, Attr, Entity, or Notation node.
1180 1180
1181 if (!n->parentNode()) { 1181 if (!n->parentNode()) {
1182 es.throwDOMException(InvalidNodeTypeError, ExceptionMessages::failedToEx ecute(methodName, "Range", "the given Node has no parent.")); 1182 es.throwDOMException(InvalidNodeTypeError, ExceptionMessages::failedToEx ecute(methodName, "Range", "the given Node has no parent."));
1183 return; 1183 return;
1184 } 1184 }
1185 1185
1186 switch (n->nodeType()) { 1186 switch (n->nodeType()) {
1187 case Node::ATTRIBUTE_NODE: 1187 case Node::ATTRIBUTE_NODE:
1188 case Node::DOCUMENT_FRAGMENT_NODE: 1188 case Node::DOCUMENT_FRAGMENT_NODE:
1189 case Node::DOCUMENT_NODE: 1189 case Node::DOCUMENT_NODE:
1190 case Node::ENTITY_NODE: 1190 case Node::ENTITY_NODE:
1191 case Node::NOTATION_NODE: 1191 case Node::NOTATION_NODE:
1192 es.throwDOMException(InvalidNodeTypeError); 1192 es.throwUninformativeAndGenericDOMException(InvalidNodeTypeError);
1193 return; 1193 return;
1194 case Node::CDATA_SECTION_NODE: 1194 case Node::CDATA_SECTION_NODE:
1195 case Node::COMMENT_NODE: 1195 case Node::COMMENT_NODE:
1196 case Node::DOCUMENT_TYPE_NODE: 1196 case Node::DOCUMENT_TYPE_NODE:
1197 case Node::ELEMENT_NODE: 1197 case Node::ELEMENT_NODE:
1198 case Node::PROCESSING_INSTRUCTION_NODE: 1198 case Node::PROCESSING_INSTRUCTION_NODE:
1199 case Node::TEXT_NODE: 1199 case Node::TEXT_NODE:
1200 case Node::XPATH_NAMESPACE_NODE: 1200 case Node::XPATH_NAMESPACE_NODE:
1201 break; 1201 break;
1202 } 1202 }
1203 1203
1204 Node* root = n; 1204 Node* root = n;
1205 while (ContainerNode* parent = root->parentNode()) 1205 while (ContainerNode* parent = root->parentNode())
1206 root = parent; 1206 root = parent;
1207 1207
1208 switch (root->nodeType()) { 1208 switch (root->nodeType()) {
1209 case Node::ATTRIBUTE_NODE: 1209 case Node::ATTRIBUTE_NODE:
1210 case Node::DOCUMENT_NODE: 1210 case Node::DOCUMENT_NODE:
1211 case Node::DOCUMENT_FRAGMENT_NODE: 1211 case Node::DOCUMENT_FRAGMENT_NODE:
1212 case Node::ELEMENT_NODE: 1212 case Node::ELEMENT_NODE:
1213 break; 1213 break;
1214 case Node::CDATA_SECTION_NODE: 1214 case Node::CDATA_SECTION_NODE:
1215 case Node::COMMENT_NODE: 1215 case Node::COMMENT_NODE:
1216 case Node::DOCUMENT_TYPE_NODE: 1216 case Node::DOCUMENT_TYPE_NODE:
1217 case Node::ENTITY_NODE: 1217 case Node::ENTITY_NODE:
1218 case Node::NOTATION_NODE: 1218 case Node::NOTATION_NODE:
1219 case Node::PROCESSING_INSTRUCTION_NODE: 1219 case Node::PROCESSING_INSTRUCTION_NODE:
1220 case Node::TEXT_NODE: 1220 case Node::TEXT_NODE:
1221 case Node::XPATH_NAMESPACE_NODE: 1221 case Node::XPATH_NAMESPACE_NODE:
1222 es.throwDOMException(InvalidNodeTypeError); 1222 es.throwUninformativeAndGenericDOMException(InvalidNodeTypeError);
1223 return; 1223 return;
1224 } 1224 }
1225 } 1225 }
1226 1226
1227 PassRefPtr<Range> Range::cloneRange(ExceptionState& es) const 1227 PassRefPtr<Range> Range::cloneRange(ExceptionState& es) const
1228 { 1228 {
1229 if (!m_start.container()) { 1229 if (!m_start.container()) {
1230 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("cloneRange", "Range", "The range has no container. Perhaps 'detatch()' has b een invoked on this object?")); 1230 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("cloneRange", "Range", "The range has no container. Perhaps 'detatch()' has b een invoked on this object?"));
1231 return 0; 1231 return 0;
1232 } 1232 }
(...skipping 29 matching lines...) Expand all
1262 } 1262 }
1263 1263
1264 void Range::selectNode(Node* refNode, ExceptionState& es) 1264 void Range::selectNode(Node* refNode, ExceptionState& es)
1265 { 1265 {
1266 if (!m_start.container()) { 1266 if (!m_start.container()) {
1267 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("selectNode", "Range", "The range has no container. Perhaps 'detatch()' has b een invoked on this object?")); 1267 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("selectNode", "Range", "The range has no container. Perhaps 'detatch()' has b een invoked on this object?"));
1268 return; 1268 return;
1269 } 1269 }
1270 1270
1271 if (!refNode) { 1271 if (!refNode) {
1272 es.throwDOMException(NotFoundError); 1272 es.throwUninformativeAndGenericDOMException(NotFoundError);
1273 return; 1273 return;
1274 } 1274 }
1275 1275
1276 if (!refNode->parentNode()) { 1276 if (!refNode->parentNode()) {
1277 es.throwDOMException(InvalidNodeTypeError, ExceptionMessages::failedToEx ecute("selectNode", "Range", "the given Node has no parent.")); 1277 es.throwDOMException(InvalidNodeTypeError, ExceptionMessages::failedToEx ecute("selectNode", "Range", "the given Node has no parent."));
1278 return; 1278 return;
1279 } 1279 }
1280 1280
1281 // InvalidNodeTypeError: Raised if an ancestor of refNode is an Entity, Nota tion or 1281 // InvalidNodeTypeError: Raised if an ancestor of refNode is an Entity, Nota tion or
1282 // DocumentType node or if refNode is a Document, DocumentFragment, ShadowRo ot, Attr, Entity, or Notation 1282 // DocumentType node or if refNode is a Document, DocumentFragment, ShadowRo ot, Attr, Entity, or Notation
1283 // node. 1283 // node.
1284 for (ContainerNode* anc = refNode->parentNode(); anc; anc = anc->parentNode( )) { 1284 for (ContainerNode* anc = refNode->parentNode(); anc; anc = anc->parentNode( )) {
1285 switch (anc->nodeType()) { 1285 switch (anc->nodeType()) {
1286 case Node::ATTRIBUTE_NODE: 1286 case Node::ATTRIBUTE_NODE:
1287 case Node::CDATA_SECTION_NODE: 1287 case Node::CDATA_SECTION_NODE:
1288 case Node::COMMENT_NODE: 1288 case Node::COMMENT_NODE:
1289 case Node::DOCUMENT_FRAGMENT_NODE: 1289 case Node::DOCUMENT_FRAGMENT_NODE:
1290 case Node::DOCUMENT_NODE: 1290 case Node::DOCUMENT_NODE:
1291 case Node::ELEMENT_NODE: 1291 case Node::ELEMENT_NODE:
1292 case Node::PROCESSING_INSTRUCTION_NODE: 1292 case Node::PROCESSING_INSTRUCTION_NODE:
1293 case Node::TEXT_NODE: 1293 case Node::TEXT_NODE:
1294 case Node::XPATH_NAMESPACE_NODE: 1294 case Node::XPATH_NAMESPACE_NODE:
1295 break; 1295 break;
1296 case Node::DOCUMENT_TYPE_NODE: 1296 case Node::DOCUMENT_TYPE_NODE:
1297 case Node::ENTITY_NODE: 1297 case Node::ENTITY_NODE:
1298 case Node::NOTATION_NODE: 1298 case Node::NOTATION_NODE:
1299 es.throwDOMException(InvalidNodeTypeError); 1299 es.throwUninformativeAndGenericDOMException(InvalidNodeTypeError );
1300 return; 1300 return;
1301 } 1301 }
1302 } 1302 }
1303 1303
1304 switch (refNode->nodeType()) { 1304 switch (refNode->nodeType()) {
1305 case Node::CDATA_SECTION_NODE: 1305 case Node::CDATA_SECTION_NODE:
1306 case Node::COMMENT_NODE: 1306 case Node::COMMENT_NODE:
1307 case Node::DOCUMENT_TYPE_NODE: 1307 case Node::DOCUMENT_TYPE_NODE:
1308 case Node::ELEMENT_NODE: 1308 case Node::ELEMENT_NODE:
1309 case Node::PROCESSING_INSTRUCTION_NODE: 1309 case Node::PROCESSING_INSTRUCTION_NODE:
1310 case Node::TEXT_NODE: 1310 case Node::TEXT_NODE:
1311 case Node::XPATH_NAMESPACE_NODE: 1311 case Node::XPATH_NAMESPACE_NODE:
1312 break; 1312 break;
1313 case Node::ATTRIBUTE_NODE: 1313 case Node::ATTRIBUTE_NODE:
1314 case Node::DOCUMENT_FRAGMENT_NODE: 1314 case Node::DOCUMENT_FRAGMENT_NODE:
1315 case Node::DOCUMENT_NODE: 1315 case Node::DOCUMENT_NODE:
1316 case Node::ENTITY_NODE: 1316 case Node::ENTITY_NODE:
1317 case Node::NOTATION_NODE: 1317 case Node::NOTATION_NODE:
1318 es.throwDOMException(InvalidNodeTypeError); 1318 es.throwUninformativeAndGenericDOMException(InvalidNodeTypeError);
1319 return; 1319 return;
1320 } 1320 }
1321 1321
1322 if (m_ownerDocument != &refNode->document()) 1322 if (m_ownerDocument != &refNode->document())
1323 setDocument(refNode->document()); 1323 setDocument(refNode->document());
1324 1324
1325 setStartBefore(refNode); 1325 setStartBefore(refNode);
1326 setEndAfter(refNode); 1326 setEndAfter(refNode);
1327 } 1327 }
1328 1328
1329 void Range::selectNodeContents(Node* refNode, ExceptionState& es) 1329 void Range::selectNodeContents(Node* refNode, ExceptionState& es)
1330 { 1330 {
1331 if (!m_start.container()) { 1331 if (!m_start.container()) {
1332 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("selectNodeContents", "Range", "The range has no container. Perhaps 'detatch( )' has been invoked on this object?")); 1332 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("selectNodeContents", "Range", "The range has no container. Perhaps 'detatch( )' has been invoked on this object?"));
1333 return; 1333 return;
1334 } 1334 }
1335 1335
1336 if (!refNode) { 1336 if (!refNode) {
1337 es.throwDOMException(NotFoundError); 1337 es.throwUninformativeAndGenericDOMException(NotFoundError);
1338 return; 1338 return;
1339 } 1339 }
1340 1340
1341 // InvalidNodeTypeError: Raised if refNode or an ancestor of refNode is an E ntity, Notation 1341 // InvalidNodeTypeError: Raised if refNode or an ancestor of refNode is an E ntity, Notation
1342 // or DocumentType node. 1342 // or DocumentType node.
1343 for (Node* n = refNode; n; n = n->parentNode()) { 1343 for (Node* n = refNode; n; n = n->parentNode()) {
1344 switch (n->nodeType()) { 1344 switch (n->nodeType()) {
1345 case Node::ATTRIBUTE_NODE: 1345 case Node::ATTRIBUTE_NODE:
1346 case Node::CDATA_SECTION_NODE: 1346 case Node::CDATA_SECTION_NODE:
1347 case Node::COMMENT_NODE: 1347 case Node::COMMENT_NODE:
1348 case Node::DOCUMENT_FRAGMENT_NODE: 1348 case Node::DOCUMENT_FRAGMENT_NODE:
1349 case Node::DOCUMENT_NODE: 1349 case Node::DOCUMENT_NODE:
1350 case Node::ELEMENT_NODE: 1350 case Node::ELEMENT_NODE:
1351 case Node::PROCESSING_INSTRUCTION_NODE: 1351 case Node::PROCESSING_INSTRUCTION_NODE:
1352 case Node::TEXT_NODE: 1352 case Node::TEXT_NODE:
1353 case Node::XPATH_NAMESPACE_NODE: 1353 case Node::XPATH_NAMESPACE_NODE:
1354 break; 1354 break;
1355 case Node::DOCUMENT_TYPE_NODE: 1355 case Node::DOCUMENT_TYPE_NODE:
1356 case Node::ENTITY_NODE: 1356 case Node::ENTITY_NODE:
1357 case Node::NOTATION_NODE: 1357 case Node::NOTATION_NODE:
1358 es.throwDOMException(InvalidNodeTypeError); 1358 es.throwUninformativeAndGenericDOMException(InvalidNodeTypeError );
1359 return; 1359 return;
1360 } 1360 }
1361 } 1361 }
1362 1362
1363 if (m_ownerDocument != &refNode->document()) 1363 if (m_ownerDocument != &refNode->document())
1364 setDocument(refNode->document()); 1364 setDocument(refNode->document());
1365 1365
1366 m_start.setToStartOfNode(refNode); 1366 m_start.setToStartOfNode(refNode);
1367 m_end.setToEndOfNode(refNode); 1367 m_end.setToEndOfNode(refNode);
1368 } 1368 }
1369 1369
1370 void Range::surroundContents(PassRefPtr<Node> passNewParent, ExceptionState& es) 1370 void Range::surroundContents(PassRefPtr<Node> passNewParent, ExceptionState& es)
1371 { 1371 {
1372 RefPtr<Node> newParent = passNewParent; 1372 RefPtr<Node> newParent = passNewParent;
1373 1373
1374 if (!m_start.container()) { 1374 if (!m_start.container()) {
1375 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("surroundContents", "Range", "The range has no container. Perhaps 'detatch()' has been invoked on this object?")); 1375 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te("surroundContents", "Range", "The range has no container. Perhaps 'detatch()' has been invoked on this object?"));
1376 return; 1376 return;
1377 } 1377 }
1378 1378
1379 if (!newParent) { 1379 if (!newParent) {
1380 es.throwDOMException(NotFoundError); 1380 es.throwUninformativeAndGenericDOMException(NotFoundError);
1381 return; 1381 return;
1382 } 1382 }
1383 1383
1384 // InvalidNodeTypeError: Raised if node is an Attr, Entity, DocumentType, No tation, 1384 // InvalidNodeTypeError: Raised if node is an Attr, Entity, DocumentType, No tation,
1385 // Document, or DocumentFragment node. 1385 // Document, or DocumentFragment node.
1386 switch (newParent->nodeType()) { 1386 switch (newParent->nodeType()) {
1387 case Node::ATTRIBUTE_NODE: 1387 case Node::ATTRIBUTE_NODE:
1388 case Node::DOCUMENT_FRAGMENT_NODE: 1388 case Node::DOCUMENT_FRAGMENT_NODE:
1389 case Node::DOCUMENT_NODE: 1389 case Node::DOCUMENT_NODE:
1390 case Node::DOCUMENT_TYPE_NODE: 1390 case Node::DOCUMENT_TYPE_NODE:
1391 case Node::ENTITY_NODE: 1391 case Node::ENTITY_NODE:
1392 case Node::NOTATION_NODE: 1392 case Node::NOTATION_NODE:
1393 es.throwDOMException(InvalidNodeTypeError); 1393 es.throwUninformativeAndGenericDOMException(InvalidNodeTypeError);
1394 return; 1394 return;
1395 case Node::CDATA_SECTION_NODE: 1395 case Node::CDATA_SECTION_NODE:
1396 case Node::COMMENT_NODE: 1396 case Node::COMMENT_NODE:
1397 case Node::ELEMENT_NODE: 1397 case Node::ELEMENT_NODE:
1398 case Node::PROCESSING_INSTRUCTION_NODE: 1398 case Node::PROCESSING_INSTRUCTION_NODE:
1399 case Node::TEXT_NODE: 1399 case Node::TEXT_NODE:
1400 case Node::XPATH_NAMESPACE_NODE: 1400 case Node::XPATH_NAMESPACE_NODE:
1401 break; 1401 break;
1402 } 1402 }
1403 1403
1404 // Raise a HierarchyRequestError if m_start.container() doesn't accept child ren like newParent. 1404 // Raise a HierarchyRequestError if m_start.container() doesn't accept child ren like newParent.
1405 Node* parentOfNewParent = m_start.container(); 1405 Node* parentOfNewParent = m_start.container();
1406 1406
1407 // If m_start.container() is a character data node, it will be split and it will be its parent that will 1407 // If m_start.container() is a character data node, it will be split and it will be its parent that will
1408 // need to accept newParent (or in the case of a comment, it logically "woul d" be inserted into the parent, 1408 // need to accept newParent (or in the case of a comment, it logically "woul d" be inserted into the parent,
1409 // although this will fail below for another reason). 1409 // although this will fail below for another reason).
1410 if (parentOfNewParent->isCharacterDataNode()) 1410 if (parentOfNewParent->isCharacterDataNode())
1411 parentOfNewParent = parentOfNewParent->parentNode(); 1411 parentOfNewParent = parentOfNewParent->parentNode();
1412 if (!parentOfNewParent || !parentOfNewParent->childTypeAllowed(newParent->no deType())) { 1412 if (!parentOfNewParent || !parentOfNewParent->childTypeAllowed(newParent->no deType())) {
1413 es.throwDOMException(HierarchyRequestError); 1413 es.throwUninformativeAndGenericDOMException(HierarchyRequestError);
1414 return; 1414 return;
1415 } 1415 }
1416 1416
1417 if (newParent->contains(m_start.container())) { 1417 if (newParent->contains(m_start.container())) {
1418 es.throwDOMException(HierarchyRequestError); 1418 es.throwUninformativeAndGenericDOMException(HierarchyRequestError);
1419 return; 1419 return;
1420 } 1420 }
1421 1421
1422 // FIXME: Do we need a check if the node would end up with a child node of a type not 1422 // FIXME: Do we need a check if the node would end up with a child node of a type not
1423 // allowed by the type of node? 1423 // allowed by the type of node?
1424 1424
1425 // BAD_BOUNDARYPOINTS_ERR: Raised if the Range partially selects a non-Text node. 1425 // BAD_BOUNDARYPOINTS_ERR: Raised if the Range partially selects a non-Text node.
1426 Node* startNonTextContainer = m_start.container(); 1426 Node* startNonTextContainer = m_start.container();
1427 if (startNonTextContainer->nodeType() == Node::TEXT_NODE) 1427 if (startNonTextContainer->nodeType() == Node::TEXT_NODE)
1428 startNonTextContainer = startNonTextContainer->parentNode(); 1428 startNonTextContainer = startNonTextContainer->parentNode();
1429 Node* endNonTextContainer = m_end.container(); 1429 Node* endNonTextContainer = m_end.container();
1430 if (endNonTextContainer->nodeType() == Node::TEXT_NODE) 1430 if (endNonTextContainer->nodeType() == Node::TEXT_NODE)
1431 endNonTextContainer = endNonTextContainer->parentNode(); 1431 endNonTextContainer = endNonTextContainer->parentNode();
1432 if (startNonTextContainer != endNonTextContainer) { 1432 if (startNonTextContainer != endNonTextContainer) {
1433 es.throwDOMException(InvalidStateError); 1433 es.throwUninformativeAndGenericDOMException(InvalidStateError);
1434 return; 1434 return;
1435 } 1435 }
1436 1436
1437 while (Node* n = newParent->firstChild()) { 1437 while (Node* n = newParent->firstChild()) {
1438 toContainerNode(newParent.get())->removeChild(n, es); 1438 toContainerNode(newParent.get())->removeChild(n, es);
1439 if (es.hadException()) 1439 if (es.hadException())
1440 return; 1440 return;
1441 } 1441 }
1442 RefPtr<DocumentFragment> fragment = extractContents(es); 1442 RefPtr<DocumentFragment> fragment = extractContents(es);
1443 if (es.hadException()) 1443 if (es.hadException())
(...skipping 22 matching lines...) Expand all
1466 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te(methodName, "Range", "The range has no container. Perhaps 'detatch()' has bee n invoked on this object?")); 1466 es.throwDOMException(InvalidStateError, ExceptionMessages::failedToExecu te(methodName, "Range", "The range has no container. Perhaps 'detatch()' has bee n invoked on this object?"));
1467 return; 1467 return;
1468 } 1468 }
1469 1469
1470 if (!commonAncestorContainer(es) || es.hadException()) 1470 if (!commonAncestorContainer(es) || es.hadException())
1471 return; 1471 return;
1472 1472
1473 Node* pastLast = pastLastNode(); 1473 Node* pastLast = pastLastNode();
1474 for (Node* n = firstNode(); n != pastLast; n = NodeTraversal::next(n)) { 1474 for (Node* n = firstNode(); n != pastLast; n = NodeTraversal::next(n)) {
1475 if (n->nodeType() == Node::DOCUMENT_TYPE_NODE) { 1475 if (n->nodeType() == Node::DOCUMENT_TYPE_NODE) {
1476 es.throwDOMException(HierarchyRequestError); 1476 es.throwUninformativeAndGenericDOMException(HierarchyRequestError);
1477 return; 1477 return;
1478 } 1478 }
1479 } 1479 }
1480 } 1480 }
1481 1481
1482 Node* Range::firstNode() const 1482 Node* Range::firstNode() const
1483 { 1483 {
1484 if (!m_start.container()) 1484 if (!m_start.container())
1485 return 0; 1485 return 0;
1486 if (m_start.container()->offsetInCharacters()) 1486 if (m_start.container()->offsetInCharacters())
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
1901 1901
1902 void showTree(const WebCore::Range* range) 1902 void showTree(const WebCore::Range* range)
1903 { 1903 {
1904 if (range && range->boundaryPointsValid()) { 1904 if (range && range->boundaryPointsValid()) {
1905 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E"); 1905 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E");
1906 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset()); 1906 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset());
1907 } 1907 }
1908 } 1908 }
1909 1909
1910 #endif 1910 #endif
OLDNEW
« no previous file with comments | « Source/core/dom/Node.cpp ('k') | Source/core/editing/markup.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698