Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: third_party/WebKit/Source/core/editing/PositionIterator.cpp

Issue 1372153007: [Editing] Speed up PositionIterator::computePosition from O(n) to O(1). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 15 matching lines...) Expand all
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 template <typename Strategy> 31 template <typename Strategy>
32 PositionIteratorAlgorithm<Strategy>::PositionIteratorAlgorithm(Node* anchorNode, int offsetInAnchor) 32 PositionIteratorAlgorithm<Strategy>::PositionIteratorAlgorithm(Node* anchorNode, int offsetInAnchor)
33 : m_anchorNode(anchorNode) 33 : m_anchorNode(anchorNode)
34 , m_nodeAfterPositionInAnchor(Strategy::childAt(*anchorNode, offsetInAnchor) ) 34 , m_nodeAfterPositionInAnchor(Strategy::childAt(*anchorNode, offsetInAnchor) )
35 , m_offsetInAnchor(m_nodeAfterPositionInAnchor ? 0 : offsetInAnchor) 35 , m_offsetInAnchor(m_nodeAfterPositionInAnchor ? 0 : offsetInAnchor)
36 , m_domTreeVersion(anchorNode->document().domTreeVersion())
37 , m_depthToAnchorNode(0)
36 { 38 {
39 for (Node* node = Strategy::parent(*anchorNode); node; node = Strategy::pare nt(*node)) {
40 // Each m_offsetsInAnchorNode[offset] should be index of node,
yosin_UTC9 2015/10/21 06:01:15 should be an index of node in parent node.
yoichio 2015/10/22 04:33:57 Done.
41 // but let's delay to calculate the index until it is needed.
yosin_UTC9 2015/10/21 06:01:16 Please add a reason why we want to postpone.
yoichio 2015/10/22 04:33:58 Done.
42 m_offsetsInAnchorNode.append(-1);
yosin_UTC9 2015/10/21 06:01:16 Could you name |-1|?
yoichio 2015/10/22 04:33:57 Done.
43 m_depthToAnchorNode++;
yosin_UTC9 2015/10/21 06:01:16 nit: prefer prefix: |++m_depthToAnchorNode|.
yoichio 2015/10/22 04:33:58 Done.
44 }
45 if (m_nodeAfterPositionInAnchor)
yosin_UTC9 2015/10/21 06:01:16 nit: early return?
yoichio 2015/10/22 04:33:57 We need initialize |m_OffsetsInAnchorNode| and |m_
46 m_offsetsInAnchorNode.append(offsetInAnchor);
37 } 47 }
38 template <typename Strategy> 48 template <typename Strategy>
39 PositionIteratorAlgorithm<Strategy>::PositionIteratorAlgorithm(const PositionTem plate<Strategy>& pos) 49 PositionIteratorAlgorithm<Strategy>::PositionIteratorAlgorithm(const PositionTem plate<Strategy>& pos)
40 : PositionIteratorAlgorithm(pos.anchorNode(), pos.computeEditingOffset()) 50 : PositionIteratorAlgorithm(pos.anchorNode(), pos.computeEditingOffset())
41 { 51 {
42 } 52 }
43 53
44 template <typename Strategy> 54 template <typename Strategy>
45 PositionIteratorAlgorithm<Strategy>::PositionIteratorAlgorithm() 55 PositionIteratorAlgorithm<Strategy>::PositionIteratorAlgorithm()
46 : m_anchorNode(nullptr) 56 : m_anchorNode(nullptr)
47 , m_nodeAfterPositionInAnchor(nullptr) 57 , m_nodeAfterPositionInAnchor(nullptr)
48 , m_offsetInAnchor(0) 58 , m_offsetInAnchor(0)
59 , m_domTreeVersion(0)
yosin_UTC9 2015/10/21 06:01:16 m_domTreeVersion(anchorNode->document().domTreeVer
yoichio 2015/10/22 04:33:57 Because anchorNode is null we can't.
60 , m_depthToAnchorNode(0)
49 { 61 {
50 } 62 }
51 63
52 template <typename Strategy> 64 template <typename Strategy>
53 PositionTemplate<Strategy> PositionIteratorAlgorithm<Strategy>::deprecatedComput ePosition() const 65 PositionTemplate<Strategy> PositionIteratorAlgorithm<Strategy>::deprecatedComput ePosition() const
54 { 66 {
67 ASSERT(m_domTreeVersion == m_anchorNode->document().domTreeVersion());
yosin_UTC9 2015/10/21 06:01:16 Having function for checking is better, e.g. |Ephe
yoichio 2015/10/22 04:33:58 Add comment.
55 if (m_nodeAfterPositionInAnchor) { 68 if (m_nodeAfterPositionInAnchor) {
56 ASSERT(Strategy::parent(*m_nodeAfterPositionInAnchor) == m_anchorNode); 69 ASSERT(Strategy::parent(*m_nodeAfterPositionInAnchor) == m_anchorNode);
70 ASSERT(m_offsetsInAnchorNode[m_depthToAnchorNode] >= 0);
yosin_UTC9 2015/10/21 06:01:16 Once we have |kInvalidOffset|, or another, we can
yoichio 2015/10/22 04:33:57 Done.
57 // FIXME: This check is inadaquete because any ancestor could be ignored by editing 71 // FIXME: This check is inadaquete because any ancestor could be ignored by editing
58 if (Strategy::editingIgnoresContent(Strategy::parent(*m_nodeAfterPositio nInAnchor))) 72 if (Strategy::editingIgnoresContent(Strategy::parent(*m_nodeAfterPositio nInAnchor)))
59 return PositionTemplate<Strategy>::beforeNode(m_anchorNode); 73 return PositionTemplate<Strategy>::beforeNode(m_anchorNode);
60 return PositionTemplate<Strategy>::inParentBeforeNode(*m_nodeAfterPositi onInAnchor); 74 return PositionTemplate<Strategy>(m_anchorNode, m_offsetsInAnchorNode[m_ depthToAnchorNode]);
61 } 75 }
62 if (Strategy::hasChildren(*m_anchorNode)) 76 if (Strategy::hasChildren(*m_anchorNode))
63 return PositionTemplate<Strategy>::lastPositionInOrAfterNode(m_anchorNod e); 77 return PositionTemplate<Strategy>::lastPositionInOrAfterNode(m_anchorNod e);
64 return PositionTemplate<Strategy>::editingPositionOf(m_anchorNode, m_offsetI nAnchor); 78 return PositionTemplate<Strategy>::editingPositionOf(m_anchorNode, m_offsetI nAnchor);
65 } 79 }
66 80
67 template <typename Strategy> 81 template <typename Strategy>
68 PositionTemplate<Strategy> PositionIteratorAlgorithm<Strategy>::computePosition( ) const 82 PositionTemplate<Strategy> PositionIteratorAlgorithm<Strategy>::computePosition( ) const
69 { 83 {
84 ASSERT(m_domTreeVersion == m_anchorNode->document().domTreeVersion());
85 // Assume that we have the following DOM tree:
86 // A
87 // |-B
88 // | |-E
89 // | +-F
90 // |
91 // |-C
92 // +-D
93 // |-G
94 // +-H
70 if (m_nodeAfterPositionInAnchor) { 95 if (m_nodeAfterPositionInAnchor) {
96 // For example, position is before E, F.
71 ASSERT(Strategy::parent(*m_nodeAfterPositionInAnchor) == m_anchorNode); 97 ASSERT(Strategy::parent(*m_nodeAfterPositionInAnchor) == m_anchorNode);
72 return PositionTemplate<Strategy>::inParentBeforeNode(*m_nodeAfterPositi onInAnchor); 98 ASSERT(m_offsetsInAnchorNode[m_depthToAnchorNode] >= 0);
99 // FIXME: This should be
yosin_UTC9 2015/10/21 06:01:15 s/FIXME/TODO(yoichio)/
yoichio 2015/10/22 04:33:57 Done.
100 // PositionTemplate<Strategy>(m_anchorNode, PositionAnchorType::BeforeAn chor);
yosin_UTC9 2015/10/21 06:01:15 Not sure meaning of this comment. Do you try to sa
yoichio 2015/10/22 04:33:57 Done.
101 return PositionTemplate<Strategy>(m_anchorNode, m_offsetsInAnchorNode[m_ depthToAnchorNode]);
73 } 102 }
74 if (Strategy::hasChildren(*m_anchorNode)) 103 if (Strategy::hasChildren(*m_anchorNode))
104 // For example, position is the end of B.
75 return PositionTemplate<Strategy>::lastPositionInOrAfterNode(m_anchorNod e); 105 return PositionTemplate<Strategy>::lastPositionInOrAfterNode(m_anchorNod e);
76 if (m_anchorNode->isTextNode()) 106 if (m_anchorNode->isTextNode())
77 return PositionTemplate<Strategy>(m_anchorNode, m_offsetInAnchor); 107 return PositionTemplate<Strategy>(m_anchorNode, m_offsetInAnchor);
78 if (m_offsetInAnchor) 108 if (m_offsetInAnchor)
109 // For example, position is after G.
79 return PositionTemplate<Strategy>(m_anchorNode, PositionAnchorType::Afte rAnchor); 110 return PositionTemplate<Strategy>(m_anchorNode, PositionAnchorType::Afte rAnchor);
111 // For example, position is before G.
80 return PositionTemplate<Strategy>(m_anchorNode, PositionAnchorType::BeforeAn chor); 112 return PositionTemplate<Strategy>(m_anchorNode, PositionAnchorType::BeforeAn chor);
81 } 113 }
82 114
83 template <typename Strategy> 115 template <typename Strategy>
84 void PositionIteratorAlgorithm<Strategy>::increment() 116 void PositionIteratorAlgorithm<Strategy>::increment()
85 { 117 {
86 if (!m_anchorNode) 118 if (!m_anchorNode)
87 return; 119 return;
120 ASSERT(m_domTreeVersion == m_anchorNode->document().domTreeVersion());
88 121
122 // Assume that we have the following DOM tree:
123 // A
124 // |-B
125 // | |-E
126 // | +-F
127 // |
128 // |-C
129 // +-D
130 // |-G
131 // +-H
132 // Let |anchor| as |m_anchorNode| and
133 // |child| as |m_nodeAfterPositionInAnchor|.
89 if (m_nodeAfterPositionInAnchor) { 134 if (m_nodeAfterPositionInAnchor) {
135 // Case #1.
136 // This is a point just before |child|.
137 // Let |anchor| is A and |child| is B,
138 // then next |anchor| is B and |child| is E.
90 m_anchorNode = m_nodeAfterPositionInAnchor; 139 m_anchorNode = m_nodeAfterPositionInAnchor;
91 m_nodeAfterPositionInAnchor = Strategy::firstChild(*m_anchorNode); 140 m_nodeAfterPositionInAnchor = Strategy::firstChild(*m_anchorNode);
92 m_offsetInAnchor = 0; 141 m_offsetInAnchor = 0;
142 // Increment depth intializing with 0.
143 m_depthToAnchorNode++;
yosin_UTC9 2015/10/21 06:01:16 nit: prefer prefix form: |++m_depthToAnchorNode|.
yoichio 2015/10/22 04:33:57 Done.
144 if (m_depthToAnchorNode >= m_offsetsInAnchorNode.size())
yosin_UTC9 2015/10/21 06:01:16 m_depthToAnchorNode == m_offsetsInAnchorNode.size(
yoichio 2015/10/22 04:33:58 Done.
145 m_offsetsInAnchorNode.append(0);
yosin_UTC9 2015/10/21 06:01:15 why zero?
yoichio 2015/10/22 04:33:57 Because m_nodeAfterPositionInAnchor is firstChild
146 else
147 m_offsetsInAnchorNode[m_depthToAnchorNode] = 0;
93 return; 148 return;
94 } 149 }
95 150
96 if (m_anchorNode->layoutObject() && !Strategy::hasChildren(*m_anchorNode) && m_offsetInAnchor < Strategy::lastOffsetForEditing(m_anchorNode)) { 151 if (m_anchorNode->layoutObject() && !Strategy::hasChildren(*m_anchorNode) && m_offsetInAnchor < Strategy::lastOffsetForEditing(m_anchorNode)) {
152 // Case #2. This is the next of Case #1 or #2 itself.
153 // Position is (|anchor|, |m_offsetInAchor|).
154 // In this case |anchor| is a leaf(E,F,C,G or H) and
155 // |m_offsetInAnchor| is not on the end of |anchor|.
156 // Then just increment |m_offsetInAnchor|.
97 m_offsetInAnchor = uncheckedNextOffset(m_anchorNode, m_offsetInAnchor); 157 m_offsetInAnchor = uncheckedNextOffset(m_anchorNode, m_offsetInAnchor);
98 } else { 158 } else {
159 // Case #3. This is the next of Case #2 or #3.
160 // Position is the end of |anchor|.
161 // 3-a. If |anchor| has next sibling (let E),
162 // next |anchor| is B and |child| is F (next is Case #1.)
163 // 3-b. If |anchor| doesn't have next sibling (let F),
164 // next |anchor| is B and |child| is null. (next is Case #3.)
99 m_nodeAfterPositionInAnchor = m_anchorNode; 165 m_nodeAfterPositionInAnchor = m_anchorNode;
100 m_anchorNode = Strategy::parent(*m_nodeAfterPositionInAnchor); 166 m_anchorNode = Strategy::parent(*m_nodeAfterPositionInAnchor);
167 if (!m_anchorNode)
168 return;
169 ASSERT(m_depthToAnchorNode > 0);
170 m_depthToAnchorNode--;
yosin_UTC9 2015/10/21 06:01:16 nit: prefer prefix form.
yoichio 2015/10/22 04:33:58 Done.
171 // Increment offset of |child| or initialize if it have never been
172 // used.
173 if (m_offsetsInAnchorNode[m_depthToAnchorNode] == -1)
174 m_offsetsInAnchorNode[m_depthToAnchorNode] = Strategy::index(*m_node AfterPositionInAnchor) + 1;
175 else
176 m_offsetsInAnchorNode[m_depthToAnchorNode]++;
yosin_UTC9 2015/10/21 06:01:16 nit: prefer prefix form.
yoichio 2015/10/22 04:33:57 Done.
101 m_nodeAfterPositionInAnchor = Strategy::nextSibling(*m_nodeAfterPosition InAnchor); 177 m_nodeAfterPositionInAnchor = Strategy::nextSibling(*m_nodeAfterPosition InAnchor);
102 m_offsetInAnchor = 0; 178 m_offsetInAnchor = 0;
103 } 179 }
104 } 180 }
105 181
106 template <typename Strategy> 182 template <typename Strategy>
107 void PositionIteratorAlgorithm<Strategy>::decrement() 183 void PositionIteratorAlgorithm<Strategy>::decrement()
108 { 184 {
109 if (!m_anchorNode) 185 if (!m_anchorNode)
110 return; 186 return;
187 ASSERT(m_domTreeVersion == m_anchorNode->document().domTreeVersion());
111 188
189 // Assume that we have the following DOM tree:
190 // A
191 // |-B
192 // | |-E
193 // | +-F
194 // |
195 // |-C
196 // +-D
197 // |-G
198 // +-H
199 // Let |anchor| as |m_anchorNode| and
200 // |child| as |m_nodeAfterPositionInAnchor|.
201 // decrement() is complex but logically reverse of increment(), of course:)
112 if (m_nodeAfterPositionInAnchor) { 202 if (m_nodeAfterPositionInAnchor) {
113 m_anchorNode = Strategy::previousSibling(*m_nodeAfterPositionInAnchor); 203 m_anchorNode = Strategy::previousSibling(*m_nodeAfterPositionInAnchor);
114 if (m_anchorNode) { 204 if (m_anchorNode) {
205 // Case #1-a. This is a revese of increment()::Case#3-a.
206 // |child| has a previous sibling.
207 // Let |anchor| is B and |child| is F,
208 // next |anchor| is E and |child| is null.
115 m_nodeAfterPositionInAnchor = nullptr; 209 m_nodeAfterPositionInAnchor = nullptr;
116 m_offsetInAnchor = Strategy::hasChildren(*m_anchorNode) ? 0 : Strate gy::lastOffsetForEditing(m_anchorNode); 210 m_offsetInAnchor = Strategy::hasChildren(*m_anchorNode) ? 0 : Strate gy::lastOffsetForEditing(m_anchorNode);
211 // Decrement offset of |child| or initialize if it have never been
212 // used.
213 if (m_offsetsInAnchorNode[m_depthToAnchorNode] == -1)
214 m_offsetsInAnchorNode[m_depthToAnchorNode] = Strategy::index(*m_ nodeAfterPositionInAnchor);
215 else
216 m_offsetsInAnchorNode[m_depthToAnchorNode]--;
217 ASSERT(m_offsetsInAnchorNode[m_depthToAnchorNode] >= 0);
218 // Increment depth intializing with last offset.
219 m_depthToAnchorNode++;
220 if (m_depthToAnchorNode >= m_offsetsInAnchorNode.size())
221 m_offsetsInAnchorNode.append(m_offsetInAnchor);
222 else
223 m_offsetsInAnchorNode[m_depthToAnchorNode] = m_offsetInAnchor;
117 } else { 224 } else {
225 // Case #1-b. This is a revese of increment()::Case#1.
226 // |child| doesn't have a previous sibling.
227 // Let |anchor| is B and |child| is E,
228 // next |anchor| is A and |child| is B.
118 m_nodeAfterPositionInAnchor = Strategy::parent(*m_nodeAfterPositionI nAnchor); 229 m_nodeAfterPositionInAnchor = Strategy::parent(*m_nodeAfterPositionI nAnchor);
119 m_anchorNode = Strategy::parent(*m_nodeAfterPositionInAnchor); 230 m_anchorNode = Strategy::parent(*m_nodeAfterPositionInAnchor);
231 if (!m_anchorNode)
232 return;
120 m_offsetInAnchor = 0; 233 m_offsetInAnchor = 0;
234 // Decrement depth and intialize if needs.
235 ASSERT(m_depthToAnchorNode > 0);
236 m_depthToAnchorNode--;
237 if (m_offsetsInAnchorNode[m_depthToAnchorNode] == -1)
238 m_offsetsInAnchorNode[m_depthToAnchorNode] = Strategy::index(*m_ nodeAfterPositionInAnchor);
121 } 239 }
122 return; 240 return;
123 } 241 }
124 242
125 if (Strategy::hasChildren(*m_anchorNode)) { 243 if (Strategy::hasChildren(*m_anchorNode)) {
244 // Case #2. This is a reverse of increment()::Case3-b.
245 // Let |anchor| is B, next |anchor| is F.
126 m_anchorNode = Strategy::lastChild(*m_anchorNode); 246 m_anchorNode = Strategy::lastChild(*m_anchorNode);
127 m_offsetInAnchor = Strategy::hasChildren(*m_anchorNode)? 0 : Strategy::l astOffsetForEditing(m_anchorNode); 247 m_offsetInAnchor = Strategy::hasChildren(*m_anchorNode)? 0 : Strategy::l astOffsetForEditing(m_anchorNode);
248 // Decrement depth initializing with -1 because
249 // |m_nodeAfterPositionInAnchor| is null so still unneeded.
250 if (m_depthToAnchorNode >= m_offsetsInAnchorNode.size())
251 m_offsetsInAnchorNode.append(-1);
252 else
253 m_offsetsInAnchorNode[m_depthToAnchorNode] = -1;
254 m_depthToAnchorNode++;
128 } else { 255 } else {
129 if (m_offsetInAnchor && m_anchorNode->layoutObject()) { 256 if (m_offsetInAnchor && m_anchorNode->layoutObject()) {
257 // Case #3-a. This is a reverse of increment()::Case#2.
258 // In this case |anchor| is a leaf(E,F,C,G or H) and
259 // |m_offsetInAnchor| is not on the beginning of |anchor|.
260 // Then just decrement |m_offsetInAnchor|.
130 m_offsetInAnchor = uncheckedPreviousOffset(m_anchorNode, m_offsetInA nchor); 261 m_offsetInAnchor = uncheckedPreviousOffset(m_anchorNode, m_offsetInA nchor);
131 } else { 262 } else {
263 // Case #3-b. This is a reverse of increment()::Case#1.
264 // In this case |anchor| is a leaf(E,F,C,G or H) and
265 // |m_offsetInAnchor| is on the beginning of |anchor|.
266 // Let |anchor| is E,
267 // next |anchor| is B and |child| is E.
132 m_nodeAfterPositionInAnchor = m_anchorNode; 268 m_nodeAfterPositionInAnchor = m_anchorNode;
133 m_anchorNode = Strategy::parent(*m_anchorNode); 269 m_anchorNode = Strategy::parent(*m_anchorNode);
270 if (!m_anchorNode)
271 return;
272 ASSERT(m_depthToAnchorNode > 0);
273 m_depthToAnchorNode--;
274 if (m_offsetsInAnchorNode[m_depthToAnchorNode] == -1)
275 m_offsetsInAnchorNode[m_depthToAnchorNode] = Strategy::index(*m_ nodeAfterPositionInAnchor);
134 } 276 }
135 } 277 }
136 } 278 }
137 279
138 template <typename Strategy> 280 template <typename Strategy>
139 bool PositionIteratorAlgorithm<Strategy>::atStart() const 281 bool PositionIteratorAlgorithm<Strategy>::atStart() const
140 { 282 {
141 if (!m_anchorNode) 283 if (!m_anchorNode)
142 return true; 284 return true;
285 ASSERT(m_domTreeVersion == m_anchorNode->document().domTreeVersion());
143 if (Strategy::parent(*m_anchorNode)) 286 if (Strategy::parent(*m_anchorNode))
144 return false; 287 return false;
145 return (!Strategy::hasChildren(*m_anchorNode) && !m_offsetInAnchor) || (m_no deAfterPositionInAnchor && !Strategy::previousSibling(*m_nodeAfterPositionInAnch or)); 288 return (!Strategy::hasChildren(*m_anchorNode) && !m_offsetInAnchor) || (m_no deAfterPositionInAnchor && !Strategy::previousSibling(*m_nodeAfterPositionInAnch or));
146 } 289 }
147 290
148 template <typename Strategy> 291 template <typename Strategy>
149 bool PositionIteratorAlgorithm<Strategy>::atEnd() const 292 bool PositionIteratorAlgorithm<Strategy>::atEnd() const
150 { 293 {
151 if (!m_anchorNode) 294 if (!m_anchorNode)
152 return true; 295 return true;
296 ASSERT(m_domTreeVersion == m_anchorNode->document().domTreeVersion());
153 if (m_nodeAfterPositionInAnchor) 297 if (m_nodeAfterPositionInAnchor)
154 return false; 298 return false;
155 return !Strategy::parent(*m_anchorNode) && (Strategy::hasChildren(*m_anchorN ode) || m_offsetInAnchor >= Strategy::lastOffsetForEditing(m_anchorNode)); 299 return !Strategy::parent(*m_anchorNode) && (Strategy::hasChildren(*m_anchorN ode) || m_offsetInAnchor >= Strategy::lastOffsetForEditing(m_anchorNode));
156 } 300 }
157 301
158 template <typename Strategy> 302 template <typename Strategy>
159 bool PositionIteratorAlgorithm<Strategy>::atStartOfNode() const 303 bool PositionIteratorAlgorithm<Strategy>::atStartOfNode() const
160 { 304 {
161 if (!m_anchorNode) 305 if (!m_anchorNode)
162 return true; 306 return true;
307 ASSERT(m_domTreeVersion == m_anchorNode->document().domTreeVersion());
163 if (!m_nodeAfterPositionInAnchor) 308 if (!m_nodeAfterPositionInAnchor)
164 return !Strategy::hasChildren(*m_anchorNode) && !m_offsetInAnchor; 309 return !Strategy::hasChildren(*m_anchorNode) && !m_offsetInAnchor;
165 return !Strategy::previousSibling(*m_nodeAfterPositionInAnchor); 310 return !Strategy::previousSibling(*m_nodeAfterPositionInAnchor);
166 } 311 }
167 312
168 template <typename Strategy> 313 template <typename Strategy>
169 bool PositionIteratorAlgorithm<Strategy>::atEndOfNode() const 314 bool PositionIteratorAlgorithm<Strategy>::atEndOfNode() const
170 { 315 {
171 if (!m_anchorNode) 316 if (!m_anchorNode)
172 return true; 317 return true;
318 ASSERT(m_domTreeVersion == m_anchorNode->document().domTreeVersion());
173 if (m_nodeAfterPositionInAnchor) 319 if (m_nodeAfterPositionInAnchor)
174 return false; 320 return false;
175 return Strategy::hasChildren(*m_anchorNode) || m_offsetInAnchor >= Strategy: :lastOffsetForEditing(m_anchorNode); 321 return Strategy::hasChildren(*m_anchorNode) || m_offsetInAnchor >= Strategy: :lastOffsetForEditing(m_anchorNode);
176 } 322 }
177 323
178 template class PositionIteratorAlgorithm<EditingStrategy>; 324 template class PositionIteratorAlgorithm<EditingStrategy>;
179 template class PositionIteratorAlgorithm<EditingInComposedTreeStrategy>; 325 template class PositionIteratorAlgorithm<EditingInComposedTreeStrategy>;
180 326
181 } // namespace blink 327 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698