| 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 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 | 432 |
| 433 VisiblePosition right = VisiblePosition(pos, DOWNSTREAM); | 433 VisiblePosition right = VisiblePosition(pos, DOWNSTREAM); |
| 434 ASSERT(right != *this); | 434 ASSERT(right != *this); |
| 435 | 435 |
| 436 if (!stayInEditableContent) | 436 if (!stayInEditableContent) |
| 437 return right; | 437 return right; |
| 438 | 438 |
| 439 return directionOfEnclosingBlock(right.deepEquivalent()) == LTR ? honorEditi
ngBoundaryAtOrAfter(right) : honorEditingBoundaryAtOrBefore(right); | 439 return directionOfEnclosingBlock(right.deepEquivalent()) == LTR ? honorEditi
ngBoundaryAtOrAfter(right) : honorEditingBoundaryAtOrBefore(right); |
| 440 } | 440 } |
| 441 | 441 |
| 442 static VisiblePosition honorEditingBoundaryAtOrBeforeOf(const VisiblePosition& p
os, const Position& anchor) | 442 PositionWithAffinity honorEditingBoundaryAtOrBeforeOf(const PositionWithAffinity
& pos, const Position& anchor) |
| 443 { | 443 { |
| 444 if (pos.isNull()) | 444 if (pos.isNull()) |
| 445 return pos; | 445 return pos; |
| 446 | 446 |
| 447 ContainerNode* highestRoot = highestEditableRoot(anchor); | 447 ContainerNode* highestRoot = highestEditableRoot(anchor); |
| 448 | 448 |
| 449 // Return empty position if pos is not somewhere inside the editable region
containing this position | 449 // Return empty position if pos is not somewhere inside the editable region
containing this position |
| 450 if (highestRoot && !pos.deepEquivalent().deprecatedNode()->isDescendantOf(hi
ghestRoot)) | 450 if (highestRoot && !pos.position().deprecatedNode()->isDescendantOf(highestR
oot)) |
| 451 return VisiblePosition(); | 451 return PositionWithAffinity(); |
| 452 | 452 |
| 453 // Return pos itself if the two are from the very same editable region, or b
oth are non-editable | 453 // Return pos itself if the two are from the very same editable region, or b
oth are non-editable |
| 454 // FIXME: In the non-editable case, just because the new position is non-edi
table doesn't mean movement | 454 // FIXME: In the non-editable case, just because the new position is non-edi
table doesn't mean movement |
| 455 // to it is allowed. VisibleSelection::adjustForEditableContent has this pr
oblem too. | 455 // to it is allowed. VisibleSelection::adjustForEditableContent has this pr
oblem too. |
| 456 if (highestEditableRoot(pos.deepEquivalent()) == highestRoot) | 456 if (highestEditableRoot(pos.position()) == highestRoot) |
| 457 return pos; | 457 return pos; |
| 458 | 458 |
| 459 // Return empty position if this position is non-editable, but pos is editab
le | 459 // Return empty position if this position is non-editable, but pos is editab
le |
| 460 // FIXME: Move to the previous non-editable region. | 460 // FIXME: Move to the previous non-editable region. |
| 461 if (!highestRoot) | 461 if (!highestRoot) |
| 462 return VisiblePosition(); | 462 return PositionWithAffinity(); |
| 463 | 463 |
| 464 // Return the last position before pos that is in the same editable region a
s this position | 464 // Return the last position before pos that is in the same editable region a
s this position |
| 465 return lastEditableVisiblePositionBeforePositionInRoot(pos.deepEquivalent(),
highestRoot); | 465 return lastEditablePositionBeforePositionInRoot(pos.position(), highestRoot)
; |
| 466 } | 466 } |
| 467 | 467 |
| 468 VisiblePosition VisiblePosition::honorEditingBoundaryAtOrBefore(const VisiblePos
ition &pos) const | 468 VisiblePosition VisiblePosition::honorEditingBoundaryAtOrBefore(const VisiblePos
ition &pos) const |
| 469 { | 469 { |
| 470 return honorEditingBoundaryAtOrBeforeOf(pos, deepEquivalent()); | 470 return VisiblePosition(honorEditingBoundaryAtOrBeforeOf(PositionWithAffinity
(pos.deepEquivalent(), pos.affinity()), deepEquivalent())); |
| 471 } | 471 } |
| 472 | 472 |
| 473 VisiblePosition VisiblePosition::honorEditingBoundaryAtOrAfter(const VisiblePosi
tion &pos) const | 473 VisiblePosition VisiblePosition::honorEditingBoundaryAtOrAfter(const VisiblePosi
tion &pos) const |
| 474 { | 474 { |
| 475 if (pos.isNull()) | 475 if (pos.isNull()) |
| 476 return pos; | 476 return pos; |
| 477 | 477 |
| 478 ContainerNode* highestRoot = highestEditableRoot(deepEquivalent()); | 478 ContainerNode* highestRoot = highestEditableRoot(deepEquivalent()); |
| 479 | 479 |
| 480 // Return empty position if pos is not somewhere inside the editable region
containing this position | 480 // Return empty position if pos is not somewhere inside the editable region
containing this position |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 // The new position should be in the same block flow element. Favor that. | 614 // The new position should be in the same block flow element. Favor that. |
| 615 Element* originalBlock = node ? enclosingBlockFlowElement(*node) : 0; | 615 Element* originalBlock = node ? enclosingBlockFlowElement(*node) : 0; |
| 616 bool nextIsOutsideOriginalBlock = !nextNode->isDescendantOf(originalBlock) &
& nextNode != originalBlock; | 616 bool nextIsOutsideOriginalBlock = !nextNode->isDescendantOf(originalBlock) &
& nextNode != originalBlock; |
| 617 bool prevIsOutsideOriginalBlock = !prevNode->isDescendantOf(originalBlock) &
& prevNode != originalBlock; | 617 bool prevIsOutsideOriginalBlock = !prevNode->isDescendantOf(originalBlock) &
& prevNode != originalBlock; |
| 618 if (nextIsOutsideOriginalBlock && !prevIsOutsideOriginalBlock) | 618 if (nextIsOutsideOriginalBlock && !prevIsOutsideOriginalBlock) |
| 619 return prev; | 619 return prev; |
| 620 | 620 |
| 621 return next; | 621 return next; |
| 622 } | 622 } |
| 623 | 623 |
| 624 Position canonicalPositionOf(const Position& position) |
| 625 { |
| 626 return canonicalPosition(position); |
| 627 } |
| 628 |
| 624 void VisiblePosition::init(const Position& position, EAffinity affinity) | 629 void VisiblePosition::init(const Position& position, EAffinity affinity) |
| 625 { | 630 { |
| 626 m_affinity = affinity; | 631 m_affinity = affinity; |
| 627 | 632 |
| 628 m_deepPosition = canonicalPosition(position); | 633 m_deepPosition = canonicalPosition(position); |
| 629 | 634 |
| 635 if (m_affinity != UPSTREAM) |
| 636 return; |
| 637 |
| 638 if (isNull()) { |
| 639 m_affinity = DOWNSTREAM; |
| 640 return; |
| 641 } |
| 642 |
| 630 // When not at a line wrap, make sure to end up with DOWNSTREAM affinity. | 643 // When not at a line wrap, make sure to end up with DOWNSTREAM affinity. |
| 631 if (m_affinity == UPSTREAM && (isNull() || inSameLine(VisiblePosition(positi
on, DOWNSTREAM), *this))) | 644 if (!inSameLine(PositionWithAffinity(m_deepPosition, DOWNSTREAM), PositionWi
thAffinity(m_deepPosition, UPSTREAM))) |
| 632 m_affinity = DOWNSTREAM; | 645 return; |
| 646 m_affinity = DOWNSTREAM; |
| 633 } | 647 } |
| 634 | 648 |
| 635 UChar32 VisiblePosition::characterAfter() const | 649 UChar32 VisiblePosition::characterAfter() const |
| 636 { | 650 { |
| 637 // We canonicalize to the first of two equivalent candidates, but the second
of the two candidates | 651 // We canonicalize to the first of two equivalent candidates, but the second
of the two candidates |
| 638 // is the one that will be inside the text node containing the character aft
er this visible position. | 652 // is the one that will be inside the text node containing the character aft
er this visible position. |
| 639 Position pos = m_deepPosition.downstream(); | 653 Position pos = m_deepPosition.downstream(); |
| 640 if (!pos.containerNode() || !pos.containerNode()->isTextNode()) | 654 if (!pos.containerNode() || !pos.containerNode()->isTextNode()) |
| 641 return 0; | 655 return 0; |
| 642 switch (pos.anchorType()) { | 656 switch (pos.anchorType()) { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 else | 813 else |
| 800 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n"); | 814 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n"); |
| 801 } | 815 } |
| 802 | 816 |
| 803 void showTree(const blink::VisiblePosition& vpos) | 817 void showTree(const blink::VisiblePosition& vpos) |
| 804 { | 818 { |
| 805 vpos.showTreeForThis(); | 819 vpos.showTreeForThis(); |
| 806 } | 820 } |
| 807 | 821 |
| 808 #endif | 822 #endif |
| OLD | NEW |