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

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

Issue 1338953002: Introduce composed tree version of startOfWord() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-09-14T11:03:14 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
« no previous file with comments | « Source/core/editing/VisibleUnits.h ('k') | Source/core/editing/VisibleUnitsTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 needMoreContext = true; 821 needMoreContext = true;
822 return 0; 822 return 0;
823 } 823 }
824 needMoreContext = false; 824 needMoreContext = false;
825 int start, end; 825 int start, end;
826 U16_BACK_1(characters, 0, offset); 826 U16_BACK_1(characters, 0, offset);
827 findWordBoundary(characters, length, offset, &start, &end); 827 findWordBoundary(characters, length, offset, &start, &end);
828 return start; 828 return start;
829 } 829 }
830 830
831 VisiblePosition startOfWord(const VisiblePosition& c, EWordSide side) 831 template <typename Strategy>
832 static VisiblePositionTemplate<Strategy> startOfWordAlgorithm(const VisiblePosit ionTemplate<Strategy>& c, EWordSide side)
832 { 833 {
833 // FIXME: This returns a null VP for c at the start of the document 834 // TODO(yosin) This returns a null VP for c at the start of the document
834 // and side == LeftWordIfOnBoundary 835 // and |side| == |LeftWordIfOnBoundary|
835 VisiblePosition p = c; 836 VisiblePositionTemplate<Strategy> p = c;
836 if (side == RightWordIfOnBoundary) { 837 if (side == RightWordIfOnBoundary) {
837 // at paragraph end, the startofWord is the current position 838 // at paragraph end, the startofWord is the current position
838 if (isEndOfParagraph(c)) 839 if (isEndOfParagraph(c))
839 return c; 840 return c;
840 841
841 p = nextPositionOf(c); 842 p = nextPositionOf(c);
842 if (p.isNull()) 843 if (p.isNull())
843 return c; 844 return c;
844 } 845 }
845 return previousBoundary(p, startWordBoundary); 846 return previousBoundary(p, startWordBoundary);
846 } 847 }
847 848
849 VisiblePosition startOfWord(const VisiblePosition& c, EWordSide side)
850 {
851 return startOfWordAlgorithm<EditingStrategy>(c, side);
852 }
853
854 VisiblePositionInComposedTree startOfWord(const VisiblePositionInComposedTree& c , EWordSide side)
855 {
856 return startOfWordAlgorithm<EditingInComposedTreeStrategy>(c, side);
857 }
858
848 static unsigned endWordBoundary(const UChar* characters, unsigned length, unsign ed offset, BoundarySearchContextAvailability mayHaveMoreContext, bool& needMoreC ontext) 859 static unsigned endWordBoundary(const UChar* characters, unsigned length, unsign ed offset, BoundarySearchContextAvailability mayHaveMoreContext, bool& needMoreC ontext)
849 { 860 {
850 ASSERT(offset <= length); 861 ASSERT(offset <= length);
851 if (mayHaveMoreContext && endOfFirstWordBoundaryContext(characters + offset, length - offset) == static_cast<int>(length - offset)) { 862 if (mayHaveMoreContext && endOfFirstWordBoundaryContext(characters + offset, length - offset) == static_cast<int>(length - offset)) {
852 needMoreContext = true; 863 needMoreContext = true;
853 return length; 864 return length;
854 } 865 }
855 needMoreContext = false; 866 needMoreContext = false;
856 return findWordEndBoundary(characters, length, offset); 867 return findWordEndBoundary(characters, length, offset);
857 } 868 }
(...skipping 2343 matching lines...) Expand 10 before | Expand all | Expand 10 after
3201 { 3212 {
3202 return previousPositionOfAlgorithm<EditingStrategy>(visiblePosition, rule); 3213 return previousPositionOfAlgorithm<EditingStrategy>(visiblePosition, rule);
3203 } 3214 }
3204 3215
3205 VisiblePositionInComposedTree previousPositionOf(const VisiblePositionInComposed Tree& visiblePosition, EditingBoundaryCrossingRule rule) 3216 VisiblePositionInComposedTree previousPositionOf(const VisiblePositionInComposed Tree& visiblePosition, EditingBoundaryCrossingRule rule)
3206 { 3217 {
3207 return previousPositionOfAlgorithm<EditingInComposedTreeStrategy>(visiblePos ition, rule); 3218 return previousPositionOfAlgorithm<EditingInComposedTreeStrategy>(visiblePos ition, rule);
3208 } 3219 }
3209 3220
3210 } // namespace blink 3221 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/editing/VisibleUnits.h ('k') | Source/core/editing/VisibleUnitsTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698