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

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

Issue 434393003: Use tighter typing in editing: VisiblePosition & VisibleSelection (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 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/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 576 matching lines...) Expand 10 before | Expand all | Expand 10 after
587 Position next = canonicalizeCandidate(nextCandidate(position)); 587 Position next = canonicalizeCandidate(nextCandidate(position));
588 Position prev = canonicalizeCandidate(previousCandidate(position)); 588 Position prev = canonicalizeCandidate(previousCandidate(position));
589 Node* nextNode = next.deprecatedNode(); 589 Node* nextNode = next.deprecatedNode();
590 Node* prevNode = prev.deprecatedNode(); 590 Node* prevNode = prev.deprecatedNode();
591 591
592 // The new position must be in the same editable element. Enforce that first . 592 // The new position must be in the same editable element. Enforce that first .
593 // Unless the descent is from a non-editable html element to an editable bod y. 593 // Unless the descent is from a non-editable html element to an editable bod y.
594 if (isHTMLHtmlElement(node) && !node->hasEditableStyle() && node->document() .body() && node->document().body()->hasEditableStyle()) 594 if (isHTMLHtmlElement(node) && !node->hasEditableStyle() && node->document() .body() && node->document().body()->hasEditableStyle())
595 return next.isNotNull() ? next : prev; 595 return next.isNotNull() ? next : prev;
596 596
597 Node* editingRoot = editableRootForPosition(position); 597 Element* editingRoot = editableRootForPosition(position);
598 598
599 // If the html element is editable, descending into its body will look like a descent 599 // If the html element is editable, descending into its body will look like a descent
600 // from non-editable to editable content since rootEditableElement() always stops at the body. 600 // from non-editable to editable content since rootEditableElement() always stops at the body.
601 if (isHTMLHtmlElement(editingRoot) || position.deprecatedNode()->isDocumentN ode()) 601 if (isHTMLHtmlElement(editingRoot) || position.deprecatedNode()->isDocumentN ode())
602 return next.isNotNull() ? next : prev; 602 return next.isNotNull() ? next : prev;
603 603
604 bool prevIsInSameEditableElement = prevNode && editableRootForPosition(prev) == editingRoot; 604 bool prevIsInSameEditableElement = prevNode && editableRootForPosition(prev) == editingRoot;
605 bool nextIsInSameEditableElement = nextNode && editableRootForPosition(next) == editingRoot; 605 bool nextIsInSameEditableElement = nextNode && editableRootForPosition(next) == editingRoot;
606 if (prevIsInSameEditableElement && !nextIsInSameEditableElement) 606 if (prevIsInSameEditableElement && !nextIsInSameEditableElement)
607 return prev; 607 return prev;
608 608
609 if (nextIsInSameEditableElement && !prevIsInSameEditableElement) 609 if (nextIsInSameEditableElement && !prevIsInSameEditableElement)
610 return next; 610 return next;
611 611
612 if (!nextIsInSameEditableElement && !prevIsInSameEditableElement) 612 if (!nextIsInSameEditableElement && !prevIsInSameEditableElement)
613 return Position(); 613 return Position();
614 614
615 // The new position should be in the same block flow element. Favor that. 615 // The new position should be in the same block flow element. Favor that.
616 Node* originalBlock = node ? enclosingBlockFlowElement(*node) : 0; 616 Element* originalBlock = node ? enclosingBlockFlowElement(*node) : 0;
617 bool nextIsOutsideOriginalBlock = !nextNode->isDescendantOf(originalBlock) & & nextNode != originalBlock; 617 bool nextIsOutsideOriginalBlock = !nextNode->isDescendantOf(originalBlock) & & nextNode != originalBlock;
618 bool prevIsOutsideOriginalBlock = !prevNode->isDescendantOf(originalBlock) & & prevNode != originalBlock; 618 bool prevIsOutsideOriginalBlock = !prevNode->isDescendantOf(originalBlock) & & prevNode != originalBlock;
619 if (nextIsOutsideOriginalBlock && !prevIsOutsideOriginalBlock) 619 if (nextIsOutsideOriginalBlock && !prevIsOutsideOriginalBlock)
620 return prev; 620 return prev;
621 621
622 return next; 622 return next;
623 } 623 }
624 624
625 UChar32 VisiblePosition::characterAfter() const 625 UChar32 VisiblePosition::characterAfter() const
626 { 626 {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 } 743 }
744 744
745 Element* enclosingBlockFlowElement(const VisiblePosition& visiblePosition) 745 Element* enclosingBlockFlowElement(const VisiblePosition& visiblePosition)
746 { 746 {
747 if (visiblePosition.isNull()) 747 if (visiblePosition.isNull())
748 return 0; 748 return 0;
749 749
750 return enclosingBlockFlowElement(*visiblePosition.deepEquivalent().deprecate dNode()); 750 return enclosingBlockFlowElement(*visiblePosition.deepEquivalent().deprecate dNode());
751 } 751 }
752 752
753 bool isFirstVisiblePositionInNode(const VisiblePosition &visiblePosition, const Node *node) 753 bool isFirstVisiblePositionInNode(const VisiblePosition& visiblePosition, const ContainerNode* node)
754 { 754 {
755 if (visiblePosition.isNull()) 755 if (visiblePosition.isNull())
756 return false; 756 return false;
757 757
758 if (!visiblePosition.deepEquivalent().containerNode()->isDescendantOf(node)) 758 if (!visiblePosition.deepEquivalent().containerNode()->isDescendantOf(node))
759 return false; 759 return false;
760 760
761 VisiblePosition previous = visiblePosition.previous(); 761 VisiblePosition previous = visiblePosition.previous();
762 return previous.isNull() || !previous.deepEquivalent().deprecatedNode()->isD escendantOf(node); 762 return previous.isNull() || !previous.deepEquivalent().deprecatedNode()->isD escendantOf(node);
763 } 763 }
764 764
765 bool isLastVisiblePositionInNode(const VisiblePosition &visiblePosition, const N ode *node) 765 bool isLastVisiblePositionInNode(const VisiblePosition& visiblePosition, const C ontainerNode* node)
766 { 766 {
767 if (visiblePosition.isNull()) 767 if (visiblePosition.isNull())
768 return false; 768 return false;
769 769
770 if (!visiblePosition.deepEquivalent().containerNode()->isDescendantOf(node)) 770 if (!visiblePosition.deepEquivalent().containerNode()->isDescendantOf(node))
771 return false; 771 return false;
772 772
773 VisiblePosition next = visiblePosition.next(); 773 VisiblePosition next = visiblePosition.next();
774 return next.isNull() || !next.deepEquivalent().deprecatedNode()->isDescendan tOf(node); 774 return next.isNull() || !next.deepEquivalent().deprecatedNode()->isDescendan tOf(node);
775 } 775 }
(...skipping 12 matching lines...) Expand all
788 if (vpos) 788 if (vpos)
789 vpos->showTreeForThis(); 789 vpos->showTreeForThis();
790 } 790 }
791 791
792 void showTree(const blink::VisiblePosition& vpos) 792 void showTree(const blink::VisiblePosition& vpos)
793 { 793 {
794 vpos.showTreeForThis(); 794 vpos.showTreeForThis();
795 } 795 }
796 796
797 #endif 797 #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