OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 10 matching lines...) Expand all Loading... | |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
27 #include "core/editing/PositionIterator.h" | 27 #include "core/editing/PositionIterator.h" |
28 | 28 |
29 namespace blink { | 29 namespace blink { |
30 | 30 |
31 static const int kInvalidOffset = -1; | |
32 | |
31 template <typename Strategy> | 33 template <typename Strategy> |
32 PositionIteratorAlgorithm<Strategy>::PositionIteratorAlgorithm(Node* anchorNode, int offsetInAnchor) | 34 PositionIteratorAlgorithm<Strategy>::PositionIteratorAlgorithm(Node* anchorNode, int offsetInAnchor) |
33 : m_anchorNode(anchorNode) | 35 : m_anchorNode(anchorNode) |
34 , m_nodeAfterPositionInAnchor(Strategy::childAt(*anchorNode, offsetInAnchor) ) | 36 , m_nodeAfterPositionInAnchor(Strategy::childAt(*anchorNode, offsetInAnchor) ) |
35 , m_offsetInAnchor(m_nodeAfterPositionInAnchor ? 0 : offsetInAnchor) | 37 , m_offsetInAnchor(m_nodeAfterPositionInAnchor ? 0 : offsetInAnchor) |
38 , m_depthToAnchorNode(0) | |
39 , m_domTreeVersion(anchorNode->document().domTreeVersion()) | |
36 { | 40 { |
41 for (Node* node = Strategy::parent(*anchorNode); node; node = Strategy::pare nt(*node)) { | |
42 // Each m_offsetsInAnchorNode[offset] should be an index of node in | |
43 // parent, but delay to calculate the index until it is needed for | |
44 // performance. | |
45 m_offsetsInAnchorNode.append(kInvalidOffset); | |
46 ++m_depthToAnchorNode; | |
47 } | |
48 if (m_nodeAfterPositionInAnchor) | |
49 m_offsetsInAnchorNode.append(offsetInAnchor); | |
37 } | 50 } |
38 template <typename Strategy> | 51 template <typename Strategy> |
39 PositionIteratorAlgorithm<Strategy>::PositionIteratorAlgorithm(const PositionTem plate<Strategy>& pos) | 52 PositionIteratorAlgorithm<Strategy>::PositionIteratorAlgorithm(const PositionTem plate<Strategy>& pos) |
40 : PositionIteratorAlgorithm(pos.anchorNode(), pos.computeEditingOffset()) | 53 : PositionIteratorAlgorithm(pos.anchorNode(), pos.computeEditingOffset()) |
41 { | 54 { |
42 } | 55 } |
43 | 56 |
44 template <typename Strategy> | 57 template <typename Strategy> |
45 PositionIteratorAlgorithm<Strategy>::PositionIteratorAlgorithm() | 58 PositionIteratorAlgorithm<Strategy>::PositionIteratorAlgorithm() |
46 : m_anchorNode(nullptr) | 59 : m_anchorNode(nullptr) |
47 , m_nodeAfterPositionInAnchor(nullptr) | 60 , m_nodeAfterPositionInAnchor(nullptr) |
48 , m_offsetInAnchor(0) | 61 , m_offsetInAnchor(0) |
62 , m_depthToAnchorNode(0) | |
63 , m_domTreeVersion(0) | |
49 { | 64 { |
50 } | 65 } |
51 | 66 |
52 template <typename Strategy> | 67 template <typename Strategy> |
53 PositionTemplate<Strategy> PositionIteratorAlgorithm<Strategy>::deprecatedComput ePosition() const | 68 PositionTemplate<Strategy> PositionIteratorAlgorithm<Strategy>::deprecatedComput ePosition() const |
54 { | 69 { |
70 // TODO(yoichio): Share code to check domTreeVersion with EphemeralRange. | |
71 ASSERT(m_domTreeVersion == m_anchorNode->document().domTreeVersion()); | |
yosin_UTC9
2015/10/22 05:26:09
Let's introduce isTreeClean() or another name rath
yoichio
2015/10/22 06:46:08
Done.
| |
55 if (m_nodeAfterPositionInAnchor) { | 72 if (m_nodeAfterPositionInAnchor) { |
56 ASSERT(Strategy::parent(*m_nodeAfterPositionInAnchor) == m_anchorNode); | 73 ASSERT(Strategy::parent(*m_nodeAfterPositionInAnchor) == m_anchorNode); |
74 ASSERT(m_offsetsInAnchorNode[m_depthToAnchorNode] != kInvalidOffset); | |
57 // FIXME: This check is inadaquete because any ancestor could be ignored by editing | 75 // FIXME: This check is inadaquete because any ancestor could be ignored by editing |
58 if (Strategy::editingIgnoresContent(Strategy::parent(*m_nodeAfterPositio nInAnchor))) | 76 if (Strategy::editingIgnoresContent(Strategy::parent(*m_nodeAfterPositio nInAnchor))) |
59 return PositionTemplate<Strategy>::beforeNode(m_anchorNode); | 77 return PositionTemplate<Strategy>::beforeNode(m_anchorNode); |
60 return PositionTemplate<Strategy>::inParentBeforeNode(*m_nodeAfterPositi onInAnchor); | 78 return PositionTemplate<Strategy>(m_anchorNode, m_offsetsInAnchorNode[m_ depthToAnchorNode]); |
61 } | 79 } |
62 if (Strategy::hasChildren(*m_anchorNode)) | 80 if (Strategy::hasChildren(*m_anchorNode)) |
63 return PositionTemplate<Strategy>::lastPositionInOrAfterNode(m_anchorNod e); | 81 return PositionTemplate<Strategy>::lastPositionInOrAfterNode(m_anchorNod e); |
64 return PositionTemplate<Strategy>::editingPositionOf(m_anchorNode, m_offsetI nAnchor); | 82 return PositionTemplate<Strategy>::editingPositionOf(m_anchorNode, m_offsetI nAnchor); |
65 } | 83 } |
66 | 84 |
67 template <typename Strategy> | 85 template <typename Strategy> |
68 PositionTemplate<Strategy> PositionIteratorAlgorithm<Strategy>::computePosition( ) const | 86 PositionTemplate<Strategy> PositionIteratorAlgorithm<Strategy>::computePosition( ) const |
69 { | 87 { |
88 ASSERT(m_domTreeVersion == m_anchorNode->document().domTreeVersion()); | |
89 // Assume that we have the following DOM tree: | |
90 // A | |
91 // |-B | |
92 // | |-E | |
93 // | +-F | |
94 // | | |
95 // |-C | |
96 // +-D | |
97 // |-G | |
98 // +-H | |
70 if (m_nodeAfterPositionInAnchor) { | 99 if (m_nodeAfterPositionInAnchor) { |
100 // For example, position is before E, F. | |
71 ASSERT(Strategy::parent(*m_nodeAfterPositionInAnchor) == m_anchorNode); | 101 ASSERT(Strategy::parent(*m_nodeAfterPositionInAnchor) == m_anchorNode); |
72 return PositionTemplate<Strategy>::inParentBeforeNode(*m_nodeAfterPositi onInAnchor); | 102 ASSERT(m_offsetsInAnchorNode[m_depthToAnchorNode] != kInvalidOffset); |
103 // TODO(yoichio): This should be equivalent to | |
104 // PositionTemplate<Strategy>(m_anchorNode, PositionAnchorType::BeforeAn chor); | |
105 return PositionTemplate<Strategy>(m_anchorNode, m_offsetsInAnchorNode[m_ depthToAnchorNode]); | |
73 } | 106 } |
74 if (Strategy::hasChildren(*m_anchorNode)) | 107 if (Strategy::hasChildren(*m_anchorNode)) |
108 // For example, position is the end of B. | |
75 return PositionTemplate<Strategy>::lastPositionInOrAfterNode(m_anchorNod e); | 109 return PositionTemplate<Strategy>::lastPositionInOrAfterNode(m_anchorNod e); |
76 if (m_anchorNode->isTextNode()) | 110 if (m_anchorNode->isTextNode()) |
77 return PositionTemplate<Strategy>(m_anchorNode, m_offsetInAnchor); | 111 return PositionTemplate<Strategy>(m_anchorNode, m_offsetInAnchor); |
78 if (m_offsetInAnchor) | 112 if (m_offsetInAnchor) |
113 // For example, position is after G. | |
79 return PositionTemplate<Strategy>(m_anchorNode, PositionAnchorType::Afte rAnchor); | 114 return PositionTemplate<Strategy>(m_anchorNode, PositionAnchorType::Afte rAnchor); |
115 // For example, position is before G. | |
80 return PositionTemplate<Strategy>(m_anchorNode, PositionAnchorType::BeforeAn chor); | 116 return PositionTemplate<Strategy>(m_anchorNode, PositionAnchorType::BeforeAn chor); |
81 } | 117 } |
82 | 118 |
83 template <typename Strategy> | 119 template <typename Strategy> |
84 void PositionIteratorAlgorithm<Strategy>::increment() | 120 void PositionIteratorAlgorithm<Strategy>::increment() |
85 { | 121 { |
86 if (!m_anchorNode) | 122 if (!m_anchorNode) |
87 return; | 123 return; |
124 ASSERT(m_domTreeVersion == m_anchorNode->document().domTreeVersion()); | |
88 | 125 |
126 // Assume that we have the following DOM tree: | |
127 // A | |
128 // |-B | |
129 // | |-E | |
130 // | +-F | |
131 // | | |
132 // |-C | |
133 // +-D | |
134 // |-G | |
135 // +-H | |
136 // Let |anchor| as |m_anchorNode| and | |
137 // |child| as |m_nodeAfterPositionInAnchor|. | |
89 if (m_nodeAfterPositionInAnchor) { | 138 if (m_nodeAfterPositionInAnchor) { |
139 // Case #1. | |
yosin_UTC9
2015/10/22 05:26:09
Case #1: Move to firstChild()
yoichio
2015/10/22 06:46:08
Done.
| |
140 // This is a point just before |child|. | |
141 // Let |anchor| is A and |child| is B, | |
142 // then next |anchor| is B and |child| is E. | |
90 m_anchorNode = m_nodeAfterPositionInAnchor; | 143 m_anchorNode = m_nodeAfterPositionInAnchor; |
91 m_nodeAfterPositionInAnchor = Strategy::firstChild(*m_anchorNode); | 144 m_nodeAfterPositionInAnchor = Strategy::firstChild(*m_anchorNode); |
92 m_offsetInAnchor = 0; | 145 m_offsetInAnchor = 0; |
146 // Increment depth intializing with 0. | |
147 ++m_depthToAnchorNode; | |
148 if (m_depthToAnchorNode == m_offsetsInAnchorNode.size()) | |
149 m_offsetsInAnchorNode.append(0); | |
150 else | |
151 m_offsetsInAnchorNode[m_depthToAnchorNode] = 0; | |
93 return; | 152 return; |
94 } | 153 } |
95 | 154 |
96 if (m_anchorNode->layoutObject() && !Strategy::hasChildren(*m_anchorNode) && m_offsetInAnchor < Strategy::lastOffsetForEditing(m_anchorNode)) { | 155 if (m_anchorNode->layoutObject() && !Strategy::hasChildren(*m_anchorNode) && m_offsetInAnchor < Strategy::lastOffsetForEditing(m_anchorNode)) { |
156 // Case #2. This is the next of Case #1 or #2 itself. | |
157 // Position is (|anchor|, |m_offsetInAchor|). | |
158 // In this case |anchor| is a leaf(E,F,C,G or H) and | |
159 // |m_offsetInAnchor| is not on the end of |anchor|. | |
160 // Then just increment |m_offsetInAnchor|. | |
97 m_offsetInAnchor = uncheckedNextOffset(m_anchorNode, m_offsetInAnchor); | 161 m_offsetInAnchor = uncheckedNextOffset(m_anchorNode, m_offsetInAnchor); |
98 } else { | 162 } else { |
163 // Case #3. This is the next of Case #2 or #3. | |
164 // Position is the end of |anchor|. | |
165 // 3-a. If |anchor| has next sibling (let E), | |
166 // next |anchor| is B and |child| is F (next is Case #1.) | |
167 // 3-b. If |anchor| doesn't have next sibling (let F), | |
168 // next |anchor| is B and |child| is null. (next is Case #3.) | |
99 m_nodeAfterPositionInAnchor = m_anchorNode; | 169 m_nodeAfterPositionInAnchor = m_anchorNode; |
100 m_anchorNode = Strategy::parent(*m_nodeAfterPositionInAnchor); | 170 m_anchorNode = Strategy::parent(*m_nodeAfterPositionInAnchor); |
171 if (!m_anchorNode) | |
172 return; | |
173 ASSERT(m_depthToAnchorNode > 0); | |
174 --m_depthToAnchorNode; | |
175 // Increment offset of |child| or initialize if it have never been | |
176 // used. | |
177 if (m_offsetsInAnchorNode[m_depthToAnchorNode] == kInvalidOffset) | |
178 m_offsetsInAnchorNode[m_depthToAnchorNode] = Strategy::index(*m_node AfterPositionInAnchor) + 1; | |
179 else | |
180 ++m_offsetsInAnchorNode[m_depthToAnchorNode]; | |
101 m_nodeAfterPositionInAnchor = Strategy::nextSibling(*m_nodeAfterPosition InAnchor); | 181 m_nodeAfterPositionInAnchor = Strategy::nextSibling(*m_nodeAfterPosition InAnchor); |
102 m_offsetInAnchor = 0; | 182 m_offsetInAnchor = 0; |
103 } | 183 } |
104 } | 184 } |
105 | 185 |
106 template <typename Strategy> | 186 template <typename Strategy> |
107 void PositionIteratorAlgorithm<Strategy>::decrement() | 187 void PositionIteratorAlgorithm<Strategy>::decrement() |
108 { | 188 { |
109 if (!m_anchorNode) | 189 if (!m_anchorNode) |
110 return; | 190 return; |
191 ASSERT(m_domTreeVersion == m_anchorNode->document().domTreeVersion()); | |
111 | 192 |
193 // Assume that we have the following DOM tree: | |
194 // A | |
195 // |-B | |
196 // | |-E | |
197 // | +-F | |
198 // | | |
199 // |-C | |
200 // +-D | |
201 // |-G | |
202 // +-H | |
203 // Let |anchor| as |m_anchorNode| and | |
204 // |child| as |m_nodeAfterPositionInAnchor|. | |
205 // decrement() is complex but logically reverse of increment(), of course:) | |
112 if (m_nodeAfterPositionInAnchor) { | 206 if (m_nodeAfterPositionInAnchor) { |
113 m_anchorNode = Strategy::previousSibling(*m_nodeAfterPositionInAnchor); | 207 m_anchorNode = Strategy::previousSibling(*m_nodeAfterPositionInAnchor); |
114 if (m_anchorNode) { | 208 if (m_anchorNode) { |
209 // Case #1-a. This is a revese of increment()::Case#3-a. | |
210 // |child| has a previous sibling. | |
211 // Let |anchor| is B and |child| is F, | |
212 // next |anchor| is E and |child| is null. | |
115 m_nodeAfterPositionInAnchor = nullptr; | 213 m_nodeAfterPositionInAnchor = nullptr; |
116 m_offsetInAnchor = Strategy::hasChildren(*m_anchorNode) ? 0 : Strate gy::lastOffsetForEditing(m_anchorNode); | 214 m_offsetInAnchor = Strategy::hasChildren(*m_anchorNode) ? 0 : Strate gy::lastOffsetForEditing(m_anchorNode); |
215 // Decrement offset of |child| or initialize if it have never been | |
216 // used. | |
217 if (m_offsetsInAnchorNode[m_depthToAnchorNode] == kInvalidOffset) | |
218 m_offsetsInAnchorNode[m_depthToAnchorNode] = Strategy::index(*m_ nodeAfterPositionInAnchor); | |
219 else | |
220 --m_offsetsInAnchorNode[m_depthToAnchorNode]; | |
221 ASSERT(m_offsetsInAnchorNode[m_depthToAnchorNode] >= 0); | |
222 // Increment depth intializing with last offset. | |
223 m_depthToAnchorNode++; | |
yosin_UTC9
2015/10/22 05:26:09
nit: prefer prefix form.
yoichio
2015/10/22 06:46:08
Done.
| |
224 if (m_depthToAnchorNode >= m_offsetsInAnchorNode.size()) | |
225 m_offsetsInAnchorNode.append(m_offsetInAnchor); | |
226 else | |
227 m_offsetsInAnchorNode[m_depthToAnchorNode] = m_offsetInAnchor; | |
yosin_UTC9
2015/10/22 05:26:09
Optional: early return?
yoichio
2015/10/22 06:46:08
Done.
| |
117 } else { | 228 } else { |
229 // Case #1-b. This is a revese of increment()::Case#1. | |
230 // |child| doesn't have a previous sibling. | |
231 // Let |anchor| is B and |child| is E, | |
232 // next |anchor| is A and |child| is B. | |
118 m_nodeAfterPositionInAnchor = Strategy::parent(*m_nodeAfterPositionI nAnchor); | 233 m_nodeAfterPositionInAnchor = Strategy::parent(*m_nodeAfterPositionI nAnchor); |
119 m_anchorNode = Strategy::parent(*m_nodeAfterPositionInAnchor); | 234 m_anchorNode = Strategy::parent(*m_nodeAfterPositionInAnchor); |
235 if (!m_anchorNode) | |
236 return; | |
120 m_offsetInAnchor = 0; | 237 m_offsetInAnchor = 0; |
238 // Decrement depth and intialize if needs. | |
239 ASSERT(m_depthToAnchorNode > 0); | |
240 --m_depthToAnchorNode; | |
241 if (m_offsetsInAnchorNode[m_depthToAnchorNode] == kInvalidOffset) | |
242 m_offsetsInAnchorNode[m_depthToAnchorNode] = Strategy::index(*m_ nodeAfterPositionInAnchor); | |
121 } | 243 } |
122 return; | 244 return; |
123 } | 245 } |
124 | 246 |
125 if (Strategy::hasChildren(*m_anchorNode)) { | 247 if (Strategy::hasChildren(*m_anchorNode)) { |
248 // Case #2. This is a reverse of increment()::Case3-b. | |
249 // Let |anchor| is B, next |anchor| is F. | |
126 m_anchorNode = Strategy::lastChild(*m_anchorNode); | 250 m_anchorNode = Strategy::lastChild(*m_anchorNode); |
127 m_offsetInAnchor = Strategy::hasChildren(*m_anchorNode)? 0 : Strategy::l astOffsetForEditing(m_anchorNode); | 251 m_offsetInAnchor = Strategy::hasChildren(*m_anchorNode)? 0 : Strategy::l astOffsetForEditing(m_anchorNode); |
252 // Decrement depth initializing with -1 because | |
253 // |m_nodeAfterPositionInAnchor| is null so still unneeded. | |
254 if (m_depthToAnchorNode >= m_offsetsInAnchorNode.size()) | |
255 m_offsetsInAnchorNode.append(kInvalidOffset); | |
256 else | |
257 m_offsetsInAnchorNode[m_depthToAnchorNode] = kInvalidOffset; | |
258 ++m_depthToAnchorNode; | |
yosin_UTC9
2015/10/22 05:26:09
Optional: early return?
yoichio
2015/10/22 06:46:08
Done.
| |
128 } else { | 259 } else { |
129 if (m_offsetInAnchor && m_anchorNode->layoutObject()) { | 260 if (m_offsetInAnchor && m_anchorNode->layoutObject()) { |
261 // Case #3-a. This is a reverse of increment()::Case#2. | |
262 // In this case |anchor| is a leaf(E,F,C,G or H) and | |
263 // |m_offsetInAnchor| is not on the beginning of |anchor|. | |
264 // Then just decrement |m_offsetInAnchor|. | |
130 m_offsetInAnchor = uncheckedPreviousOffset(m_anchorNode, m_offsetInA nchor); | 265 m_offsetInAnchor = uncheckedPreviousOffset(m_anchorNode, m_offsetInA nchor); |
yosin_UTC9
2015/10/22 05:26:09
Optional: early return?
yoichio
2015/10/22 06:46:08
Done.
| |
131 } else { | 266 } else { |
267 // Case #3-b. This is a reverse of increment()::Case#1. | |
268 // In this case |anchor| is a leaf(E,F,C,G or H) and | |
269 // |m_offsetInAnchor| is on the beginning of |anchor|. | |
270 // Let |anchor| is E, | |
271 // next |anchor| is B and |child| is E. | |
132 m_nodeAfterPositionInAnchor = m_anchorNode; | 272 m_nodeAfterPositionInAnchor = m_anchorNode; |
133 m_anchorNode = Strategy::parent(*m_anchorNode); | 273 m_anchorNode = Strategy::parent(*m_anchorNode); |
274 if (!m_anchorNode) | |
275 return; | |
276 ASSERT(m_depthToAnchorNode > 0); | |
277 --m_depthToAnchorNode; | |
278 if (m_offsetsInAnchorNode[m_depthToAnchorNode] == kInvalidOffset) | |
279 m_offsetsInAnchorNode[m_depthToAnchorNode] = Strategy::index(*m_ nodeAfterPositionInAnchor); | |
134 } | 280 } |
135 } | 281 } |
136 } | 282 } |
137 | 283 |
138 template <typename Strategy> | 284 template <typename Strategy> |
139 bool PositionIteratorAlgorithm<Strategy>::atStart() const | 285 bool PositionIteratorAlgorithm<Strategy>::atStart() const |
140 { | 286 { |
141 if (!m_anchorNode) | 287 if (!m_anchorNode) |
142 return true; | 288 return true; |
289 ASSERT(m_domTreeVersion == m_anchorNode->document().domTreeVersion()); | |
143 if (Strategy::parent(*m_anchorNode)) | 290 if (Strategy::parent(*m_anchorNode)) |
144 return false; | 291 return false; |
145 return (!Strategy::hasChildren(*m_anchorNode) && !m_offsetInAnchor) || (m_no deAfterPositionInAnchor && !Strategy::previousSibling(*m_nodeAfterPositionInAnch or)); | 292 return (!Strategy::hasChildren(*m_anchorNode) && !m_offsetInAnchor) || (m_no deAfterPositionInAnchor && !Strategy::previousSibling(*m_nodeAfterPositionInAnch or)); |
146 } | 293 } |
147 | 294 |
148 template <typename Strategy> | 295 template <typename Strategy> |
149 bool PositionIteratorAlgorithm<Strategy>::atEnd() const | 296 bool PositionIteratorAlgorithm<Strategy>::atEnd() const |
150 { | 297 { |
151 if (!m_anchorNode) | 298 if (!m_anchorNode) |
152 return true; | 299 return true; |
300 ASSERT(m_domTreeVersion == m_anchorNode->document().domTreeVersion()); | |
153 if (m_nodeAfterPositionInAnchor) | 301 if (m_nodeAfterPositionInAnchor) |
154 return false; | 302 return false; |
155 return !Strategy::parent(*m_anchorNode) && (Strategy::hasChildren(*m_anchorN ode) || m_offsetInAnchor >= Strategy::lastOffsetForEditing(m_anchorNode)); | 303 return !Strategy::parent(*m_anchorNode) && (Strategy::hasChildren(*m_anchorN ode) || m_offsetInAnchor >= Strategy::lastOffsetForEditing(m_anchorNode)); |
156 } | 304 } |
157 | 305 |
158 template <typename Strategy> | 306 template <typename Strategy> |
159 bool PositionIteratorAlgorithm<Strategy>::atStartOfNode() const | 307 bool PositionIteratorAlgorithm<Strategy>::atStartOfNode() const |
160 { | 308 { |
161 if (!m_anchorNode) | 309 if (!m_anchorNode) |
162 return true; | 310 return true; |
311 ASSERT(m_domTreeVersion == m_anchorNode->document().domTreeVersion()); | |
163 if (!m_nodeAfterPositionInAnchor) | 312 if (!m_nodeAfterPositionInAnchor) |
164 return !Strategy::hasChildren(*m_anchorNode) && !m_offsetInAnchor; | 313 return !Strategy::hasChildren(*m_anchorNode) && !m_offsetInAnchor; |
165 return !Strategy::previousSibling(*m_nodeAfterPositionInAnchor); | 314 return !Strategy::previousSibling(*m_nodeAfterPositionInAnchor); |
166 } | 315 } |
167 | 316 |
168 template <typename Strategy> | 317 template <typename Strategy> |
169 bool PositionIteratorAlgorithm<Strategy>::atEndOfNode() const | 318 bool PositionIteratorAlgorithm<Strategy>::atEndOfNode() const |
170 { | 319 { |
171 if (!m_anchorNode) | 320 if (!m_anchorNode) |
172 return true; | 321 return true; |
322 ASSERT(m_domTreeVersion == m_anchorNode->document().domTreeVersion()); | |
173 if (m_nodeAfterPositionInAnchor) | 323 if (m_nodeAfterPositionInAnchor) |
174 return false; | 324 return false; |
175 return Strategy::hasChildren(*m_anchorNode) || m_offsetInAnchor >= Strategy: :lastOffsetForEditing(m_anchorNode); | 325 return Strategy::hasChildren(*m_anchorNode) || m_offsetInAnchor >= Strategy: :lastOffsetForEditing(m_anchorNode); |
176 } | 326 } |
177 | 327 |
178 template class PositionIteratorAlgorithm<EditingStrategy>; | 328 template class PositionIteratorAlgorithm<EditingStrategy>; |
179 template class PositionIteratorAlgorithm<EditingInComposedTreeStrategy>; | 329 template class PositionIteratorAlgorithm<EditingInComposedTreeStrategy>; |
180 | 330 |
181 } // namespace blink | 331 } // namespace blink |
OLD | NEW |