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

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

Issue 2205823002: Cleanup function names in SpellChecker and TextCheckingHelper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
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 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 if (!element) 137 if (!element)
138 return; 138 return;
139 isTextField = isHTMLInputElement(*textControl) && toHTMLInputElement (*textControl).isTextField(); 139 isTextField = isHTMLInputElement(*textControl) && toHTMLInputElement (*textControl).isTextField();
140 } 140 }
141 141
142 if (isTextField || !parent->isAlreadySpellChecked()) { 142 if (isTextField || !parent->isAlreadySpellChecked()) {
143 if (EditingStrategy::editingIgnoresContent(element)) 143 if (EditingStrategy::editingIgnoresContent(element))
144 return; 144 return;
145 // We always recheck textfields because markers are removed from the m on blur. 145 // We always recheck textfields because markers are removed from the m on blur.
146 VisibleSelection selection = VisibleSelection::selectionFromContents OfNode(element); 146 VisibleSelection selection = VisibleSelection::selectionFromContents OfNode(element);
147 markMisspellingsAndBadGrammar(selection); 147 markMisspellings(selection);
148 if (!isTextField) 148 if (!isTextField)
149 parent->setAlreadySpellChecked(true); 149 parent->setAlreadySpellChecked(true);
150 } 150 }
151 } 151 }
152 } 152 }
153 153
154 void SpellChecker::ignoreSpelling() 154 void SpellChecker::ignoreSpelling()
155 { 155 {
156 removeMarkers(frame().selection().selection(), DocumentMarker::Spelling); 156 removeMarkers(frame().selection().selection(), DocumentMarker::Spelling);
157 } 157 }
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 // If we did not find a misspelled word, wrap and try again (but don't bothe r if we started at the beginning of the 231 // If we did not find a misspelled word, wrap and try again (but don't bothe r if we started at the beginning of the
232 // block rather than at a selection). 232 // block rather than at a selection).
233 if (startedWithSelection && !misspelledWord) { 233 if (startedWithSelection && !misspelledWord) {
234 spellingSearchStart = Position::editingPositionOf(topNode, 0); 234 spellingSearchStart = Position::editingPositionOf(topNode, 0);
235 // going until the end of the very first chunk we tested is far enough 235 // going until the end of the very first chunk we tested is far enough
236 spellingSearchEnd = Position::editingPositionOf(searchEndNodeAfterWrap, searchEndOffsetAfterWrap); 236 spellingSearchEnd = Position::editingPositionOf(searchEndNodeAfterWrap, searchEndOffsetAfterWrap);
237 misspelledWord = TextCheckingHelper(spellCheckerClient(), spellingSearch Start, spellingSearchEnd).findFirstMisspelling(misspellingOffset, false); 237 misspelledWord = TextCheckingHelper(spellCheckerClient(), spellingSearch Start, spellingSearchEnd).findFirstMisspelling(misspellingOffset, false);
238 } 238 }
239 239
240 if (!misspelledWord.isEmpty()) { 240 if (!misspelledWord.isEmpty()) {
241 // We found a misspelling, but not any earlier bad grammar. Select the m isspelling, update the spelling panel, and store 241 // We found a misspelling. Select the misspelling, update the spelling
242 // a marker so we draw the red squiggle later. 242 // panel, and store a marker so we draw the red squiggle later.
243 243
244 const EphemeralRange misspellingRange = calculateCharacterSubrange(Ephem eralRange(spellingSearchStart, spellingSearchEnd), misspellingOffset, misspelled Word.length()); 244 const EphemeralRange misspellingRange = calculateCharacterSubrange(Ephem eralRange(spellingSearchStart, spellingSearchEnd), misspellingOffset, misspelled Word.length());
245 frame().selection().setSelection(VisibleSelection(misspellingRange)); 245 frame().selection().setSelection(VisibleSelection(misspellingRange));
246 frame().selection().revealSelection(); 246 frame().selection().revealSelection();
247 spellCheckerClient().updateSpellingUIWithMisspelledWord(misspelledWord); 247 spellCheckerClient().updateSpellingUIWithMisspelledWord(misspelledWord);
248 frame().document()->markers().addMarker(misspellingRange.startPosition() , misspellingRange.endPosition(), DocumentMarker::Spelling); 248 frame().document()->markers().addMarker(misspellingRange.startPosition() , misspellingRange.endPosition(), DocumentMarker::Spelling);
249 } 249 }
250 } 250 }
251 251
252 void SpellChecker::showSpellingGuessPanel() 252 void SpellChecker::showSpellingGuessPanel()
253 { 253 {
254 if (spellCheckerClient().spellingUIIsShowing()) { 254 if (spellCheckerClient().spellingUIIsShowing()) {
255 spellCheckerClient().showSpellingUI(false); 255 spellCheckerClient().showSpellingUI(false);
256 return; 256 return;
257 } 257 }
258 258
259 advanceToNextMisspelling(true); 259 advanceToNextMisspelling(true);
260 spellCheckerClient().showSpellingUI(true); 260 spellCheckerClient().showSpellingUI(true);
261 } 261 }
262 262
263 void SpellChecker::clearMisspellingsAndBadGrammar(const VisibleSelection &moving Selection) 263 void SpellChecker::clearMisspellings(const VisibleSelection &movingSelection)
264 { 264 {
265 removeMarkers(movingSelection, DocumentMarker::MisspellingMarkers()); 265 removeMarkers(movingSelection, DocumentMarker::MisspellingMarkers());
266 } 266 }
267 267
268 void SpellChecker::markMisspellingsAndBadGrammar(const VisibleSelection &movingS election) 268 void SpellChecker::markMisspellings(const VisibleSelection &movingSelection)
269 { 269 {
270 if (unifiedTextCheckerEnabled()) { 270 if (unifiedTextCheckerEnabled()) {
271 if (!isContinuousSpellCheckingEnabled()) 271 if (!isContinuousSpellCheckingEnabled())
272 return; 272 return;
273 273
274 // markMisspellingsAndBadGrammar() is triggered by selection change, in which case we check spelling, but don't autocorrect misspellings. 274 // markMisspellings() is triggered by selection change, in which
275 // case we check spelling, but don't autocorrect misspellings.
275 markAllMisspellingsInRange(movingSelection.toNormalizedEphemeralRange()) ; 276 markAllMisspellingsInRange(movingSelection.toNormalizedEphemeralRange()) ;
276 return; 277 return;
277 } 278 }
278 279
279 markMisspellings(movingSelection); 280 markMisspellingsWithTextCheckingHelper(movingSelection);
280 } 281 }
281 282
282 void SpellChecker::markMisspellingsAfterLineBreak(const VisibleSelection& wordSe lection) 283 void SpellChecker::markMisspellingsAfterLineBreak(const VisibleSelection& wordSe lection)
283 { 284 {
284 TRACE_EVENT0("blink", "SpellChecker::markMisspellingsAfterLineBreak"); 285 TRACE_EVENT0("blink", "SpellChecker::markMisspellingsAfterLineBreak");
285 286
286 if (!unifiedTextCheckerEnabled()) { 287 if (!unifiedTextCheckerEnabled()) {
287 markMisspellings(wordSelection); 288 markMisspellingsWithTextCheckingHelper(wordSelection);
288 return; 289 return;
289 } 290 }
290 291
291 if (isContinuousSpellCheckingEnabled()) 292 if (isContinuousSpellCheckingEnabled())
292 markAllMisspellingsInRange(wordSelection.toNormalizedEphemeralRange()); 293 markAllMisspellingsInRange(wordSelection.toNormalizedEphemeralRange());
293 } 294 }
294 295
295 void SpellChecker::markMisspellingsAfterTypingToWord(const VisiblePosition &word Start, const VisibleSelection& selectionAfterTyping) 296 void SpellChecker::markMisspellingsAfterTypingToWord(const VisiblePosition &word Start, const VisibleSelection& selectionAfterTyping)
296 { 297 {
297 TRACE_EVENT0("blink", "SpellChecker::markMisspellingsAfterTypingToWord"); 298 TRACE_EVENT0("blink", "SpellChecker::markMisspellingsAfterTypingToWord");
298 299
299 if (unifiedTextCheckerEnabled()) { 300 if (unifiedTextCheckerEnabled()) {
300 TextCheckingTypeMask textCheckingOptions = 0; 301 TextCheckingTypeMask textCheckingOptions = 0;
301 302
302 if (isContinuousSpellCheckingEnabled()) 303 if (isContinuousSpellCheckingEnabled())
303 textCheckingOptions |= TextCheckingTypeSpelling; 304 textCheckingOptions |= TextCheckingTypeSpelling;
304 305
305 if (!(textCheckingOptions & TextCheckingTypeSpelling)) 306 if (!(textCheckingOptions & TextCheckingTypeSpelling))
306 return; 307 return;
307 308
308 VisibleSelection adjacentWords = VisibleSelection(startOfWord(wordStart, LeftWordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary)); 309 VisibleSelection adjacentWords = VisibleSelection(startOfWord(wordStart, LeftWordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary));
309 markAllMisspellingsInRange(adjacentWords.toNormalizedEphemeralRange()); 310 markAllMisspellingsInRange(adjacentWords.toNormalizedEphemeralRange());
310 return; 311 return;
311 } 312 }
312 313
313 if (!isContinuousSpellCheckingEnabled()) 314 if (!isContinuousSpellCheckingEnabled())
314 return; 315 return;
315 316
316 // Check spelling of one word 317 // Check spelling of one word
317 markMisspellings(VisibleSelection(startOfWord(wordStart, LeftWordIfOnBoundar y), endOfWord(wordStart, RightWordIfOnBoundary))); 318 markMisspellingsWithTextCheckingHelper(VisibleSelection(startOfWord(wordStar t, LeftWordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary)));
318 } 319 }
319 320
320 bool SpellChecker::isSpellCheckingEnabledFor(Node* node) const 321 bool SpellChecker::isSpellCheckingEnabledFor(Node* node) const
321 { 322 {
322 if (!node) 323 if (!node)
323 return false; 324 return false;
324 const Element* focusedElement = node->isElementNode() ? toElement(node) : no de->parentElement(); 325 const Element* focusedElement = node->isElementNode() ? toElement(node) : no de->parentElement();
325 if (!focusedElement) 326 if (!focusedElement)
326 return false; 327 return false;
327 return focusedElement->isSpellCheckingEnabled(); 328 return focusedElement->isSpellCheckingEnabled();
(...skipping 14 matching lines...) Expand all
342 if (isHTMLInputElement(textControl) && toHTMLInputElement(textControl)-> type() == InputTypeNames::password) 343 if (isHTMLInputElement(textControl) && toHTMLInputElement(textControl)-> type() == InputTypeNames::password)
343 return false; 344 return false;
344 } 345 }
345 if (HTMLElement* element = Traversal<HTMLElement>::firstAncestorOrSelf(*sele ction.start().anchorNode())) { 346 if (HTMLElement* element = Traversal<HTMLElement>::firstAncestorOrSelf(*sele ction.start().anchorNode())) {
346 if (element->spellcheck()) 347 if (element->spellcheck())
347 return true; 348 return true;
348 } 349 }
349 return false; 350 return false;
350 } 351 }
351 352
352 void SpellChecker::markMisspellings(const VisibleSelection& selection) 353 void SpellChecker::markMisspellingsWithTextCheckingHelper(const VisibleSelection & selection)
353 { 354 {
354 // This function is called with a selection already expanded to word boundar ies. 355 // This function is called with a selection already expanded to word boundar ies.
355 // TODO(xiaochengh): Might be nice to assert that here. 356 // TODO(xiaochengh): Might be nice to assert that here.
356 357
357 // This function is used only for as-you-type checking, so if that's off we do nothing. Note that 358 // This function is used only for as-you-type checking, so if that's off we do nothing.
358 // grammar checking can only be on if spell checking is also on.
359 if (!isContinuousSpellCheckingEnabled()) 359 if (!isContinuousSpellCheckingEnabled())
360 return; 360 return;
361 361
362 TRACE_EVENT0("blink", "SpellChecker::markMisspellings"); 362 TRACE_EVENT0("blink", "SpellChecker::markMisspellings");
363 363
364 const EphemeralRange& range = selection.toNormalizedEphemeralRange(); 364 const EphemeralRange& range = selection.toNormalizedEphemeralRange();
365 if (range.isNull()) 365 if (range.isNull())
366 return; 366 return;
367 367
368 // If we're not in an editable node, bail. 368 // If we're not in an editable node, bail.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 408
409 static EphemeralRange expandRangeToSentenceBoundary(const EphemeralRange& range) 409 static EphemeralRange expandRangeToSentenceBoundary(const EphemeralRange& range)
410 { 410 {
411 DCHECK(range.isNotNull()); 411 DCHECK(range.isNotNull());
412 const VisiblePosition& visibleStart = createVisiblePosition(range.startPosit ion()); 412 const VisiblePosition& visibleStart = createVisiblePosition(range.startPosit ion());
413 DCHECK(visibleStart.isNotNull()); 413 DCHECK(visibleStart.isNotNull());
414 const Position& sentenceStart = startOfSentence(visibleStart).deepEquivalent (); 414 const Position& sentenceStart = startOfSentence(visibleStart).deepEquivalent ();
415 return expandEndToSentenceBoundary(EphemeralRange(sentenceStart.isNull() ? r ange.startPosition() : sentenceStart, range.endPosition())); 415 return expandEndToSentenceBoundary(EphemeralRange(sentenceStart.isNull() ? r ange.startPosition() : sentenceStart, range.endPosition()));
416 } 416 }
417 417
418 void SpellChecker::chunkAndMarkAllMisspellingsAndBadGrammar(Node* node, const Ep hemeralRange& insertedRange) 418 void SpellChecker::chunkAndMarkAllMisspellings(Node* node, const EphemeralRange& insertedRange)
419 { 419 {
420 TRACE_EVENT0("blink", "SpellChecker::chunkAndMarkAllMisspellingsAndBadGramma r"); 420 TRACE_EVENT0("blink", "SpellChecker::chunkAndMarkAllMisspellings");
421 if (!node) 421 if (!node)
422 return; 422 return;
423 EphemeralRange paragraphRange(Position::firstPositionInNode(node), Position: :lastPositionInNode(node)); 423 EphemeralRange paragraphRange(Position::firstPositionInNode(node), Position: :lastPositionInNode(node));
424 TextCheckingParagraph textToCheck(insertedRange, paragraphRange); 424 TextCheckingParagraph textToCheck(insertedRange, paragraphRange);
425 chunkAndMarkAllMisspellings(textToCheck); 425 chunkAndMarkAllMisspellings(textToCheck);
426 } 426 }
427 427
428 void SpellChecker::chunkAndMarkAllMisspellings(const TextCheckingParagraph& full ParagraphToCheck) 428 void SpellChecker::chunkAndMarkAllMisspellings(const TextCheckingParagraph& full ParagraphToCheck)
429 { 429 {
430 if (fullParagraphToCheck.isEmpty()) 430 if (fullParagraphToCheck.isEmpty())
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 } 744 }
745 745
746 void SpellChecker::spellCheckOldSelection(const VisibleSelection& oldSelection, const VisibleSelection& newAdjacentWords) 746 void SpellChecker::spellCheckOldSelection(const VisibleSelection& oldSelection, const VisibleSelection& newAdjacentWords)
747 { 747 {
748 TRACE_EVENT0("blink", "SpellChecker::spellCheckOldSelection"); 748 TRACE_EVENT0("blink", "SpellChecker::spellCheckOldSelection");
749 749
750 VisiblePosition oldStart(oldSelection.visibleStart()); 750 VisiblePosition oldStart(oldSelection.visibleStart());
751 VisibleSelection oldAdjacentWords = VisibleSelection(startOfWord(oldStart, L eftWordIfOnBoundary), endOfWord(oldStart, RightWordIfOnBoundary)); 751 VisibleSelection oldAdjacentWords = VisibleSelection(startOfWord(oldStart, L eftWordIfOnBoundary), endOfWord(oldStart, RightWordIfOnBoundary));
752 if (oldAdjacentWords == newAdjacentWords) 752 if (oldAdjacentWords == newAdjacentWords)
753 return; 753 return;
754 markMisspellingsAndBadGrammar(oldAdjacentWords); 754 markMisspellings(oldAdjacentWords);
755 } 755 }
756 756
757 static Node* findFirstMarkable(Node* node) 757 static Node* findFirstMarkable(Node* node)
758 { 758 {
759 while (node) { 759 while (node) {
760 if (!node->layoutObject()) 760 if (!node->layoutObject())
761 return 0; 761 return 0;
762 if (node->layoutObject()->isText()) 762 if (node->layoutObject()->isText())
763 return node; 763 return node;
764 if (node->layoutObject()->isTextControl()) 764 if (node->layoutObject()->isTextControl())
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 visitor->trace(m_frame); 824 visitor->trace(m_frame);
825 visitor->trace(m_spellCheckRequester); 825 visitor->trace(m_spellCheckRequester);
826 } 826 }
827 827
828 void SpellChecker::prepareForLeakDetection() 828 void SpellChecker::prepareForLeakDetection()
829 { 829 {
830 m_spellCheckRequester->prepareForLeakDetection(); 830 m_spellCheckRequester->prepareForLeakDetection();
831 } 831 }
832 832
833 } // namespace blink 833 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698