| 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 10 matching lines...) Expand all Loading... |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "core/editing/Position.h" | 27 #include "core/editing/Position.h" |
| 28 | 28 |
| 29 #include "core/dom/shadow/ElementShadow.h" | 29 #include "core/dom/shadow/ElementShadow.h" |
| 30 #include "core/editing/EditingUtilities.h" | 30 #include "core/editing/EditingUtilities.h" |
| 31 #include "core/editing/PositionIterator.h" | |
| 32 #include "core/editing/TextAffinity.h" | 31 #include "core/editing/TextAffinity.h" |
| 33 #include "core/editing/VisibleUnits.h" | 32 #include "core/editing/VisibleUnits.h" |
| 34 #include "core/layout/LayoutBlock.h" | 33 #include "core/layout/LayoutObject.h" |
| 35 #include "core/layout/LayoutInline.h" | |
| 36 #include "core/layout/LayoutText.h" | |
| 37 #include "core/layout/line/InlineTextBox.h" | |
| 38 #include "wtf/text/CString.h" | 34 #include "wtf/text/CString.h" |
| 39 #include <stdio.h> | 35 #include <stdio.h> |
| 40 | 36 |
| 41 namespace blink { | 37 namespace blink { |
| 42 | 38 |
| 43 #if ENABLE(ASSERT) | 39 #if ENABLE(ASSERT) |
| 44 static bool canBeAnchorNode(Node* node) | 40 static bool canBeAnchorNode(Node* node) |
| 45 { | 41 { |
| 46 if (!node || node->isFirstLetterPseudoElement()) | 42 if (!node || node->isFirstLetterPseudoElement()) |
| 47 return true; | 43 return true; |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 return mostForwardCaretPosition(*this, rule); | 448 return mostForwardCaretPosition(*this, rule); |
| 453 } | 449 } |
| 454 | 450 |
| 455 template <typename Strategy> | 451 template <typename Strategy> |
| 456 PositionAlgorithm<Strategy> PositionAlgorithm<Strategy>::downstream(EditingBound
aryCrossingRule rule) const | 452 PositionAlgorithm<Strategy> PositionAlgorithm<Strategy>::downstream(EditingBound
aryCrossingRule rule) const |
| 457 { | 453 { |
| 458 return mostBackwardCaretPosition(*this, rule); | 454 return mostBackwardCaretPosition(*this, rule); |
| 459 } | 455 } |
| 460 | 456 |
| 461 template <typename Strategy> | 457 template <typename Strategy> |
| 462 static bool inRenderedTextAlgorithm(const PositionAlgorithm<Strategy>& position) | |
| 463 { | |
| 464 Node* const anchorNode = position.anchorNode(); | |
| 465 if (!anchorNode || !anchorNode->isTextNode()) | |
| 466 return false; | |
| 467 | |
| 468 LayoutObject* layoutObject = anchorNode->layoutObject(); | |
| 469 if (!layoutObject) | |
| 470 return false; | |
| 471 | |
| 472 const int offsetInNode = position.computeEditingOffset(); | |
| 473 LayoutText* textLayoutObject = toLayoutText(layoutObject); | |
| 474 for (InlineTextBox *box = textLayoutObject->firstTextBox(); box; box = box->
nextTextBox()) { | |
| 475 if (offsetInNode < static_cast<int>(box->start()) && !textLayoutObject->
containsReversedText()) { | |
| 476 // The offset we're looking for is before this node | |
| 477 // this means the offset must be in content that is | |
| 478 // not laid out. Return false. | |
| 479 return false; | |
| 480 } | |
| 481 if (box->containsCaretOffset(offsetInNode)) { | |
| 482 // Return false for offsets inside composed characters. | |
| 483 return offsetInNode == 0 || offsetInNode == textLayoutObject->nextOf
fset(textLayoutObject->previousOffset(offsetInNode)); | |
| 484 } | |
| 485 } | |
| 486 | |
| 487 return false; | |
| 488 } | |
| 489 | |
| 490 bool inRenderedText(const Position& position) | |
| 491 { | |
| 492 return inRenderedTextAlgorithm<EditingStrategy>(position); | |
| 493 } | |
| 494 | |
| 495 bool inRenderedText(const PositionInComposedTree& position) | |
| 496 { | |
| 497 return inRenderedTextAlgorithm<EditingInComposedTreeStrategy>(position); | |
| 498 } | |
| 499 | |
| 500 template <typename Strategy> | |
| 501 void PositionAlgorithm<Strategy>::debugPosition(const char* msg) const | 458 void PositionAlgorithm<Strategy>::debugPosition(const char* msg) const |
| 502 { | 459 { |
| 503 static const char* const anchorTypes[] = { | 460 static const char* const anchorTypes[] = { |
| 504 "OffsetInAnchor", | 461 "OffsetInAnchor", |
| 505 "BeforeAnchor", | 462 "BeforeAnchor", |
| 506 "AfterAnchor", | 463 "AfterAnchor", |
| 507 "BeforeChildren", | 464 "BeforeChildren", |
| 508 "AfterChildren", | 465 "AfterChildren", |
| 509 "Invalid", | 466 "Invalid", |
| 510 }; | 467 }; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 | 630 |
| 674 void showTree(const blink::Position* pos) | 631 void showTree(const blink::Position* pos) |
| 675 { | 632 { |
| 676 if (pos) | 633 if (pos) |
| 677 pos->showTreeForThis(); | 634 pos->showTreeForThis(); |
| 678 else | 635 else |
| 679 fprintf(stderr, "Cannot showTree for (nil)\n"); | 636 fprintf(stderr, "Cannot showTree for (nil)\n"); |
| 680 } | 637 } |
| 681 | 638 |
| 682 #endif | 639 #endif |
| OLD | NEW |