| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 #include "core/editing/markers/DocumentMarkerController.h" | 45 #include "core/editing/markers/DocumentMarkerController.h" |
| 46 #include "core/editing/spellcheck/SpellCheckRequester.h" | 46 #include "core/editing/spellcheck/SpellCheckRequester.h" |
| 47 #include "core/editing/spellcheck/TextCheckingParagraph.h" | 47 #include "core/editing/spellcheck/TextCheckingParagraph.h" |
| 48 #include "core/frame/LocalFrame.h" | 48 #include "core/frame/LocalFrame.h" |
| 49 #include "core/frame/Settings.h" | 49 #include "core/frame/Settings.h" |
| 50 #include "core/html/HTMLInputElement.h" | 50 #include "core/html/HTMLInputElement.h" |
| 51 #include "core/layout/LayoutTextControl.h" | 51 #include "core/layout/LayoutTextControl.h" |
| 52 #include "core/loader/EmptyClients.h" | 52 #include "core/loader/EmptyClients.h" |
| 53 #include "core/page/Page.h" | 53 #include "core/page/Page.h" |
| 54 #include "core/page/SpellCheckerClient.h" | 54 #include "core/page/SpellCheckerClient.h" |
| 55 #include "platform/RuntimeEnabledFeatures.h" |
| 55 #include "platform/text/TextBreakIterator.h" | 56 #include "platform/text/TextBreakIterator.h" |
| 56 #include "platform/text/TextCheckerClient.h" | 57 #include "platform/text/TextCheckerClient.h" |
| 57 | 58 |
| 58 namespace blink { | 59 namespace blink { |
| 59 | 60 |
| 60 using namespace HTMLNames; | 61 using namespace HTMLNames; |
| 61 | 62 |
| 62 namespace { | 63 namespace { |
| 63 | 64 |
| 64 bool isPositionInTextField(const Position& selectionStart) { | 65 bool isPositionInTextField(const Position& selectionStart) { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 continue; | 181 continue; |
| 181 for (Node& node : | 182 for (Node& node : |
| 182 NodeTraversal::startsAt(toLocalFrame(frame)->document()->rootNode())) { | 183 NodeTraversal::startsAt(toLocalFrame(frame)->document()->rootNode())) { |
| 183 if (node.isElementNode()) | 184 if (node.isElementNode()) |
| 184 toElement(node).setAlreadySpellChecked(false); | 185 toElement(node).setAlreadySpellChecked(false); |
| 185 } | 186 } |
| 186 } | 187 } |
| 187 } | 188 } |
| 188 | 189 |
| 189 void SpellChecker::didBeginEditing(Element* element) { | 190 void SpellChecker::didBeginEditing(Element* element) { |
| 191 if (RuntimeEnabledFeatures::idleTimeSpellCheckingEnabled()) |
| 192 return; |
| 193 |
| 190 if (!isSpellCheckingEnabled()) | 194 if (!isSpellCheckingEnabled()) |
| 191 return; | 195 return; |
| 192 | 196 |
| 193 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | 197 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 194 // needs to be audited. See http://crbug.com/590369 for more details. | 198 // needs to be audited. See http://crbug.com/590369 for more details. |
| 195 // In the long term we should use idle time spell checker to prevent | 199 // In the long term we should use idle time spell checker to prevent |
| 196 // synchronous layout caused by spell checking (see crbug.com/517298). | 200 // synchronous layout caused by spell checking (see crbug.com/517298). |
| 197 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 201 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 198 | 202 |
| 199 DocumentLifecycle::DisallowTransitionScope disallowTransition( | 203 DocumentLifecycle::DisallowTransitionScope disallowTransition( |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 spellCheckerClient().showSpellingUI(true); | 363 spellCheckerClient().showSpellingUI(true); |
| 360 } | 364 } |
| 361 | 365 |
| 362 void SpellChecker::clearMisspellingsForMovingParagraphs( | 366 void SpellChecker::clearMisspellingsForMovingParagraphs( |
| 363 const VisibleSelection& movingSelection) { | 367 const VisibleSelection& movingSelection) { |
| 364 removeMarkers(movingSelection, DocumentMarker::MisspellingMarkers()); | 368 removeMarkers(movingSelection, DocumentMarker::MisspellingMarkers()); |
| 365 } | 369 } |
| 366 | 370 |
| 367 void SpellChecker::markMisspellingsForMovingParagraphs( | 371 void SpellChecker::markMisspellingsForMovingParagraphs( |
| 368 const VisibleSelection& movingSelection) { | 372 const VisibleSelection& movingSelection) { |
| 373 if (RuntimeEnabledFeatures::idleTimeSpellCheckingEnabled()) |
| 374 return; |
| 375 |
| 369 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | 376 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 370 // needs to be audited. See http://crbug.com/590369 for more details. | 377 // needs to be audited. See http://crbug.com/590369 for more details. |
| 371 // In the long term we should use idle time spell checker to prevent | 378 // In the long term we should use idle time spell checker to prevent |
| 372 // synchronous layout caused by spell checking (see crbug.com/517298). | 379 // synchronous layout caused by spell checking (see crbug.com/517298). |
| 373 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 380 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 374 | 381 |
| 375 DocumentLifecycle::DisallowTransitionScope disallowTransition( | 382 DocumentLifecycle::DisallowTransitionScope disallowTransition( |
| 376 frame().document()->lifecycle()); | 383 frame().document()->lifecycle()); |
| 377 | 384 |
| 378 markMisspellingsInternal(movingSelection); | 385 markMisspellingsInternal(movingSelection); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 391 if (!editableNode || !hasEditableStyle(*editableNode)) | 398 if (!editableNode || !hasEditableStyle(*editableNode)) |
| 392 return; | 399 return; |
| 393 | 400 |
| 394 TextCheckingParagraph fullParagraphToCheck( | 401 TextCheckingParagraph fullParagraphToCheck( |
| 395 expandRangeToSentenceBoundary(range)); | 402 expandRangeToSentenceBoundary(range)); |
| 396 chunkAndMarkAllMisspellings(fullParagraphToCheck); | 403 chunkAndMarkAllMisspellings(fullParagraphToCheck); |
| 397 } | 404 } |
| 398 | 405 |
| 399 void SpellChecker::markMisspellingsAfterApplyingCommand( | 406 void SpellChecker::markMisspellingsAfterApplyingCommand( |
| 400 const CompositeEditCommand& cmd) { | 407 const CompositeEditCommand& cmd) { |
| 408 if (RuntimeEnabledFeatures::idleTimeSpellCheckingEnabled()) |
| 409 return; |
| 410 |
| 401 if (!isSpellCheckingEnabled()) | 411 if (!isSpellCheckingEnabled()) |
| 402 return; | 412 return; |
| 403 if (!isSpellCheckingEnabledFor(cmd.endingSelection())) | 413 if (!isSpellCheckingEnabledFor(cmd.endingSelection())) |
| 404 return; | 414 return; |
| 405 | 415 |
| 406 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | 416 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 407 // needs to be audited. See http://crbug.com/590369 for more details. | 417 // needs to be audited. See http://crbug.com/590369 for more details. |
| 408 // In the long term we should use idle time spell checker to prevent | 418 // In the long term we should use idle time spell checker to prevent |
| 409 // synchronous layout caused by spell checking (see crbug.com/517298). | 419 // synchronous layout caused by spell checking (see crbug.com/517298). |
| 410 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 420 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| (...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 // In the long term we should use idle time spell checker to prevent | 871 // In the long term we should use idle time spell checker to prevent |
| 862 // synchronous layout caused by spell checking (see crbug.com/517298). | 872 // synchronous layout caused by spell checking (see crbug.com/517298). |
| 863 oldSelectionStart.document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 873 oldSelectionStart.document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 864 | 874 |
| 865 return isEditablePosition(oldSelectionStart); | 875 return isEditablePosition(oldSelectionStart); |
| 866 } | 876 } |
| 867 | 877 |
| 868 void SpellChecker::respondToChangedSelection( | 878 void SpellChecker::respondToChangedSelection( |
| 869 const Position& oldSelectionStart, | 879 const Position& oldSelectionStart, |
| 870 FrameSelection::SetSelectionOptions options) { | 880 FrameSelection::SetSelectionOptions options) { |
| 881 if (RuntimeEnabledFeatures::idleTimeSpellCheckingEnabled()) |
| 882 return; |
| 883 |
| 871 TRACE_EVENT0("blink", "SpellChecker::respondToChangedSelection"); | 884 TRACE_EVENT0("blink", "SpellChecker::respondToChangedSelection"); |
| 872 if (!isSpellCheckingEnabledFor(oldSelectionStart)) | 885 if (!isSpellCheckingEnabledFor(oldSelectionStart)) |
| 873 return; | 886 return; |
| 874 | 887 |
| 875 // When spell checking is off, existing markers disappear after the selection | 888 // When spell checking is off, existing markers disappear after the selection |
| 876 // changes. | 889 // changes. |
| 877 if (!isSpellCheckingEnabled()) { | 890 if (!isSpellCheckingEnabled()) { |
| 878 frame().document()->markers().removeMarkers(DocumentMarker::Spelling); | 891 frame().document()->markers().removeMarkers(DocumentMarker::Spelling); |
| 879 frame().document()->markers().removeMarkers(DocumentMarker::Grammar); | 892 frame().document()->markers().removeMarkers(DocumentMarker::Grammar); |
| 880 return; | 893 return; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 917 void SpellChecker::removeSpellingMarkersUnderWords( | 930 void SpellChecker::removeSpellingMarkersUnderWords( |
| 918 const Vector<String>& words) { | 931 const Vector<String>& words) { |
| 919 MarkerRemoverPredicate removerPredicate(words); | 932 MarkerRemoverPredicate removerPredicate(words); |
| 920 | 933 |
| 921 DocumentMarkerController& markerController = frame().document()->markers(); | 934 DocumentMarkerController& markerController = frame().document()->markers(); |
| 922 markerController.removeMarkers(removerPredicate); | 935 markerController.removeMarkers(removerPredicate); |
| 923 markerController.repaintMarkers(); | 936 markerController.repaintMarkers(); |
| 924 } | 937 } |
| 925 | 938 |
| 926 void SpellChecker::spellCheckAfterBlur() { | 939 void SpellChecker::spellCheckAfterBlur() { |
| 940 if (RuntimeEnabledFeatures::idleTimeSpellCheckingEnabled()) |
| 941 return; |
| 942 |
| 927 if (!frame().selection().selection().isContentEditable()) | 943 if (!frame().selection().selection().isContentEditable()) |
| 928 return; | 944 return; |
| 929 | 945 |
| 930 if (isPositionInTextField(frame().selection().selection().start())) { | 946 if (isPositionInTextField(frame().selection().selection().start())) { |
| 931 // textFieldDidEndEditing() and textFieldDidBeginEditing() handle this. | 947 // textFieldDidEndEditing() and textFieldDidBeginEditing() handle this. |
| 932 return; | 948 return; |
| 933 } | 949 } |
| 934 | 950 |
| 935 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | 951 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 936 // needs to be audited. See http://crbug.com/590369 for more details. | 952 // needs to be audited. See http://crbug.com/590369 for more details. |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 startOfNextParagraph(createVisiblePosition(paragraphEnd)); | 1170 startOfNextParagraph(createVisiblePosition(paragraphEnd)); |
| 1155 paragraphStart = newParagraphStart.toParentAnchoredPosition(); | 1171 paragraphStart = newParagraphStart.toParentAnchoredPosition(); |
| 1156 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPosition(); | 1172 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPosition(); |
| 1157 firstIteration = false; | 1173 firstIteration = false; |
| 1158 totalLengthProcessed += currentLength; | 1174 totalLengthProcessed += currentLength; |
| 1159 } | 1175 } |
| 1160 return std::make_pair(firstFoundItem, firstFoundOffset); | 1176 return std::make_pair(firstFoundItem, firstFoundOffset); |
| 1161 } | 1177 } |
| 1162 | 1178 |
| 1163 } // namespace blink | 1179 } // namespace blink |
| OLD | NEW |