Chromium Code Reviews| 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 15 matching lines...) Expand all Loading... | |
| 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()) | |
| 36 { | 37 { |
| 38 m_depthToAnchorNode = 0; | |
|
hajimehoshi
2015/10/08 04:57:27
m_depthToAnchorNode can be initialized the same wa
yoichio
2015/10/21 04:35:04
Done.
| |
| 39 for (Node* node = Strategy::parent(*anchorNode); node; node = Strategy::pare nt(*node)) { | |
| 40 // Each m_offsetsInAnchorNode[offset] should be index of node, | |
| 41 // but let delay to calculate the index until it is needed. | |
|
hajimehoshi
2015/10/08 04:57:27
let's?
yoichio
2015/10/21 04:35:05
Done.
| |
| 42 m_offsetsInAnchorNode.append(-1); | |
| 43 m_depthToAnchorNode++; | |
| 44 } | |
| 45 if (m_nodeAfterPositionInAnchor) | |
| 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) | |
| 49 { | 60 { |
|
hajimehoshi
2015/10/08 04:57:27
m_depthToAnchorNode is not initialized in this cas
yoichio
2015/10/21 04:35:05
No. Done.
| |
| 50 } | 61 } |
| 51 | 62 |
| 52 template <typename Strategy> | 63 template <typename Strategy> |
| 53 PositionTemplate<Strategy> PositionIteratorAlgorithm<Strategy>::deprecatedComput ePosition() const | 64 PositionTemplate<Strategy> PositionIteratorAlgorithm<Strategy>::deprecatedComput ePosition() const |
| 54 { | 65 { |
| 66 ASSERT(m_domTreeVersion == m_anchorNode->document().domTreeVersion()); | |
| 55 if (m_nodeAfterPositionInAnchor) { | 67 if (m_nodeAfterPositionInAnchor) { |
| 56 ASSERT(Strategy::parent(*m_nodeAfterPositionInAnchor) == m_anchorNode); | 68 ASSERT(Strategy::parent(*m_nodeAfterPositionInAnchor) == m_anchorNode); |
| 69 ASSERT(m_offsetsInAnchorNode[m_depthToAnchorNode] >= 0); | |
| 57 // FIXME: This check is inadaquete because any ancestor could be ignored by editing | 70 // FIXME: This check is inadaquete because any ancestor could be ignored by editing |
| 58 if (Strategy::editingIgnoresContent(Strategy::parent(*m_nodeAfterPositio nInAnchor))) | 71 if (Strategy::editingIgnoresContent(Strategy::parent(*m_nodeAfterPositio nInAnchor))) |
| 59 return PositionTemplate<Strategy>::beforeNode(m_anchorNode); | 72 return PositionTemplate<Strategy>::beforeNode(m_anchorNode); |
| 60 return PositionTemplate<Strategy>::inParentBeforeNode(*m_nodeAfterPositi onInAnchor); | 73 return PositionTemplate<Strategy>(m_anchorNode, m_offsetsInAnchorNode[m_ depthToAnchorNode]); |
| 61 } | 74 } |
| 62 if (Strategy::hasChildren(*m_anchorNode)) | 75 if (Strategy::hasChildren(*m_anchorNode)) |
| 63 return PositionTemplate<Strategy>::lastPositionInOrAfterNode(m_anchorNod e); | 76 return PositionTemplate<Strategy>::lastPositionInOrAfterNode(m_anchorNod e); |
| 64 return PositionTemplate<Strategy>::editingPositionOf(m_anchorNode, m_offsetI nAnchor); | 77 return PositionTemplate<Strategy>::editingPositionOf(m_anchorNode, m_offsetI nAnchor); |
| 65 } | 78 } |
| 66 | 79 |
| 67 template <typename Strategy> | 80 template <typename Strategy> |
| 68 PositionTemplate<Strategy> PositionIteratorAlgorithm<Strategy>::computePosition( ) const | 81 PositionTemplate<Strategy> PositionIteratorAlgorithm<Strategy>::computePosition( ) const |
| 69 { | 82 { |
| 83 ASSERT(m_domTreeVersion == m_anchorNode->document().domTreeVersion()); | |
| 70 if (m_nodeAfterPositionInAnchor) { | 84 if (m_nodeAfterPositionInAnchor) { |
| 71 ASSERT(Strategy::parent(*m_nodeAfterPositionInAnchor) == m_anchorNode); | 85 ASSERT(Strategy::parent(*m_nodeAfterPositionInAnchor) == m_anchorNode); |
| 72 return PositionTemplate<Strategy>::inParentBeforeNode(*m_nodeAfterPositi onInAnchor); | 86 ASSERT(m_offsetsInAnchorNode[m_depthToAnchorNode] >= 0); |
| 87 return PositionTemplate<Strategy>(m_anchorNode, m_offsetsInAnchorNode[m_ depthToAnchorNode]); | |
| 73 } | 88 } |
| 74 if (Strategy::hasChildren(*m_anchorNode)) | 89 if (Strategy::hasChildren(*m_anchorNode)) |
| 75 return PositionTemplate<Strategy>::lastPositionInOrAfterNode(m_anchorNod e); | 90 return PositionTemplate<Strategy>::lastPositionInOrAfterNode(m_anchorNod e); |
| 76 if (m_anchorNode->isTextNode()) | 91 if (m_anchorNode->isTextNode()) |
| 77 return PositionTemplate<Strategy>(m_anchorNode, m_offsetInAnchor); | 92 return PositionTemplate<Strategy>(m_anchorNode, m_offsetInAnchor); |
| 78 if (m_offsetInAnchor) | 93 if (m_offsetInAnchor) |
| 79 return PositionTemplate<Strategy>(m_anchorNode, PositionAnchorType::Afte rAnchor); | 94 return PositionTemplate<Strategy>(m_anchorNode, PositionAnchorType::Afte rAnchor); |
| 80 return PositionTemplate<Strategy>(m_anchorNode, PositionAnchorType::BeforeAn chor); | 95 return PositionTemplate<Strategy>(m_anchorNode, PositionAnchorType::BeforeAn chor); |
| 81 } | 96 } |
| 82 | 97 |
| 83 template <typename Strategy> | 98 template <typename Strategy> |
| 84 void PositionIteratorAlgorithm<Strategy>::increment() | 99 void PositionIteratorAlgorithm<Strategy>::increment() |
| 85 { | 100 { |
| 86 if (!m_anchorNode) | 101 if (!m_anchorNode) |
| 87 return; | 102 return; |
| 103 ASSERT(m_domTreeVersion == m_anchorNode->document().domTreeVersion()); | |
| 88 | 104 |
| 105 // We have following DOM tree: | |
|
hajimehoshi
2015/10/08 04:57:27
Assume that we have the following DOM tree:
yoichio
2015/10/21 04:35:05
Done.
| |
| 106 // A | |
| 107 // |-B | |
| 108 // | |-E | |
| 109 // | +-F | |
| 110 // | | |
| 111 // |-C | |
| 112 // +-D | |
| 113 // |-G | |
| 114 // +-H | |
| 115 // Let |anchor| as |m_anchorNode| and | |
|
hajimehoshi
2015/10/08 04:57:27
No breaking line here.
yoichio
2015/10/21 04:35:04
No. I prefer comment in 80 columns.
| |
| 116 // |child| as |m_nodeAfterPositionInAnchor|. | |
| 89 if (m_nodeAfterPositionInAnchor) { | 117 if (m_nodeAfterPositionInAnchor) { |
| 118 // Case #1. | |
| 119 // This is a point just before |child|. | |
| 120 // Let |anchor| is A and |child| is B, | |
|
hajimehoshi
2015/10/08 04:57:27
I prefer least breaking-lines, so in this case, I
yoichio
2015/10/21 04:35:05
Ditto.
| |
| 121 // then next |anchor| is B and |child| is E. | |
| 90 m_anchorNode = m_nodeAfterPositionInAnchor; | 122 m_anchorNode = m_nodeAfterPositionInAnchor; |
| 91 m_nodeAfterPositionInAnchor = Strategy::firstChild(*m_anchorNode); | 123 m_nodeAfterPositionInAnchor = Strategy::firstChild(*m_anchorNode); |
| 92 m_offsetInAnchor = 0; | 124 m_offsetInAnchor = 0; |
| 125 // Increment depth intializing with 0. | |
| 126 m_depthToAnchorNode++; | |
| 127 if (m_depthToAnchorNode >= m_offsetsInAnchorNode.size()) | |
| 128 m_offsetsInAnchorNode.append(0); | |
| 129 else | |
| 130 m_offsetsInAnchorNode[m_depthToAnchorNode] = 0; | |
| 93 return; | 131 return; |
| 94 } | 132 } |
| 95 | 133 |
| 96 if (m_anchorNode->layoutObject() && !Strategy::hasChildren(*m_anchorNode) && m_offsetInAnchor < Strategy::lastOffsetForEditing(m_anchorNode)) { | 134 if (m_anchorNode->layoutObject() && !Strategy::hasChildren(*m_anchorNode) && m_offsetInAnchor < Strategy::lastOffsetForEditing(m_anchorNode)) { |
| 135 // Case #2. This is the next of Case #1 or #2 itself. | |
| 136 // Position is (|anchor|, |m_offsetInAchor|). | |
| 137 // In this case |anchor| is a leaf(E,F,C,G or H) and | |
| 138 // |m_offsetInAnchor| is not on the end of |anchor|. | |
| 139 // Then just increment |m_offsetInAnchor|. | |
| 97 m_offsetInAnchor = uncheckedNextOffset(m_anchorNode, m_offsetInAnchor); | 140 m_offsetInAnchor = uncheckedNextOffset(m_anchorNode, m_offsetInAnchor); |
| 98 } else { | 141 } else { |
| 142 // Case #3. This is the next of Case #2 or #3. | |
| 143 // Position is the end of |anchor|. | |
| 144 // 3-a. If |anchor| has next sibling (let E), | |
| 145 // next |anchor| is B and |child| is F (next is Case #1.) | |
| 146 // 3-b. If |anchor| doesn't have next sibling (let F), | |
| 147 // next |anchor| is B and |child| is null. (next is Case #3.) | |
| 99 m_nodeAfterPositionInAnchor = m_anchorNode; | 148 m_nodeAfterPositionInAnchor = m_anchorNode; |
| 100 m_anchorNode = Strategy::parent(*m_nodeAfterPositionInAnchor); | 149 m_anchorNode = Strategy::parent(*m_nodeAfterPositionInAnchor); |
| 150 if (!m_anchorNode) | |
| 151 return; | |
| 152 ASSERT(m_depthToAnchorNode > 0); | |
| 153 m_depthToAnchorNode--; | |
| 154 // Increment offset of |child| or initialize if it have never been | |
| 155 // used. | |
| 156 if (m_offsetsInAnchorNode[m_depthToAnchorNode] == -1) | |
| 157 m_offsetsInAnchorNode[m_depthToAnchorNode] = Strategy::index(*m_node AfterPositionInAnchor) + 1; | |
| 158 else | |
| 159 m_offsetsInAnchorNode[m_depthToAnchorNode]++; | |
| 101 m_nodeAfterPositionInAnchor = Strategy::nextSibling(*m_nodeAfterPosition InAnchor); | 160 m_nodeAfterPositionInAnchor = Strategy::nextSibling(*m_nodeAfterPosition InAnchor); |
| 102 m_offsetInAnchor = 0; | 161 m_offsetInAnchor = 0; |
| 103 } | 162 } |
| 104 } | 163 } |
| 105 | 164 |
| 106 template <typename Strategy> | 165 template <typename Strategy> |
| 107 void PositionIteratorAlgorithm<Strategy>::decrement() | 166 void PositionIteratorAlgorithm<Strategy>::decrement() |
| 108 { | 167 { |
| 109 if (!m_anchorNode) | 168 if (!m_anchorNode) |
| 110 return; | 169 return; |
| 170 ASSERT(m_domTreeVersion == m_anchorNode->document().domTreeVersion()); | |
| 111 | 171 |
| 172 // We have following DOM tree: | |
|
hajimehoshi
2015/10/08 04:57:27
ditto
yoichio
2015/10/21 04:35:05
Done.
| |
| 173 // A | |
| 174 // |-B | |
| 175 // | |-E | |
| 176 // | +-F | |
| 177 // | | |
| 178 // |-C | |
| 179 // +-D | |
| 180 // |-G | |
| 181 // +-H | |
| 182 // Let |anchor| as |m_anchorNode| and | |
| 183 // |child| as |m_nodeAfterPositionInAnchor|. | |
| 184 // decrement() is complex but logically reverse of increment(), of course:) | |
| 112 if (m_nodeAfterPositionInAnchor) { | 185 if (m_nodeAfterPositionInAnchor) { |
| 113 m_anchorNode = Strategy::previousSibling(*m_nodeAfterPositionInAnchor); | 186 m_anchorNode = Strategy::previousSibling(*m_nodeAfterPositionInAnchor); |
| 114 if (m_anchorNode) { | 187 if (m_anchorNode) { |
| 188 // Case #1-a. This is a revese of increment()::Case#3-a. | |
| 189 // |child| has a previous sibling. | |
| 190 // Let |anchor| is B and |child| is F, | |
| 191 // next |anchor| is E and |child| is null. | |
| 115 m_nodeAfterPositionInAnchor = nullptr; | 192 m_nodeAfterPositionInAnchor = nullptr; |
| 116 m_offsetInAnchor = Strategy::hasChildren(*m_anchorNode) ? 0 : Strate gy::lastOffsetForEditing(m_anchorNode); | 193 m_offsetInAnchor = Strategy::hasChildren(*m_anchorNode) ? 0 : Strate gy::lastOffsetForEditing(m_anchorNode); |
| 194 // Decrement offset of |child| or initialize if it have never been | |
| 195 // used. | |
| 196 if (m_offsetsInAnchorNode[m_depthToAnchorNode] == -1) | |
| 197 m_offsetsInAnchorNode[m_depthToAnchorNode] = Strategy::index(*m_ nodeAfterPositionInAnchor); | |
| 198 else | |
| 199 m_offsetsInAnchorNode[m_depthToAnchorNode]--; | |
| 200 ASSERT(m_offsetsInAnchorNode[m_depthToAnchorNode] >= 0); | |
| 201 // Increment depth intializing with last offset. | |
| 202 m_depthToAnchorNode++; | |
| 203 if (m_depthToAnchorNode >= m_offsetsInAnchorNode.size()) | |
| 204 m_offsetsInAnchorNode.append(m_offsetInAnchor); | |
| 205 else | |
| 206 m_offsetsInAnchorNode[m_depthToAnchorNode] = m_offsetInAnchor; | |
| 117 } else { | 207 } else { |
| 208 // Case #1-b. This is a revese of increment()::Case#1. | |
| 209 // |child| doesn't have a previous sibling. | |
| 210 // Let |anchor| is B and |child| is E, | |
| 211 // next |anchor| is A and |child| is B. | |
| 118 m_nodeAfterPositionInAnchor = Strategy::parent(*m_nodeAfterPositionI nAnchor); | 212 m_nodeAfterPositionInAnchor = Strategy::parent(*m_nodeAfterPositionI nAnchor); |
| 119 m_anchorNode = Strategy::parent(*m_nodeAfterPositionInAnchor); | 213 m_anchorNode = Strategy::parent(*m_nodeAfterPositionInAnchor); |
| 214 if (!m_anchorNode) | |
| 215 return; | |
| 120 m_offsetInAnchor = 0; | 216 m_offsetInAnchor = 0; |
| 217 // Decrement depth and intialize if needs. | |
| 218 ASSERT(m_depthToAnchorNode > 0); | |
| 219 m_depthToAnchorNode--; | |
| 220 if (m_offsetsInAnchorNode[m_depthToAnchorNode] == -1) | |
| 221 m_offsetsInAnchorNode[m_depthToAnchorNode] = Strategy::index(*m_ nodeAfterPositionInAnchor); | |
| 121 } | 222 } |
| 122 return; | 223 return; |
| 123 } | 224 } |
| 124 | 225 |
| 125 if (Strategy::hasChildren(*m_anchorNode)) { | 226 if (Strategy::hasChildren(*m_anchorNode)) { |
| 227 // Case #2. This is a reverse of increment()::Case3-b. | |
| 228 // Let |anchor| is B, next |anchor| is F. | |
| 126 m_anchorNode = Strategy::lastChild(*m_anchorNode); | 229 m_anchorNode = Strategy::lastChild(*m_anchorNode); |
| 127 m_offsetInAnchor = Strategy::hasChildren(*m_anchorNode)? 0 : Strategy::l astOffsetForEditing(m_anchorNode); | 230 m_offsetInAnchor = Strategy::hasChildren(*m_anchorNode)? 0 : Strategy::l astOffsetForEditing(m_anchorNode); |
| 231 // Decrement depth initializing with -1 because | |
| 232 // |m_nodeAfterPositionInAnchor| is null so still unneeded. | |
| 233 if (m_depthToAnchorNode >= m_offsetsInAnchorNode.size()) | |
| 234 m_offsetsInAnchorNode.append(-1); | |
| 235 else | |
| 236 m_offsetsInAnchorNode[m_depthToAnchorNode] = -1; | |
| 237 m_depthToAnchorNode++; | |
| 128 } else { | 238 } else { |
| 129 if (m_offsetInAnchor && m_anchorNode->layoutObject()) { | 239 if (m_offsetInAnchor && m_anchorNode->layoutObject()) { |
| 240 // Case #3-a. This is a reverse of increment()::Case#2. | |
| 241 // In this case |anchor| is a leaf(E,F,C,G or H) and | |
| 242 // |m_offsetInAnchor| is not on the beginning of |anchor|. | |
| 243 // Then just decrement |m_offsetInAnchor|. | |
| 130 m_offsetInAnchor = uncheckedPreviousOffset(m_anchorNode, m_offsetInA nchor); | 244 m_offsetInAnchor = uncheckedPreviousOffset(m_anchorNode, m_offsetInA nchor); |
| 131 } else { | 245 } else { |
| 246 // Case #3-b. This is a reverse of increment()::Case#1. | |
| 247 // In this case |anchor| is a leaf(E,F,C,G or H) and | |
| 248 // |m_offsetInAnchor| is on the beginning of |anchor|. | |
| 249 // Let |anchor| is E, | |
| 250 // next |anchor| is B and |child| is E. | |
| 132 m_nodeAfterPositionInAnchor = m_anchorNode; | 251 m_nodeAfterPositionInAnchor = m_anchorNode; |
| 133 m_anchorNode = Strategy::parent(*m_anchorNode); | 252 m_anchorNode = Strategy::parent(*m_anchorNode); |
| 253 if (!m_anchorNode) | |
| 254 return; | |
| 255 ASSERT(m_depthToAnchorNode > 0); | |
| 256 m_depthToAnchorNode--; | |
| 257 if (m_offsetsInAnchorNode[m_depthToAnchorNode] == -1) | |
| 258 m_offsetsInAnchorNode[m_depthToAnchorNode] = Strategy::index(*m_ nodeAfterPositionInAnchor); | |
| 134 } | 259 } |
| 135 } | 260 } |
| 136 } | 261 } |
| 137 | 262 |
| 138 template <typename Strategy> | 263 template <typename Strategy> |
| 139 bool PositionIteratorAlgorithm<Strategy>::atStart() const | 264 bool PositionIteratorAlgorithm<Strategy>::atStart() const |
| 140 { | 265 { |
| 141 if (!m_anchorNode) | 266 if (!m_anchorNode) |
| 142 return true; | 267 return true; |
| 268 ASSERT(m_domTreeVersion == m_anchorNode->document().domTreeVersion()); | |
| 143 if (Strategy::parent(*m_anchorNode)) | 269 if (Strategy::parent(*m_anchorNode)) |
| 144 return false; | 270 return false; |
| 145 return (!Strategy::hasChildren(*m_anchorNode) && !m_offsetInAnchor) || (m_no deAfterPositionInAnchor && !Strategy::previousSibling(*m_nodeAfterPositionInAnch or)); | 271 return (!Strategy::hasChildren(*m_anchorNode) && !m_offsetInAnchor) || (m_no deAfterPositionInAnchor && !Strategy::previousSibling(*m_nodeAfterPositionInAnch or)); |
| 146 } | 272 } |
| 147 | 273 |
| 148 template <typename Strategy> | 274 template <typename Strategy> |
| 149 bool PositionIteratorAlgorithm<Strategy>::atEnd() const | 275 bool PositionIteratorAlgorithm<Strategy>::atEnd() const |
| 150 { | 276 { |
| 151 if (!m_anchorNode) | 277 if (!m_anchorNode) |
| 152 return true; | 278 return true; |
| 279 ASSERT(m_domTreeVersion == m_anchorNode->document().domTreeVersion()); | |
| 153 if (m_nodeAfterPositionInAnchor) | 280 if (m_nodeAfterPositionInAnchor) |
| 154 return false; | 281 return false; |
| 155 return !Strategy::parent(*m_anchorNode) && (Strategy::hasChildren(*m_anchorN ode) || m_offsetInAnchor >= Strategy::lastOffsetForEditing(m_anchorNode)); | 282 return !Strategy::parent(*m_anchorNode) && (Strategy::hasChildren(*m_anchorN ode) || m_offsetInAnchor >= Strategy::lastOffsetForEditing(m_anchorNode)); |
| 156 } | 283 } |
| 157 | 284 |
| 158 template <typename Strategy> | 285 template <typename Strategy> |
| 159 bool PositionIteratorAlgorithm<Strategy>::atStartOfNode() const | 286 bool PositionIteratorAlgorithm<Strategy>::atStartOfNode() const |
| 160 { | 287 { |
| 161 if (!m_anchorNode) | 288 if (!m_anchorNode) |
| 162 return true; | 289 return true; |
| 290 ASSERT(m_domTreeVersion == m_anchorNode->document().domTreeVersion()); | |
| 163 if (!m_nodeAfterPositionInAnchor) | 291 if (!m_nodeAfterPositionInAnchor) |
| 164 return !Strategy::hasChildren(*m_anchorNode) && !m_offsetInAnchor; | 292 return !Strategy::hasChildren(*m_anchorNode) && !m_offsetInAnchor; |
| 165 return !Strategy::previousSibling(*m_nodeAfterPositionInAnchor); | 293 return !Strategy::previousSibling(*m_nodeAfterPositionInAnchor); |
| 166 } | 294 } |
| 167 | 295 |
| 168 template <typename Strategy> | 296 template <typename Strategy> |
| 169 bool PositionIteratorAlgorithm<Strategy>::atEndOfNode() const | 297 bool PositionIteratorAlgorithm<Strategy>::atEndOfNode() const |
| 170 { | 298 { |
| 171 if (!m_anchorNode) | 299 if (!m_anchorNode) |
| 172 return true; | 300 return true; |
| 301 ASSERT(m_domTreeVersion == m_anchorNode->document().domTreeVersion()); | |
| 173 if (m_nodeAfterPositionInAnchor) | 302 if (m_nodeAfterPositionInAnchor) |
| 174 return false; | 303 return false; |
| 175 return Strategy::hasChildren(*m_anchorNode) || m_offsetInAnchor >= Strategy: :lastOffsetForEditing(m_anchorNode); | 304 return Strategy::hasChildren(*m_anchorNode) || m_offsetInAnchor >= Strategy: :lastOffsetForEditing(m_anchorNode); |
| 176 } | 305 } |
| 177 | 306 |
| 178 template class PositionIteratorAlgorithm<EditingStrategy>; | 307 template class PositionIteratorAlgorithm<EditingStrategy>; |
| 179 template class PositionIteratorAlgorithm<EditingInComposedTreeStrategy>; | 308 template class PositionIteratorAlgorithm<EditingInComposedTreeStrategy>; |
| 180 | 309 |
| 181 } // namespace blink | 310 } // namespace blink |
| OLD | NEW |