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 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 int offsetB = positionB.computeOffsetInContainerNode(); | 307 int offsetB = positionB.computeOffsetInContainerNode(); |
308 return comparePositionsInComposedTree(containerA, offsetA, containerB, offse
tB); | 308 return comparePositionsInComposedTree(containerA, offsetA, containerB, offse
tB); |
309 } | 309 } |
310 | 310 |
311 template <typename Strategy> | 311 template <typename Strategy> |
312 int PositionAlgorithm<Strategy>::compareTo(const PositionAlgorithm<Strategy>& ot
her) const | 312 int PositionAlgorithm<Strategy>::compareTo(const PositionAlgorithm<Strategy>& ot
her) const |
313 { | 313 { |
314 return comparePositions(*this, other); | 314 return comparePositions(*this, other); |
315 } | 315 } |
316 | 316 |
| 317 // TODO(yosin) To avoid forward declaration, we should move implementation of |
| 318 // |uncheckedPreviousOffsetForBackwardDeletion()| here. |
| 319 static int uncheckedPreviousOffsetForBackwardDeletion(const Node*, int current); |
| 320 |
317 template <typename Strategy> | 321 template <typename Strategy> |
318 PositionAlgorithm<Strategy> PositionAlgorithm<Strategy>::previous(PositionMoveTy
pe moveType) const | 322 PositionAlgorithm<Strategy> PositionAlgorithm<Strategy>::previous(PositionMoveTy
pe moveType) const |
319 { | 323 { |
320 Node* node = anchorNode(); | 324 Node* node = anchorNode(); |
321 if (!node) | 325 if (!node) |
322 return PositionAlgorithm<Strategy>(*this); | 326 return PositionAlgorithm<Strategy>(*this); |
323 | 327 |
324 int offset = computeEditingOffset(); | 328 int offset = computeEditingOffset(); |
325 | 329 |
326 if (offset > 0) { | 330 if (offset > 0) { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 // 2) The new offset is a bogus offset like (<br>, 1), and there is no
child. | 381 // 2) The new offset is a bogus offset like (<br>, 1), and there is no
child. |
378 // Going from 0 to 1 is correct. | 382 // Going from 0 to 1 is correct. |
379 return editingPositionOf(node, (moveType == Character) ? uncheckedNextOf
fset(node, offset) : offset + 1); | 383 return editingPositionOf(node, (moveType == Character) ? uncheckedNextOf
fset(node, offset) : offset + 1); |
380 } | 384 } |
381 | 385 |
382 if (ContainerNode* parent = Strategy::parent(*node)) | 386 if (ContainerNode* parent = Strategy::parent(*node)) |
383 return editingPositionOf(parent, Strategy::index(*node) + 1); | 387 return editingPositionOf(parent, Strategy::index(*node) + 1); |
384 return PositionAlgorithm<Strategy>(*this); | 388 return PositionAlgorithm<Strategy>(*this); |
385 } | 389 } |
386 | 390 |
387 template <typename Strategy> | 391 int uncheckedPreviousOffset(const Node* n, int current) |
388 int PositionAlgorithm<Strategy>::uncheckedPreviousOffset(const Node* n, int curr
ent) | |
389 { | 392 { |
390 return n->layoutObject() ? n->layoutObject()->previousOffset(current) : curr
ent - 1; | 393 return n->layoutObject() ? n->layoutObject()->previousOffset(current) : curr
ent - 1; |
391 } | 394 } |
392 | 395 |
393 template <typename Strategy> | 396 static int uncheckedPreviousOffsetForBackwardDeletion(const Node* n, int current
) |
394 int PositionAlgorithm<Strategy>::uncheckedPreviousOffsetForBackwardDeletion(cons
t Node* n, int current) | |
395 { | 397 { |
396 return n->layoutObject() ? n->layoutObject()->previousOffsetForBackwardDelet
ion(current) : current - 1; | 398 return n->layoutObject() ? n->layoutObject()->previousOffsetForBackwardDelet
ion(current) : current - 1; |
397 } | 399 } |
398 | 400 |
399 template <typename Strategy> | 401 int uncheckedNextOffset(const Node* n, int current) |
400 int PositionAlgorithm<Strategy>::uncheckedNextOffset(const Node* n, int current) | |
401 { | 402 { |
402 return n->layoutObject() ? n->layoutObject()->nextOffset(current) : current
+ 1; | 403 return n->layoutObject() ? n->layoutObject()->nextOffset(current) : current
+ 1; |
403 } | 404 } |
404 | 405 |
405 template <typename Strategy> | 406 template <typename Strategy> |
406 bool PositionAlgorithm<Strategy>::atFirstEditingPositionForNode() const | 407 bool PositionAlgorithm<Strategy>::atFirstEditingPositionForNode() const |
407 { | 408 { |
408 if (isNull()) | 409 if (isNull()) |
409 return true; | 410 return true; |
410 // FIXME: Position before anchor shouldn't be considered as at the first edi
ting position for node | 411 // FIXME: Position before anchor shouldn't be considered as at the first edi
ting position for node |
(...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1360 | 1361 |
1361 void showTree(const blink::Position* pos) | 1362 void showTree(const blink::Position* pos) |
1362 { | 1363 { |
1363 if (pos) | 1364 if (pos) |
1364 pos->showTreeForThis(); | 1365 pos->showTreeForThis(); |
1365 else | 1366 else |
1366 fprintf(stderr, "Cannot showTree for (nil)\n"); | 1367 fprintf(stderr, "Cannot showTree for (nil)\n"); |
1367 } | 1368 } |
1368 | 1369 |
1369 #endif | 1370 #endif |
OLD | NEW |