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

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

Issue 2765133002: [WIP] Add DocumentMarkerController::addGrammarMarker() and addSpellingMarker() (Closed)
Patch Set: Rebase 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 int length, 540 int length,
542 const String& description) { 541 const String& description) {
543 DCHECK_GT(length, 0); 542 DCHECK_GT(length, 0);
544 DCHECK_GE(location, 0); 543 DCHECK_GE(location, 0);
545 const EphemeralRange& rangeToMark = 544 const EphemeralRange& rangeToMark =
546 calculateCharacterSubrange(checkingRange, location, length); 545 calculateCharacterSubrange(checkingRange, location, length);
547 if (!SpellChecker::isSpellCheckingEnabledAt(rangeToMark.startPosition())) 546 if (!SpellChecker::isSpellCheckingEnabledAt(rangeToMark.startPosition()))
548 return; 547 return;
549 if (!SpellChecker::isSpellCheckingEnabledAt(rangeToMark.endPosition())) 548 if (!SpellChecker::isSpellCheckingEnabledAt(rangeToMark.endPosition()))
550 return; 549 return;
551 document->markers().addMarker(rangeToMark.startPosition(), 550
552 rangeToMark.endPosition(), type, description); 551 DCHECK(type == DocumentMarker::Grammar || type == DocumentMarker::Spelling);
yosin_UTC9 2017/03/30 01:48:57 nit: Could you add |<< type| for ease of debugging
552 if (type == DocumentMarker::Grammar) {
553 document->markers().addGrammarMarker(
554 rangeToMark.startPosition(), rangeToMark.endPosition(), description);
555 } else {
556 document->markers().addSpellingMarker(
557 rangeToMark.startPosition(), rangeToMark.endPosition(), description);
558 }
553 } 559 }
554 560
555 void SpellChecker::markAndReplaceFor( 561 void SpellChecker::markAndReplaceFor(
556 SpellCheckRequest* request, 562 SpellCheckRequest* request,
557 const Vector<TextCheckingResult>& results) { 563 const Vector<TextCheckingResult>& results) {
558 TRACE_EVENT0("blink", "SpellChecker::markAndReplaceFor"); 564 TRACE_EVENT0("blink", "SpellChecker::markAndReplaceFor");
559 DCHECK(request); 565 DCHECK(request);
560 if (!frame().selection().isAvailable()) { 566 if (!frame().selection().isAvailable()) {
561 // "editing/spelling/spellcheck-async-remove-frame.html" reaches here. 567 // "editing/spelling/spellcheck-async-remove-frame.html" reaches here.
562 return; 568 return;
(...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after
1181 if (!input.isFocusedElementInDocument()) 1187 if (!input.isFocusedElementInDocument())
1182 return false; 1188 return false;
1183 } 1189 }
1184 } 1190 }
1185 HTMLElement* element = 1191 HTMLElement* element =
1186 Traversal<HTMLElement>::firstAncestorOrSelf(*position.anchorNode()); 1192 Traversal<HTMLElement>::firstAncestorOrSelf(*position.anchorNode());
1187 return element && element->isSpellCheckingEnabled(); 1193 return element && element->isSpellCheckingEnabled();
1188 } 1194 }
1189 1195
1190 } // namespace blink 1196 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698