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

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

Issue 2274183003: Force expandEnd/RangeToSentenceBoundary to return a valid EphemeralRange (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 | « no previous file | 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) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 } 92 }
93 return false; 93 return false;
94 } 94 }
95 95
96 static EphemeralRange expandEndToSentenceBoundary(const EphemeralRange& range) 96 static EphemeralRange expandEndToSentenceBoundary(const EphemeralRange& range)
97 { 97 {
98 DCHECK(range.isNotNull()); 98 DCHECK(range.isNotNull());
99 const VisiblePosition& visibleEnd = createVisiblePosition(range.endPosition( )); 99 const VisiblePosition& visibleEnd = createVisiblePosition(range.endPosition( ));
100 DCHECK(visibleEnd.isNotNull()); 100 DCHECK(visibleEnd.isNotNull());
101 const Position& sentenceEnd = endOfSentence(visibleEnd).deepEquivalent(); 101 const Position& sentenceEnd = endOfSentence(visibleEnd).deepEquivalent();
102 // TODO(xiaochengh): |sentenceEnd < range.startPosition()| seems possible, 102 // TODO(xiaochengh): |sentenceEnd < range.endPosition()| is possible,
103 // which would trigger a DCHECK in EphemeralRange's constructor. Need more 103 // which would trigger a DCHECK in EphemeralRange's constructor if we return
104 // investigation, and if that is really the case, fix it. 104 // it directly. However, this shouldn't happen and needs to be fixed.
105 return EphemeralRange(range.startPosition(), sentenceEnd.isNotNull() ? sente nceEnd : range.endPosition()); 105 return EphemeralRange(range.startPosition(), sentenceEnd.isNotNull() && sent enceEnd > range.endPosition() ? sentenceEnd : range.endPosition());
106 } 106 }
107 107
108 static EphemeralRange expandRangeToSentenceBoundary(const EphemeralRange& range) 108 static EphemeralRange expandRangeToSentenceBoundary(const EphemeralRange& range)
109 { 109 {
110 DCHECK(range.isNotNull()); 110 DCHECK(range.isNotNull());
111 const VisiblePosition& visibleStart = createVisiblePosition(range.startPosit ion()); 111 const VisiblePosition& visibleStart = createVisiblePosition(range.startPosit ion());
112 DCHECK(visibleStart.isNotNull()); 112 DCHECK(visibleStart.isNotNull());
113 const Position& sentenceStart = startOfSentence(visibleStart).deepEquivalent (); 113 const Position& sentenceStart = startOfSentence(visibleStart).deepEquivalent ();
114 const VisiblePosition& visibleEnd = createVisiblePosition(range.endPosition( )); 114 // TODO(xiaochengh): |sentenceStart > range.startPosition()| is possible,
115 DCHECK(visibleStart.isNotNull()); 115 // which would trigger a DCHECK in EphemeralRange's constructor if we return
116 const Position& sentenceEnd = endOfSentence(visibleEnd).deepEquivalent(); 116 // it directly. However, this shouldn't happen and needs to be fixed.
117 return EphemeralRange(sentenceStart.isNull() ? range.startPosition() : sente nceStart, sentenceEnd.isNull() ? range.endPosition() : sentenceEnd); 117 return expandEndToSentenceBoundary(EphemeralRange(sentenceStart.isNotNull() && sentenceStart < range.startPosition() ? sentenceStart : range.startPosition() , range.endPosition()));
118 } 118 }
119 119
120 } // namespace 120 } // namespace
121 121
122 SpellChecker* SpellChecker::create(LocalFrame& frame) 122 SpellChecker* SpellChecker::create(LocalFrame& frame)
123 { 123 {
124 return new SpellChecker(frame); 124 return new SpellChecker(frame);
125 } 125 }
126 126
127 static SpellCheckerClient& emptySpellCheckerClient() 127 static SpellCheckerClient& emptySpellCheckerClient()
(...skipping 812 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 VisiblePosition newParagraphStart = startOfNextParagraph(createVisiblePo sition(paragraphEnd)); 940 VisiblePosition newParagraphStart = startOfNextParagraph(createVisiblePo sition(paragraphEnd));
941 paragraphStart = newParagraphStart.toParentAnchoredPosition(); 941 paragraphStart = newParagraphStart.toParentAnchoredPosition();
942 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPositio n(); 942 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPositio n();
943 firstIteration = false; 943 firstIteration = false;
944 totalLengthProcessed += currentLength; 944 totalLengthProcessed += currentLength;
945 } 945 }
946 return std::make_pair(firstFoundItem, firstFoundOffset); 946 return std::make_pair(firstFoundItem, firstFoundOffset);
947 } 947 }
948 948
949 } // namespace blink 949 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698