| OLD | NEW |
| 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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 // going until the end of the very first chunk we tested is far enough | 291 // going until the end of the very first chunk we tested is far enough |
| 292 spellingSearchEnd = Position::editingPositionOf(searchEndNodeAfterWrap,
searchEndOffsetAfterWrap); | 292 spellingSearchEnd = Position::editingPositionOf(searchEndNodeAfterWrap,
searchEndOffsetAfterWrap); |
| 293 misspelledItem = findFirstMisspelling(spellingSearchStart, spellingSearc
hEnd); | 293 misspelledItem = findFirstMisspelling(spellingSearchStart, spellingSearc
hEnd); |
| 294 } | 294 } |
| 295 | 295 |
| 296 if (!misspelledWord.isEmpty()) { | 296 if (!misspelledWord.isEmpty()) { |
| 297 // We found a misspelling. Select the misspelling, update the spelling p
anel, and store | 297 // We found a misspelling. Select the misspelling, update the spelling p
anel, and store |
| 298 // a marker so we draw the red squiggle later. | 298 // a marker so we draw the red squiggle later. |
| 299 | 299 |
| 300 const EphemeralRange misspellingRange = calculateCharacterSubrange(Ephem
eralRange(spellingSearchStart, spellingSearchEnd), misspellingOffset, misspelled
Word.length()); | 300 const EphemeralRange misspellingRange = calculateCharacterSubrange(Ephem
eralRange(spellingSearchStart, spellingSearchEnd), misspellingOffset, misspelled
Word.length()); |
| 301 frame().selection().setSelection(createVisibleSelection(misspellingRange
)); | 301 frame().selection().setSelection(createVisibleSelectionDeprecated(misspe
llingRange)); |
| 302 frame().selection().revealSelection(); | 302 frame().selection().revealSelection(); |
| 303 spellCheckerClient().updateSpellingUIWithMisspelledWord(misspelledWord); | 303 spellCheckerClient().updateSpellingUIWithMisspelledWord(misspelledWord); |
| 304 frame().document()->markers().addMarker(misspellingRange.startPosition()
, misspellingRange.endPosition(), DocumentMarker::Spelling); | 304 frame().document()->markers().addMarker(misspellingRange.startPosition()
, misspellingRange.endPosition(), DocumentMarker::Spelling); |
| 305 } | 305 } |
| 306 } | 306 } |
| 307 | 307 |
| 308 void SpellChecker::showSpellingGuessPanel() | 308 void SpellChecker::showSpellingGuessPanel() |
| 309 { | 309 { |
| 310 if (spellCheckerClient().spellingUIIsShowing()) { | 310 if (spellCheckerClient().spellingUIIsShowing()) { |
| 311 spellCheckerClient().showSpellingUI(false); | 311 spellCheckerClient().showSpellingUI(false); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 // Since the word containing the current selection is never marked, this doe
s a check to | 387 // Since the word containing the current selection is never marked, this doe
s a check to |
| 388 // see if typing made a new word that is not in the current selection. Basic
ally, you | 388 // see if typing made a new word that is not in the current selection. Basic
ally, you |
| 389 // get this by being at the end of a word and typing a space. | 389 // get this by being at the end of a word and typing a space. |
| 390 VisiblePosition start = createVisiblePosition(cmd.endingSelection().start(),
cmd.endingSelection().affinity()); | 390 VisiblePosition start = createVisiblePosition(cmd.endingSelection().start(),
cmd.endingSelection().affinity()); |
| 391 VisiblePosition previous = previousPositionOf(start); | 391 VisiblePosition previous = previousPositionOf(start); |
| 392 | 392 |
| 393 VisiblePosition wordStartOfPrevious = startOfWord(previous, LeftWordIfOnBoun
dary); | 393 VisiblePosition wordStartOfPrevious = startOfWord(previous, LeftWordIfOnBoun
dary); |
| 394 | 394 |
| 395 if (cmd.commandTypeOfOpenCommand() == TypingCommand::InsertParagraphSeparato
r) { | 395 if (cmd.commandTypeOfOpenCommand() == TypingCommand::InsertParagraphSeparato
r) { |
| 396 VisiblePosition nextWord = nextWordPosition(start); | 396 VisiblePosition nextWord = nextWordPosition(start); |
| 397 VisibleSelection words = createVisibleSelection(wordStartOfPrevious, end
OfWord(nextWord)); | 397 VisibleSelection words = createVisibleSelectionDeprecated(wordStartOfPre
vious, endOfWord(nextWord)); |
| 398 markMisspellingsAfterLineBreak(words); | 398 markMisspellingsAfterLineBreak(words); |
| 399 return; | 399 return; |
| 400 } | 400 } |
| 401 | 401 |
| 402 if (previous.isNull()) | 402 if (previous.isNull()) |
| 403 return; | 403 return; |
| 404 VisiblePosition currentWordStart = startOfWord(start, LeftWordIfOnBoundary); | 404 VisiblePosition currentWordStart = startOfWord(start, LeftWordIfOnBoundary); |
| 405 if (wordStartOfPrevious.deepEquivalent() == currentWordStart.deepEquivalent(
)) | 405 if (wordStartOfPrevious.deepEquivalent() == currentWordStart.deepEquivalent(
)) |
| 406 return; | 406 return; |
| 407 markMisspellingsAfterTypingToWord(wordStartOfPrevious); | 407 markMisspellingsAfterTypingToWord(wordStartOfPrevious); |
| 408 } | 408 } |
| 409 | 409 |
| 410 void SpellChecker::markMisspellingsAfterLineBreak(const VisibleSelection& wordSe
lection) | 410 void SpellChecker::markMisspellingsAfterLineBreak(const VisibleSelection& wordSe
lection) |
| 411 { | 411 { |
| 412 TRACE_EVENT0("blink", "SpellChecker::markMisspellingsAfterLineBreak"); | 412 TRACE_EVENT0("blink", "SpellChecker::markMisspellingsAfterLineBreak"); |
| 413 | 413 |
| 414 markMisspellingsAndBadGrammar(wordSelection); | 414 markMisspellingsAndBadGrammar(wordSelection); |
| 415 } | 415 } |
| 416 | 416 |
| 417 void SpellChecker::markMisspellingsAfterTypingToWord(const VisiblePosition &word
Start) | 417 void SpellChecker::markMisspellingsAfterTypingToWord(const VisiblePosition &word
Start) |
| 418 { | 418 { |
| 419 TRACE_EVENT0("blink", "SpellChecker::markMisspellingsAfterTypingToWord"); | 419 TRACE_EVENT0("blink", "SpellChecker::markMisspellingsAfterTypingToWord"); |
| 420 | 420 |
| 421 VisibleSelection adjacentWords = createVisibleSelection(startOfWord(wordStar
t, LeftWordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary)); | 421 VisibleSelection adjacentWords = createVisibleSelectionDeprecated(startOfWor
d(wordStart, LeftWordIfOnBoundary), endOfWord(wordStart, RightWordIfOnBoundary))
; |
| 422 markMisspellingsAndBadGrammar(adjacentWords); | 422 markMisspellingsAndBadGrammar(adjacentWords); |
| 423 } | 423 } |
| 424 | 424 |
| 425 bool SpellChecker::isSpellCheckingEnabledInFocusedNode() const | 425 bool SpellChecker::isSpellCheckingEnabledInFocusedNode() const |
| 426 { | 426 { |
| 427 Node* focusedNode = frame().selection().start().anchorNode(); | 427 Node* focusedNode = frame().selection().start().anchorNode(); |
| 428 if (!focusedNode) | 428 if (!focusedNode) |
| 429 return false; | 429 return false; |
| 430 const Element* focusedElement = focusedNode->isElementNode() ? toElement(foc
usedNode) : focusedNode->parentElement(); | 430 const Element* focusedElement = focusedNode->isElementNode() ? toElement(foc
usedNode) : focusedNode->parentElement(); |
| 431 if (!focusedElement) | 431 if (!focusedElement) |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 691 { | 691 { |
| 692 EphemeralRange caretRange = frame().selection().selection().toNormalizedEphe
meralRange(); | 692 EphemeralRange caretRange = frame().selection().selection().toNormalizedEphe
meralRange(); |
| 693 if (caretRange.isNull()) | 693 if (caretRange.isNull()) |
| 694 return; | 694 return; |
| 695 DocumentMarkerVector markers = frame().document()->markers().markersInRange(
caretRange, DocumentMarker::MisspellingMarkers()); | 695 DocumentMarkerVector markers = frame().document()->markers().markersInRange(
caretRange, DocumentMarker::MisspellingMarkers()); |
| 696 if (markers.size() < 1 || markers[0]->startOffset() >= markers[0]->endOffset
()) | 696 if (markers.size() < 1 || markers[0]->startOffset() >= markers[0]->endOffset
()) |
| 697 return; | 697 return; |
| 698 EphemeralRange markerRange = EphemeralRange(Position(caretRange.startPositio
n().computeContainerNode(), markers[0]->startOffset()), Position(caretRange.endP
osition().computeContainerNode(), markers[0]->endOffset())); | 698 EphemeralRange markerRange = EphemeralRange(Position(caretRange.startPositio
n().computeContainerNode(), markers[0]->startOffset()), Position(caretRange.endP
osition().computeContainerNode(), markers[0]->endOffset())); |
| 699 if (markerRange.isNull()) | 699 if (markerRange.isNull()) |
| 700 return; | 700 return; |
| 701 frame().selection().setSelection(createVisibleSelection(markerRange), Charac
terGranularity); | 701 frame().selection().setSelection(createVisibleSelectionDeprecated(markerRang
e), CharacterGranularity); |
| 702 | 702 |
| 703 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | 703 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 704 // needs to be audited. See http://crbug.com/590369 for more details. | 704 // needs to be audited. See http://crbug.com/590369 for more details. |
| 705 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 705 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 706 | 706 |
| 707 frame().editor().replaceSelectionWithText(text, false, false); | 707 frame().editor().replaceSelectionWithText(text, false, false); |
| 708 } | 708 } |
| 709 | 709 |
| 710 static bool shouldCheckOldSelection(const VisibleSelection& oldSelection) | 710 static bool shouldCheckOldSelection(const VisibleSelection& oldSelection) |
| 711 { | 711 { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 | 753 |
| 754 VisibleSelection newAdjacentWords; | 754 VisibleSelection newAdjacentWords; |
| 755 const VisibleSelection newSelection = frame().selection().selection(); | 755 const VisibleSelection newSelection = frame().selection().selection(); |
| 756 if (isSelectionInTextFormControl(newSelection)) { | 756 if (isSelectionInTextFormControl(newSelection)) { |
| 757 const Position newStart = newSelection.start(); | 757 const Position newStart = newSelection.start(); |
| 758 newAdjacentWords.setWithoutValidation(HTMLTextFormControlElement::startO
fWord(newStart), HTMLTextFormControlElement::endOfWord(newStart)); | 758 newAdjacentWords.setWithoutValidation(HTMLTextFormControlElement::startO
fWord(newStart), HTMLTextFormControlElement::endOfWord(newStart)); |
| 759 } else { | 759 } else { |
| 760 const bool caretBrowsing = frame().settings() && frame().settings()->car
etBrowsingEnabled(); | 760 const bool caretBrowsing = frame().settings() && frame().settings()->car
etBrowsingEnabled(); |
| 761 if (newSelection.isContentEditable() || caretBrowsing) { | 761 if (newSelection.isContentEditable() || caretBrowsing) { |
| 762 const VisiblePosition newStart(newSelection.visibleStart()); | 762 const VisiblePosition newStart(newSelection.visibleStart()); |
| 763 newAdjacentWords = createVisibleSelection(startOfWord(newStart, Left
WordIfOnBoundary), endOfWord(newStart, RightWordIfOnBoundary)); | 763 newAdjacentWords = createVisibleSelectionDeprecated(startOfWord(newS
tart, LeftWordIfOnBoundary), endOfWord(newStart, RightWordIfOnBoundary)); |
| 764 } | 764 } |
| 765 } | 765 } |
| 766 | 766 |
| 767 // When typing we check spelling elsewhere, so don't redo it here. | 767 // When typing we check spelling elsewhere, so don't redo it here. |
| 768 // If this is a change in selection resulting from a delete operation, | 768 // If this is a change in selection resulting from a delete operation, |
| 769 // oldSelection may no longer be in the document. | 769 // oldSelection may no longer be in the document. |
| 770 // FIXME(http://crbug.com/382809): if oldSelection is on a textarea | 770 // FIXME(http://crbug.com/382809): if oldSelection is on a textarea |
| 771 // element, we cause synchronous layout. | 771 // element, we cause synchronous layout. |
| 772 spellCheckOldSelection(oldSelection, newAdjacentWords); | 772 spellCheckOldSelection(oldSelection, newAdjacentWords); |
| 773 } | 773 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 } | 809 } |
| 810 | 810 |
| 811 void SpellChecker::spellCheckOldSelection(const VisibleSelection& oldSelection,
const VisibleSelection& newAdjacentWords) | 811 void SpellChecker::spellCheckOldSelection(const VisibleSelection& oldSelection,
const VisibleSelection& newAdjacentWords) |
| 812 { | 812 { |
| 813 if (!isSpellCheckingEnabled()) | 813 if (!isSpellCheckingEnabled()) |
| 814 return; | 814 return; |
| 815 | 815 |
| 816 TRACE_EVENT0("blink", "SpellChecker::spellCheckOldSelection"); | 816 TRACE_EVENT0("blink", "SpellChecker::spellCheckOldSelection"); |
| 817 | 817 |
| 818 VisiblePosition oldStart(oldSelection.visibleStart()); | 818 VisiblePosition oldStart(oldSelection.visibleStart()); |
| 819 VisibleSelection oldAdjacentWords = createVisibleSelection(startOfWord(oldSt
art, LeftWordIfOnBoundary), endOfWord(oldStart, RightWordIfOnBoundary)); | 819 VisibleSelection oldAdjacentWords = createVisibleSelectionDeprecated(startOf
Word(oldStart, LeftWordIfOnBoundary), endOfWord(oldStart, RightWordIfOnBoundary)
); |
| 820 if (oldAdjacentWords == newAdjacentWords) | 820 if (oldAdjacentWords == newAdjacentWords) |
| 821 return; | 821 return; |
| 822 markMisspellingsAndBadGrammar(oldAdjacentWords); | 822 markMisspellingsAndBadGrammar(oldAdjacentWords); |
| 823 } | 823 } |
| 824 | 824 |
| 825 static Node* findFirstMarkable(Node* node) | 825 static Node* findFirstMarkable(Node* node) |
| 826 { | 826 { |
| 827 while (node) { | 827 while (node) { |
| 828 if (!node->layoutObject()) | 828 if (!node->layoutObject()) |
| 829 return 0; | 829 return 0; |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1000 VisiblePosition newParagraphStart = startOfNextParagraph(createVisiblePo
sition(paragraphEnd)); | 1000 VisiblePosition newParagraphStart = startOfNextParagraph(createVisiblePo
sition(paragraphEnd)); |
| 1001 paragraphStart = newParagraphStart.toParentAnchoredPosition(); | 1001 paragraphStart = newParagraphStart.toParentAnchoredPosition(); |
| 1002 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPositio
n(); | 1002 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPositio
n(); |
| 1003 firstIteration = false; | 1003 firstIteration = false; |
| 1004 totalLengthProcessed += currentLength; | 1004 totalLengthProcessed += currentLength; |
| 1005 } | 1005 } |
| 1006 return std::make_pair(firstFoundItem, firstFoundOffset); | 1006 return std::make_pair(firstFoundItem, firstFoundOffset); |
| 1007 } | 1007 } |
| 1008 | 1008 |
| 1009 } // namespace blink | 1009 } // namespace blink |
| OLD | NEW |