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 m_deepPosition = canonicalPosition(position); | 63 m_deepPosition = canonicalPosition(position); |
64 | 64 |
65 // When not at a line wrap, make sure to end up with DOWNSTREAM affinity. | 65 // When not at a line wrap, make sure to end up with DOWNSTREAM affinity. |
66 if (m_affinity == UPSTREAM && (isNull() || inSameLine(VisiblePosition(positi on, DOWNSTREAM), *this))) | 66 if (m_affinity == UPSTREAM && (isNull() || inSameLine(VisiblePosition(positi on, DOWNSTREAM), *this))) |
67 m_affinity = DOWNSTREAM; | 67 m_affinity = DOWNSTREAM; |
68 } | 68 } |
69 | 69 |
70 VisiblePosition VisiblePosition::next(EditingBoundaryCrossingRule rule) const | 70 VisiblePosition VisiblePosition::next(EditingBoundaryCrossingRule rule) const |
71 { | 71 { |
72 // FIXME: Support CanSkipEditingBoundary | |
73 ASSERT(rule == CanCrossEditingBoundary || rule == CannotCrossEditingBoundary ); | |
74 VisiblePosition next(nextVisuallyDistinctCandidate(m_deepPosition), m_affini ty); | 72 VisiblePosition next(nextVisuallyDistinctCandidate(m_deepPosition), m_affini ty); |
75 | 73 |
76 if (rule == CanCrossEditingBoundary) | 74 switch (rule) { |
75 case CanCrossEditingBoundary: | |
77 return next; | 76 return next; |
78 | 77 case CannotCrossEditingBoundary: |
79 return honorEditingBoundaryAtOrAfter(next); | 78 return honorEditingBoundaryAtOrAfter(next); |
79 case CanSkipOverEditingBoundary: | |
80 return skipToEndOfEditingBoundary(next); | |
81 } | |
80 } | 82 } |
yosin_UTC9
2013/09/06 01:31:15
Please fix compilation error, visibleposition.cpp(
| |
81 | 83 |
82 VisiblePosition VisiblePosition::previous(EditingBoundaryCrossingRule rule) cons t | 84 VisiblePosition VisiblePosition::previous(EditingBoundaryCrossingRule rule) cons t |
83 { | 85 { |
84 // FIXME: Support CanSkipEditingBoundary | |
85 ASSERT(rule == CanCrossEditingBoundary || rule == CannotCrossEditingBoundary ); | |
86 // find first previous DOM position that is visible | |
87 Position pos = previousVisuallyDistinctCandidate(m_deepPosition); | 86 Position pos = previousVisuallyDistinctCandidate(m_deepPosition); |
88 | 87 |
89 // return null visible position if there is no previous visible position | 88 // return null visible position if there is no previous visible position |
90 if (pos.atStartOfTree()) | 89 if (pos.atStartOfTree()) |
91 return VisiblePosition(); | 90 return VisiblePosition(); |
92 | 91 |
93 VisiblePosition prev = VisiblePosition(pos, DOWNSTREAM); | 92 VisiblePosition prev = VisiblePosition(pos, DOWNSTREAM); |
94 ASSERT(prev != *this); | 93 ASSERT(prev != *this); |
95 | 94 |
96 #ifndef NDEBUG | 95 #ifndef NDEBUG |
97 // we should always be able to make the affinity DOWNSTREAM, because going p revious from an | 96 // we should always be able to make the affinity DOWNSTREAM, because going p revious from an |
98 // UPSTREAM position can never yield another UPSTREAM position (unless line wrap length is 0!). | 97 // UPSTREAM position can never yield another UPSTREAM position (unless line wrap length is 0!). |
99 if (prev.isNotNull() && m_affinity == UPSTREAM) { | 98 if (prev.isNotNull() && m_affinity == UPSTREAM) { |
100 VisiblePosition temp = prev; | 99 VisiblePosition temp = prev; |
101 temp.setAffinity(UPSTREAM); | 100 temp.setAffinity(UPSTREAM); |
102 ASSERT(inSameLine(temp, prev)); | 101 ASSERT(inSameLine(temp, prev)); |
103 } | 102 } |
104 #endif | 103 #endif |
105 | 104 |
106 if (rule == CanCrossEditingBoundary) | 105 switch (rule) { |
106 case CanCrossEditingBoundary: | |
107 return prev; | 107 return prev; |
108 | 108 case CannotCrossEditingBoundary: |
109 return honorEditingBoundaryAtOrBefore(prev); | 109 return honorEditingBoundaryAtOrBefore(prev); |
110 case CanSkipOverEditingBoundary: | |
111 return skipToStartOfEditingBoundary(prev); | |
112 } | |
yosin_UTC9
2013/09/06 01:31:15
Please fix compilation error: visibleposition.cpp(
dmazzoni
2013/09/06 07:29:26
Done, added assert_not_reached and same below.
| |
110 } | 113 } |
111 | 114 |
112 Position VisiblePosition::leftVisuallyDistinctCandidate() const | 115 Position VisiblePosition::leftVisuallyDistinctCandidate() const |
113 { | 116 { |
114 Position p = m_deepPosition; | 117 Position p = m_deepPosition; |
115 if (p.isNull()) | 118 if (p.isNull()) |
116 return Position(); | 119 return Position(); |
117 | 120 |
118 Position downstreamStart = p.downstream(); | 121 Position downstreamStart = p.downstream(); |
119 TextDirection primaryDirection = p.primaryDirection(); | 122 TextDirection primaryDirection = p.primaryDirection(); |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
487 | 490 |
488 // Return empty position if this position is non-editable, but pos is editab le | 491 // Return empty position if this position is non-editable, but pos is editab le |
489 // FIXME: Move to the next non-editable region. | 492 // FIXME: Move to the next non-editable region. |
490 if (!highestRoot) | 493 if (!highestRoot) |
491 return VisiblePosition(); | 494 return VisiblePosition(); |
492 | 495 |
493 // Return the next position after pos that is in the same editable region as this position | 496 // Return the next position after pos that is in the same editable region as this position |
494 return firstEditablePositionAfterPositionInRoot(pos.deepEquivalent(), highes tRoot); | 497 return firstEditablePositionAfterPositionInRoot(pos.deepEquivalent(), highes tRoot); |
495 } | 498 } |
496 | 499 |
500 VisiblePosition VisiblePosition::skipToStartOfEditingBoundary(const VisiblePosit ion &pos) const | |
501 { | |
502 if (pos.isNull()) | |
503 return pos; | |
504 | |
505 Node* highestRoot = highestEditableRoot(deepEquivalent()); | |
506 Node* highestRootOfPos = highestEditableRoot(pos.deepEquivalent()); | |
507 | |
508 // Return pos itself if the two are from the very same editable region, or b oth are non-editable. | |
509 if (highestRootOfPos == highestRoot) | |
510 return pos; | |
511 | |
512 // If |pos| has an editable root, skip to the start | |
513 if (highestRootOfPos) | |
514 return previousVisuallyDistinctCandidate(Position(highestRootOfPos, Posi tion::PositionIsBeforeAnchor).parentAnchoredEquivalent()); | |
515 | |
516 // 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 | |
517 return lastEditablePositionBeforePositionInRoot(pos.deepEquivalent(), highes tRoot); | |
518 } | |
519 | |
520 VisiblePosition VisiblePosition::skipToEndOfEditingBoundary(const VisiblePositio n &pos) const | |
521 { | |
522 if (pos.isNull()) | |
523 return pos; | |
524 | |
525 Node* highestRoot = highestEditableRoot(deepEquivalent()); | |
526 Node* highestRootOfPos = highestEditableRoot(pos.deepEquivalent()); | |
527 | |
528 // Return pos itself if the two are from the very same editable region, or b oth are non-editable. | |
529 if (highestRootOfPos == highestRoot) | |
530 return pos; | |
531 | |
532 // If |pos| has an editable root, skip to the end | |
533 if (highestRootOfPos) | |
534 return Position(highestRootOfPos, Position::PositionIsAfterAnchor).paren tAnchoredEquivalent(); | |
535 | |
536 // That must mean that |pos| is not editable. Return the next position after pos that is in the same editable region as this position | |
537 return firstEditablePositionAfterPositionInRoot(pos.deepEquivalent(), highes tRoot); | |
538 } | |
539 | |
497 static Position canonicalizeCandidate(const Position& candidate) | 540 static Position canonicalizeCandidate(const Position& candidate) |
498 { | 541 { |
499 if (candidate.isNull()) | 542 if (candidate.isNull()) |
500 return Position(); | 543 return Position(); |
501 ASSERT(candidate.isCandidate()); | 544 ASSERT(candidate.isCandidate()); |
502 Position upstream = candidate.upstream(); | 545 Position upstream = candidate.upstream(); |
503 if (upstream.isCandidate()) | 546 if (upstream.isCandidate()) |
504 return upstream; | 547 return upstream; |
505 return candidate; | 548 return candidate; |
506 } | 549 } |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
754 if (vpos) | 797 if (vpos) |
755 vpos->showTreeForThis(); | 798 vpos->showTreeForThis(); |
756 } | 799 } |
757 | 800 |
758 void showTree(const WebCore::VisiblePosition& vpos) | 801 void showTree(const WebCore::VisiblePosition& vpos) |
759 { | 802 { |
760 vpos.showTreeForThis(); | 803 vpos.showTreeForThis(); |
761 } | 804 } |
762 | 805 |
763 #endif | 806 #endif |
OLD | NEW |