| 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 } | 57 } |
| 58 | 58 |
| 59 VisiblePosition VisiblePosition::createWithoutCanonicalization(const PositionWit
hAffinity& canonicalized) | 59 VisiblePosition VisiblePosition::createWithoutCanonicalization(const PositionWit
hAffinity& canonicalized) |
| 60 { | 60 { |
| 61 VisiblePosition visiblePosition; | 61 VisiblePosition visiblePosition; |
| 62 visiblePosition.m_deepPosition = canonicalized.position(); | 62 visiblePosition.m_deepPosition = canonicalized.position(); |
| 63 visiblePosition.m_affinity = canonicalized.affinity(); | 63 visiblePosition.m_affinity = canonicalized.affinity(); |
| 64 return visiblePosition; | 64 return visiblePosition; |
| 65 } | 65 } |
| 66 | 66 |
| 67 template <typename Strategy> | |
| 68 PositionWithAffinityTemplate<Strategy> honorEditingBoundaryAtOrBeforeAlgorithm(c
onst PositionWithAffinityTemplate<Strategy>& pos, const PositionAlgorithm<Strate
gy>& anchor) | |
| 69 { | |
| 70 if (pos.isNull()) | |
| 71 return pos; | |
| 72 | |
| 73 ContainerNode* highestRoot = highestEditableRoot(anchor); | |
| 74 | |
| 75 // Return empty position if pos is not somewhere inside the editable region
containing this position | |
| 76 if (highestRoot && !pos.position().anchorNode()->isDescendantOf(highestRoot)
) | |
| 77 return PositionWithAffinityTemplate<Strategy>(); | |
| 78 | |
| 79 // Return pos itself if the two are from the very same editable region, or b
oth are non-editable | |
| 80 // FIXME: In the non-editable case, just because the new position is non-edi
table doesn't mean movement | |
| 81 // to it is allowed. VisibleSelection::adjustForEditableContent has this pr
oblem too. | |
| 82 if (highestEditableRoot(pos.position()) == highestRoot) | |
| 83 return pos; | |
| 84 | |
| 85 // Return empty position if this position is non-editable, but pos is editab
le | |
| 86 // FIXME: Move to the previous non-editable region. | |
| 87 if (!highestRoot) | |
| 88 return PositionWithAffinityTemplate<Strategy>(); | |
| 89 | |
| 90 // Return the last position before pos that is in the same editable region a
s this position | |
| 91 return lastEditablePositionBeforePositionInRoot(pos.position(), highestRoot)
; | |
| 92 } | |
| 93 | |
| 94 PositionWithAffinity honorEditingBoundaryAtOrBeforeOf(const PositionWithAffinity
& pos, const Position& anchor) | |
| 95 { | |
| 96 return honorEditingBoundaryAtOrBeforeAlgorithm(pos, anchor); | |
| 97 } | |
| 98 | |
| 99 PositionInComposedTreeWithAffinity honorEditingBoundaryAtOrBeforeOf(const Positi
onInComposedTreeWithAffinity& pos, const PositionInComposedTree& anchor) | |
| 100 { | |
| 101 return honorEditingBoundaryAtOrBeforeAlgorithm(pos, anchor); | |
| 102 } | |
| 103 | |
| 104 VisiblePosition honorEditingBoundaryAtOrBefore(const VisiblePosition& pos, const
Position& anchor) | |
| 105 { | |
| 106 return createVisiblePosition(honorEditingBoundaryAtOrBeforeOf(pos.toPosition
WithAffinity(), anchor)); | |
| 107 } | |
| 108 | |
| 109 VisiblePosition honorEditingBoundaryAtOrAfter(const VisiblePosition& pos, const
Position& anchor) | |
| 110 { | |
| 111 if (pos.isNull()) | |
| 112 return pos; | |
| 113 | |
| 114 ContainerNode* highestRoot = highestEditableRoot(anchor); | |
| 115 | |
| 116 // Return empty position if pos is not somewhere inside the editable region
containing this position | |
| 117 if (highestRoot && !pos.deepEquivalent().anchorNode()->isDescendantOf(highes
tRoot)) | |
| 118 return VisiblePosition(); | |
| 119 | |
| 120 // Return pos itself if the two are from the very same editable region, or b
oth are non-editable | |
| 121 // FIXME: In the non-editable case, just because the new position is non-edi
table doesn't mean movement | |
| 122 // to it is allowed. VisibleSelection::adjustForEditableContent has this pr
oblem too. | |
| 123 if (highestEditableRoot(pos.deepEquivalent()) == highestRoot) | |
| 124 return pos; | |
| 125 | |
| 126 // Return empty position if this position is non-editable, but pos is editab
le | |
| 127 // FIXME: Move to the next non-editable region. | |
| 128 if (!highestRoot) | |
| 129 return VisiblePosition(); | |
| 130 | |
| 131 // Return the next position after pos that is in the same editable region as
this position | |
| 132 return firstEditableVisiblePositionAfterPositionInRoot(pos.deepEquivalent(),
highestRoot); | |
| 133 } | |
| 134 | |
| 135 template<typename Strategy> | 67 template<typename Strategy> |
| 136 static PositionWithAffinityTemplate<Strategy> createVisiblePositionAlgorithm(con
st PositionAlgorithm<Strategy>& position, TextAffinity affinity) | 68 static PositionWithAffinityTemplate<Strategy> createVisiblePositionAlgorithm(con
st PositionAlgorithm<Strategy>& position, TextAffinity affinity) |
| 137 { | 69 { |
| 138 const PositionAlgorithm<Strategy> deepPosition = canonicalPositionOf(positio
n); | 70 const PositionAlgorithm<Strategy> deepPosition = canonicalPositionOf(positio
n); |
| 139 if (deepPosition.isNull()) | 71 if (deepPosition.isNull()) |
| 140 return PositionWithAffinityTemplate<Strategy>(); | 72 return PositionWithAffinityTemplate<Strategy>(); |
| 141 if (affinity == TextAffinity::Downstream) | 73 if (affinity == TextAffinity::Downstream) |
| 142 return PositionWithAffinityTemplate<Strategy>(deepPosition); | 74 return PositionWithAffinityTemplate<Strategy>(deepPosition); |
| 143 | 75 |
| 144 // When not at a line wrap, make sure to end up with | 76 // When not at a line wrap, make sure to end up with |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 else | 135 else |
| 204 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n"); | 136 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n"); |
| 205 } | 137 } |
| 206 | 138 |
| 207 void showTree(const blink::VisiblePosition& vpos) | 139 void showTree(const blink::VisiblePosition& vpos) |
| 208 { | 140 { |
| 209 vpos.showTreeForThis(); | 141 vpos.showTreeForThis(); |
| 210 } | 142 } |
| 211 | 143 |
| 212 #endif | 144 #endif |
| OLD | NEW |