Chromium Code Reviews| 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 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 769 DocumentMarkerVector markers = frame().document()->markers().markersInRange( caretRange, DocumentMarker::MisspellingMarkers()); | 769 DocumentMarkerVector markers = frame().document()->markers().markersInRange( caretRange, DocumentMarker::MisspellingMarkers()); |
| 770 if (markers.size() < 1 || markers[0]->startOffset() >= markers[0]->endOffset ()) | 770 if (markers.size() < 1 || markers[0]->startOffset() >= markers[0]->endOffset ()) |
| 771 return; | 771 return; |
| 772 EphemeralRange markerRange = EphemeralRange(Position(caretRange.startPositio n().computeContainerNode(), markers[0]->startOffset()), Position(caretRange.endP osition().computeContainerNode(), markers[0]->endOffset())); | 772 EphemeralRange markerRange = EphemeralRange(Position(caretRange.startPositio n().computeContainerNode(), markers[0]->startOffset()), Position(caretRange.endP osition().computeContainerNode(), markers[0]->endOffset())); |
| 773 if (markerRange.isNull()) | 773 if (markerRange.isNull()) |
| 774 return; | 774 return; |
| 775 frame().selection().setSelection(VisibleSelection(markerRange), CharacterGra nularity); | 775 frame().selection().setSelection(VisibleSelection(markerRange), CharacterGra nularity); |
| 776 frame().editor().replaceSelectionWithText(text, false, false); | 776 frame().editor().replaceSelectionWithText(text, false, false); |
| 777 } | 777 } |
| 778 | 778 |
| 779 static bool shouldCheckOldSelection(const VisibleSelection& oldSelection) | |
| 780 { | |
| 781 if (!oldSelection.start().inShadowIncludingDocument()) | |
| 782 return false; | |
| 783 if (isSelectionInTextField(oldSelection)) | |
| 784 return false; | |
| 785 if (isSelectionInTextArea(oldSelection)) | |
| 786 return true; | |
| 787 oldSelection.start().document()->updateStyleAndLayoutIgnorePendingStylesheet s(); | |
| 788 return oldSelection.isContentEditable(); | |
| 789 } | |
| 790 | |
| 779 void SpellChecker::respondToChangedSelection(const VisibleSelection& oldSelectio n, FrameSelection::SetSelectionOptions options) | 791 void SpellChecker::respondToChangedSelection(const VisibleSelection& oldSelectio n, FrameSelection::SetSelectionOptions options) |
| 780 { | 792 { |
| 781 TRACE_EVENT0("blink", "SpellChecker::respondToChangedSelection"); | 793 TRACE_EVENT0("blink", "SpellChecker::respondToChangedSelection"); |
| 782 if (!isSpellCheckingEnabledFor(oldSelection)) | 794 if (!isSpellCheckingEnabledFor(oldSelection)) |
| 783 return; | 795 return; |
| 784 | 796 |
| 785 bool closeTyping = options & FrameSelection::CloseTyping; | 797 bool closeTyping = options & FrameSelection::CloseTyping; |
| 786 bool isContinuousSpellCheckingEnabled = this->isContinuousSpellCheckingEnabl ed(); | 798 bool isContinuousSpellCheckingEnabled = this->isContinuousSpellCheckingEnabl ed(); |
| 787 bool isContinuousGrammarCheckingEnabled = isContinuousSpellCheckingEnabled; | 799 bool isContinuousGrammarCheckingEnabled = isContinuousSpellCheckingEnabled; |
| 788 if (isContinuousSpellCheckingEnabled) { | 800 if (isContinuousSpellCheckingEnabled && closeTyping) { |
|
yoichio
2016/06/24 09:52:39
Why do you introduce the |closeTyping| condition?
yosin_UTC9
2016/06/27 01:46:49
This if-statement does nothing if |!closeTyping| e
yoichio
2016/06/27 02:10:40
I see. then we can move the |shouldCheckOldSelecti
yosin_UTC9
2016/06/27 04:11:07
You're right. Good catch!
I moved it.
| |
| 789 VisibleSelection newAdjacentWords; | 801 VisibleSelection newAdjacentWords; |
| 790 bool caretBrowsing = frame().settings() && frame().settings()->caretBrow singEnabled(); | 802 bool caretBrowsing = frame().settings() && frame().settings()->caretBrow singEnabled(); |
| 791 const VisibleSelection newSelection = frame().selection().selection(); | 803 const VisibleSelection newSelection = frame().selection().selection(); |
| 792 if (isSelectionInTextFormControl(newSelection)) { | 804 if (isSelectionInTextFormControl(newSelection)) { |
| 793 Position newStart = newSelection.start(); | 805 Position newStart = newSelection.start(); |
| 794 newAdjacentWords.setWithoutValidation(HTMLTextFormControlElement::st artOfWord(newStart), HTMLTextFormControlElement::endOfWord(newStart)); | 806 newAdjacentWords.setWithoutValidation(HTMLTextFormControlElement::st artOfWord(newStart), HTMLTextFormControlElement::endOfWord(newStart)); |
| 795 } else if (newSelection.isContentEditable() || caretBrowsing) { | 807 } else { |
| 796 VisiblePosition newStart(newSelection.visibleStart()); | 808 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 797 newAdjacentWords = VisibleSelection(startOfWord(newStart, LeftWordIf OnBoundary), endOfWord(newStart, RightWordIfOnBoundary)); | 809 if (newSelection.isContentEditable() || caretBrowsing) { |
| 810 VisiblePosition newStart(newSelection.visibleStart()); | |
| 811 newAdjacentWords = VisibleSelection(startOfWord(newStart, LeftWo rdIfOnBoundary), endOfWord(newStart, RightWordIfOnBoundary)); | |
| 812 } | |
| 798 } | 813 } |
| 799 | 814 |
| 800 // When typing we check spelling elsewhere, so don't redo it here. | 815 // When typing we check spelling elsewhere, so don't redo it here. |
| 801 // If this is a change in selection resulting from a delete operation, | 816 // If this is a change in selection resulting from a delete operation, |
| 802 // oldSelection may no longer be in the document. | 817 // oldSelection may no longer be in the document. |
| 803 // FIXME(http://crbug.com/382809): if oldSelection is on a textarea | 818 // FIXME(http://crbug.com/382809): if oldSelection is on a textarea |
| 804 // element, we cause synchronous layout. | 819 // element, we cause synchronous layout. |
| 805 if (closeTyping | 820 if (shouldCheckOldSelection(oldSelection)) |
| 806 && !isSelectionInTextField(oldSelection) | |
| 807 && (isSelectionInTextArea(oldSelection) || oldSelection.isContentEdi table()) | |
| 808 && oldSelection.start().inShadowIncludingDocument()) { | |
| 809 spellCheckOldSelection(oldSelection, newAdjacentWords); | 821 spellCheckOldSelection(oldSelection, newAdjacentWords); |
| 810 } | |
| 811 } | 822 } |
| 812 | 823 |
| 813 // When continuous spell checking is off, existing markers disappear after t he selection changes. | 824 // When continuous spell checking is off, existing markers disappear after t he selection changes. |
| 814 if (!isContinuousSpellCheckingEnabled) | 825 if (!isContinuousSpellCheckingEnabled) |
| 815 frame().document()->markers().removeMarkers(DocumentMarker::Spelling); | 826 frame().document()->markers().removeMarkers(DocumentMarker::Spelling); |
| 816 if (!isContinuousGrammarCheckingEnabled) | 827 if (!isContinuousGrammarCheckingEnabled) |
| 817 frame().document()->markers().removeMarkers(DocumentMarker::Grammar); | 828 frame().document()->markers().removeMarkers(DocumentMarker::Grammar); |
| 818 } | 829 } |
| 819 | 830 |
| 820 void SpellChecker::removeSpellingMarkers() | 831 void SpellChecker::removeSpellingMarkers() |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 945 visitor->trace(m_frame); | 956 visitor->trace(m_frame); |
| 946 visitor->trace(m_spellCheckRequester); | 957 visitor->trace(m_spellCheckRequester); |
| 947 } | 958 } |
| 948 | 959 |
| 949 void SpellChecker::prepareForLeakDetection() | 960 void SpellChecker::prepareForLeakDetection() |
| 950 { | 961 { |
| 951 m_spellCheckRequester->prepareForLeakDetection(); | 962 m_spellCheckRequester->prepareForLeakDetection(); |
| 952 } | 963 } |
| 953 | 964 |
| 954 } // namespace blink | 965 } // namespace blink |
| OLD | NEW |