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

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

Issue 2732863004: Add VisibleUnits::startOfWordPosition (Closed)
Patch Set: Created 3 years, 9 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 | « third_party/WebKit/Source/core/editing/VisibleUnits.h ('k') | no next file » | 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 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights
3 * reserved. 3 * 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 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 return 0; 1036 return 0;
1037 } 1037 }
1038 needMoreContext = false; 1038 needMoreContext = false;
1039 int start, end; 1039 int start, end;
1040 U16_BACK_1(characters, 0, offset); 1040 U16_BACK_1(characters, 0, offset);
1041 findWordBoundary(characters, length, offset, &start, &end); 1041 findWordBoundary(characters, length, offset, &start, &end);
1042 return start; 1042 return start;
1043 } 1043 }
1044 1044
1045 template <typename Strategy> 1045 template <typename Strategy>
1046 static VisiblePositionTemplate<Strategy> startOfWordAlgorithm( 1046 static PositionTemplate<Strategy> startOfWordAlgorithm(
1047 const VisiblePositionTemplate<Strategy>& c, 1047 const VisiblePositionTemplate<Strategy>& c,
1048 EWordSide side) { 1048 EWordSide side) {
1049 DCHECK(c.isValid()) << c; 1049 DCHECK(c.isValid()) << c;
1050 // TODO(yosin) This returns a null VP for c at the start of the document 1050 // TODO(yosin) This returns a null VP for c at the start of the document
1051 // and |side| == |LeftWordIfOnBoundary| 1051 // and |side| == |LeftWordIfOnBoundary|
1052 VisiblePositionTemplate<Strategy> p = c; 1052 VisiblePositionTemplate<Strategy> p = c;
1053 if (side == RightWordIfOnBoundary) { 1053 if (side == RightWordIfOnBoundary) {
1054 // at paragraph end, the startofWord is the current position 1054 // at paragraph end, the startofWord is the current position
1055 if (isEndOfParagraph(c)) 1055 if (isEndOfParagraph(c))
1056 return c; 1056 return c.deepEquivalent();
1057 1057
1058 p = nextPositionOf(c); 1058 p = nextPositionOf(c);
1059 if (p.isNull()) 1059 if (p.isNull())
1060 return c; 1060 return c.deepEquivalent();
1061 } 1061 }
1062 return createVisiblePosition(previousBoundary(p, startWordBoundary)); 1062 return previousBoundary(p, startWordBoundary);
1063 } 1063 }
1064 1064
1065 VisiblePosition startOfWord(const VisiblePosition& c, EWordSide side) { 1065 Position startOfWordPosition(const VisiblePosition& position, EWordSide side) {
1066 return startOfWordAlgorithm<EditingStrategy>(c, side); 1066 return startOfWordAlgorithm<EditingStrategy>(position, side);
1067 } 1067 }
1068 1068
1069 VisiblePositionInFlatTree startOfWord(const VisiblePositionInFlatTree& c, 1069 VisiblePosition startOfWord(const VisiblePosition& position, EWordSide side) {
1070 return createVisiblePosition(startOfWordPosition(position, side));
1071 }
1072
1073 PositionInFlatTree startOfWordPosition(
1074 const VisiblePositionInFlatTree& position,
1075 EWordSide side) {
1076 return startOfWordAlgorithm<EditingInFlatTreeStrategy>(position, side);
1077 }
1078
1079 VisiblePositionInFlatTree startOfWord(const VisiblePositionInFlatTree& position,
1070 EWordSide side) { 1080 EWordSide side) {
1071 return startOfWordAlgorithm<EditingInFlatTreeStrategy>(c, side); 1081 return createVisiblePosition(startOfWordPosition(position, side));
1072 } 1082 }
1073 1083
1074 static unsigned endWordBoundary( 1084 static unsigned endWordBoundary(
1075 const UChar* characters, 1085 const UChar* characters,
1076 unsigned length, 1086 unsigned length,
1077 unsigned offset, 1087 unsigned offset,
1078 BoundarySearchContextAvailability mayHaveMoreContext, 1088 BoundarySearchContextAvailability mayHaveMoreContext,
1079 bool& needMoreContext) { 1089 bool& needMoreContext) {
1080 DCHECK_LE(offset, length); 1090 DCHECK_LE(offset, length);
1081 if (mayHaveMoreContext && 1091 if (mayHaveMoreContext &&
(...skipping 2905 matching lines...) Expand 10 before | Expand all | Expand 10 after
3987 3997
3988 VisiblePositionInFlatTree previousPositionOf( 3998 VisiblePositionInFlatTree previousPositionOf(
3989 const VisiblePositionInFlatTree& visiblePosition, 3999 const VisiblePositionInFlatTree& visiblePosition,
3990 EditingBoundaryCrossingRule rule) { 4000 EditingBoundaryCrossingRule rule) {
3991 DCHECK(visiblePosition.isValid()) << visiblePosition; 4001 DCHECK(visiblePosition.isValid()) << visiblePosition;
3992 return previousPositionOfAlgorithm<EditingInFlatTreeStrategy>( 4002 return previousPositionOfAlgorithm<EditingInFlatTreeStrategy>(
3993 visiblePosition.deepEquivalent(), rule); 4003 visiblePosition.deepEquivalent(), rule);
3994 } 4004 }
3995 4005
3996 } // namespace blink 4006 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/VisibleUnits.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698