| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 } | 62 } |
| 63 | 63 |
| 64 VisiblePosition VisiblePosition::createWithoutCanonicalization(const PositionWit
hAffinity& canonicalized) | 64 VisiblePosition VisiblePosition::createWithoutCanonicalization(const PositionWit
hAffinity& canonicalized) |
| 65 { | 65 { |
| 66 VisiblePosition visiblePosition; | 66 VisiblePosition visiblePosition; |
| 67 visiblePosition.m_deepPosition = canonicalized.position(); | 67 visiblePosition.m_deepPosition = canonicalized.position(); |
| 68 visiblePosition.m_affinity = canonicalized.affinity(); | 68 visiblePosition.m_affinity = canonicalized.affinity(); |
| 69 return visiblePosition; | 69 return visiblePosition; |
| 70 } | 70 } |
| 71 | 71 |
| 72 // TODO(yosin) We should move implementation of |skipToEndOfEditingBoundary()| | |
| 73 // here to avoid forward declaration. | |
| 74 static VisiblePosition skipToEndOfEditingBoundary(const VisiblePosition&, const
Position& anchor); | |
| 75 | |
| 76 // TODO(yosin) We should move |nextPositionOf()| to "VisibleUnits.cpp". | |
| 77 VisiblePosition nextPositionOf(const VisiblePosition& visiblePosition, EditingBo
undaryCrossingRule rule) | |
| 78 { | |
| 79 VisiblePosition next(nextVisuallyDistinctCandidate(visiblePosition.deepEquiv
alent()), visiblePosition.affinity()); | |
| 80 | |
| 81 switch (rule) { | |
| 82 case CanCrossEditingBoundary: | |
| 83 return next; | |
| 84 case CannotCrossEditingBoundary: | |
| 85 return honorEditingBoundaryAtOrAfter(next, visiblePosition.deepEquivalen
t()); | |
| 86 case CanSkipOverEditingBoundary: | |
| 87 return skipToEndOfEditingBoundary(next, visiblePosition.deepEquivalent()
); | |
| 88 } | |
| 89 ASSERT_NOT_REACHED(); | |
| 90 return honorEditingBoundaryAtOrAfter(next, visiblePosition.deepEquivalent())
; | |
| 91 } | |
| 92 | |
| 93 // TODO(yosin) We should move implementation of |skipToStartOfEditingBoundary()| | |
| 94 // here to avoid forward declaration. | |
| 95 static VisiblePosition skipToStartOfEditingBoundary(const VisiblePosition&, cons
t Position& anchor); | |
| 96 | |
| 97 VisiblePosition previousPositionOf(const VisiblePosition& visiblePosition, Editi
ngBoundaryCrossingRule rule) | |
| 98 { | |
| 99 Position pos = previousVisuallyDistinctCandidate(visiblePosition.deepEquival
ent()); | |
| 100 | |
| 101 // return null visible position if there is no previous visible position | |
| 102 if (pos.atStartOfTree()) | |
| 103 return VisiblePosition(); | |
| 104 | |
| 105 VisiblePosition prev = VisiblePosition(pos); | |
| 106 ASSERT(prev.deepEquivalent() != visiblePosition.deepEquivalent()); | |
| 107 | |
| 108 #if ENABLE(ASSERT) | |
| 109 // we should always be able to make the affinity |TextAffinity::Downstream|, | |
| 110 // because going previous from an |TextAffinity::Upstream| position can | |
| 111 // never yield another |TextAffinity::Upstream position| (unless line wrap | |
| 112 // length is 0!). | |
| 113 if (prev.isNotNull() && visiblePosition.affinity() == TextAffinity::Upstream
) { | |
| 114 ASSERT(inSameLine(PositionWithAffinity(prev.deepEquivalent()), PositionW
ithAffinity(prev.deepEquivalent(), TextAffinity::Upstream))); | |
| 115 } | |
| 116 #endif | |
| 117 | |
| 118 switch (rule) { | |
| 119 case CanCrossEditingBoundary: | |
| 120 return prev; | |
| 121 case CannotCrossEditingBoundary: | |
| 122 return honorEditingBoundaryAtOrBefore(prev, visiblePosition.deepEquivale
nt()); | |
| 123 case CanSkipOverEditingBoundary: | |
| 124 return skipToStartOfEditingBoundary(prev, visiblePosition.deepEquivalent
()); | |
| 125 } | |
| 126 | |
| 127 ASSERT_NOT_REACHED(); | |
| 128 return honorEditingBoundaryAtOrBefore(prev, visiblePosition.deepEquivalent()
); | |
| 129 } | |
| 130 | |
| 131 // TODO(yosin) We should move |rightVisuallyDistinctCandidate()| with | 72 // TODO(yosin) We should move |rightVisuallyDistinctCandidate()| with |
| 132 // |rightPositionOf()| to "VisibleUnits.cpp". | 73 // |rightPositionOf()| to "VisibleUnits.cpp". |
| 133 static Position leftVisuallyDistinctCandidate(const VisiblePosition& visiblePosi
tion) | 74 static Position leftVisuallyDistinctCandidate(const VisiblePosition& visiblePosi
tion) |
| 134 { | 75 { |
| 135 const Position deepPosition = visiblePosition.deepEquivalent(); | 76 const Position deepPosition = visiblePosition.deepEquivalent(); |
| 136 Position p = deepPosition; | 77 Position p = deepPosition; |
| 137 if (p.isNull()) | 78 if (p.isNull()) |
| 138 return Position(); | 79 return Position(); |
| 139 | 80 |
| 140 Position downstreamStart = mostForwardCaretPosition(p); | 81 Position downstreamStart = mostForwardCaretPosition(p); |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 | 461 |
| 521 // Return empty position if this position is non-editable, but pos is editab
le | 462 // Return empty position if this position is non-editable, but pos is editab
le |
| 522 // FIXME: Move to the next non-editable region. | 463 // FIXME: Move to the next non-editable region. |
| 523 if (!highestRoot) | 464 if (!highestRoot) |
| 524 return VisiblePosition(); | 465 return VisiblePosition(); |
| 525 | 466 |
| 526 // Return the next position after pos that is in the same editable region as
this position | 467 // Return the next position after pos that is in the same editable region as
this position |
| 527 return firstEditableVisiblePositionAfterPositionInRoot(pos.deepEquivalent(),
highestRoot); | 468 return firstEditableVisiblePositionAfterPositionInRoot(pos.deepEquivalent(),
highestRoot); |
| 528 } | 469 } |
| 529 | 470 |
| 530 // TODO(yosin) We should move implementation of |skipToStartOfEditingBoundary()| | |
| 531 // at forward declaration and re-format comments to fit 80 chars. | |
| 532 static VisiblePosition skipToStartOfEditingBoundary(const VisiblePosition& pos,
const Position& anchor) | |
| 533 { | |
| 534 if (pos.isNull()) | |
| 535 return pos; | |
| 536 | |
| 537 ContainerNode* highestRoot = highestEditableRoot(anchor); | |
| 538 ContainerNode* highestRootOfPos = highestEditableRoot(pos.deepEquivalent()); | |
| 539 | |
| 540 // Return pos itself if the two are from the very same editable region, or b
oth are non-editable. | |
| 541 if (highestRootOfPos == highestRoot) | |
| 542 return pos; | |
| 543 | |
| 544 // If this is not editable but |pos| has an editable root, skip to the start | |
| 545 if (!highestRoot && highestRootOfPos) | |
| 546 return VisiblePosition(previousVisuallyDistinctCandidate(Position(highes
tRootOfPos, PositionAnchorType::BeforeAnchor).parentAnchoredEquivalent())); | |
| 547 | |
| 548 // That must mean that |pos| is not editable. Return the last position befor
e pos that is in the same editable region as this position | |
| 549 return lastEditableVisiblePositionBeforePositionInRoot(pos.deepEquivalent(),
highestRoot); | |
| 550 } | |
| 551 | |
| 552 // TODO(yosin) We should move implementation of |skipToEndOfEditingBoundary()| | |
| 553 // at forward declaration and re-format comments to fit 80 chars. | |
| 554 static VisiblePosition skipToEndOfEditingBoundary(const VisiblePosition& pos, co
nst Position& anchor) | |
| 555 { | |
| 556 if (pos.isNull()) | |
| 557 return pos; | |
| 558 | |
| 559 ContainerNode* highestRoot = highestEditableRoot(anchor); | |
| 560 ContainerNode* highestRootOfPos = highestEditableRoot(pos.deepEquivalent()); | |
| 561 | |
| 562 // Return pos itself if the two are from the very same editable region, or b
oth are non-editable. | |
| 563 if (highestRootOfPos == highestRoot) | |
| 564 return pos; | |
| 565 | |
| 566 // If this is not editable but |pos| has an editable root, skip to the end | |
| 567 if (!highestRoot && highestRootOfPos) | |
| 568 return VisiblePosition(Position(highestRootOfPos, PositionAnchorType::Af
terAnchor).parentAnchoredEquivalent()); | |
| 569 | |
| 570 // That must mean that |pos| is not editable. Return the next position after
pos that is in the same editable region as this position | |
| 571 return firstEditableVisiblePositionAfterPositionInRoot(pos.deepEquivalent(),
highestRoot); | |
| 572 } | |
| 573 | |
| 574 template <typename PositionType> | 471 template <typename PositionType> |
| 575 static PositionType canonicalizeCandidate(const PositionType& candidate) | 472 static PositionType canonicalizeCandidate(const PositionType& candidate) |
| 576 { | 473 { |
| 577 if (candidate.isNull()) | 474 if (candidate.isNull()) |
| 578 return PositionType(); | 475 return PositionType(); |
| 579 ASSERT(isVisuallyEquivalentCandidate(candidate)); | 476 ASSERT(isVisuallyEquivalentCandidate(candidate)); |
| 580 PositionType upstream = mostBackwardCaretPosition(candidate); | 477 PositionType upstream = mostBackwardCaretPosition(candidate); |
| 581 if (isVisuallyEquivalentCandidate(upstream)) | 478 if (isVisuallyEquivalentCandidate(upstream)) |
| 582 return upstream; | 479 return upstream; |
| 583 return candidate; | 480 return candidate; |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 else | 687 else |
| 791 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n"); | 688 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n"); |
| 792 } | 689 } |
| 793 | 690 |
| 794 void showTree(const blink::VisiblePosition& vpos) | 691 void showTree(const blink::VisiblePosition& vpos) |
| 795 { | 692 { |
| 796 vpos.showTreeForThis(); | 693 vpos.showTreeForThis(); |
| 797 } | 694 } |
| 798 | 695 |
| 799 #endif | 696 #endif |
| OLD | NEW |