| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 return next; | 73 return next; |
| 74 case CannotCrossEditingBoundary: | 74 case CannotCrossEditingBoundary: |
| 75 return honorEditingBoundaryAtOrAfter(next); | 75 return honorEditingBoundaryAtOrAfter(next); |
| 76 case CanSkipOverEditingBoundary: | 76 case CanSkipOverEditingBoundary: |
| 77 return skipToEndOfEditingBoundary(next); | 77 return skipToEndOfEditingBoundary(next); |
| 78 } | 78 } |
| 79 ASSERT_NOT_REACHED(); | 79 ASSERT_NOT_REACHED(); |
| 80 return honorEditingBoundaryAtOrAfter(next); | 80 return honorEditingBoundaryAtOrAfter(next); |
| 81 } | 81 } |
| 82 | 82 |
| 83 VisiblePosition VisiblePosition::previous(EditingBoundaryCrossingRule rule) cons
t | 83 VisiblePosition previousPositionOf(const VisiblePosition& visiblePosition, Editi
ngBoundaryCrossingRule rule) |
| 84 { | 84 { |
| 85 Position pos = previousVisuallyDistinctCandidate(m_deepPosition); | 85 Position pos = previousVisuallyDistinctCandidate(visiblePosition.deepEquival
ent()); |
| 86 | 86 |
| 87 // return null visible position if there is no previous visible position | 87 // return null visible position if there is no previous visible position |
| 88 if (pos.atStartOfTree()) | 88 if (pos.atStartOfTree()) |
| 89 return VisiblePosition(); | 89 return VisiblePosition(); |
| 90 | 90 |
| 91 VisiblePosition prev = VisiblePosition(pos); | 91 VisiblePosition prev = VisiblePosition(pos); |
| 92 ASSERT(prev.deepEquivalent() != m_deepPosition); | 92 ASSERT(prev.deepEquivalent() != visiblePosition.deepEquivalent()); |
| 93 | 93 |
| 94 #if ENABLE(ASSERT) | 94 #if ENABLE(ASSERT) |
| 95 // we should always be able to make the affinity |TextAffinity::Downstream|, | 95 // we should always be able to make the affinity |TextAffinity::Downstream|, |
| 96 // because going previous from an |TextAffinity::Upstream| position can | 96 // because going previous from an |TextAffinity::Upstream| position can |
| 97 // never yield another |TextAffinity::Upstream position| (unless line wrap | 97 // never yield another |TextAffinity::Upstream position| (unless line wrap |
| 98 // length is 0!). | 98 // length is 0!). |
| 99 if (prev.isNotNull() && m_affinity == TextAffinity::Upstream) { | 99 if (prev.isNotNull() && visiblePosition.affinity() == TextAffinity::Upstream
) { |
| 100 ASSERT(inSameLine(PositionWithAffinity(prev.deepEquivalent()), PositionW
ithAffinity(prev.deepEquivalent(), TextAffinity::Upstream))); | 100 ASSERT(inSameLine(PositionWithAffinity(prev.deepEquivalent()), PositionW
ithAffinity(prev.deepEquivalent(), TextAffinity::Upstream))); |
| 101 } | 101 } |
| 102 #endif | 102 #endif |
| 103 | 103 |
| 104 switch (rule) { | 104 switch (rule) { |
| 105 case CanCrossEditingBoundary: | 105 case CanCrossEditingBoundary: |
| 106 return prev; | 106 return prev; |
| 107 case CannotCrossEditingBoundary: | 107 case CannotCrossEditingBoundary: |
| 108 return honorEditingBoundaryAtOrBefore(prev); | 108 return visiblePosition.honorEditingBoundaryAtOrBefore(prev); |
| 109 case CanSkipOverEditingBoundary: | 109 case CanSkipOverEditingBoundary: |
| 110 return skipToStartOfEditingBoundary(prev); | 110 return visiblePosition.skipToStartOfEditingBoundary(prev); |
| 111 } | 111 } |
| 112 | 112 |
| 113 ASSERT_NOT_REACHED(); | 113 ASSERT_NOT_REACHED(); |
| 114 return honorEditingBoundaryAtOrBefore(prev); | 114 return visiblePosition.honorEditingBoundaryAtOrBefore(prev); |
| 115 } | 115 } |
| 116 | 116 |
| 117 Position VisiblePosition::leftVisuallyDistinctCandidate() const | 117 Position VisiblePosition::leftVisuallyDistinctCandidate() const |
| 118 { | 118 { |
| 119 Position p = m_deepPosition; | 119 Position p = m_deepPosition; |
| 120 if (p.isNull()) | 120 if (p.isNull()) |
| 121 return Position(); | 121 return Position(); |
| 122 | 122 |
| 123 Position downstreamStart = mostForwardCaretPosition(p); | 123 Position downstreamStart = mostForwardCaretPosition(p); |
| 124 TextDirection primaryDirection = primaryDirectionOf(*p.anchorNode()); | 124 TextDirection primaryDirection = primaryDirectionOf(*p.anchorNode()); |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 return 0; | 674 return 0; |
| 675 unsigned offset = static_cast<unsigned>(pos.offsetInContainerNode()); | 675 unsigned offset = static_cast<unsigned>(pos.offsetInContainerNode()); |
| 676 Text* textNode = toText(containerNode); | 676 Text* textNode = toText(containerNode); |
| 677 unsigned length = textNode->length(); | 677 unsigned length = textNode->length(); |
| 678 if (offset >= length) | 678 if (offset >= length) |
| 679 return 0; | 679 return 0; |
| 680 | 680 |
| 681 return textNode->data().characterStartingAt(offset); | 681 return textNode->data().characterStartingAt(offset); |
| 682 } | 682 } |
| 683 | 683 |
| 684 UChar32 VisiblePosition::characterBefore() const |
| 685 { |
| 686 return previousPositionOf(*this).characterAfter(); |
| 687 } |
| 688 |
| 684 LayoutRect VisiblePosition::localCaretRect(LayoutObject*& layoutObject) const | 689 LayoutRect VisiblePosition::localCaretRect(LayoutObject*& layoutObject) const |
| 685 { | 690 { |
| 686 PositionWithAffinity positionWithAffinity(m_deepPosition, m_affinity); | 691 PositionWithAffinity positionWithAffinity(m_deepPosition, m_affinity); |
| 687 return localCaretRectOfPosition(positionWithAffinity, layoutObject); | 692 return localCaretRectOfPosition(positionWithAffinity, layoutObject); |
| 688 } | 693 } |
| 689 | 694 |
| 690 IntRect VisiblePosition::absoluteCaretBounds() const | 695 IntRect VisiblePosition::absoluteCaretBounds() const |
| 691 { | 696 { |
| 692 LayoutObject* layoutObject; | 697 LayoutObject* layoutObject; |
| 693 LayoutRect localRect = localCaretRect(layoutObject); | 698 LayoutRect localRect = localCaretRect(layoutObject); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 else | 774 else |
| 770 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n"); | 775 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n"); |
| 771 } | 776 } |
| 772 | 777 |
| 773 void showTree(const blink::VisiblePosition& vpos) | 778 void showTree(const blink::VisiblePosition& vpos) |
| 774 { | 779 { |
| 775 vpos.showTreeForThis(); | 780 vpos.showTreeForThis(); |
| 776 } | 781 } |
| 777 | 782 |
| 778 #endif | 783 #endif |
| OLD | NEW |