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

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

Issue 2765133002: [WIP] Add DocumentMarkerController::addGrammarMarker() and addSpellingMarker() (Closed)
Patch Set: Respond to comments Created 3 years, 8 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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 // panel, and store a marker so we draw the red squiggle later. 295 // panel, and store a marker so we draw the red squiggle later.
296 296
297 const EphemeralRange misspellingRange = calculateCharacterSubrange( 297 const EphemeralRange misspellingRange = calculateCharacterSubrange(
298 EphemeralRange(spellingSearchStart, spellingSearchEnd), 298 EphemeralRange(spellingSearchStart, spellingSearchEnd),
299 misspellingOffset, misspelledWord.length()); 299 misspellingOffset, misspelledWord.length());
300 frame().selection().setSelection(SelectionInDOMTree::Builder() 300 frame().selection().setSelection(SelectionInDOMTree::Builder()
301 .setBaseAndExtent(misspellingRange) 301 .setBaseAndExtent(misspellingRange)
302 .build()); 302 .build());
303 frame().selection().revealSelection(); 303 frame().selection().revealSelection();
304 spellCheckerClient().updateSpellingUIWithMisspelledWord(misspelledWord); 304 spellCheckerClient().updateSpellingUIWithMisspelledWord(misspelledWord);
305 frame().document()->markers().addMarker(misspellingRange.startPosition(), 305 frame().document()->markers().addSpellingMarker(
306 misspellingRange.endPosition(), 306 misspellingRange.startPosition(), misspellingRange.endPosition());
307 DocumentMarker::Spelling);
308 } 307 }
309 } 308 }
310 309
311 void SpellChecker::showSpellingGuessPanel() { 310 void SpellChecker::showSpellingGuessPanel() {
312 if (spellCheckerClient().spellingUIIsShowing()) { 311 if (spellCheckerClient().spellingUIIsShowing()) {
313 spellCheckerClient().showSpellingUI(false); 312 spellCheckerClient().showSpellingUI(false);
314 return; 313 return;
315 } 314 }
316 315
317 advanceToNextMisspelling(true); 316 advanceToNextMisspelling(true);
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 int length, 533 int length,
535 const String& description) { 534 const String& description) {
536 DCHECK_GT(length, 0); 535 DCHECK_GT(length, 0);
537 DCHECK_GE(location, 0); 536 DCHECK_GE(location, 0);
538 const EphemeralRange& rangeToMark = 537 const EphemeralRange& rangeToMark =
539 calculateCharacterSubrange(checkingRange, location, length); 538 calculateCharacterSubrange(checkingRange, location, length);
540 if (!SpellChecker::isSpellCheckingEnabledAt(rangeToMark.startPosition())) 539 if (!SpellChecker::isSpellCheckingEnabledAt(rangeToMark.startPosition()))
541 return; 540 return;
542 if (!SpellChecker::isSpellCheckingEnabledAt(rangeToMark.endPosition())) 541 if (!SpellChecker::isSpellCheckingEnabledAt(rangeToMark.endPosition()))
543 return; 542 return;
544 document->markers().addMarker(rangeToMark.startPosition(), 543
545 rangeToMark.endPosition(), type, description); 544 DCHECK(type == DocumentMarker::Grammar || type == DocumentMarker::Spelling)
545 << type;
546 if (type == DocumentMarker::Grammar) {
547 document->markers().addGrammarMarker(
548 rangeToMark.startPosition(), rangeToMark.endPosition(), description);
549 } else {
550 document->markers().addSpellingMarker(
551 rangeToMark.startPosition(), rangeToMark.endPosition(), description);
552 }
546 } 553 }
547 554
548 void SpellChecker::markAndReplaceFor( 555 void SpellChecker::markAndReplaceFor(
549 SpellCheckRequest* request, 556 SpellCheckRequest* request,
550 const Vector<TextCheckingResult>& results) { 557 const Vector<TextCheckingResult>& results) {
551 TRACE_EVENT0("blink", "SpellChecker::markAndReplaceFor"); 558 TRACE_EVENT0("blink", "SpellChecker::markAndReplaceFor");
552 DCHECK(request); 559 DCHECK(request);
553 if (!frame().selection().isAvailable()) { 560 if (!frame().selection().isAvailable()) {
554 // "editing/spelling/spellcheck-async-remove-frame.html" reaches here. 561 // "editing/spelling/spellcheck-async-remove-frame.html" reaches here.
555 return; 562 return;
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 if (!input.isFocusedElementInDocument()) 1181 if (!input.isFocusedElementInDocument())
1175 return false; 1182 return false;
1176 } 1183 }
1177 } 1184 }
1178 HTMLElement* element = 1185 HTMLElement* element =
1179 Traversal<HTMLElement>::firstAncestorOrSelf(*position.anchorNode()); 1186 Traversal<HTMLElement>::firstAncestorOrSelf(*position.anchorNode());
1180 return element && element->isSpellCheckingEnabled(); 1187 return element && element->isSpellCheckingEnabled();
1181 } 1188 }
1182 1189
1183 } // namespace blink 1190 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698