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

Side by Side Diff: Source/core/editing/VisiblePosition.cpp

Issue 1245843003: [CodeHealth] Use Position::anchorNode instead of deprecatedNode. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 5 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 | « Source/core/editing/VisiblePosition.h ('k') | Source/core/editing/VisibleSelection.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 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed.
3 * Portions Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved. 3 * Portions Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 442
443 template <typename PositionWithAffinityType> 443 template <typename PositionWithAffinityType>
444 PositionWithAffinityType honorEditingBoundaryAtOrBeforeAlgorithm(const PositionW ithAffinityType& pos, const typename PositionWithAffinityType::PositionType& anc hor) 444 PositionWithAffinityType honorEditingBoundaryAtOrBeforeAlgorithm(const PositionW ithAffinityType& pos, const typename PositionWithAffinityType::PositionType& anc hor)
445 { 445 {
446 if (pos.isNull()) 446 if (pos.isNull())
447 return pos; 447 return pos;
448 448
449 ContainerNode* highestRoot = highestEditableRoot(anchor); 449 ContainerNode* highestRoot = highestEditableRoot(anchor);
450 450
451 // Return empty position if pos is not somewhere inside the editable region containing this position 451 // Return empty position if pos is not somewhere inside the editable region containing this position
452 if (highestRoot && !pos.position().deprecatedNode()->isDescendantOf(highestR oot)) 452 if (highestRoot && !pos.position().anchorNode()->isDescendantOf(highestRoot) )
453 return PositionWithAffinityType(); 453 return PositionWithAffinityType();
454 454
455 // Return pos itself if the two are from the very same editable region, or b oth are non-editable 455 // Return pos itself if the two are from the very same editable region, or b oth are non-editable
456 // FIXME: In the non-editable case, just because the new position is non-edi table doesn't mean movement 456 // FIXME: In the non-editable case, just because the new position is non-edi table doesn't mean movement
457 // to it is allowed. VisibleSelection::adjustForEditableContent has this pr oblem too. 457 // to it is allowed. VisibleSelection::adjustForEditableContent has this pr oblem too.
458 if (highestEditableRoot(pos.position()) == highestRoot) 458 if (highestEditableRoot(pos.position()) == highestRoot)
459 return pos; 459 return pos;
460 460
461 // Return empty position if this position is non-editable, but pos is editab le 461 // Return empty position if this position is non-editable, but pos is editab le
462 // FIXME: Move to the previous non-editable region. 462 // FIXME: Move to the previous non-editable region.
(...skipping 20 matching lines...) Expand all
483 } 483 }
484 484
485 VisiblePosition VisiblePosition::honorEditingBoundaryAtOrAfter(const VisiblePosi tion &pos) const 485 VisiblePosition VisiblePosition::honorEditingBoundaryAtOrAfter(const VisiblePosi tion &pos) const
486 { 486 {
487 if (pos.isNull()) 487 if (pos.isNull())
488 return pos; 488 return pos;
489 489
490 ContainerNode* highestRoot = highestEditableRoot(deepEquivalent()); 490 ContainerNode* highestRoot = highestEditableRoot(deepEquivalent());
491 491
492 // Return empty position if pos is not somewhere inside the editable region containing this position 492 // Return empty position if pos is not somewhere inside the editable region containing this position
493 if (highestRoot && !pos.deepEquivalent().deprecatedNode()->isDescendantOf(hi ghestRoot)) 493 if (highestRoot && !pos.deepEquivalent().anchorNode()->isDescendantOf(highes tRoot))
494 return VisiblePosition(); 494 return VisiblePosition();
495 495
496 // Return pos itself if the two are from the very same editable region, or b oth are non-editable 496 // Return pos itself if the two are from the very same editable region, or b oth are non-editable
497 // FIXME: In the non-editable case, just because the new position is non-edi table doesn't mean movement 497 // FIXME: In the non-editable case, just because the new position is non-edi table doesn't mean movement
498 // to it is allowed. VisibleSelection::adjustForEditableContent has this pr oblem too. 498 // to it is allowed. VisibleSelection::adjustForEditableContent has this pr oblem too.
499 if (highestEditableRoot(pos.deepEquivalent()) == highestRoot) 499 if (highestEditableRoot(pos.deepEquivalent()) == highestRoot)
500 return pos; 500 return pos;
501 501
502 // Return empty position if this position is non-editable, but pos is editab le 502 // Return empty position if this position is non-editable, but pos is editab le
503 // FIXME: Move to the next non-editable region. 503 // FIXME: Move to the next non-editable region.
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 if (candidate.isCandidate()) 590 if (candidate.isCandidate())
591 return candidate; 591 return candidate;
592 candidate = position.downstream(); 592 candidate = position.downstream();
593 if (candidate.isCandidate()) 593 if (candidate.isCandidate())
594 return candidate; 594 return candidate;
595 595
596 // When neither upstream or downstream gets us to a candidate (upstream/down stream won't leave 596 // When neither upstream or downstream gets us to a candidate (upstream/down stream won't leave
597 // blocks or enter new ones), we search forward and backward until we find o ne. 597 // blocks or enter new ones), we search forward and backward until we find o ne.
598 PositionType next = canonicalizeCandidate(nextCandidate(position)); 598 PositionType next = canonicalizeCandidate(nextCandidate(position));
599 PositionType prev = canonicalizeCandidate(previousCandidate(position)); 599 PositionType prev = canonicalizeCandidate(previousCandidate(position));
600 Node* nextNode = next.deprecatedNode(); 600 Node* nextNode = next.anchorNode();
601 Node* prevNode = prev.deprecatedNode(); 601 Node* prevNode = prev.anchorNode();
602 602
603 // The new position must be in the same editable element. Enforce that first . 603 // The new position must be in the same editable element. Enforce that first .
604 // Unless the descent is from a non-editable html element to an editable bod y. 604 // Unless the descent is from a non-editable html element to an editable bod y.
605 if (isHTMLHtmlElement(node) && !node->hasEditableStyle() && node->document() .body() && node->document().body()->hasEditableStyle()) 605 if (isHTMLHtmlElement(node) && !node->hasEditableStyle() && node->document() .body() && node->document().body()->hasEditableStyle())
606 return next.isNotNull() ? next : prev; 606 return next.isNotNull() ? next : prev;
607 607
608 Element* editingRoot = editableRootForPosition(position); 608 Element* editingRoot = editableRootForPosition(position);
609 609
610 // If the html element is editable, descending into its body will look like a descent 610 // If the html element is editable, descending into its body will look like a descent
611 // from non-editable to editable content since rootEditableElement() always stops at the body. 611 // from non-editable to editable content since rootEditableElement() always stops at the body.
612 if (isHTMLHtmlElement(editingRoot) || position.deprecatedNode()->isDocumentN ode()) 612 if (isHTMLHtmlElement(editingRoot) || position.anchorNode()->isDocumentNode( ))
613 return next.isNotNull() ? next : prev; 613 return next.isNotNull() ? next : prev;
614 614
615 bool prevIsInSameEditableElement = prevNode && editableRootForPosition(prev) == editingRoot; 615 bool prevIsInSameEditableElement = prevNode && editableRootForPosition(prev) == editingRoot;
616 bool nextIsInSameEditableElement = nextNode && editableRootForPosition(next) == editingRoot; 616 bool nextIsInSameEditableElement = nextNode && editableRootForPosition(next) == editingRoot;
617 if (prevIsInSameEditableElement && !nextIsInSameEditableElement) 617 if (prevIsInSameEditableElement && !nextIsInSameEditableElement)
618 return prev; 618 return prev;
619 619
620 if (nextIsInSameEditableElement && !prevIsInSameEditableElement) 620 if (nextIsInSameEditableElement && !prevIsInSameEditableElement)
621 return next; 621 return next;
622 622
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 TrackExceptionState exceptionState; 783 TrackExceptionState exceptionState;
784 r->setEnd(p.containerNode(), p.offsetInContainerNode(), exceptionState); 784 r->setEnd(p.containerNode(), p.offsetInContainerNode(), exceptionState);
785 return !exceptionState.hadException(); 785 return !exceptionState.hadException();
786 } 786 }
787 787
788 Element* enclosingBlockFlowElement(const VisiblePosition& visiblePosition) 788 Element* enclosingBlockFlowElement(const VisiblePosition& visiblePosition)
789 { 789 {
790 if (visiblePosition.isNull()) 790 if (visiblePosition.isNull())
791 return 0; 791 return 0;
792 792
793 return enclosingBlockFlowElement(*visiblePosition.deepEquivalent().deprecate dNode()); 793 return enclosingBlockFlowElement(*visiblePosition.deepEquivalent().anchorNod e());
794 } 794 }
795 795
796 bool isFirstVisiblePositionInNode(const VisiblePosition& visiblePosition, const ContainerNode* node) 796 bool isFirstVisiblePositionInNode(const VisiblePosition& visiblePosition, const ContainerNode* node)
797 { 797 {
798 if (visiblePosition.isNull()) 798 if (visiblePosition.isNull())
799 return false; 799 return false;
800 800
801 if (!visiblePosition.deepEquivalent().containerNode()->isDescendantOf(node)) 801 if (!visiblePosition.deepEquivalent().containerNode()->isDescendantOf(node))
802 return false; 802 return false;
803 803
804 VisiblePosition previous = visiblePosition.previous(); 804 VisiblePosition previous = visiblePosition.previous();
805 return previous.isNull() || !previous.deepEquivalent().deprecatedNode()->isD escendantOf(node); 805 return previous.isNull() || !previous.deepEquivalent().anchorNode()->isDesce ndantOf(node);
806 } 806 }
807 807
808 bool isLastVisiblePositionInNode(const VisiblePosition& visiblePosition, const C ontainerNode* node) 808 bool isLastVisiblePositionInNode(const VisiblePosition& visiblePosition, const C ontainerNode* node)
809 { 809 {
810 if (visiblePosition.isNull()) 810 if (visiblePosition.isNull())
811 return false; 811 return false;
812 812
813 if (!visiblePosition.deepEquivalent().containerNode()->isDescendantOf(node)) 813 if (!visiblePosition.deepEquivalent().containerNode()->isDescendantOf(node))
814 return false; 814 return false;
815 815
816 VisiblePosition next = visiblePosition.next(); 816 VisiblePosition next = visiblePosition.next();
817 return next.isNull() || !next.deepEquivalent().deprecatedNode()->isDescendan tOf(node); 817 return next.isNull() || !next.deepEquivalent().anchorNode()->isDescendantOf( node);
818 } 818 }
819 819
820 DEFINE_TRACE(VisiblePosition) 820 DEFINE_TRACE(VisiblePosition)
821 { 821 {
822 visitor->trace(m_deepPosition); 822 visitor->trace(m_deepPosition);
823 } 823 }
824 824
825 } // namespace blink 825 } // namespace blink
826 826
827 #ifndef NDEBUG 827 #ifndef NDEBUG
828 828
829 void showTree(const blink::VisiblePosition* vpos) 829 void showTree(const blink::VisiblePosition* vpos)
830 { 830 {
831 if (vpos) 831 if (vpos)
832 vpos->showTreeForThis(); 832 vpos->showTreeForThis();
833 else 833 else
834 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n"); 834 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n");
835 } 835 }
836 836
837 void showTree(const blink::VisiblePosition& vpos) 837 void showTree(const blink::VisiblePosition& vpos)
838 { 838 {
839 vpos.showTreeForThis(); 839 vpos.showTreeForThis();
840 } 840 }
841 841
842 #endif 842 #endif
OLDNEW
« no previous file with comments | « Source/core/editing/VisiblePosition.h ('k') | Source/core/editing/VisibleSelection.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698