OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2008, 2009, 2010 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 { | 162 { |
163 RenderedPosition base(visibleBase); | 163 RenderedPosition base(visibleBase); |
164 RenderedPosition extent(visibleExtent); | 164 RenderedPosition extent(visibleExtent); |
165 | 165 |
166 if (base.isNull() || extent.isNull() || base.isEquivalent(extent)) | 166 if (base.isNull() || extent.isNull() || base.isEquivalent(extent)) |
167 return; | 167 return; |
168 | 168 |
169 if (base.atLeftBoundaryOfBidiRun()) { | 169 if (base.atLeftBoundaryOfBidiRun()) { |
170 if (!extent.atRightBoundaryOfBidiRun(base.bidiLevelOnRight()) | 170 if (!extent.atRightBoundaryOfBidiRun(base.bidiLevelOnRight()) |
171 && base.isEquivalent(extent.leftBoundaryOfBidiRun(base.bidiLevelOnRi
ght()))) { | 171 && base.isEquivalent(extent.leftBoundaryOfBidiRun(base.bidiLevelOnRi
ght()))) { |
172 visibleBase = VisiblePosition(base.positionAtLeftBoundaryOfBiDiRun()
); | 172 visibleBase = createVisiblePosition(base.positionAtLeftBoundaryOfBiD
iRun()); |
173 return; | 173 return; |
174 } | 174 } |
175 return; | 175 return; |
176 } | 176 } |
177 | 177 |
178 if (base.atRightBoundaryOfBidiRun()) { | 178 if (base.atRightBoundaryOfBidiRun()) { |
179 if (!extent.atLeftBoundaryOfBidiRun(base.bidiLevelOnLeft()) | 179 if (!extent.atLeftBoundaryOfBidiRun(base.bidiLevelOnLeft()) |
180 && base.isEquivalent(extent.rightBoundaryOfBidiRun(base.bidiLevelOnL
eft()))) { | 180 && base.isEquivalent(extent.rightBoundaryOfBidiRun(base.bidiLevelOnL
eft()))) { |
181 visibleBase = VisiblePosition(base.positionAtRightBoundaryOfBiDiRun(
)); | 181 visibleBase = createVisiblePosition(base.positionAtRightBoundaryOfBi
DiRun()); |
182 return; | 182 return; |
183 } | 183 } |
184 return; | 184 return; |
185 } | 185 } |
186 | 186 |
187 if (extent.atLeftBoundaryOfBidiRun() && extent.isEquivalent(base.leftBoundar
yOfBidiRun(extent.bidiLevelOnRight()))) { | 187 if (extent.atLeftBoundaryOfBidiRun() && extent.isEquivalent(base.leftBoundar
yOfBidiRun(extent.bidiLevelOnRight()))) { |
188 visibleExtent = VisiblePosition(extent.positionAtLeftBoundaryOfBiDiRun()
); | 188 visibleExtent = createVisiblePosition(extent.positionAtLeftBoundaryOfBiD
iRun()); |
189 return; | 189 return; |
190 } | 190 } |
191 | 191 |
192 if (extent.atRightBoundaryOfBidiRun() && extent.isEquivalent(base.rightBound
aryOfBidiRun(extent.bidiLevelOnLeft()))) { | 192 if (extent.atRightBoundaryOfBidiRun() && extent.isEquivalent(base.rightBound
aryOfBidiRun(extent.bidiLevelOnLeft()))) { |
193 visibleExtent = VisiblePosition(extent.positionAtRightBoundaryOfBiDiRun(
)); | 193 visibleExtent = createVisiblePosition(extent.positionAtRightBoundaryOfBi
DiRun()); |
194 return; | 194 return; |
195 } | 195 } |
196 } | 196 } |
197 | 197 |
198 template <typename Strategy> | 198 template <typename Strategy> |
199 void FrameSelection::setNonDirectionalSelectionIfNeededAlgorithm(const VisibleSe
lection& passedNewSelection, TextGranularity granularity, | 199 void FrameSelection::setNonDirectionalSelectionIfNeededAlgorithm(const VisibleSe
lection& passedNewSelection, TextGranularity granularity, |
200 EndPointsAdjustmentMode endpointsAdjustmentMode) | 200 EndPointsAdjustmentMode endpointsAdjustmentMode) |
201 { | 201 { |
202 VisibleSelection newSelection = passedNewSelection; | 202 VisibleSelection newSelection = passedNewSelection; |
203 bool isDirectional = shouldAlwaysUseDirectionalSelection(m_frame) || newSele
ction.isDirectional(); | 203 bool isDirectional = shouldAlwaysUseDirectionalSelection(m_frame) || newSele
ction.isDirectional(); |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 bool movingBackwardsMovedPositionToStartOfCurrentWord = positionAfterCur
rentWord.deepEquivalent() == previousWordPosition(nextWordPosition(originalPosit
ion)).deepEquivalent(); | 644 bool movingBackwardsMovedPositionToStartOfCurrentWord = positionAfterCur
rentWord.deepEquivalent() == previousWordPosition(nextWordPosition(originalPosit
ion)).deepEquivalent(); |
645 if (movingBackwardsMovedPositionToStartOfCurrentWord) | 645 if (movingBackwardsMovedPositionToStartOfCurrentWord) |
646 positionAfterCurrentWord = positionAfterSpacingAndFollowingWord; | 646 positionAfterCurrentWord = positionAfterSpacingAndFollowingWord; |
647 } | 647 } |
648 return positionAfterCurrentWord; | 648 return positionAfterCurrentWord; |
649 } | 649 } |
650 | 650 |
651 static void adjustPositionForUserSelectAll(VisiblePosition& pos, bool isForward) | 651 static void adjustPositionForUserSelectAll(VisiblePosition& pos, bool isForward) |
652 { | 652 { |
653 if (Node* rootUserSelectAll = EditingStrategy::rootUserSelectAllForNode(pos.
deepEquivalent().anchorNode())) | 653 if (Node* rootUserSelectAll = EditingStrategy::rootUserSelectAllForNode(pos.
deepEquivalent().anchorNode())) |
654 pos = VisiblePosition(isForward ? mostForwardCaretPosition(positionAfter
Node(rootUserSelectAll), CanCrossEditingBoundary) : mostBackwardCaretPosition(po
sitionBeforeNode(rootUserSelectAll), CanCrossEditingBoundary)); | 654 pos = createVisiblePosition(isForward ? mostForwardCaretPosition(positio
nAfterNode(rootUserSelectAll), CanCrossEditingBoundary) : mostBackwardCaretPosit
ion(positionBeforeNode(rootUserSelectAll), CanCrossEditingBoundary)); |
655 } | 655 } |
656 | 656 |
657 VisiblePosition FrameSelection::modifyExtendingRight(TextGranularity granularity
) | 657 VisiblePosition FrameSelection::modifyExtendingRight(TextGranularity granularity
) |
658 { | 658 { |
659 VisiblePosition pos(m_selection.extent(), m_selection.affinity()); | 659 VisiblePosition pos = createVisiblePosition(m_selection.extent(), m_selectio
n.affinity()); |
660 | 660 |
661 // The difference between modifyExtendingRight and modifyExtendingForward is
: | 661 // The difference between modifyExtendingRight and modifyExtendingForward is
: |
662 // modifyExtendingForward always extends forward logically. | 662 // modifyExtendingForward always extends forward logically. |
663 // modifyExtendingRight behaves the same as modifyExtendingForward except fo
r extending character or word, | 663 // modifyExtendingRight behaves the same as modifyExtendingForward except fo
r extending character or word, |
664 // it extends forward logically if the enclosing block is LTR direction, | 664 // it extends forward logically if the enclosing block is LTR direction, |
665 // but it extends backward logically if the enclosing block is RTL direction
. | 665 // but it extends backward logically if the enclosing block is RTL direction
. |
666 switch (granularity) { | 666 switch (granularity) { |
667 case CharacterGranularity: | 667 case CharacterGranularity: |
668 if (directionOfEnclosingBlock() == LTR) | 668 if (directionOfEnclosingBlock() == LTR) |
669 pos = nextPositionOf(pos, CanSkipOverEditingBoundary); | 669 pos = nextPositionOf(pos, CanSkipOverEditingBoundary); |
(...skipping 21 matching lines...) Expand all Loading... |
691 // FIXME: implement all of the above? | 691 // FIXME: implement all of the above? |
692 pos = modifyExtendingForward(granularity); | 692 pos = modifyExtendingForward(granularity); |
693 break; | 693 break; |
694 } | 694 } |
695 adjustPositionForUserSelectAll(pos, directionOfEnclosingBlock() == LTR); | 695 adjustPositionForUserSelectAll(pos, directionOfEnclosingBlock() == LTR); |
696 return pos; | 696 return pos; |
697 } | 697 } |
698 | 698 |
699 VisiblePosition FrameSelection::modifyExtendingForward(TextGranularity granulari
ty) | 699 VisiblePosition FrameSelection::modifyExtendingForward(TextGranularity granulari
ty) |
700 { | 700 { |
701 VisiblePosition pos(m_selection.extent(), m_selection.affinity()); | 701 VisiblePosition pos = createVisiblePosition(m_selection.extent(), m_selectio
n.affinity()); |
702 switch (granularity) { | 702 switch (granularity) { |
703 case CharacterGranularity: | 703 case CharacterGranularity: |
704 pos = nextPositionOf(pos, CanSkipOverEditingBoundary); | 704 pos = nextPositionOf(pos, CanSkipOverEditingBoundary); |
705 break; | 705 break; |
706 case WordGranularity: | 706 case WordGranularity: |
707 pos = nextWordPositionForPlatform(pos); | 707 pos = nextWordPositionForPlatform(pos); |
708 break; | 708 break; |
709 case SentenceGranularity: | 709 case SentenceGranularity: |
710 pos = nextSentencePosition(pos); | 710 pos = nextSentencePosition(pos); |
711 break; | 711 break; |
(...skipping 24 matching lines...) Expand all Loading... |
736 return pos; | 736 return pos; |
737 } | 737 } |
738 | 738 |
739 VisiblePosition FrameSelection::modifyMovingRight(TextGranularity granularity) | 739 VisiblePosition FrameSelection::modifyMovingRight(TextGranularity granularity) |
740 { | 740 { |
741 VisiblePosition pos; | 741 VisiblePosition pos; |
742 switch (granularity) { | 742 switch (granularity) { |
743 case CharacterGranularity: | 743 case CharacterGranularity: |
744 if (isRange()) { | 744 if (isRange()) { |
745 if (directionOfSelection() == LTR) | 745 if (directionOfSelection() == LTR) |
746 pos = VisiblePosition(m_selection.end(), m_selection.affinity())
; | 746 pos = createVisiblePosition(m_selection.end(), m_selection.affin
ity()); |
747 else | 747 else |
748 pos = VisiblePosition(m_selection.start(), m_selection.affinity(
)); | 748 pos = createVisiblePosition(m_selection.start(), m_selection.aff
inity()); |
749 } else { | 749 } else { |
750 pos = rightPositionOf(VisiblePosition(m_selection.extent(), m_select
ion.affinity())); | 750 pos = rightPositionOf(createVisiblePosition(m_selection.extent(), m_
selection.affinity())); |
751 } | 751 } |
752 break; | 752 break; |
753 case WordGranularity: { | 753 case WordGranularity: { |
754 bool skipsSpaceWhenMovingRight = m_frame && m_frame->editor().behavior()
.shouldSkipSpaceWhenMovingRight(); | 754 bool skipsSpaceWhenMovingRight = m_frame && m_frame->editor().behavior()
.shouldSkipSpaceWhenMovingRight(); |
755 pos = rightWordPosition(VisiblePosition(m_selection.extent(), m_selectio
n.affinity()), skipsSpaceWhenMovingRight); | 755 pos = rightWordPosition(createVisiblePosition(m_selection.extent(), m_se
lection.affinity()), skipsSpaceWhenMovingRight); |
756 break; | 756 break; |
757 } | 757 } |
758 case SentenceGranularity: | 758 case SentenceGranularity: |
759 case LineGranularity: | 759 case LineGranularity: |
760 case ParagraphGranularity: | 760 case ParagraphGranularity: |
761 case SentenceBoundary: | 761 case SentenceBoundary: |
762 case ParagraphBoundary: | 762 case ParagraphBoundary: |
763 case DocumentBoundary: | 763 case DocumentBoundary: |
764 // FIXME: Implement all of the above. | 764 // FIXME: Implement all of the above. |
765 pos = modifyMovingForward(granularity); | 765 pos = modifyMovingForward(granularity); |
766 break; | 766 break; |
767 case LineBoundary: | 767 case LineBoundary: |
768 pos = rightBoundaryOfLine(startForPlatform(), directionOfEnclosingBlock(
)); | 768 pos = rightBoundaryOfLine(startForPlatform(), directionOfEnclosingBlock(
)); |
769 break; | 769 break; |
770 } | 770 } |
771 return pos; | 771 return pos; |
772 } | 772 } |
773 | 773 |
774 VisiblePosition FrameSelection::modifyMovingForward(TextGranularity granularity) | 774 VisiblePosition FrameSelection::modifyMovingForward(TextGranularity granularity) |
775 { | 775 { |
776 VisiblePosition pos; | 776 VisiblePosition pos; |
777 // FIXME: Stay in editable content for the less common granularities. | 777 // FIXME: Stay in editable content for the less common granularities. |
778 switch (granularity) { | 778 switch (granularity) { |
779 case CharacterGranularity: | 779 case CharacterGranularity: |
780 if (isRange()) | 780 if (isRange()) |
781 pos = VisiblePosition(m_selection.end(), m_selection.affinity()); | 781 pos = createVisiblePosition(m_selection.end(), m_selection.affinity(
)); |
782 else | 782 else |
783 pos = nextPositionOf(VisiblePosition(m_selection.extent(), m_selecti
on.affinity()), CanSkipOverEditingBoundary); | 783 pos = nextPositionOf(createVisiblePosition(m_selection.extent(), m_s
election.affinity()), CanSkipOverEditingBoundary); |
784 break; | 784 break; |
785 case WordGranularity: | 785 case WordGranularity: |
786 pos = nextWordPositionForPlatform(VisiblePosition(m_selection.extent(),
m_selection.affinity())); | 786 pos = nextWordPositionForPlatform(createVisiblePosition(m_selection.exte
nt(), m_selection.affinity())); |
787 break; | 787 break; |
788 case SentenceGranularity: | 788 case SentenceGranularity: |
789 pos = nextSentencePosition(VisiblePosition(m_selection.extent(), m_selec
tion.affinity())); | 789 pos = nextSentencePosition(createVisiblePosition(m_selection.extent(), m
_selection.affinity())); |
790 break; | 790 break; |
791 case LineGranularity: { | 791 case LineGranularity: { |
792 // down-arrowing from a range selection that ends at the start of a line
needs | 792 // down-arrowing from a range selection that ends at the start of a line
needs |
793 // to leave the selection at that line start (no need to call nextLinePo
sition!) | 793 // to leave the selection at that line start (no need to call nextLinePo
sition!) |
794 pos = endForPlatform(); | 794 pos = endForPlatform(); |
795 if (!isRange() || !isStartOfLine(pos)) | 795 if (!isRange() || !isStartOfLine(pos)) |
796 pos = nextLinePosition(pos, lineDirectionPointForBlockDirectionNavig
ation(START)); | 796 pos = nextLinePosition(pos, lineDirectionPointForBlockDirectionNavig
ation(START)); |
797 break; | 797 break; |
798 } | 798 } |
799 case ParagraphGranularity: | 799 case ParagraphGranularity: |
(...skipping 14 matching lines...) Expand all Loading... |
814 pos = endOfEditableContent(pos); | 814 pos = endOfEditableContent(pos); |
815 else | 815 else |
816 pos = endOfDocument(pos); | 816 pos = endOfDocument(pos); |
817 break; | 817 break; |
818 } | 818 } |
819 return pos; | 819 return pos; |
820 } | 820 } |
821 | 821 |
822 VisiblePosition FrameSelection::modifyExtendingLeft(TextGranularity granularity) | 822 VisiblePosition FrameSelection::modifyExtendingLeft(TextGranularity granularity) |
823 { | 823 { |
824 VisiblePosition pos(m_selection.extent(), m_selection.affinity()); | 824 VisiblePosition pos = createVisiblePosition(m_selection.extent(), m_selectio
n.affinity()); |
825 | 825 |
826 // The difference between modifyExtendingLeft and modifyExtendingBackward is
: | 826 // The difference between modifyExtendingLeft and modifyExtendingBackward is
: |
827 // modifyExtendingBackward always extends backward logically. | 827 // modifyExtendingBackward always extends backward logically. |
828 // modifyExtendingLeft behaves the same as modifyExtendingBackward except fo
r extending character or word, | 828 // modifyExtendingLeft behaves the same as modifyExtendingBackward except fo
r extending character or word, |
829 // it extends backward logically if the enclosing block is LTR direction, | 829 // it extends backward logically if the enclosing block is LTR direction, |
830 // but it extends forward logically if the enclosing block is RTL direction. | 830 // but it extends forward logically if the enclosing block is RTL direction. |
831 switch (granularity) { | 831 switch (granularity) { |
832 case CharacterGranularity: | 832 case CharacterGranularity: |
833 if (directionOfEnclosingBlock() == LTR) | 833 if (directionOfEnclosingBlock() == LTR) |
834 pos = previousPositionOf(pos, CanSkipOverEditingBoundary); | 834 pos = previousPositionOf(pos, CanSkipOverEditingBoundary); |
(...skipping 20 matching lines...) Expand all Loading... |
855 case DocumentBoundary: | 855 case DocumentBoundary: |
856 pos = modifyExtendingBackward(granularity); | 856 pos = modifyExtendingBackward(granularity); |
857 break; | 857 break; |
858 } | 858 } |
859 adjustPositionForUserSelectAll(pos, !(directionOfEnclosingBlock() == LTR)); | 859 adjustPositionForUserSelectAll(pos, !(directionOfEnclosingBlock() == LTR)); |
860 return pos; | 860 return pos; |
861 } | 861 } |
862 | 862 |
863 VisiblePosition FrameSelection::modifyExtendingBackward(TextGranularity granular
ity) | 863 VisiblePosition FrameSelection::modifyExtendingBackward(TextGranularity granular
ity) |
864 { | 864 { |
865 VisiblePosition pos(m_selection.extent(), m_selection.affinity()); | 865 VisiblePosition pos = createVisiblePosition(m_selection.extent(), m_selectio
n.affinity()); |
866 | 866 |
867 // Extending a selection backward by word or character from just after a tab
le selects | 867 // Extending a selection backward by word or character from just after a tab
le selects |
868 // the table. This "makes sense" from the user perspective, esp. when delet
ing. | 868 // the table. This "makes sense" from the user perspective, esp. when delet
ing. |
869 // It was done here instead of in VisiblePosition because we want VPs to ite
rate | 869 // It was done here instead of in VisiblePosition because we want VPs to ite
rate |
870 // over everything. | 870 // over everything. |
871 switch (granularity) { | 871 switch (granularity) { |
872 case CharacterGranularity: | 872 case CharacterGranularity: |
873 pos = previousPositionOf(pos, CanSkipOverEditingBoundary); | 873 pos = previousPositionOf(pos, CanSkipOverEditingBoundary); |
874 break; | 874 break; |
875 case WordGranularity: | 875 case WordGranularity: |
(...skipping 29 matching lines...) Expand all Loading... |
905 return pos; | 905 return pos; |
906 } | 906 } |
907 | 907 |
908 VisiblePosition FrameSelection::modifyMovingLeft(TextGranularity granularity) | 908 VisiblePosition FrameSelection::modifyMovingLeft(TextGranularity granularity) |
909 { | 909 { |
910 VisiblePosition pos; | 910 VisiblePosition pos; |
911 switch (granularity) { | 911 switch (granularity) { |
912 case CharacterGranularity: | 912 case CharacterGranularity: |
913 if (isRange()) { | 913 if (isRange()) { |
914 if (directionOfSelection() == LTR) | 914 if (directionOfSelection() == LTR) |
915 pos = VisiblePosition(m_selection.start(), m_selection.affinity(
)); | 915 pos = createVisiblePosition(m_selection.start(), m_selection.aff
inity()); |
916 else | 916 else |
917 pos = VisiblePosition(m_selection.end(), m_selection.affinity())
; | 917 pos = createVisiblePosition(m_selection.end(), m_selection.affin
ity()); |
918 } else { | 918 } else { |
919 pos = leftPositionOf(VisiblePosition(m_selection.extent(), m_selecti
on.affinity())); | 919 pos = leftPositionOf(createVisiblePosition(m_selection.extent(), m_s
election.affinity())); |
920 } | 920 } |
921 break; | 921 break; |
922 case WordGranularity: { | 922 case WordGranularity: { |
923 bool skipsSpaceWhenMovingRight = m_frame && m_frame->editor().behavior()
.shouldSkipSpaceWhenMovingRight(); | 923 bool skipsSpaceWhenMovingRight = m_frame && m_frame->editor().behavior()
.shouldSkipSpaceWhenMovingRight(); |
924 pos = leftWordPosition(VisiblePosition(m_selection.extent(), m_selection
.affinity()), skipsSpaceWhenMovingRight); | 924 pos = leftWordPosition(createVisiblePosition(m_selection.extent(), m_sel
ection.affinity()), skipsSpaceWhenMovingRight); |
925 break; | 925 break; |
926 } | 926 } |
927 case SentenceGranularity: | 927 case SentenceGranularity: |
928 case LineGranularity: | 928 case LineGranularity: |
929 case ParagraphGranularity: | 929 case ParagraphGranularity: |
930 case SentenceBoundary: | 930 case SentenceBoundary: |
931 case ParagraphBoundary: | 931 case ParagraphBoundary: |
932 case DocumentBoundary: | 932 case DocumentBoundary: |
933 // FIXME: Implement all of the above. | 933 // FIXME: Implement all of the above. |
934 pos = modifyMovingBackward(granularity); | 934 pos = modifyMovingBackward(granularity); |
935 break; | 935 break; |
936 case LineBoundary: | 936 case LineBoundary: |
937 pos = leftBoundaryOfLine(startForPlatform(), directionOfEnclosingBlock()
); | 937 pos = leftBoundaryOfLine(startForPlatform(), directionOfEnclosingBlock()
); |
938 break; | 938 break; |
939 } | 939 } |
940 return pos; | 940 return pos; |
941 } | 941 } |
942 | 942 |
943 VisiblePosition FrameSelection::modifyMovingBackward(TextGranularity granularity
) | 943 VisiblePosition FrameSelection::modifyMovingBackward(TextGranularity granularity
) |
944 { | 944 { |
945 VisiblePosition pos; | 945 VisiblePosition pos; |
946 switch (granularity) { | 946 switch (granularity) { |
947 case CharacterGranularity: | 947 case CharacterGranularity: |
948 if (isRange()) | 948 if (isRange()) |
949 pos = VisiblePosition(m_selection.start(), m_selection.affinity()); | 949 pos = createVisiblePosition(m_selection.start(), m_selection.affinit
y()); |
950 else | 950 else |
951 pos = previousPositionOf(VisiblePosition(m_selection.extent(), m_sel
ection.affinity()), CanSkipOverEditingBoundary); | 951 pos = previousPositionOf(createVisiblePosition(m_selection.extent(),
m_selection.affinity()), CanSkipOverEditingBoundary); |
952 break; | 952 break; |
953 case WordGranularity: | 953 case WordGranularity: |
954 pos = previousWordPosition(VisiblePosition(m_selection.extent(), m_selec
tion.affinity())); | 954 pos = previousWordPosition(createVisiblePosition(m_selection.extent(), m
_selection.affinity())); |
955 break; | 955 break; |
956 case SentenceGranularity: | 956 case SentenceGranularity: |
957 pos = previousSentencePosition(VisiblePosition(m_selection.extent(), m_s
election.affinity())); | 957 pos = previousSentencePosition(createVisiblePosition(m_selection.extent(
), m_selection.affinity())); |
958 break; | 958 break; |
959 case LineGranularity: | 959 case LineGranularity: |
960 pos = previousLinePosition(startForPlatform(), lineDirectionPointForBloc
kDirectionNavigation(START)); | 960 pos = previousLinePosition(startForPlatform(), lineDirectionPointForBloc
kDirectionNavigation(START)); |
961 break; | 961 break; |
962 case ParagraphGranularity: | 962 case ParagraphGranularity: |
963 pos = previousParagraphPosition(startForPlatform(), lineDirectionPointFo
rBlockDirectionNavigation(START)); | 963 pos = previousParagraphPosition(startForPlatform(), lineDirectionPointFo
rBlockDirectionNavigation(START)); |
964 break; | 964 break; |
965 case SentenceBoundary: | 965 case SentenceBoundary: |
966 pos = startOfSentence(startForPlatform()); | 966 pos = startOfSentence(startForPlatform()); |
967 break; | 967 break; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1112 trialFrameSelection->setSelection(m_selection); | 1112 trialFrameSelection->setSelection(m_selection); |
1113 trialFrameSelection->modify(alter, verticalDistance, direction, NotUserT
riggered); | 1113 trialFrameSelection->modify(alter, verticalDistance, direction, NotUserT
riggered); |
1114 } | 1114 } |
1115 | 1115 |
1116 willBeModified(alter, direction == DirectionUp ? DirectionBackward : Directi
onForward); | 1116 willBeModified(alter, direction == DirectionUp ? DirectionBackward : Directi
onForward); |
1117 | 1117 |
1118 VisiblePosition pos; | 1118 VisiblePosition pos; |
1119 LayoutUnit xPos = 0; | 1119 LayoutUnit xPos = 0; |
1120 switch (alter) { | 1120 switch (alter) { |
1121 case AlterationMove: | 1121 case AlterationMove: |
1122 pos = VisiblePosition(direction == DirectionUp ? m_selection.start() : m
_selection.end(), m_selection.affinity()); | 1122 pos = createVisiblePosition(direction == DirectionUp ? m_selection.start
() : m_selection.end(), m_selection.affinity()); |
1123 xPos = lineDirectionPointForBlockDirectionNavigation(direction == Direct
ionUp ? START : END); | 1123 xPos = lineDirectionPointForBlockDirectionNavigation(direction == Direct
ionUp ? START : END); |
1124 m_selection.setAffinity(direction == DirectionUp ? TextAffinity::Upstrea
m : TextAffinity::Downstream); | 1124 m_selection.setAffinity(direction == DirectionUp ? TextAffinity::Upstrea
m : TextAffinity::Downstream); |
1125 break; | 1125 break; |
1126 case AlterationExtend: | 1126 case AlterationExtend: |
1127 pos = VisiblePosition(m_selection.extent(), m_selection.affinity()); | 1127 pos = createVisiblePosition(m_selection.extent(), m_selection.affinity()
); |
1128 xPos = lineDirectionPointForBlockDirectionNavigation(EXTENT); | 1128 xPos = lineDirectionPointForBlockDirectionNavigation(EXTENT); |
1129 m_selection.setAffinity(TextAffinity::Downstream); | 1129 m_selection.setAffinity(TextAffinity::Downstream); |
1130 break; | 1130 break; |
1131 } | 1131 } |
1132 | 1132 |
1133 int startY; | 1133 int startY; |
1134 if (!absoluteCaretY(pos, startY)) | 1134 if (!absoluteCaretY(pos, startY)) |
1135 return false; | 1135 return false; |
1136 if (direction == DirectionUp) | 1136 if (direction == DirectionUp) |
1137 startY = -startY; | 1137 startY = -startY; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1223 case EXTENT: | 1223 case EXTENT: |
1224 pos = m_selection.extent(); | 1224 pos = m_selection.extent(); |
1225 break; | 1225 break; |
1226 } | 1226 } |
1227 | 1227 |
1228 LocalFrame* frame = pos.document()->frame(); | 1228 LocalFrame* frame = pos.document()->frame(); |
1229 if (!frame) | 1229 if (!frame) |
1230 return x; | 1230 return x; |
1231 | 1231 |
1232 if (m_xPosForVerticalArrowNavigation == NoXPosForVerticalArrowNavigation())
{ | 1232 if (m_xPosForVerticalArrowNavigation == NoXPosForVerticalArrowNavigation())
{ |
1233 VisiblePosition visiblePosition(pos, m_selection.affinity()); | 1233 VisiblePosition visiblePosition = createVisiblePosition(pos, m_selection
.affinity()); |
1234 // VisiblePosition creation can fail here if a node containing the selec
tion becomes visibility:hidden | 1234 // VisiblePosition creation can fail here if a node containing the selec
tion becomes visibility:hidden |
1235 // after the selection is created and before this function is called. | 1235 // after the selection is created and before this function is called. |
1236 x = lineDirectionPointForBlockDirectionNavigationOf(visiblePosition); | 1236 x = lineDirectionPointForBlockDirectionNavigationOf(visiblePosition); |
1237 m_xPosForVerticalArrowNavigation = x; | 1237 m_xPosForVerticalArrowNavigation = x; |
1238 } else { | 1238 } else { |
1239 x = m_xPosForVerticalArrowNavigation; | 1239 x = m_xPosForVerticalArrowNavigation; |
1240 } | 1240 } |
1241 | 1241 |
1242 return x; | 1242 return x; |
1243 } | 1243 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1310 IntRect FrameSelection::absoluteCaretBounds() | 1310 IntRect FrameSelection::absoluteCaretBounds() |
1311 { | 1311 { |
1312 ASSERT(m_frame->document()->lifecycle().state() != DocumentLifecycle::InPain
tInvalidation); | 1312 ASSERT(m_frame->document()->lifecycle().state() != DocumentLifecycle::InPain
tInvalidation); |
1313 m_frame->document()->updateLayoutIgnorePendingStylesheets(); | 1313 m_frame->document()->updateLayoutIgnorePendingStylesheets(); |
1314 if (!isNonOrphanedCaret(m_selection)) { | 1314 if (!isNonOrphanedCaret(m_selection)) { |
1315 clearCaretRect(); | 1315 clearCaretRect(); |
1316 } else { | 1316 } else { |
1317 if (isTextFormControl(m_selection)) | 1317 if (isTextFormControl(m_selection)) |
1318 updateCaretRect(PositionWithAffinity(isVisuallyEquivalentCandidate(m
_selection.start()) ? m_selection.start() : Position(), m_selection.affinity()))
; | 1318 updateCaretRect(PositionWithAffinity(isVisuallyEquivalentCandidate(m
_selection.start()) ? m_selection.start() : Position(), m_selection.affinity()))
; |
1319 else | 1319 else |
1320 updateCaretRect(VisiblePosition(m_selection.start(), m_selection.aff
inity())); | 1320 updateCaretRect(createVisiblePosition(m_selection.start(), m_selecti
on.affinity())); |
1321 } | 1321 } |
1322 return absoluteBoundsForLocalRect(m_selection.start().anchorNode(), localCar
etRectWithoutUpdate()); | 1322 return absoluteBoundsForLocalRect(m_selection.start().anchorNode(), localCar
etRectWithoutUpdate()); |
1323 } | 1323 } |
1324 | 1324 |
1325 static LayoutRect localCaretRect(const VisibleSelection& m_selection, const Posi
tionWithAffinity& caretPosition, LayoutObject*& layoutObject) | 1325 static LayoutRect localCaretRect(const VisibleSelection& m_selection, const Posi
tionWithAffinity& caretPosition, LayoutObject*& layoutObject) |
1326 { | 1326 { |
1327 layoutObject = nullptr; | 1327 layoutObject = nullptr; |
1328 if (!isNonOrphanedCaret(m_selection)) | 1328 if (!isNonOrphanedCaret(m_selection)) |
1329 return LayoutRect(); | 1329 return LayoutRect(); |
1330 | 1330 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1443 ContainerNode* ownerElementParent = ownerElement->parentNode(); | 1443 ContainerNode* ownerElementParent = ownerElement->parentNode(); |
1444 if (!ownerElementParent) | 1444 if (!ownerElementParent) |
1445 return; | 1445 return; |
1446 | 1446 |
1447 // This method's purpose is it to make it easier to select iframes (in order
to delete them). Don't do anything if the iframe isn't deletable. | 1447 // This method's purpose is it to make it easier to select iframes (in order
to delete them). Don't do anything if the iframe isn't deletable. |
1448 if (!ownerElementParent->hasEditableStyle()) | 1448 if (!ownerElementParent->hasEditableStyle()) |
1449 return; | 1449 return; |
1450 | 1450 |
1451 // Create compute positions before and after the element. | 1451 // Create compute positions before and after the element. |
1452 unsigned ownerElementNodeIndex = ownerElement->nodeIndex(); | 1452 unsigned ownerElementNodeIndex = ownerElement->nodeIndex(); |
1453 VisiblePosition beforeOwnerElement(VisiblePosition(Position(ownerElementPare
nt, ownerElementNodeIndex))); | 1453 VisiblePosition beforeOwnerElement = createVisiblePosition(Position(ownerEle
mentParent, ownerElementNodeIndex)); |
1454 VisiblePosition afterOwnerElement(VisiblePosition(Position(ownerElementParen
t, ownerElementNodeIndex + 1), VP_UPSTREAM_IF_POSSIBLE)); | 1454 VisiblePosition afterOwnerElement = createVisiblePosition(Position(ownerElem
entParent, ownerElementNodeIndex + 1), VP_UPSTREAM_IF_POSSIBLE); |
1455 | 1455 |
1456 // Focus on the parent frame, and then select from before this element to af
ter. | 1456 // Focus on the parent frame, and then select from before this element to af
ter. |
1457 VisibleSelection newSelection(beforeOwnerElement, afterOwnerElement); | 1457 VisibleSelection newSelection(beforeOwnerElement, afterOwnerElement); |
1458 page->focusController().setFocusedFrame(parent); | 1458 page->focusController().setFocusedFrame(parent); |
1459 toLocalFrame(parent)->selection().setSelection(newSelection); | 1459 toLocalFrame(parent)->selection().setSelection(newSelection); |
1460 } | 1460 } |
1461 | 1461 |
1462 void FrameSelection::selectAll() | 1462 void FrameSelection::selectAll() |
1463 { | 1463 { |
1464 Document* document = m_frame->document(); | 1464 Document* document = m_frame->document(); |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1876 { | 1876 { |
1877 LayoutRect rect; | 1877 LayoutRect rect; |
1878 | 1878 |
1879 switch (selectionType()) { | 1879 switch (selectionType()) { |
1880 case NoSelection: | 1880 case NoSelection: |
1881 return; | 1881 return; |
1882 case CaretSelection: | 1882 case CaretSelection: |
1883 rect = LayoutRect(absoluteCaretBounds()); | 1883 rect = LayoutRect(absoluteCaretBounds()); |
1884 break; | 1884 break; |
1885 case RangeSelection: | 1885 case RangeSelection: |
1886 rect = LayoutRect(revealExtentOption == RevealExtent ? absoluteCaretBoun
dsOf(VisiblePosition(extent())) : enclosingIntRect(unclippedBounds())); | 1886 rect = LayoutRect(revealExtentOption == RevealExtent ? absoluteCaretBoun
dsOf(createVisiblePosition(extent())) : enclosingIntRect(unclippedBounds())); |
1887 break; | 1887 break; |
1888 } | 1888 } |
1889 | 1889 |
1890 Position start = this->start(); | 1890 Position start = this->start(); |
1891 ASSERT(start.anchorNode()); | 1891 ASSERT(start.anchorNode()); |
1892 if (start.anchorNode() && start.anchorNode()->layoutObject()) { | 1892 if (start.anchorNode() && start.anchorNode()->layoutObject()) { |
1893 // FIXME: This code only handles scrolling the startContainer's layer, b
ut | 1893 // FIXME: This code only handles scrolling the startContainer's layer, b
ut |
1894 // the selection rect could intersect more than just that. | 1894 // the selection rect could intersect more than just that. |
1895 if (DocumentLoader* documentLoader = m_frame->loader().documentLoader()) | 1895 if (DocumentLoader* documentLoader = m_frame->loader().documentLoader()) |
1896 documentLoader->initialScrollState().wasScrolledByUser = true; | 1896 documentLoader->initialScrollState().wasScrolledByUser = true; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2091 | 2091 |
2092 void showTree(const blink::FrameSelection* sel) | 2092 void showTree(const blink::FrameSelection* sel) |
2093 { | 2093 { |
2094 if (sel) | 2094 if (sel) |
2095 sel->showTreeForThis(); | 2095 sel->showTreeForThis(); |
2096 else | 2096 else |
2097 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n"); | 2097 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n"); |
2098 } | 2098 } |
2099 | 2099 |
2100 #endif | 2100 #endif |
OLD | NEW |