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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 VisiblePosition::VisiblePosition(const PositionInComposedTree& pos, TextAffinity
affinity) | 57 VisiblePosition::VisiblePosition(const PositionInComposedTree& pos, TextAffinity
affinity) |
58 { | 58 { |
59 init(pos, affinity); | 59 init(pos, affinity); |
60 } | 60 } |
61 | 61 |
62 VisiblePosition::VisiblePosition(const PositionWithAffinity& positionWithAffinit
y) | 62 VisiblePosition::VisiblePosition(const PositionWithAffinity& positionWithAffinit
y) |
63 { | 63 { |
64 init(positionWithAffinity.position(), positionWithAffinity.affinity()); | 64 init(positionWithAffinity.position(), positionWithAffinity.affinity()); |
65 } | 65 } |
66 | 66 |
| 67 // TODO(yosin) We should move implementation of |skipToEndOfEditingBoundary()| |
| 68 // here to avoid forward declaration. |
| 69 static VisiblePosition skipToEndOfEditingBoundary(const VisiblePosition&, const
Position& anchor); |
| 70 |
67 // TODO(yosin) We should move |nextPositionOf()| to "VisibleUnits.cpp". | 71 // TODO(yosin) We should move |nextPositionOf()| to "VisibleUnits.cpp". |
68 VisiblePosition nextPositionOf(const VisiblePosition& visiblePosition, EditingBo
undaryCrossingRule rule) | 72 VisiblePosition nextPositionOf(const VisiblePosition& visiblePosition, EditingBo
undaryCrossingRule rule) |
69 { | 73 { |
70 VisiblePosition next(nextVisuallyDistinctCandidate(visiblePosition.deepEquiv
alent()), visiblePosition.affinity()); | 74 VisiblePosition next(nextVisuallyDistinctCandidate(visiblePosition.deepEquiv
alent()), visiblePosition.affinity()); |
71 | 75 |
72 switch (rule) { | 76 switch (rule) { |
73 case CanCrossEditingBoundary: | 77 case CanCrossEditingBoundary: |
74 return next; | 78 return next; |
75 case CannotCrossEditingBoundary: | 79 case CannotCrossEditingBoundary: |
76 return visiblePosition.honorEditingBoundaryAtOrAfter(next); | 80 return visiblePosition.honorEditingBoundaryAtOrAfter(next); |
77 case CanSkipOverEditingBoundary: | 81 case CanSkipOverEditingBoundary: |
78 return visiblePosition.skipToEndOfEditingBoundary(next); | 82 return skipToEndOfEditingBoundary(next, visiblePosition.deepEquivalent()
); |
79 } | 83 } |
80 ASSERT_NOT_REACHED(); | 84 ASSERT_NOT_REACHED(); |
81 return visiblePosition.honorEditingBoundaryAtOrAfter(next); | 85 return visiblePosition.honorEditingBoundaryAtOrAfter(next); |
82 } | 86 } |
83 | 87 |
| 88 // TODO(yosin) We should move implementation of |skipToStartOfEditingBoundary()| |
| 89 // here to avoid forward declaration. |
| 90 static VisiblePosition skipToStartOfEditingBoundary(const VisiblePosition&, cons
t Position& anchor); |
| 91 |
84 VisiblePosition previousPositionOf(const VisiblePosition& visiblePosition, Editi
ngBoundaryCrossingRule rule) | 92 VisiblePosition previousPositionOf(const VisiblePosition& visiblePosition, Editi
ngBoundaryCrossingRule rule) |
85 { | 93 { |
86 Position pos = previousVisuallyDistinctCandidate(visiblePosition.deepEquival
ent()); | 94 Position pos = previousVisuallyDistinctCandidate(visiblePosition.deepEquival
ent()); |
87 | 95 |
88 // return null visible position if there is no previous visible position | 96 // return null visible position if there is no previous visible position |
89 if (pos.atStartOfTree()) | 97 if (pos.atStartOfTree()) |
90 return VisiblePosition(); | 98 return VisiblePosition(); |
91 | 99 |
92 VisiblePosition prev = VisiblePosition(pos); | 100 VisiblePosition prev = VisiblePosition(pos); |
93 ASSERT(prev.deepEquivalent() != visiblePosition.deepEquivalent()); | 101 ASSERT(prev.deepEquivalent() != visiblePosition.deepEquivalent()); |
94 | 102 |
95 #if ENABLE(ASSERT) | 103 #if ENABLE(ASSERT) |
96 // we should always be able to make the affinity |TextAffinity::Downstream|, | 104 // we should always be able to make the affinity |TextAffinity::Downstream|, |
97 // because going previous from an |TextAffinity::Upstream| position can | 105 // because going previous from an |TextAffinity::Upstream| position can |
98 // never yield another |TextAffinity::Upstream position| (unless line wrap | 106 // never yield another |TextAffinity::Upstream position| (unless line wrap |
99 // length is 0!). | 107 // length is 0!). |
100 if (prev.isNotNull() && visiblePosition.affinity() == TextAffinity::Upstream
) { | 108 if (prev.isNotNull() && visiblePosition.affinity() == TextAffinity::Upstream
) { |
101 ASSERT(inSameLine(PositionWithAffinity(prev.deepEquivalent()), PositionW
ithAffinity(prev.deepEquivalent(), TextAffinity::Upstream))); | 109 ASSERT(inSameLine(PositionWithAffinity(prev.deepEquivalent()), PositionW
ithAffinity(prev.deepEquivalent(), TextAffinity::Upstream))); |
102 } | 110 } |
103 #endif | 111 #endif |
104 | 112 |
105 switch (rule) { | 113 switch (rule) { |
106 case CanCrossEditingBoundary: | 114 case CanCrossEditingBoundary: |
107 return prev; | 115 return prev; |
108 case CannotCrossEditingBoundary: | 116 case CannotCrossEditingBoundary: |
109 return visiblePosition.honorEditingBoundaryAtOrBefore(prev); | 117 return visiblePosition.honorEditingBoundaryAtOrBefore(prev); |
110 case CanSkipOverEditingBoundary: | 118 case CanSkipOverEditingBoundary: |
111 return visiblePosition.skipToStartOfEditingBoundary(prev); | 119 return skipToStartOfEditingBoundary(prev, visiblePosition.deepEquivalent
()); |
112 } | 120 } |
113 | 121 |
114 ASSERT_NOT_REACHED(); | 122 ASSERT_NOT_REACHED(); |
115 return visiblePosition.honorEditingBoundaryAtOrBefore(prev); | 123 return visiblePosition.honorEditingBoundaryAtOrBefore(prev); |
116 } | 124 } |
117 | 125 |
118 // TODO(yosin) We should move |rightVisuallyDistinctCandidate()| with | 126 // TODO(yosin) We should move |rightVisuallyDistinctCandidate()| with |
119 // |rightPositionOf()| to "VisibleUnits.cpp". | 127 // |rightPositionOf()| to "VisibleUnits.cpp". |
120 static Position leftVisuallyDistinctCandidate(const VisiblePosition& visiblePosi
tion) | 128 static Position leftVisuallyDistinctCandidate(const VisiblePosition& visiblePosi
tion) |
121 { | 129 { |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 | 515 |
508 // Return empty position if this position is non-editable, but pos is editab
le | 516 // Return empty position if this position is non-editable, but pos is editab
le |
509 // FIXME: Move to the next non-editable region. | 517 // FIXME: Move to the next non-editable region. |
510 if (!highestRoot) | 518 if (!highestRoot) |
511 return VisiblePosition(); | 519 return VisiblePosition(); |
512 | 520 |
513 // Return the next position after pos that is in the same editable region as
this position | 521 // Return the next position after pos that is in the same editable region as
this position |
514 return firstEditableVisiblePositionAfterPositionInRoot(pos.deepEquivalent(),
highestRoot); | 522 return firstEditableVisiblePositionAfterPositionInRoot(pos.deepEquivalent(),
highestRoot); |
515 } | 523 } |
516 | 524 |
517 VisiblePosition VisiblePosition::skipToStartOfEditingBoundary(const VisiblePosit
ion &pos) const | 525 // TODO(yosin) We should move implementation of |skipToStartOfEditingBoundary()| |
| 526 // at forward declaration and re-format comments to fit 80 chars. |
| 527 static VisiblePosition skipToStartOfEditingBoundary(const VisiblePosition& pos,
const Position& anchor) |
518 { | 528 { |
519 if (pos.isNull()) | 529 if (pos.isNull()) |
520 return pos; | 530 return pos; |
521 | 531 |
522 ContainerNode* highestRoot = highestEditableRoot(deepEquivalent()); | 532 ContainerNode* highestRoot = highestEditableRoot(anchor); |
523 ContainerNode* highestRootOfPos = highestEditableRoot(pos.deepEquivalent()); | 533 ContainerNode* highestRootOfPos = highestEditableRoot(pos.deepEquivalent()); |
524 | 534 |
525 // Return pos itself if the two are from the very same editable region, or b
oth are non-editable. | 535 // Return pos itself if the two are from the very same editable region, or b
oth are non-editable. |
526 if (highestRootOfPos == highestRoot) | 536 if (highestRootOfPos == highestRoot) |
527 return pos; | 537 return pos; |
528 | 538 |
529 // If this is not editable but |pos| has an editable root, skip to the start | 539 // If this is not editable but |pos| has an editable root, skip to the start |
530 if (!highestRoot && highestRootOfPos) | 540 if (!highestRoot && highestRootOfPos) |
531 return VisiblePosition(previousVisuallyDistinctCandidate(Position(highes
tRootOfPos, PositionAnchorType::BeforeAnchor).parentAnchoredEquivalent())); | 541 return VisiblePosition(previousVisuallyDistinctCandidate(Position(highes
tRootOfPos, PositionAnchorType::BeforeAnchor).parentAnchoredEquivalent())); |
532 | 542 |
533 // 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 | 543 // 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 |
534 return lastEditableVisiblePositionBeforePositionInRoot(pos.deepEquivalent(),
highestRoot); | 544 return lastEditableVisiblePositionBeforePositionInRoot(pos.deepEquivalent(),
highestRoot); |
535 } | 545 } |
536 | 546 |
537 VisiblePosition VisiblePosition::skipToEndOfEditingBoundary(const VisiblePositio
n &pos) const | 547 // TODO(yosin) We should move implementation of |skipToEndOfEditingBoundary()| |
| 548 // at forward declaration and re-format comments to fit 80 chars. |
| 549 static VisiblePosition skipToEndOfEditingBoundary(const VisiblePosition& pos, co
nst Position& anchor) |
538 { | 550 { |
539 if (pos.isNull()) | 551 if (pos.isNull()) |
540 return pos; | 552 return pos; |
541 | 553 |
542 ContainerNode* highestRoot = highestEditableRoot(deepEquivalent()); | 554 ContainerNode* highestRoot = highestEditableRoot(anchor); |
543 ContainerNode* highestRootOfPos = highestEditableRoot(pos.deepEquivalent()); | 555 ContainerNode* highestRootOfPos = highestEditableRoot(pos.deepEquivalent()); |
544 | 556 |
545 // Return pos itself if the two are from the very same editable region, or b
oth are non-editable. | 557 // Return pos itself if the two are from the very same editable region, or b
oth are non-editable. |
546 if (highestRootOfPos == highestRoot) | 558 if (highestRootOfPos == highestRoot) |
547 return pos; | 559 return pos; |
548 | 560 |
549 // If this is not editable but |pos| has an editable root, skip to the end | 561 // If this is not editable but |pos| has an editable root, skip to the end |
550 if (!highestRoot && highestRootOfPos) | 562 if (!highestRoot && highestRootOfPos) |
551 return VisiblePosition(Position(highestRootOfPos, PositionAnchorType::Af
terAnchor).parentAnchoredEquivalent()); | 563 return VisiblePosition(Position(highestRootOfPos, PositionAnchorType::Af
terAnchor).parentAnchoredEquivalent()); |
552 | 564 |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 else | 801 else |
790 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n"); | 802 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n"); |
791 } | 803 } |
792 | 804 |
793 void showTree(const blink::VisiblePosition& vpos) | 805 void showTree(const blink::VisiblePosition& vpos) |
794 { | 806 { |
795 vpos.showTreeForThis(); | 807 vpos.showTreeForThis(); |
796 } | 808 } |
797 | 809 |
798 #endif | 810 #endif |
OLD | NEW |