OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv
ed. |
3 * Portions Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved. | 3 * Portions Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
587 Position next = canonicalizeCandidate(nextCandidate(position)); | 587 Position next = canonicalizeCandidate(nextCandidate(position)); |
588 Position prev = canonicalizeCandidate(previousCandidate(position)); | 588 Position prev = canonicalizeCandidate(previousCandidate(position)); |
589 Node* nextNode = next.deprecatedNode(); | 589 Node* nextNode = next.deprecatedNode(); |
590 Node* prevNode = prev.deprecatedNode(); | 590 Node* prevNode = prev.deprecatedNode(); |
591 | 591 |
592 // The new position must be in the same editable element. Enforce that first
. | 592 // The new position must be in the same editable element. Enforce that first
. |
593 // Unless the descent is from a non-editable html element to an editable bod
y. | 593 // Unless the descent is from a non-editable html element to an editable bod
y. |
594 if (isHTMLHtmlElement(node) && !node->hasEditableStyle() && node->document()
.body() && node->document().body()->hasEditableStyle()) | 594 if (isHTMLHtmlElement(node) && !node->hasEditableStyle() && node->document()
.body() && node->document().body()->hasEditableStyle()) |
595 return next.isNotNull() ? next : prev; | 595 return next.isNotNull() ? next : prev; |
596 | 596 |
597 Node* editingRoot = editableRootForPosition(position); | 597 Element* editingRoot = editableRootForPosition(position); |
598 | 598 |
599 // If the html element is editable, descending into its body will look like
a descent | 599 // If the html element is editable, descending into its body will look like
a descent |
600 // from non-editable to editable content since rootEditableElement() always
stops at the body. | 600 // from non-editable to editable content since rootEditableElement() always
stops at the body. |
601 if (isHTMLHtmlElement(editingRoot) || position.deprecatedNode()->isDocumentN
ode()) | 601 if (isHTMLHtmlElement(editingRoot) || position.deprecatedNode()->isDocumentN
ode()) |
602 return next.isNotNull() ? next : prev; | 602 return next.isNotNull() ? next : prev; |
603 | 603 |
604 bool prevIsInSameEditableElement = prevNode && editableRootForPosition(prev)
== editingRoot; | 604 bool prevIsInSameEditableElement = prevNode && editableRootForPosition(prev)
== editingRoot; |
605 bool nextIsInSameEditableElement = nextNode && editableRootForPosition(next)
== editingRoot; | 605 bool nextIsInSameEditableElement = nextNode && editableRootForPosition(next)
== editingRoot; |
606 if (prevIsInSameEditableElement && !nextIsInSameEditableElement) | 606 if (prevIsInSameEditableElement && !nextIsInSameEditableElement) |
607 return prev; | 607 return prev; |
608 | 608 |
609 if (nextIsInSameEditableElement && !prevIsInSameEditableElement) | 609 if (nextIsInSameEditableElement && !prevIsInSameEditableElement) |
610 return next; | 610 return next; |
611 | 611 |
612 if (!nextIsInSameEditableElement && !prevIsInSameEditableElement) | 612 if (!nextIsInSameEditableElement && !prevIsInSameEditableElement) |
613 return Position(); | 613 return Position(); |
614 | 614 |
615 // The new position should be in the same block flow element. Favor that. | 615 // The new position should be in the same block flow element. Favor that. |
616 Node* originalBlock = node ? enclosingBlockFlowElement(*node) : 0; | 616 Element* originalBlock = node ? enclosingBlockFlowElement(*node) : 0; |
617 bool nextIsOutsideOriginalBlock = !nextNode->isDescendantOf(originalBlock) &
& nextNode != originalBlock; | 617 bool nextIsOutsideOriginalBlock = !nextNode->isDescendantOf(originalBlock) &
& nextNode != originalBlock; |
618 bool prevIsOutsideOriginalBlock = !prevNode->isDescendantOf(originalBlock) &
& prevNode != originalBlock; | 618 bool prevIsOutsideOriginalBlock = !prevNode->isDescendantOf(originalBlock) &
& prevNode != originalBlock; |
619 if (nextIsOutsideOriginalBlock && !prevIsOutsideOriginalBlock) | 619 if (nextIsOutsideOriginalBlock && !prevIsOutsideOriginalBlock) |
620 return prev; | 620 return prev; |
621 | 621 |
622 return next; | 622 return next; |
623 } | 623 } |
624 | 624 |
625 UChar32 VisiblePosition::characterAfter() const | 625 UChar32 VisiblePosition::characterAfter() const |
626 { | 626 { |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 } | 743 } |
744 | 744 |
745 Element* enclosingBlockFlowElement(const VisiblePosition& visiblePosition) | 745 Element* enclosingBlockFlowElement(const VisiblePosition& visiblePosition) |
746 { | 746 { |
747 if (visiblePosition.isNull()) | 747 if (visiblePosition.isNull()) |
748 return 0; | 748 return 0; |
749 | 749 |
750 return enclosingBlockFlowElement(*visiblePosition.deepEquivalent().deprecate
dNode()); | 750 return enclosingBlockFlowElement(*visiblePosition.deepEquivalent().deprecate
dNode()); |
751 } | 751 } |
752 | 752 |
753 bool isFirstVisiblePositionInNode(const VisiblePosition &visiblePosition, const
Node *node) | 753 bool isFirstVisiblePositionInNode(const VisiblePosition& visiblePosition, const
ContainerNode* node) |
754 { | 754 { |
755 if (visiblePosition.isNull()) | 755 if (visiblePosition.isNull()) |
756 return false; | 756 return false; |
757 | 757 |
758 if (!visiblePosition.deepEquivalent().containerNode()->isDescendantOf(node)) | 758 if (!visiblePosition.deepEquivalent().containerNode()->isDescendantOf(node)) |
759 return false; | 759 return false; |
760 | 760 |
761 VisiblePosition previous = visiblePosition.previous(); | 761 VisiblePosition previous = visiblePosition.previous(); |
762 return previous.isNull() || !previous.deepEquivalent().deprecatedNode()->isD
escendantOf(node); | 762 return previous.isNull() || !previous.deepEquivalent().deprecatedNode()->isD
escendantOf(node); |
763 } | 763 } |
764 | 764 |
765 bool isLastVisiblePositionInNode(const VisiblePosition &visiblePosition, const N
ode *node) | 765 bool isLastVisiblePositionInNode(const VisiblePosition& visiblePosition, const C
ontainerNode* node) |
766 { | 766 { |
767 if (visiblePosition.isNull()) | 767 if (visiblePosition.isNull()) |
768 return false; | 768 return false; |
769 | 769 |
770 if (!visiblePosition.deepEquivalent().containerNode()->isDescendantOf(node)) | 770 if (!visiblePosition.deepEquivalent().containerNode()->isDescendantOf(node)) |
771 return false; | 771 return false; |
772 | 772 |
773 VisiblePosition next = visiblePosition.next(); | 773 VisiblePosition next = visiblePosition.next(); |
774 return next.isNull() || !next.deepEquivalent().deprecatedNode()->isDescendan
tOf(node); | 774 return next.isNull() || !next.deepEquivalent().deprecatedNode()->isDescendan
tOf(node); |
775 } | 775 } |
(...skipping 12 matching lines...) Expand all Loading... |
788 if (vpos) | 788 if (vpos) |
789 vpos->showTreeForThis(); | 789 vpos->showTreeForThis(); |
790 } | 790 } |
791 | 791 |
792 void showTree(const blink::VisiblePosition& vpos) | 792 void showTree(const blink::VisiblePosition& vpos) |
793 { | 793 { |
794 vpos.showTreeForThis(); | 794 vpos.showTreeForThis(); |
795 } | 795 } |
796 | 796 |
797 #endif | 797 #endif |
OLD | NEW |