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

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

Issue 252783002: Make Range.detach() a no-op (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/editing/FrameSelection.cpp ('k') | Source/core/editing/TextCheckingHelper.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) 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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 194
195 // If spellingSearchRange starts in the middle of a word, advance to the nex t word so we start checking 195 // If spellingSearchRange starts in the middle of a word, advance to the nex t word so we start checking
196 // at a word boundary. Going back by one char and then forward by a word doe s the trick. 196 // at a word boundary. Going back by one char and then forward by a word doe s the trick.
197 if (startedWithSelection) { 197 if (startedWithSelection) {
198 VisiblePosition oneBeforeStart = startVisiblePosition(spellingSearchRang e.get(), DOWNSTREAM).previous(); 198 VisiblePosition oneBeforeStart = startVisiblePosition(spellingSearchRang e.get(), DOWNSTREAM).previous();
199 if (oneBeforeStart.isNotNull()) 199 if (oneBeforeStart.isNotNull())
200 setStart(spellingSearchRange.get(), endOfWord(oneBeforeStart)); 200 setStart(spellingSearchRange.get(), endOfWord(oneBeforeStart));
201 // else we were already at the start of the editable node 201 // else we were already at the start of the editable node
202 } 202 }
203 203
204 if (spellingSearchRange->collapsed(IGNORE_EXCEPTION)) 204 if (spellingSearchRange->collapsed())
205 return; // nothing to search in 205 return; // nothing to search in
206 206
207 // We go to the end of our first range instead of the start of it, just to b e sure 207 // We go to the end of our first range instead of the start of it, just to b e sure
208 // we don't get foiled by any word boundary problems at the start. It means we might 208 // we don't get foiled by any word boundary problems at the start. It means we might
209 // do a tiny bit more searching. 209 // do a tiny bit more searching.
210 Node* searchEndNodeAfterWrap = spellingSearchRange->endContainer(); 210 Node* searchEndNodeAfterWrap = spellingSearchRange->endContainer();
211 int searchEndOffsetAfterWrap = spellingSearchRange->endOffset(); 211 int searchEndOffsetAfterWrap = spellingSearchRange->endOffset();
212 212
213 int misspellingOffset = 0; 213 int misspellingOffset = 0;
214 GrammarDetail grammarDetail; 214 GrammarDetail grammarDetail;
215 int grammarPhraseOffset = 0; 215 int grammarPhraseOffset = 0;
216 RefPtrWillBeRawPtr<Range> grammarSearchRange = nullptr; 216 RefPtrWillBeRawPtr<Range> grammarSearchRange = nullptr;
217 String badGrammarPhrase; 217 String badGrammarPhrase;
218 String misspelledWord; 218 String misspelledWord;
219 219
220 bool isSpelling = true; 220 bool isSpelling = true;
221 int foundOffset = 0; 221 int foundOffset = 0;
222 String foundItem; 222 String foundItem;
223 RefPtrWillBeRawPtr<Range> firstMisspellingRange = nullptr; 223 RefPtrWillBeRawPtr<Range> firstMisspellingRange = nullptr;
224 if (unifiedTextCheckerEnabled()) { 224 if (unifiedTextCheckerEnabled()) {
225 grammarSearchRange = spellingSearchRange->cloneRange(IGNORE_EXCEPTION); 225 grammarSearchRange = spellingSearchRange->cloneRange();
226 foundItem = TextCheckingHelper(spellCheckerClient(), spellingSearchRange ).findFirstMisspellingOrBadGrammar(isGrammarCheckingEnabled(), isSpelling, found Offset, grammarDetail); 226 foundItem = TextCheckingHelper(spellCheckerClient(), spellingSearchRange ).findFirstMisspellingOrBadGrammar(isGrammarCheckingEnabled(), isSpelling, found Offset, grammarDetail);
227 if (isSpelling) { 227 if (isSpelling) {
228 misspelledWord = foundItem; 228 misspelledWord = foundItem;
229 misspellingOffset = foundOffset; 229 misspellingOffset = foundOffset;
230 } else { 230 } else {
231 badGrammarPhrase = foundItem; 231 badGrammarPhrase = foundItem;
232 grammarPhraseOffset = foundOffset; 232 grammarPhraseOffset = foundOffset;
233 } 233 }
234 } else { 234 } else {
235 misspelledWord = TextCheckingHelper(spellCheckerClient(), spellingSearch Range).findFirstMisspelling(misspellingOffset, false, firstMisspellingRange); 235 misspelledWord = TextCheckingHelper(spellCheckerClient(), spellingSearch Range).findFirstMisspelling(misspellingOffset, false, firstMisspellingRange);
236 grammarSearchRange = spellingSearchRange->cloneRange(IGNORE_EXCEPTION); 236 grammarSearchRange = spellingSearchRange->cloneRange();
237 if (!misspelledWord.isEmpty()) { 237 if (!misspelledWord.isEmpty()) {
238 // Stop looking at start of next misspelled word 238 // Stop looking at start of next misspelled word
239 CharacterIterator chars(grammarSearchRange.get()); 239 CharacterIterator chars(grammarSearchRange.get());
240 chars.advance(misspellingOffset); 240 chars.advance(misspellingOffset);
241 grammarSearchRange->setEnd(chars.range()->startContainer(), chars.ra nge()->startOffset(), IGNORE_EXCEPTION); 241 grammarSearchRange->setEnd(chars.range()->startContainer(), chars.ra nge()->startOffset(), IGNORE_EXCEPTION);
242 } 242 }
243 243
244 if (isGrammarCheckingEnabled()) 244 if (isGrammarCheckingEnabled())
245 badGrammarPhrase = TextCheckingHelper(spellCheckerClient(), grammarS earchRange).findFirstBadGrammar(grammarDetail, grammarPhraseOffset, false); 245 badGrammarPhrase = TextCheckingHelper(spellCheckerClient(), grammarS earchRange).findFirstBadGrammar(grammarDetail, grammarPhraseOffset, false);
246 } 246 }
247 247
248 // If we found neither bad grammar nor a misspelled word, wrap and try again (but don't bother if we started at the beginning of the 248 // If we found neither bad grammar nor a misspelled word, wrap and try again (but don't bother if we started at the beginning of the
249 // block rather than at a selection). 249 // block rather than at a selection).
250 if (startedWithSelection && !misspelledWord && !badGrammarPhrase) { 250 if (startedWithSelection && !misspelledWord && !badGrammarPhrase) {
251 spellingSearchRange->setStart(topNode, 0, IGNORE_EXCEPTION); 251 spellingSearchRange->setStart(topNode, 0, IGNORE_EXCEPTION);
252 // going until the end of the very first chunk we tested is far enough 252 // going until the end of the very first chunk we tested is far enough
253 spellingSearchRange->setEnd(searchEndNodeAfterWrap, searchEndOffsetAfter Wrap, IGNORE_EXCEPTION); 253 spellingSearchRange->setEnd(searchEndNodeAfterWrap, searchEndOffsetAfter Wrap, IGNORE_EXCEPTION);
254 254
255 if (unifiedTextCheckerEnabled()) { 255 if (unifiedTextCheckerEnabled()) {
256 grammarSearchRange = spellingSearchRange->cloneRange(IGNORE_EXCEPTIO N); 256 grammarSearchRange = spellingSearchRange->cloneRange();
257 foundItem = TextCheckingHelper(spellCheckerClient(), spellingSearchR ange).findFirstMisspellingOrBadGrammar(isGrammarCheckingEnabled(), isSpelling, f oundOffset, grammarDetail); 257 foundItem = TextCheckingHelper(spellCheckerClient(), spellingSearchR ange).findFirstMisspellingOrBadGrammar(isGrammarCheckingEnabled(), isSpelling, f oundOffset, grammarDetail);
258 if (isSpelling) { 258 if (isSpelling) {
259 misspelledWord = foundItem; 259 misspelledWord = foundItem;
260 misspellingOffset = foundOffset; 260 misspellingOffset = foundOffset;
261 } else { 261 } else {
262 badGrammarPhrase = foundItem; 262 badGrammarPhrase = foundItem;
263 grammarPhraseOffset = foundOffset; 263 grammarPhraseOffset = foundOffset;
264 } 264 }
265 } else { 265 } else {
266 misspelledWord = TextCheckingHelper(spellCheckerClient(), spellingSe archRange).findFirstMisspelling(misspellingOffset, false, firstMisspellingRange) ; 266 misspelledWord = TextCheckingHelper(spellCheckerClient(), spellingSe archRange).findFirstMisspelling(misspellingOffset, false, firstMisspellingRange) ;
267 grammarSearchRange = spellingSearchRange->cloneRange(IGNORE_EXCEPTIO N); 267 grammarSearchRange = spellingSearchRange->cloneRange();
268 if (!misspelledWord.isEmpty()) { 268 if (!misspelledWord.isEmpty()) {
269 // Stop looking at start of next misspelled word 269 // Stop looking at start of next misspelled word
270 CharacterIterator chars(grammarSearchRange.get()); 270 CharacterIterator chars(grammarSearchRange.get());
271 chars.advance(misspellingOffset); 271 chars.advance(misspellingOffset);
272 grammarSearchRange->setEnd(chars.range()->startContainer(), char s.range()->startOffset(), IGNORE_EXCEPTION); 272 grammarSearchRange->setEnd(chars.range()->startContainer(), char s.range()->startOffset(), IGNORE_EXCEPTION);
273 } 273 }
274 274
275 if (isGrammarCheckingEnabled()) 275 if (isGrammarCheckingEnabled())
276 badGrammarPhrase = TextCheckingHelper(spellCheckerClient(), gram marSearchRange).findFirstBadGrammar(grammarDetail, grammarPhraseOffset, false); 276 badGrammarPhrase = TextCheckingHelper(spellCheckerClient(), gram marSearchRange).findFirstBadGrammar(grammarDetail, grammarPhraseOffset, false);
277 } 277 }
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 } 845 }
846 846
847 void SpellChecker::requestTextChecking(const Element& element) 847 void SpellChecker::requestTextChecking(const Element& element)
848 { 848 {
849 RefPtrWillBeRawPtr<Range> rangeToCheck = rangeOfContents(const_cast<Element* >(&element)); 849 RefPtrWillBeRawPtr<Range> rangeToCheck = rangeOfContents(const_cast<Element* >(&element));
850 m_spellCheckRequester->requestCheckingFor(SpellCheckRequest::create(TextChec kingTypeSpelling | TextCheckingTypeGrammar, TextCheckingProcessBatch, rangeToChe ck, rangeToCheck)); 850 m_spellCheckRequester->requestCheckingFor(SpellCheckRequest::create(TextChec kingTypeSpelling | TextCheckingTypeGrammar, TextCheckingProcessBatch, rangeToChe ck, rangeToCheck));
851 } 851 }
852 852
853 853
854 } // namespace WebCore 854 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/editing/FrameSelection.cpp ('k') | Source/core/editing/TextCheckingHelper.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698