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

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

Issue 1364683003: Range.intersectsNode() does not behave according to the specification. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Test rebaselined Created 5 years, 3 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
« no previous file with comments | « LayoutTests/fast/dom/Range/resources/intersectsNode.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * (C) 1999 Lars Knoll (knoll@kde.org) 2 * (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Gunnstein Lye (gunnstein@netcom.no) 3 * (C) 2000 Gunnstein Lye (gunnstein@netcom.no)
4 * (C) 2000 Frederik Holljen (frederik.holljen@hig.no) 4 * (C) 2000 Frederik Holljen (frederik.holljen@hig.no)
5 * (C) 2001 Peter Kelly (pmk@post.com) 5 * (C) 2001 Peter Kelly (pmk@post.com)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved.
7 * Copyright (C) 2011 Motorola Mobility. All rights reserved. 7 * Copyright (C) 2011 Motorola Mobility. All rights reserved.
8 * 8 *
9 * This library is free software; you can redistribute it and/or 9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public 10 * modify it under the terms of the GNU Library General Public
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 bool Range::intersectsNode(Node* refNode, ExceptionState& exceptionState) 392 bool Range::intersectsNode(Node* refNode, ExceptionState& exceptionState)
393 { 393 {
394 // http://developer.mozilla.org/en/docs/DOM:range.intersectsNode 394 // http://developer.mozilla.org/en/docs/DOM:range.intersectsNode
395 // Returns a bool if the node intersects the range. 395 // Returns a bool if the node intersects the range.
396 if (!nodeValidForIntersects(refNode, m_ownerDocument.get(), exceptionState)) 396 if (!nodeValidForIntersects(refNode, m_ownerDocument.get(), exceptionState))
397 return false; 397 return false;
398 398
399 ContainerNode* parentNode = refNode->parentNode(); 399 ContainerNode* parentNode = refNode->parentNode();
400 int nodeIndex = refNode->nodeIndex(); 400 int nodeIndex = refNode->nodeIndex();
401 401
402 if (!parentNode) { 402 if (!parentNode)
sof 2015/09/25 09:17:04 Could you move this up to the line after where par
pals 2015/09/28 11:29:06 Done.
403 // if the node is the top document we should return NODE_BEFORE_AND_AFTE R 403 return true;
404 // but we throw to match firefox behavior
405 exceptionState.throwDOMException(NotFoundError, "The node provided has n o parent.");
406 return false;
407 }
408 404
409 if (comparePoint(parentNode, nodeIndex, exceptionState) < 0 // starts before start 405 if (comparePoint(parentNode, nodeIndex, exceptionState) < 0 // starts before start
410 && comparePoint(parentNode, nodeIndex + 1, exceptionState) < 0) { // end s before start 406 && comparePoint(parentNode, nodeIndex + 1, exceptionState) < 0) { // end s before start
411 return false; 407 return false;
412 } 408 }
413 409
414 if (comparePoint(parentNode, nodeIndex, exceptionState) > 0 // starts after end 410 if (comparePoint(parentNode, nodeIndex, exceptionState) > 0 // starts after end
415 && comparePoint(parentNode, nodeIndex + 1, exceptionState) > 0) { // end s after end 411 && comparePoint(parentNode, nodeIndex + 1, exceptionState) > 0) { // end s after end
416 return false; 412 return false;
417 } 413 }
418 414
419 return true; // all other cases 415 return true; // all other cases
420 } 416 }
421 417
422 bool Range::intersectsNode(Node* refNode, const Position& start, const Position& end, ExceptionState& exceptionState) 418 bool Range::intersectsNode(Node* refNode, const Position& start, const Position& end, ExceptionState& exceptionState)
423 { 419 {
424 // http://developer.mozilla.org/en/docs/DOM:range.intersectsNode 420 // http://developer.mozilla.org/en/docs/DOM:range.intersectsNode
425 // Returns a bool if the node intersects the range. 421 // Returns a bool if the node intersects the range.
426 if (!nodeValidForIntersects(refNode, start.document(), exceptionState)) 422 if (!nodeValidForIntersects(refNode, start.document(), exceptionState))
427 return false; 423 return false;
428 424
429 ContainerNode* parentNode = refNode->parentNode(); 425 ContainerNode* parentNode = refNode->parentNode();
430 int nodeIndex = refNode->nodeIndex(); 426 int nodeIndex = refNode->nodeIndex();
431 427
432 if (!parentNode) { 428 if (!parentNode)
sof 2015/09/25 09:17:04 Ditto.
pals 2015/09/28 11:29:06 Done.
433 // if the node is the top document we should return NODE_BEFORE_AND_AFTE R 429 return true;
434 // but we throw to match firefox behavior
435 exceptionState.throwDOMException(NotFoundError, "The node provided has n o parent.");
436 return false;
437 }
438 430
439 Node* startContainerNode = start.computeContainerNode(); 431 Node* startContainerNode = start.computeContainerNode();
440 int startOffset = start.computeOffsetInContainerNode(); 432 int startOffset = start.computeOffsetInContainerNode();
441 433
442 if (compareBoundaryPoints(parentNode, nodeIndex, startContainerNode, startOf fset, exceptionState) < 0 // starts before start 434 if (compareBoundaryPoints(parentNode, nodeIndex, startContainerNode, startOf fset, exceptionState) < 0 // starts before start
443 && compareBoundaryPoints(parentNode, nodeIndex + 1, startContainerNode, startOffset, exceptionState) < 0) { // ends before start 435 && compareBoundaryPoints(parentNode, nodeIndex + 1, startContainerNode, startOffset, exceptionState) < 0) { // ends before start
444 ASSERT(!exceptionState.hadException()); 436 ASSERT(!exceptionState.hadException());
445 return false; 437 return false;
446 } 438 }
447 439
(...skipping 1234 matching lines...) Expand 10 before | Expand all | Expand 10 after
1682 { 1674 {
1683 if (range && range->boundaryPointsValid()) { 1675 if (range && range->boundaryPointsValid()) {
1684 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E"); 1676 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E");
1685 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset()); 1677 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset());
1686 } else { 1678 } else {
1687 fprintf(stderr, "Cannot show tree if range is null, or if boundary point s are invalid.\n"); 1679 fprintf(stderr, "Cannot show tree if range is null, or if boundary point s are invalid.\n");
1688 } 1680 }
1689 } 1681 }
1690 1682
1691 #endif 1683 #endif
OLDNEW
« no previous file with comments | « LayoutTests/fast/dom/Range/resources/intersectsNode.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698