| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007 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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 } | 331 } |
| 332 | 332 |
| 333 template <typename Strategy> | 333 template <typename Strategy> |
| 334 PositionAlgorithm<Strategy> nextCandidateAlgorithm(const PositionAlgorithm<Strat
egy>& position) | 334 PositionAlgorithm<Strategy> nextCandidateAlgorithm(const PositionAlgorithm<Strat
egy>& position) |
| 335 { | 335 { |
| 336 PositionIteratorAlgorithm<Strategy> p(position); | 336 PositionIteratorAlgorithm<Strategy> p(position); |
| 337 | 337 |
| 338 p.increment(); | 338 p.increment(); |
| 339 while (!p.atEnd()) { | 339 while (!p.atEnd()) { |
| 340 PositionAlgorithm<Strategy> candidate = p.computePosition(); | 340 PositionAlgorithm<Strategy> candidate = p.computePosition(); |
| 341 if (candidate.isCandidate()) | 341 if (isVisuallyEquivalentCandidate(candidate)) |
| 342 return candidate; | 342 return candidate; |
| 343 | 343 |
| 344 p.increment(); | 344 p.increment(); |
| 345 } | 345 } |
| 346 | 346 |
| 347 return PositionAlgorithm<Strategy>(); | 347 return PositionAlgorithm<Strategy>(); |
| 348 } | 348 } |
| 349 | 349 |
| 350 Position nextCandidate(const Position& position) | 350 Position nextCandidate(const Position& position) |
| 351 { | 351 { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 364 { | 364 { |
| 365 if (position.isNull()) | 365 if (position.isNull()) |
| 366 return Position(); | 366 return Position(); |
| 367 | 367 |
| 368 PositionIterator p(position); | 368 PositionIterator p(position); |
| 369 Position downstreamStart = position.downstream(); | 369 Position downstreamStart = position.downstream(); |
| 370 | 370 |
| 371 p.increment(); | 371 p.increment(); |
| 372 while (!p.atEnd()) { | 372 while (!p.atEnd()) { |
| 373 Position candidate = p.computePosition(); | 373 Position candidate = p.computePosition(); |
| 374 if (candidate.isCandidate() && candidate.downstream() != downstreamStart
) | 374 if (isVisuallyEquivalentCandidate(candidate) && candidate.downstream() !
= downstreamStart) |
| 375 return candidate; | 375 return candidate; |
| 376 | 376 |
| 377 p.increment(); | 377 p.increment(); |
| 378 } | 378 } |
| 379 | 379 |
| 380 return Position(); | 380 return Position(); |
| 381 } | 381 } |
| 382 | 382 |
| 383 template <typename Strategy> | 383 template <typename Strategy> |
| 384 PositionAlgorithm<Strategy> previousCandidateAlgorithm(const PositionAlgorithm<S
trategy>& position) | 384 PositionAlgorithm<Strategy> previousCandidateAlgorithm(const PositionAlgorithm<S
trategy>& position) |
| 385 { | 385 { |
| 386 PositionIteratorAlgorithm<Strategy> p(position); | 386 PositionIteratorAlgorithm<Strategy> p(position); |
| 387 | 387 |
| 388 p.decrement(); | 388 p.decrement(); |
| 389 while (!p.atStart()) { | 389 while (!p.atStart()) { |
| 390 PositionAlgorithm<Strategy> candidate = p.computePosition(); | 390 PositionAlgorithm<Strategy> candidate = p.computePosition(); |
| 391 if (candidate.isCandidate()) | 391 if (isVisuallyEquivalentCandidate(candidate)) |
| 392 return candidate; | 392 return candidate; |
| 393 | 393 |
| 394 p.decrement(); | 394 p.decrement(); |
| 395 } | 395 } |
| 396 | 396 |
| 397 return PositionAlgorithm<Strategy>(); | 397 return PositionAlgorithm<Strategy>(); |
| 398 } | 398 } |
| 399 | 399 |
| 400 Position previousCandidate(const Position& position) | 400 Position previousCandidate(const Position& position) |
| 401 { | 401 { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 415 { | 415 { |
| 416 if (position.isNull()) | 416 if (position.isNull()) |
| 417 return PositionAlgorithm<Strategy>(); | 417 return PositionAlgorithm<Strategy>(); |
| 418 | 418 |
| 419 PositionIteratorAlgorithm<Strategy> p(position); | 419 PositionIteratorAlgorithm<Strategy> p(position); |
| 420 PositionAlgorithm<Strategy> downstreamStart = position.downstream(); | 420 PositionAlgorithm<Strategy> downstreamStart = position.downstream(); |
| 421 | 421 |
| 422 p.decrement(); | 422 p.decrement(); |
| 423 while (!p.atStart()) { | 423 while (!p.atStart()) { |
| 424 PositionAlgorithm<Strategy> candidate = p.computePosition(); | 424 PositionAlgorithm<Strategy> candidate = p.computePosition(); |
| 425 if (candidate.isCandidate() && candidate.downstream() != downstreamStart
) | 425 if (isVisuallyEquivalentCandidate(candidate) && candidate.downstream() !
= downstreamStart) |
| 426 return candidate; | 426 return candidate; |
| 427 | 427 |
| 428 p.decrement(); | 428 p.decrement(); |
| 429 } | 429 } |
| 430 | 430 |
| 431 return PositionAlgorithm<Strategy>(); | 431 return PositionAlgorithm<Strategy>(); |
| 432 } | 432 } |
| 433 | 433 |
| 434 Position previousVisuallyDistinctCandidate(const Position& position) | 434 Position previousVisuallyDistinctCandidate(const Position& position) |
| 435 { | 435 { |
| (...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1144 | 1144 |
| 1145 // return first preceding DOM position rendered at a different location, or "thi
s" | 1145 // return first preceding DOM position rendered at a different location, or "thi
s" |
| 1146 static Position previousCharacterPosition(const Position& position, TextAffinity
affinity) | 1146 static Position previousCharacterPosition(const Position& position, TextAffinity
affinity) |
| 1147 { | 1147 { |
| 1148 if (position.isNull()) | 1148 if (position.isNull()) |
| 1149 return Position(); | 1149 return Position(); |
| 1150 | 1150 |
| 1151 Element* fromRootEditableElement = position.anchorNode()->rootEditableElemen
t(); | 1151 Element* fromRootEditableElement = position.anchorNode()->rootEditableElemen
t(); |
| 1152 | 1152 |
| 1153 bool atStartOfLine = isStartOfLine(VisiblePosition(position, affinity)); | 1153 bool atStartOfLine = isStartOfLine(VisiblePosition(position, affinity)); |
| 1154 bool rendered = position.isCandidate(); | 1154 bool rendered = isVisuallyEquivalentCandidate(position); |
| 1155 | 1155 |
| 1156 Position currentPos = position; | 1156 Position currentPos = position; |
| 1157 while (!currentPos.atStartOfTree()) { | 1157 while (!currentPos.atStartOfTree()) { |
| 1158 currentPos = currentPos.previous(); | 1158 currentPos = currentPos.previous(); |
| 1159 | 1159 |
| 1160 if (currentPos.anchorNode()->rootEditableElement() != fromRootEditableEl
ement) | 1160 if (currentPos.anchorNode()->rootEditableElement() != fromRootEditableEl
ement) |
| 1161 return position; | 1161 return position; |
| 1162 | 1162 |
| 1163 if (atStartOfLine || !rendered) { | 1163 if (atStartOfLine || !rendered) { |
| 1164 if (currentPos.isCandidate()) | 1164 if (isVisuallyEquivalentCandidate(currentPos)) |
| 1165 return currentPos; | 1165 return currentPos; |
| 1166 } else if (rendersInDifferentPosition(position, currentPos)) { | 1166 } else if (rendersInDifferentPosition(position, currentPos)) { |
| 1167 return currentPos; | 1167 return currentPos; |
| 1168 } | 1168 } |
| 1169 } | 1169 } |
| 1170 | 1170 |
| 1171 return position; | 1171 return position; |
| 1172 } | 1172 } |
| 1173 | 1173 |
| 1174 // This assumes that it starts in editable content. | 1174 // This assumes that it starts in editable content. |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1445 // if the selection starts just before a paragraph break, skip over it | 1445 // if the selection starts just before a paragraph break, skip over it |
| 1446 if (isEndOfParagraph(visiblePosition)) | 1446 if (isEndOfParagraph(visiblePosition)) |
| 1447 return visiblePosition.next().deepEquivalent().downstream(); | 1447 return visiblePosition.next().deepEquivalent().downstream(); |
| 1448 | 1448 |
| 1449 // otherwise, make sure to be at the start of the first selected node, | 1449 // otherwise, make sure to be at the start of the first selected node, |
| 1450 // instead of possibly at the end of the last node before the selection | 1450 // instead of possibly at the end of the last node before the selection |
| 1451 return visiblePosition.deepEquivalent().downstream(); | 1451 return visiblePosition.deepEquivalent().downstream(); |
| 1452 } | 1452 } |
| 1453 | 1453 |
| 1454 } // namespace blink | 1454 } // namespace blink |
| OLD | NEW |