| OLD | NEW |
| 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 VisiblePosition::VisiblePosition(const Position &pos, EAffinity affinity) | 51 VisiblePosition::VisiblePosition(const Position &pos, EAffinity affinity) |
| 52 { | 52 { |
| 53 init(pos, affinity); | 53 init(pos, affinity); |
| 54 } | 54 } |
| 55 | 55 |
| 56 VisiblePosition::VisiblePosition(const PositionWithAffinity& positionWithAffinit
y) | 56 VisiblePosition::VisiblePosition(const PositionWithAffinity& positionWithAffinit
y) |
| 57 { | 57 { |
| 58 init(positionWithAffinity.position(), positionWithAffinity.affinity()); | 58 init(positionWithAffinity.position(), positionWithAffinity.affinity()); |
| 59 } | 59 } |
| 60 | 60 |
| 61 static Position canonicalPosition(const Position& passedPosition); | |
| 62 | |
| 63 void VisiblePosition::init(const Position& position, EAffinity affinity) | |
| 64 { | |
| 65 m_affinity = affinity; | |
| 66 | |
| 67 m_deepPosition = canonicalPosition(position); | |
| 68 | |
| 69 // When not at a line wrap, make sure to end up with DOWNSTREAM affinity. | |
| 70 if (m_affinity == UPSTREAM && (isNull() || inSameLine(VisiblePosition(positi
on, DOWNSTREAM), *this))) | |
| 71 m_affinity = DOWNSTREAM; | |
| 72 } | |
| 73 | |
| 74 VisiblePosition VisiblePosition::next(EditingBoundaryCrossingRule rule) const | 61 VisiblePosition VisiblePosition::next(EditingBoundaryCrossingRule rule) const |
| 75 { | 62 { |
| 76 VisiblePosition next(nextVisuallyDistinctCandidate(m_deepPosition), m_affini
ty); | 63 VisiblePosition next(nextVisuallyDistinctCandidate(m_deepPosition), m_affini
ty); |
| 77 | 64 |
| 78 switch (rule) { | 65 switch (rule) { |
| 79 case CanCrossEditingBoundary: | 66 case CanCrossEditingBoundary: |
| 80 return next; | 67 return next; |
| 81 case CannotCrossEditingBoundary: | 68 case CannotCrossEditingBoundary: |
| 82 return honorEditingBoundaryAtOrAfter(next); | 69 return honorEditingBoundaryAtOrAfter(next); |
| 83 case CanSkipOverEditingBoundary: | 70 case CanSkipOverEditingBoundary: |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 // The new position should be in the same block flow element. Favor that. | 607 // The new position should be in the same block flow element. Favor that. |
| 621 Element* originalBlock = node ? enclosingBlockFlowElement(*node) : 0; | 608 Element* originalBlock = node ? enclosingBlockFlowElement(*node) : 0; |
| 622 bool nextIsOutsideOriginalBlock = !nextNode->isDescendantOf(originalBlock) &
& nextNode != originalBlock; | 609 bool nextIsOutsideOriginalBlock = !nextNode->isDescendantOf(originalBlock) &
& nextNode != originalBlock; |
| 623 bool prevIsOutsideOriginalBlock = !prevNode->isDescendantOf(originalBlock) &
& prevNode != originalBlock; | 610 bool prevIsOutsideOriginalBlock = !prevNode->isDescendantOf(originalBlock) &
& prevNode != originalBlock; |
| 624 if (nextIsOutsideOriginalBlock && !prevIsOutsideOriginalBlock) | 611 if (nextIsOutsideOriginalBlock && !prevIsOutsideOriginalBlock) |
| 625 return prev; | 612 return prev; |
| 626 | 613 |
| 627 return next; | 614 return next; |
| 628 } | 615 } |
| 629 | 616 |
| 617 void VisiblePosition::init(const Position& position, EAffinity affinity) |
| 618 { |
| 619 m_affinity = affinity; |
| 620 |
| 621 m_deepPosition = canonicalPosition(position); |
| 622 |
| 623 // When not at a line wrap, make sure to end up with DOWNSTREAM affinity. |
| 624 if (m_affinity == UPSTREAM && (isNull() || inSameLine(VisiblePosition(positi
on, DOWNSTREAM), *this))) |
| 625 m_affinity = DOWNSTREAM; |
| 626 } |
| 627 |
| 630 UChar32 VisiblePosition::characterAfter() const | 628 UChar32 VisiblePosition::characterAfter() const |
| 631 { | 629 { |
| 632 // We canonicalize to the first of two equivalent candidates, but the second
of the two candidates | 630 // We canonicalize to the first of two equivalent candidates, but the second
of the two candidates |
| 633 // is the one that will be inside the text node containing the character aft
er this visible position. | 631 // is the one that will be inside the text node containing the character aft
er this visible position. |
| 634 Position pos = m_deepPosition.downstream(); | 632 Position pos = m_deepPosition.downstream(); |
| 635 if (!pos.containerNode() || !pos.containerNode()->isTextNode()) | 633 if (!pos.containerNode() || !pos.containerNode()->isTextNode()) |
| 636 return 0; | 634 return 0; |
| 637 switch (pos.anchorType()) { | 635 switch (pos.anchorType()) { |
| 638 case Position::PositionIsAfterChildren: | 636 case Position::PositionIsAfterChildren: |
| 639 case Position::PositionIsAfterAnchor: | 637 case Position::PositionIsAfterAnchor: |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 else | 792 else |
| 795 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n"); | 793 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n"); |
| 796 } | 794 } |
| 797 | 795 |
| 798 void showTree(const blink::VisiblePosition& vpos) | 796 void showTree(const blink::VisiblePosition& vpos) |
| 799 { | 797 { |
| 800 vpos.showTreeForThis(); | 798 vpos.showTreeForThis(); |
| 801 } | 799 } |
| 802 | 800 |
| 803 #endif | 801 #endif |
| OLD | NEW |