Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: Source/core/editing/VisibleUnits.cpp

Issue 1310043003: Introduce previousPositionOf() for VisiblePosition (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-28T16:28:03 Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 * 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 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 return findWordEndBoundary(characters, length, offset); 690 return findWordEndBoundary(characters, length, offset);
691 } 691 }
692 692
693 VisiblePosition endOfWord(const VisiblePosition& c, EWordSide side) 693 VisiblePosition endOfWord(const VisiblePosition& c, EWordSide side)
694 { 694 {
695 VisiblePosition p = c; 695 VisiblePosition p = c;
696 if (side == LeftWordIfOnBoundary) { 696 if (side == LeftWordIfOnBoundary) {
697 if (isStartOfParagraph(c)) 697 if (isStartOfParagraph(c))
698 return c; 698 return c;
699 699
700 p = c.previous(); 700 p = previousPositionOf(c);
701 if (p.isNull()) 701 if (p.isNull())
702 return c; 702 return c;
703 } else if (isEndOfParagraph(c)) { 703 } else if (isEndOfParagraph(c)) {
704 return c; 704 return c;
705 } 705 }
706 706
707 return nextBoundary(p, endWordBoundary); 707 return nextBoundary(p, endWordBoundary);
708 } 708 }
709 709
710 static unsigned previousWordPositionBoundary(const UChar* characters, unsigned l ength, unsigned offset, BoundarySearchContextAvailability mayHaveMoreContext, bo ol& needMoreContext) 710 static unsigned previousWordPositionBoundary(const UChar* characters, unsigned l ength, unsigned offset, BoundarySearchContextAvailability mayHaveMoreContext, bo ol& needMoreContext)
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 // Please refer to https://bugs.webkit.org/show_bug.cgi?id=49107 for detail. 886 // Please refer to https://bugs.webkit.org/show_bug.cgi?id=49107 for detail.
887 VisiblePosition visPos = endPositionForLine(c, mode); 887 VisiblePosition visPos = endPositionForLine(c, mode);
888 888
889 if (mode == UseLogicalOrdering) { 889 if (mode == UseLogicalOrdering) {
890 // Make sure the end of line is at the same line as the given input posi tion. For a wrapping line, the logical end 890 // Make sure the end of line is at the same line as the given input posi tion. For a wrapping line, the logical end
891 // position for the not-last-2-lines might incorrectly hand back the log ical beginning of the next line. 891 // position for the not-last-2-lines might incorrectly hand back the log ical beginning of the next line.
892 // For example, <div contenteditable dir="rtl" style="line-break:before- white-space">abcdefg abcdefg abcdefg 892 // For example, <div contenteditable dir="rtl" style="line-break:before- white-space">abcdefg abcdefg abcdefg
893 // a abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abc defg abcdefg </div> 893 // a abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abc defg abcdefg </div>
894 // In this case, use the previous position of the computed logical end p osition. 894 // In this case, use the previous position of the computed logical end p osition.
895 if (!inSameLogicalLine(c, visPos)) 895 if (!inSameLogicalLine(c, visPos))
896 visPos = visPos.previous(); 896 visPos = previousPositionOf(visPos);
897 897
898 if (ContainerNode* editableRoot = highestEditableRoot(c.deepEquivalent() )) { 898 if (ContainerNode* editableRoot = highestEditableRoot(c.deepEquivalent() )) {
899 if (!editableRoot->contains(visPos.deepEquivalent().computeContainer Node())) 899 if (!editableRoot->contains(visPos.deepEquivalent().computeContainer Node()))
900 return VisiblePosition(lastPositionInNode(editableRoot)); 900 return VisiblePosition(lastPositionInNode(editableRoot));
901 } 901 }
902 902
903 return c.honorEditingBoundaryAtOrAfter(visPos); 903 return c.honorEditingBoundaryAtOrAfter(visPos);
904 } 904 }
905 905
906 // Make sure the end of line is at the same line as the given input position . Else use the previous position to 906 // Make sure the end of line is at the same line as the given input position . Else use the previous position to
907 // obtain end of line. This condition happens when the input position is bef ore the space character at the end 907 // obtain end of line. This condition happens when the input position is bef ore the space character at the end
908 // of a soft-wrapped non-editable line. In this scenario, endPositionForLine would incorrectly hand back a position 908 // of a soft-wrapped non-editable line. In this scenario, endPositionForLine would incorrectly hand back a position
909 // in the next line instead. This fix is to account for the discrepancy betw een lines with webkit-line-break:after-white-space style 909 // in the next line instead. This fix is to account for the discrepancy betw een lines with webkit-line-break:after-white-space style
910 // versus lines without that style, which would break before a space by defa ult. 910 // versus lines without that style, which would break before a space by defa ult.
911 if (!inSameLine(c, visPos)) { 911 if (!inSameLine(c, visPos)) {
912 visPos = c.previous(); 912 visPos = previousPositionOf(c);
913 if (visPos.isNull()) 913 if (visPos.isNull())
914 return VisiblePosition(); 914 return VisiblePosition();
915 visPos = endPositionForLine(visPos, UseInlineBoxOrdering); 915 visPos = endPositionForLine(visPos, UseInlineBoxOrdering);
916 } 916 }
917 917
918 return c.honorEditingBoundaryAtOrAfter(visPos); 918 return c.honorEditingBoundaryAtOrAfter(visPos);
919 } 919 }
920 920
921 // FIXME: Rename this function to reflect the fact it ignores bidi levels. 921 // FIXME: Rename this function to reflect the fact it ignores bidi levels.
922 VisiblePosition endOfLine(const VisiblePosition& currentPosition) 922 VisiblePosition endOfLine(const VisiblePosition& currentPosition)
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 return VisiblePosition(lastPositionInNode(doc)); 1408 return VisiblePosition(lastPositionInNode(doc));
1409 } 1409 }
1410 1410
1411 VisiblePosition endOfDocument(const VisiblePosition& c) 1411 VisiblePosition endOfDocument(const VisiblePosition& c)
1412 { 1412 {
1413 return endOfDocument(c.deepEquivalent().anchorNode()); 1413 return endOfDocument(c.deepEquivalent().anchorNode());
1414 } 1414 }
1415 1415
1416 bool isStartOfDocument(const VisiblePosition& p) 1416 bool isStartOfDocument(const VisiblePosition& p)
1417 { 1417 {
1418 return p.isNotNull() && p.previous(CanCrossEditingBoundary).isNull(); 1418 return p.isNotNull() && previousPositionOf(p, CanCrossEditingBoundary).isNul l();
1419 } 1419 }
1420 1420
1421 bool isEndOfDocument(const VisiblePosition& p) 1421 bool isEndOfDocument(const VisiblePosition& p)
1422 { 1422 {
1423 return p.isNotNull() && p.next(CanCrossEditingBoundary).isNull(); 1423 return p.isNotNull() && p.next(CanCrossEditingBoundary).isNull();
1424 } 1424 }
1425 1425
1426 // --------- 1426 // ---------
1427 1427
1428 VisiblePosition startOfEditableContent(const VisiblePosition& visiblePosition) 1428 VisiblePosition startOfEditableContent(const VisiblePosition& visiblePosition)
(...skipping 902 matching lines...) Expand 10 before | Expand all | Expand 10 after
2331 { 2331 {
2332 return isVisuallyEquivalentCandidateAlgorithm<EditingStrategy>(position); 2332 return isVisuallyEquivalentCandidateAlgorithm<EditingStrategy>(position);
2333 } 2333 }
2334 2334
2335 bool isVisuallyEquivalentCandidate(const PositionInComposedTree& position) 2335 bool isVisuallyEquivalentCandidate(const PositionInComposedTree& position)
2336 { 2336 {
2337 return isVisuallyEquivalentCandidateAlgorithm<EditingInComposedTreeStrategy> (position); 2337 return isVisuallyEquivalentCandidateAlgorithm<EditingInComposedTreeStrategy> (position);
2338 } 2338 }
2339 2339
2340 } // namespace blink 2340 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/editing/VisibleSelection.cpp ('k') | Source/core/editing/commands/ApplyBlockElementCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698