| 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 912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 // In the long term we should use idle time spell checker to prevent | 923 // In the long term we should use idle time spell checker to prevent |
| 924 // synchronous layout caused by spell checking (see crbug.com/517298). | 924 // synchronous layout caused by spell checking (see crbug.com/517298). |
| 925 oldSelectionStart.document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 925 oldSelectionStart.document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 926 | 926 |
| 927 return isEditablePosition(oldSelectionStart); | 927 return isEditablePosition(oldSelectionStart); |
| 928 } | 928 } |
| 929 | 929 |
| 930 void SpellChecker::respondToChangedSelection( | 930 void SpellChecker::respondToChangedSelection( |
| 931 const Position& oldSelectionStart, | 931 const Position& oldSelectionStart, |
| 932 FrameSelection::SetSelectionOptions options) { | 932 FrameSelection::SetSelectionOptions options) { |
| 933 if (RuntimeEnabledFeatures::idleTimeSpellCheckingEnabled()) | 933 if (RuntimeEnabledFeatures::idleTimeSpellCheckingEnabled()) { |
| 934 m_idleSpellCheckCallback->setNeedsInvocation(); |
| 934 return; | 935 return; |
| 936 } |
| 935 | 937 |
| 936 TRACE_EVENT0("blink", "SpellChecker::respondToChangedSelection"); | 938 TRACE_EVENT0("blink", "SpellChecker::respondToChangedSelection"); |
| 937 if (!isSpellCheckingEnabledFor(oldSelectionStart)) | 939 if (!isSpellCheckingEnabledFor(oldSelectionStart)) |
| 938 return; | 940 return; |
| 939 | 941 |
| 940 // When spell checking is off, existing markers disappear after the selection | 942 // When spell checking is off, existing markers disappear after the selection |
| 941 // changes. | 943 // changes. |
| 942 if (!isSpellCheckingEnabled()) { | 944 if (!isSpellCheckingEnabled()) { |
| 943 frame().document()->markers().removeMarkers(DocumentMarker::Spelling); | 945 frame().document()->markers().removeMarkers(DocumentMarker::Spelling); |
| 944 frame().document()->markers().removeMarkers(DocumentMarker::Grammar); | 946 frame().document()->markers().removeMarkers(DocumentMarker::Grammar); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 968 } | 970 } |
| 969 | 971 |
| 970 // When typing we check spelling elsewhere, so don't redo it here. | 972 // When typing we check spelling elsewhere, so don't redo it here. |
| 971 // If this is a change in selection resulting from a delete operation, | 973 // If this is a change in selection resulting from a delete operation, |
| 972 // oldSelection may no longer be in the document. | 974 // oldSelection may no longer be in the document. |
| 973 // FIXME(http://crbug.com/382809): if oldSelection is on a textarea | 975 // FIXME(http://crbug.com/382809): if oldSelection is on a textarea |
| 974 // element, we cause synchronous layout. | 976 // element, we cause synchronous layout. |
| 975 spellCheckOldSelection(oldSelectionStart, newAdjacentWords); | 977 spellCheckOldSelection(oldSelectionStart, newAdjacentWords); |
| 976 } | 978 } |
| 977 | 979 |
| 980 void SpellChecker::respondToChangedContents(const VisibleSelection& selection) { |
| 981 updateMarkersForWordsAffectedByEditing(true); |
| 982 if (RuntimeEnabledFeatures::idleTimeSpellCheckingEnabled()) |
| 983 m_idleSpellCheckCallback->setNeedsInvocation(); |
| 984 } |
| 985 |
| 978 void SpellChecker::removeSpellingMarkers() { | 986 void SpellChecker::removeSpellingMarkers() { |
| 979 frame().document()->markers().removeMarkers( | 987 frame().document()->markers().removeMarkers( |
| 980 DocumentMarker::MisspellingMarkers()); | 988 DocumentMarker::MisspellingMarkers()); |
| 981 } | 989 } |
| 982 | 990 |
| 983 void SpellChecker::removeSpellingMarkersUnderWords( | 991 void SpellChecker::removeSpellingMarkersUnderWords( |
| 984 const Vector<String>& words) { | 992 const Vector<String>& words) { |
| 985 MarkerRemoverPredicate removerPredicate(words); | 993 MarkerRemoverPredicate removerPredicate(words); |
| 986 | 994 |
| 987 DocumentMarkerController& markerController = frame().document()->markers(); | 995 DocumentMarkerController& markerController = frame().document()->markers(); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1101 frame().document()->markers().removeMarkers(range, markerTypes); | 1109 frame().document()->markers().removeMarkers(range, markerTypes); |
| 1102 } | 1110 } |
| 1103 | 1111 |
| 1104 // TODO(xiaochengh): This function is only used by unit tests. We should move it | 1112 // TODO(xiaochengh): This function is only used by unit tests. We should move it |
| 1105 // to IdleSpellCheckCallback and modify unit tests to cope with idle time spell | 1113 // to IdleSpellCheckCallback and modify unit tests to cope with idle time spell |
| 1106 // checker. | 1114 // checker. |
| 1107 void SpellChecker::cancelCheck() { | 1115 void SpellChecker::cancelCheck() { |
| 1108 m_spellCheckRequester->cancelCheck(); | 1116 m_spellCheckRequester->cancelCheck(); |
| 1109 } | 1117 } |
| 1110 | 1118 |
| 1119 void SpellChecker::documentAttached(Document* document) { |
| 1120 m_idleSpellCheckCallback->documentAttached(document); |
| 1121 } |
| 1122 |
| 1111 DEFINE_TRACE(SpellChecker) { | 1123 DEFINE_TRACE(SpellChecker) { |
| 1112 visitor->trace(m_frame); | 1124 visitor->trace(m_frame); |
| 1113 visitor->trace(m_spellCheckRequester); | 1125 visitor->trace(m_spellCheckRequester); |
| 1114 visitor->trace(m_idleSpellCheckCallback); | 1126 visitor->trace(m_idleSpellCheckCallback); |
| 1115 } | 1127 } |
| 1116 | 1128 |
| 1117 void SpellChecker::prepareForLeakDetection() { | 1129 void SpellChecker::prepareForLeakDetection() { |
| 1118 m_spellCheckRequester->prepareForLeakDetection(); | 1130 m_spellCheckRequester->prepareForLeakDetection(); |
| 1119 } | 1131 } |
| 1120 | 1132 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1232 startOfNextParagraph(createVisiblePosition(paragraphEnd)); | 1244 startOfNextParagraph(createVisiblePosition(paragraphEnd)); |
| 1233 paragraphStart = newParagraphStart.toParentAnchoredPosition(); | 1245 paragraphStart = newParagraphStart.toParentAnchoredPosition(); |
| 1234 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPosition(); | 1246 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPosition(); |
| 1235 firstIteration = false; | 1247 firstIteration = false; |
| 1236 totalLengthProcessed += currentLength; | 1248 totalLengthProcessed += currentLength; |
| 1237 } | 1249 } |
| 1238 return std::make_pair(firstFoundItem, firstFoundOffset); | 1250 return std::make_pair(firstFoundItem, firstFoundOffset); |
| 1239 } | 1251 } |
| 1240 | 1252 |
| 1241 } // namespace blink | 1253 } // namespace blink |
| OLD | NEW |