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

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

Issue 541633004: Avoid temporary range allocation in FrameSelection::respondToNodeModification. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address review comments. Created 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/dom/Range.h ('k') | Source/core/editing/FrameSelection.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 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 void Range::deleteContents(ExceptionState& exceptionState) 463 void Range::deleteContents(ExceptionState& exceptionState)
464 { 464 {
465 ASSERT(boundaryPointsValid()); 465 ASSERT(boundaryPointsValid());
466 466
467 { 467 {
468 EventQueueScope eventQueueScope; 468 EventQueueScope eventQueueScope;
469 processContents(DELETE_CONTENTS, exceptionState); 469 processContents(DELETE_CONTENTS, exceptionState);
470 } 470 }
471 } 471 }
472 472
473 static bool nodeValidForIntersects(Node* refNode, Document* expectedDocument, Ex ceptionState& exceptionState)
474 {
475 if (!refNode) {
476 exceptionState.throwDOMException(NotFoundError, "The node provided is nu ll.");
477 return false;
478 }
479
480 if (!refNode->inActiveDocument() || refNode->document() != expectedDocument) {
481 // Firefox doesn't throw an exception for these cases; it returns false.
482 return false;
483 }
484
485 return true;
486 }
487
473 bool Range::intersectsNode(Node* refNode, ExceptionState& exceptionState) 488 bool Range::intersectsNode(Node* refNode, ExceptionState& exceptionState)
474 { 489 {
475 // http://developer.mozilla.org/en/docs/DOM:range.intersectsNode 490 // http://developer.mozilla.org/en/docs/DOM:range.intersectsNode
476 // Returns a bool if the node intersects the range. 491 // Returns a bool if the node intersects the range.
477 if (!refNode) { 492 if (!nodeValidForIntersects(refNode, m_ownerDocument.get(), exceptionState))
478 exceptionState.throwDOMException(NotFoundError, "The node provided is nu ll.");
479 return false; 493 return false;
480 }
481
482 if (!refNode->inActiveDocument() || refNode->document() != m_ownerDocument) {
483 // Firefox doesn't throw an exception for these cases; it returns false.
484 return false;
485 }
486 494
487 ContainerNode* parentNode = refNode->parentNode(); 495 ContainerNode* parentNode = refNode->parentNode();
488 int nodeIndex = refNode->nodeIndex(); 496 int nodeIndex = refNode->nodeIndex();
489 497
490 if (!parentNode) { 498 if (!parentNode) {
491 // if the node is the top document we should return NODE_BEFORE_AND_AFTE R 499 // if the node is the top document we should return NODE_BEFORE_AND_AFTE R
492 // but we throw to match firefox behavior 500 // but we throw to match firefox behavior
493 exceptionState.throwDOMException(NotFoundError, "The node provided has n o parent."); 501 exceptionState.throwDOMException(NotFoundError, "The node provided has n o parent.");
494 return false; 502 return false;
495 } 503 }
496 504
497 if (comparePoint(parentNode, nodeIndex, exceptionState) < 0 // starts before start 505 if (comparePoint(parentNode, nodeIndex, exceptionState) < 0 // starts before start
498 && comparePoint(parentNode, nodeIndex + 1, exceptionState) < 0) { // end s before start 506 && comparePoint(parentNode, nodeIndex + 1, exceptionState) < 0) { // end s before start
499 return false; 507 return false;
500 } 508 }
501 509
502 if (comparePoint(parentNode, nodeIndex, exceptionState) > 0 // starts after end 510 if (comparePoint(parentNode, nodeIndex, exceptionState) > 0 // starts after end
503 && comparePoint(parentNode, nodeIndex + 1, exceptionState) > 0) { // end s after end 511 && comparePoint(parentNode, nodeIndex + 1, exceptionState) > 0) { // end s after end
504 return false; 512 return false;
505 } 513 }
506 514
507 return true; // all other cases 515 return true; // all other cases
508 } 516 }
509 517
518 bool Range::intersectsNode(Node* refNode, const Position& start, const Position& end, ExceptionState& exceptionState)
519 {
520 // http://developer.mozilla.org/en/docs/DOM:range.intersectsNode
521 // Returns a bool if the node intersects the range.
522 if (!nodeValidForIntersects(refNode, start.document(), exceptionState))
523 return false;
524
525 ContainerNode* parentNode = refNode->parentNode();
526 int nodeIndex = refNode->nodeIndex();
527
528 if (!parentNode) {
529 // if the node is the top document we should return NODE_BEFORE_AND_AFTE R
530 // but we throw to match firefox behavior
531 exceptionState.throwDOMException(NotFoundError, "The node provided has n o parent.");
532 return false;
533 }
534
535 Node* startContainerNode = start.containerNode();
536 int startOffset = start.computeOffsetInContainerNode();
537
538 if (compareBoundaryPoints(parentNode, nodeIndex, startContainerNode, startOf fset, exceptionState) < 0 // starts before start
539 && compareBoundaryPoints(parentNode, nodeIndex + 1, startContainerNode, startOffset, exceptionState) < 0) { // ends before start
540 ASSERT(!exceptionState.hadException());
541 return false;
542 }
543
544 Node* endContainerNode = end.containerNode();
545 int endOffset = end.computeOffsetInContainerNode();
546
547 if (compareBoundaryPoints(parentNode, nodeIndex, endContainerNode, endOffset , exceptionState) > 0 // starts after end
548 && compareBoundaryPoints(parentNode, nodeIndex + 1, endContainerNode, en dOffset, exceptionState) > 0) { // ends after end
549 ASSERT(!exceptionState.hadException());
550 return false;
551 }
552
553 return true; // all other cases
554 }
555
510 static inline Node* highestAncestorUnderCommonRoot(Node* node, Node* commonRoot) 556 static inline Node* highestAncestorUnderCommonRoot(Node* node, Node* commonRoot)
511 { 557 {
512 if (node == commonRoot) 558 if (node == commonRoot)
513 return 0; 559 return 0;
514 560
515 ASSERT(commonRoot->contains(node)); 561 ASSERT(commonRoot->contains(node));
516 562
517 while (node->parentNode() != commonRoot) 563 while (node->parentNode() != commonRoot)
518 node = node->parentNode(); 564 node = node->parentNode();
519 565
(...skipping 1188 matching lines...) Expand 10 before | Expand all | Expand 10 after
1708 1754
1709 void showTree(const blink::Range* range) 1755 void showTree(const blink::Range* range)
1710 { 1756 {
1711 if (range && range->boundaryPointsValid()) { 1757 if (range && range->boundaryPointsValid()) {
1712 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E"); 1758 range->startContainer()->showTreeAndMark(range->startContainer(), "S", r ange->endContainer(), "E");
1713 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset()); 1759 fprintf(stderr, "start offset: %d, end offset: %d\n", range->startOffset (), range->endOffset());
1714 } 1760 }
1715 } 1761 }
1716 1762
1717 #endif 1763 #endif
OLDNEW
« no previous file with comments | « Source/core/dom/Range.h ('k') | Source/core/editing/FrameSelection.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698