OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2009 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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 | 174 |
175 int Position::computeOffsetInContainerNode() const | 175 int Position::computeOffsetInContainerNode() const |
176 { | 176 { |
177 if (!m_anchorNode) | 177 if (!m_anchorNode) |
178 return 0; | 178 return 0; |
179 | 179 |
180 switch (anchorType()) { | 180 switch (anchorType()) { |
181 case PositionIsBeforeChildren: | 181 case PositionIsBeforeChildren: |
182 return 0; | 182 return 0; |
183 case PositionIsAfterChildren: | 183 case PositionIsAfterChildren: |
184 return lastOffsetInNode(m_anchorNode.get()); | 184 return lastOffsetInNode(*m_anchorNode); |
185 case PositionIsOffsetInAnchor: | 185 case PositionIsOffsetInAnchor: |
186 return minOffsetForNode(m_anchorNode.get(), m_offset); | 186 return minOffsetForNode(m_anchorNode.get(), m_offset); |
187 case PositionIsBeforeAnchor: | 187 case PositionIsBeforeAnchor: |
188 return m_anchorNode->nodeIndex(); | 188 return m_anchorNode->nodeIndex(); |
189 case PositionIsAfterAnchor: | 189 case PositionIsAfterAnchor: |
190 return m_anchorNode->nodeIndex() + 1; | 190 return m_anchorNode->nodeIndex() + 1; |
191 } | 191 } |
192 ASSERT_NOT_REACHED(); | 192 ASSERT_NOT_REACHED(); |
193 return 0; | 193 return 0; |
194 } | 194 } |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 | 308 |
309 // There are two reasons child might be 0: | 309 // There are two reasons child might be 0: |
310 // 1) The node is node like a text node that is not an element, and th
erefore has no children. | 310 // 1) The node is node like a text node that is not an element, and th
erefore has no children. |
311 // Going backward one character at a time is correct. | 311 // Going backward one character at a time is correct. |
312 // 2) The old offset was a bogus offset like (<br>, 1), and there is n
o child. | 312 // 2) The old offset was a bogus offset like (<br>, 1), and there is n
o child. |
313 // Going from 1 to 0 is correct. | 313 // Going from 1 to 0 is correct. |
314 switch (moveType) { | 314 switch (moveType) { |
315 case CodePoint: | 315 case CodePoint: |
316 return createLegacyEditingPosition(node, offset - 1); | 316 return createLegacyEditingPosition(node, offset - 1); |
317 case Character: | 317 case Character: |
318 return createLegacyEditingPosition(node, uncheckedPreviousOffset(nod
e, offset)); | 318 return createLegacyEditingPosition(node, uncheckedPreviousOffset(*no
de, offset)); |
319 case BackwardDeletion: | 319 case BackwardDeletion: |
320 return createLegacyEditingPosition(node, uncheckedPreviousOffsetForB
ackwardDeletion(node, offset)); | 320 return createLegacyEditingPosition(node, uncheckedPreviousOffsetForB
ackwardDeletion(*node, offset)); |
321 } | 321 } |
322 } | 322 } |
323 | 323 |
324 if (ContainerNode* parent = node->parentNode()) | 324 if (ContainerNode* parent = node->parentNode()) |
325 return createLegacyEditingPosition(parent, node->nodeIndex()); | 325 return createLegacyEditingPosition(parent, node->nodeIndex()); |
326 return *this; | 326 return *this; |
327 } | 327 } |
328 | 328 |
329 Position Position::next(PositionMoveType moveType) const | 329 Position Position::next(PositionMoveType moveType) const |
330 { | 330 { |
331 ASSERT(moveType != BackwardDeletion); | 331 ASSERT(moveType != BackwardDeletion); |
332 | 332 |
333 Node* node = deprecatedNode(); | 333 Node* node = deprecatedNode(); |
334 if (!node) | 334 if (!node) |
335 return *this; | 335 return *this; |
336 | 336 |
337 int offset = deprecatedEditingOffset(); | 337 int offset = deprecatedEditingOffset(); |
338 // FIXME: Negative offsets shouldn't be allowed. We should catch this earlie
r. | 338 // FIXME: Negative offsets shouldn't be allowed. We should catch this earlie
r. |
339 ASSERT(offset >= 0); | 339 ASSERT(offset >= 0); |
340 | 340 |
341 if (Node* child = node->traverseToChildAt(offset)) | 341 if (Node* child = node->traverseToChildAt(offset)) |
342 return firstPositionInOrBeforeNode(child); | 342 return firstPositionInOrBeforeNode(child); |
343 | 343 |
344 if (!node->hasChildren() && offset < lastOffsetForEditing(node)) { | 344 if (!node->hasChildren() && offset < lastOffsetForEditing(node)) { |
345 // There are two reasons child might be 0: | 345 // There are two reasons child might be 0: |
346 // 1) The node is node like a text node that is not an element, and th
erefore has no children. | 346 // 1) The node is node like a text node that is not an element, and th
erefore has no children. |
347 // Going forward one character at a time is correct. | 347 // Going forward one character at a time is correct. |
348 // 2) The new offset is a bogus offset like (<br>, 1), and there is no
child. | 348 // 2) The new offset is a bogus offset like (<br>, 1), and there is no
child. |
349 // Going from 0 to 1 is correct. | 349 // Going from 0 to 1 is correct. |
350 return createLegacyEditingPosition(node, (moveType == Character) ? unche
ckedNextOffset(node, offset) : offset + 1); | 350 return createLegacyEditingPosition(node, (moveType == Character) ? unche
ckedNextOffset(*node, offset) : offset + 1); |
351 } | 351 } |
352 | 352 |
353 if (ContainerNode* parent = node->parentNode()) | 353 if (ContainerNode* parent = node->parentNode()) |
354 return createLegacyEditingPosition(parent, node->nodeIndex() + 1); | 354 return createLegacyEditingPosition(parent, node->nodeIndex() + 1); |
355 return *this; | 355 return *this; |
356 } | 356 } |
357 | 357 |
358 int Position::uncheckedPreviousOffset(const Node* n, int current) | 358 int Position::uncheckedPreviousOffset(const Node& n, int current) |
359 { | 359 { |
360 return n->renderer() ? n->renderer()->previousOffset(current) : current - 1; | 360 return n.renderer() ? n.renderer()->previousOffset(current) : current - 1; |
361 } | 361 } |
362 | 362 |
363 int Position::uncheckedPreviousOffsetForBackwardDeletion(const Node* n, int curr
ent) | 363 int Position::uncheckedPreviousOffsetForBackwardDeletion(const Node& n, int curr
ent) |
364 { | 364 { |
365 return n->renderer() ? n->renderer()->previousOffsetForBackwardDeletion(curr
ent) : current - 1; | 365 return n.renderer() ? n.renderer()->previousOffsetForBackwardDeletion(curren
t) : current - 1; |
366 } | 366 } |
367 | 367 |
368 int Position::uncheckedNextOffset(const Node* n, int current) | 368 int Position::uncheckedNextOffset(const Node& n, int current) |
369 { | 369 { |
370 return n->renderer() ? n->renderer()->nextOffset(current) : current + 1; | 370 return n.renderer() ? n.renderer()->nextOffset(current) : current + 1; |
371 } | 371 } |
372 | 372 |
373 bool Position::atFirstEditingPositionForNode() const | 373 bool Position::atFirstEditingPositionForNode() const |
374 { | 374 { |
375 if (isNull()) | 375 if (isNull()) |
376 return true; | 376 return true; |
377 // FIXME: Position before anchor shouldn't be considered as at the first edi
ting position for node | 377 // FIXME: Position before anchor shouldn't be considered as at the first edi
ting position for node |
378 // since that position resides outside of the node. | 378 // since that position resides outside of the node. |
379 switch (m_anchorType) { | 379 switch (m_anchorType) { |
380 case PositionIsOffsetInAnchor: | 380 case PositionIsOffsetInAnchor: |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 lastVisible = currentPos; | 633 lastVisible = currentPos; |
634 | 634 |
635 // Don't move past a position that is visually distinct. We could rely
on code above to terminate and | 635 // Don't move past a position that is visually distinct. We could rely
on code above to terminate and |
636 // return lastVisible on the next iteration, but we terminate early to a
void doing a nodeIndex() call. | 636 // return lastVisible on the next iteration, but we terminate early to a
void doing a nodeIndex() call. |
637 if (endsOfNodeAreVisuallyDistinctPositions(currentNode) && currentPos.at
StartOfNode()) | 637 if (endsOfNodeAreVisuallyDistinctPositions(currentNode) && currentPos.at
StartOfNode()) |
638 return lastVisible; | 638 return lastVisible; |
639 | 639 |
640 // Return position after tables and nodes which have content that can be
ignored. | 640 // Return position after tables and nodes which have content that can be
ignored. |
641 if (editingIgnoresContent(currentNode) || isRenderedTableElement(current
Node)) { | 641 if (editingIgnoresContent(currentNode) || isRenderedTableElement(current
Node)) { |
642 if (currentPos.atEndOfNode()) | 642 if (currentPos.atEndOfNode()) |
643 return positionAfterNode(currentNode); | 643 return positionAfterNode(*currentNode); |
644 continue; | 644 continue; |
645 } | 645 } |
646 | 646 |
647 // return current position if it is in rendered text | 647 // return current position if it is in rendered text |
648 if (renderer->isText() && toRenderText(renderer)->firstTextBox()) { | 648 if (renderer->isText() && toRenderText(renderer)->firstTextBox()) { |
649 if (currentNode != startNode) { | 649 if (currentNode != startNode) { |
650 // This assertion fires in layout tests in the case-transform.ht
ml test because | 650 // This assertion fires in layout tests in the case-transform.ht
ml test because |
651 // of a mix-up between offsets in the text in the DOM tree with
text in the | 651 // of a mix-up between offsets in the text in the DOM tree with
text in the |
652 // render tree which can have a different length due to case tra
nsformation. | 652 // render tree which can have a different length due to case tra
nsformation. |
653 // Until we resolve that, disable this so we can run the layout
tests! | 653 // Until we resolve that, disable this so we can run the layout
tests! |
(...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1387 pos.showTreeForThis(); | 1387 pos.showTreeForThis(); |
1388 } | 1388 } |
1389 | 1389 |
1390 void showTree(const WebCore::Position* pos) | 1390 void showTree(const WebCore::Position* pos) |
1391 { | 1391 { |
1392 if (pos) | 1392 if (pos) |
1393 pos->showTreeForThis(); | 1393 pos->showTreeForThis(); |
1394 } | 1394 } |
1395 | 1395 |
1396 #endif | 1396 #endif |
OLD | NEW |