| 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 2273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2284 | 2284 |
| 2285 // When typing we check spelling elsewhere, so don't redo it here. | 2285 // When typing we check spelling elsewhere, so don't redo it here. |
| 2286 // If this is a change in selection resulting from a delete operation, | 2286 // If this is a change in selection resulting from a delete operation, |
| 2287 // oldSelection may no longer be in the document. | 2287 // oldSelection may no longer be in the document. |
| 2288 if (shouldCheckSpellingAndGrammar | 2288 if (shouldCheckSpellingAndGrammar |
| 2289 && closeTyping | 2289 && closeTyping |
| 2290 && oldSelection.isContentEditable() | 2290 && oldSelection.isContentEditable() |
| 2291 && oldSelection.start().deprecatedNode() | 2291 && oldSelection.start().deprecatedNode() |
| 2292 && oldSelection.start().anchorNode()->inDocument() | 2292 && oldSelection.start().anchorNode()->inDocument() |
| 2293 && !isSelectionInTextField(oldSelection)) { | 2293 && !isSelectionInTextField(oldSelection)) { |
| 2294 VisiblePosition oldStart(oldSelection.visibleStart()); | 2294 spellCheckOldSelection(oldSelection, newAdjacentWords, newSelectedSe
ntence); |
| 2295 VisibleSelection oldAdjacentWords = VisibleSelection(startOfWord(old
Start, LeftWordIfOnBoundary), endOfWord(oldStart, RightWordIfOnBoundary)); | |
| 2296 if (oldAdjacentWords != newAdjacentWords) { | |
| 2297 if (isContinuousGrammarCheckingEnabled) { | |
| 2298 VisibleSelection oldSelectedSentence = VisibleSelection(star
tOfSentence(oldStart), endOfSentence(oldStart)); | |
| 2299 markMisspellingsAndBadGrammar(oldAdjacentWords, oldSelectedS
entence != newSelectedSentence, oldSelectedSentence); | |
| 2300 } else | |
| 2301 markMisspellingsAndBadGrammar(oldAdjacentWords, false, oldAd
jacentWords); | |
| 2302 } | |
| 2303 } | 2295 } |
| 2304 | 2296 |
| 2305 if (!textChecker() || textChecker()->shouldEraseMarkersAfterChangeSelect
ion(TextCheckingTypeSpelling)) { | 2297 if (!textChecker() || textChecker()->shouldEraseMarkersAfterChangeSelect
ion(TextCheckingTypeSpelling)) { |
| 2306 if (RefPtr<Range> wordRange = newAdjacentWords.toNormalizedRange()) | 2298 if (RefPtr<Range> wordRange = newAdjacentWords.toNormalizedRange()) |
| 2307 m_frame->document()->markers()->removeMarkers(wordRange.get(), D
ocumentMarker::Spelling); | 2299 m_frame->document()->markers()->removeMarkers(wordRange.get(), D
ocumentMarker::Spelling); |
| 2308 } | 2300 } |
| 2309 if (!textChecker() || textChecker()->shouldEraseMarkersAfterChangeSelect
ion(TextCheckingTypeGrammar)) { | 2301 if (!textChecker() || textChecker()->shouldEraseMarkersAfterChangeSelect
ion(TextCheckingTypeGrammar)) { |
| 2310 if (RefPtr<Range> sentenceRange = newSelectedSentence.toNormalizedRa
nge()) | 2302 if (RefPtr<Range> sentenceRange = newSelectedSentence.toNormalizedRa
nge()) |
| 2311 m_frame->document()->markers()->removeMarkers(sentenceRange.get(
), DocumentMarker::Grammar); | 2303 m_frame->document()->markers()->removeMarkers(sentenceRange.get(
), DocumentMarker::Grammar); |
| 2312 } | 2304 } |
| 2313 } | 2305 } |
| 2314 | 2306 |
| 2315 // When continuous spell checking is off, existing markers disappear after t
he selection changes. | 2307 // When continuous spell checking is off, existing markers disappear after t
he selection changes. |
| 2316 if (!isContinuousSpellCheckingEnabled) | 2308 if (!isContinuousSpellCheckingEnabled) |
| 2317 m_frame->document()->markers()->removeMarkers(DocumentMarker::Spelling); | 2309 m_frame->document()->markers()->removeMarkers(DocumentMarker::Spelling); |
| 2318 if (!isContinuousGrammarCheckingEnabled) | 2310 if (!isContinuousGrammarCheckingEnabled) |
| 2319 m_frame->document()->markers()->removeMarkers(DocumentMarker::Grammar); | 2311 m_frame->document()->markers()->removeMarkers(DocumentMarker::Grammar); |
| 2320 | 2312 |
| 2321 cancelCompositionIfSelectionIsInvalid(); | 2313 cancelCompositionIfSelectionIsInvalid(); |
| 2322 | 2314 |
| 2323 notifyComponentsOnChangedSelection(oldSelection, options); | 2315 notifyComponentsOnChangedSelection(oldSelection, options); |
| 2324 } | 2316 } |
| 2325 | 2317 |
| 2318 void Editor::spellCheckAfterBlur() |
| 2319 { |
| 2320 if (!m_frame->selection()->selection().isContentEditable()) |
| 2321 return; |
| 2322 |
| 2323 if (isSelectionInTextField(m_frame->selection()->selection())) { |
| 2324 // textFieldDidEndEditing() and textFieldDidBeginEditing() handle this. |
| 2325 return; |
| 2326 } |
| 2327 |
| 2328 VisibleSelection empty; |
| 2329 spellCheckOldSelection(m_frame->selection()->selection(), empty, empty); |
| 2330 } |
| 2331 |
| 2332 void Editor::spellCheckOldSelection(const VisibleSelection& oldSelection, const
VisibleSelection& newAdjacentWords, const VisibleSelection& newSelectedSentence) |
| 2333 { |
| 2334 VisiblePosition oldStart(oldSelection.visibleStart()); |
| 2335 VisibleSelection oldAdjacentWords = VisibleSelection(startOfWord(oldStart, L
eftWordIfOnBoundary), endOfWord(oldStart, RightWordIfOnBoundary)); |
| 2336 if (oldAdjacentWords != newAdjacentWords) { |
| 2337 if (isContinuousSpellCheckingEnabled() && isGrammarCheckingEnabled()) { |
| 2338 VisibleSelection selectedSentence = VisibleSelection(startOfSentence
(oldStart), endOfSentence(oldStart)); |
| 2339 markMisspellingsAndBadGrammar(oldAdjacentWords, selectedSentence !=
newSelectedSentence, selectedSentence); |
| 2340 } else { |
| 2341 markMisspellingsAndBadGrammar(oldAdjacentWords, false, oldAdjacentWo
rds); |
| 2342 } |
| 2343 } |
| 2344 } |
| 2345 |
| 2326 static Node* findFirstMarkable(Node* node) | 2346 static Node* findFirstMarkable(Node* node) |
| 2327 { | 2347 { |
| 2328 while (node) { | 2348 while (node) { |
| 2329 if (!node->renderer()) | 2349 if (!node->renderer()) |
| 2330 return 0; | 2350 return 0; |
| 2331 if (node->renderer()->isText()) | 2351 if (node->renderer()->isText()) |
| 2332 return node; | 2352 return node; |
| 2333 if (node->renderer()->isTextControl()) | 2353 if (node->renderer()->isTextControl()) |
| 2334 node = toRenderTextControl(node->renderer())->textFormControlElement
()->visiblePositionForIndex(1).deepEquivalent().deprecatedNode(); | 2354 node = toRenderTextControl(node->renderer())->textFormControlElement
()->visiblePositionForIndex(1).deepEquivalent().deprecatedNode(); |
| 2335 else if (node->firstChild()) | 2355 else if (node->firstChild()) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2378 return WebCore::unifiedTextCheckerEnabled(m_frame); | 2398 return WebCore::unifiedTextCheckerEnabled(m_frame); |
| 2379 } | 2399 } |
| 2380 | 2400 |
| 2381 void Editor::toggleOverwriteModeEnabled() | 2401 void Editor::toggleOverwriteModeEnabled() |
| 2382 { | 2402 { |
| 2383 m_overwriteModeEnabled = !m_overwriteModeEnabled; | 2403 m_overwriteModeEnabled = !m_overwriteModeEnabled; |
| 2384 frame()->selection()->setShouldShowBlockCursor(m_overwriteModeEnabled); | 2404 frame()->selection()->setShouldShowBlockCursor(m_overwriteModeEnabled); |
| 2385 }; | 2405 }; |
| 2386 | 2406 |
| 2387 } // namespace WebCore | 2407 } // namespace WebCore |
| OLD | NEW |