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

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

Issue 544083002: Avoid allocating temporary ranges in connection with text and character iterators. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address review comments. Created 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/editing/PlainTextRange.cpp ('k') | Source/core/editing/SurroundingText.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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 badGrammarPhrase = foundItem; 244 badGrammarPhrase = foundItem;
245 grammarPhraseOffset = foundOffset; 245 grammarPhraseOffset = foundOffset;
246 } 246 }
247 } else { 247 } else {
248 misspelledWord = TextCheckingHelper(spellCheckerClient(), spellingSearch Range).findFirstMisspelling(misspellingOffset, false, firstMisspellingRange); 248 misspelledWord = TextCheckingHelper(spellCheckerClient(), spellingSearch Range).findFirstMisspelling(misspellingOffset, false, firstMisspellingRange);
249 grammarSearchRange = spellingSearchRange->cloneRange(); 249 grammarSearchRange = spellingSearchRange->cloneRange();
250 if (!misspelledWord.isEmpty()) { 250 if (!misspelledWord.isEmpty()) {
251 // Stop looking at start of next misspelled word 251 // Stop looking at start of next misspelled word
252 CharacterIterator chars(grammarSearchRange.get()); 252 CharacterIterator chars(grammarSearchRange.get());
253 chars.advance(misspellingOffset); 253 chars.advance(misspellingOffset);
254 grammarSearchRange->setEnd(chars.range()->startContainer(), chars.ra nge()->startOffset(), IGNORE_EXCEPTION); 254 grammarSearchRange->setEnd(chars.startContainer(), chars.startOffset (), IGNORE_EXCEPTION);
255 } 255 }
256 256
257 if (isGrammarCheckingEnabled()) 257 if (isGrammarCheckingEnabled())
258 badGrammarPhrase = TextCheckingHelper(spellCheckerClient(), grammarS earchRange).findFirstBadGrammar(grammarDetail, grammarPhraseOffset, false); 258 badGrammarPhrase = TextCheckingHelper(spellCheckerClient(), grammarS earchRange).findFirstBadGrammar(grammarDetail, grammarPhraseOffset, false);
259 } 259 }
260 260
261 // 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 261 // 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
262 // block rather than at a selection). 262 // block rather than at a selection).
263 if (startedWithSelection && !misspelledWord && !badGrammarPhrase) { 263 if (startedWithSelection && !misspelledWord && !badGrammarPhrase) {
264 spellingSearchRange->setStart(topNode, 0, IGNORE_EXCEPTION); 264 spellingSearchRange->setStart(topNode, 0, IGNORE_EXCEPTION);
(...skipping 10 matching lines...) Expand all
275 badGrammarPhrase = foundItem; 275 badGrammarPhrase = foundItem;
276 grammarPhraseOffset = foundOffset; 276 grammarPhraseOffset = foundOffset;
277 } 277 }
278 } else { 278 } else {
279 misspelledWord = TextCheckingHelper(spellCheckerClient(), spellingSe archRange).findFirstMisspelling(misspellingOffset, false, firstMisspellingRange) ; 279 misspelledWord = TextCheckingHelper(spellCheckerClient(), spellingSe archRange).findFirstMisspelling(misspellingOffset, false, firstMisspellingRange) ;
280 grammarSearchRange = spellingSearchRange->cloneRange(); 280 grammarSearchRange = spellingSearchRange->cloneRange();
281 if (!misspelledWord.isEmpty()) { 281 if (!misspelledWord.isEmpty()) {
282 // Stop looking at start of next misspelled word 282 // Stop looking at start of next misspelled word
283 CharacterIterator chars(grammarSearchRange.get()); 283 CharacterIterator chars(grammarSearchRange.get());
284 chars.advance(misspellingOffset); 284 chars.advance(misspellingOffset);
285 grammarSearchRange->setEnd(chars.range()->startContainer(), char s.range()->startOffset(), IGNORE_EXCEPTION); 285 grammarSearchRange->setEnd(chars.startContainer(), chars.startOf fset(), IGNORE_EXCEPTION);
286 } 286 }
287 287
288 if (isGrammarCheckingEnabled()) 288 if (isGrammarCheckingEnabled())
289 badGrammarPhrase = TextCheckingHelper(spellCheckerClient(), gram marSearchRange).findFirstBadGrammar(grammarDetail, grammarPhraseOffset, false); 289 badGrammarPhrase = TextCheckingHelper(spellCheckerClient(), gram marSearchRange).findFirstBadGrammar(grammarDetail, grammarPhraseOffset, false);
290 } 290 }
291 } 291 }
292 292
293 if (!badGrammarPhrase.isEmpty()) { 293 if (!badGrammarPhrase.isEmpty()) {
294 // We found bad grammar. Since we only searched for bad grammar up to th e first misspelled word, the bad grammar 294 // We found bad grammar. Since we only searched for bad grammar up to th e first misspelled word, the bad grammar
295 // takes precedence and we ignore any potential misspelled word. Select the grammar detail, update the spelling 295 // takes precedence and we ignore any potential misspelled word. Select the grammar detail, update the spelling
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 } 927 }
928 928
929 void SpellChecker::requestTextChecking(const Element& element) 929 void SpellChecker::requestTextChecking(const Element& element)
930 { 930 {
931 RefPtrWillBeRawPtr<Range> rangeToCheck = rangeOfContents(const_cast<Element* >(&element)); 931 RefPtrWillBeRawPtr<Range> rangeToCheck = rangeOfContents(const_cast<Element* >(&element));
932 m_spellCheckRequester->requestCheckingFor(SpellCheckRequest::create(TextChec kingTypeSpelling | TextCheckingTypeGrammar, TextCheckingProcessBatch, rangeToChe ck, rangeToCheck)); 932 m_spellCheckRequester->requestCheckingFor(SpellCheckRequest::create(TextChec kingTypeSpelling | TextCheckingTypeGrammar, TextCheckingProcessBatch, rangeToChe ck, rangeToCheck));
933 } 933 }
934 934
935 935
936 } // namespace blink 936 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/editing/PlainTextRange.cpp ('k') | Source/core/editing/SurroundingText.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698