| 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 778 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 789 oldSelection.start().document()->updateStyleAndLayoutIgnorePendingStylesheet
s(); | 789 oldSelection.start().document()->updateStyleAndLayoutIgnorePendingStylesheet
s(); |
| 790 return oldSelection.isContentEditable(); | 790 return oldSelection.isContentEditable(); |
| 791 } | 791 } |
| 792 | 792 |
| 793 void SpellChecker::respondToChangedSelection(const VisibleSelection& oldSelectio
n, FrameSelection::SetSelectionOptions options) | 793 void SpellChecker::respondToChangedSelection(const VisibleSelection& oldSelectio
n, FrameSelection::SetSelectionOptions options) |
| 794 { | 794 { |
| 795 TRACE_EVENT0("blink", "SpellChecker::respondToChangedSelection"); | 795 TRACE_EVENT0("blink", "SpellChecker::respondToChangedSelection"); |
| 796 if (!isSpellCheckingEnabledFor(oldSelection)) | 796 if (!isSpellCheckingEnabledFor(oldSelection)) |
| 797 return; | 797 return; |
| 798 | 798 |
| 799 bool closeTyping = options & FrameSelection::CloseTyping; | 799 // When continuous spell checking is off, existing markers disappear after t
he selection changes. |
| 800 bool isContinuousSpellCheckingEnabled = this->isContinuousSpellCheckingEnabl
ed(); | 800 if (!isContinuousSpellCheckingEnabled()) { |
| 801 bool isContinuousGrammarCheckingEnabled = isContinuousSpellCheckingEnabled; | 801 frame().document()->markers().removeMarkers(DocumentMarker::Spelling); |
| 802 if (isContinuousSpellCheckingEnabled && closeTyping && shouldCheckOldSelecti
on(oldSelection)) { | 802 frame().document()->markers().removeMarkers(DocumentMarker::Grammar); |
| 803 VisibleSelection newAdjacentWords; | 803 return; |
| 804 bool caretBrowsing = frame().settings() && frame().settings()->caretBrow
singEnabled(); | |
| 805 const VisibleSelection newSelection = frame().selection().selection(); | |
| 806 if (isSelectionInTextFormControl(newSelection)) { | |
| 807 Position newStart = newSelection.start(); | |
| 808 newAdjacentWords.setWithoutValidation(HTMLTextFormControlElement::st
artOfWord(newStart), HTMLTextFormControlElement::endOfWord(newStart)); | |
| 809 } else { | |
| 810 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); | |
| 811 if (newSelection.isContentEditable() || caretBrowsing) { | |
| 812 VisiblePosition newStart(newSelection.visibleStart()); | |
| 813 newAdjacentWords = VisibleSelection(startOfWord(newStart, LeftWo
rdIfOnBoundary), endOfWord(newStart, RightWordIfOnBoundary)); | |
| 814 } | |
| 815 } | |
| 816 | |
| 817 // When typing we check spelling elsewhere, so don't redo it here. | |
| 818 // If this is a change in selection resulting from a delete operation, | |
| 819 // oldSelection may no longer be in the document. | |
| 820 // FIXME(http://crbug.com/382809): if oldSelection is on a textarea | |
| 821 // element, we cause synchronous layout. | |
| 822 spellCheckOldSelection(oldSelection, newAdjacentWords); | |
| 823 } | 804 } |
| 824 | 805 |
| 825 // When continuous spell checking is off, existing markers disappear after t
he selection changes. | 806 if (!(options & FrameSelection::CloseTyping)) |
| 826 if (!isContinuousSpellCheckingEnabled) | 807 return; |
| 827 frame().document()->markers().removeMarkers(DocumentMarker::Spelling); | 808 if (!shouldCheckOldSelection(oldSelection)) |
| 828 if (!isContinuousGrammarCheckingEnabled) | 809 return; |
| 829 frame().document()->markers().removeMarkers(DocumentMarker::Grammar); | 810 |
| 811 VisibleSelection newAdjacentWords; |
| 812 const VisibleSelection newSelection = frame().selection().selection(); |
| 813 if (isSelectionInTextFormControl(newSelection)) { |
| 814 const Position newStart = newSelection.start(); |
| 815 newAdjacentWords.setWithoutValidation(HTMLTextFormControlElement::startO
fWord(newStart), HTMLTextFormControlElement::endOfWord(newStart)); |
| 816 } else { |
| 817 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 818 const bool caretBrowsing = frame().settings() && frame().settings()->car
etBrowsingEnabled(); |
| 819 if (newSelection.isContentEditable() || caretBrowsing) { |
| 820 const VisiblePosition newStart(newSelection.visibleStart()); |
| 821 newAdjacentWords = VisibleSelection(startOfWord(newStart, LeftWordIf
OnBoundary), endOfWord(newStart, RightWordIfOnBoundary)); |
| 822 } |
| 823 } |
| 824 |
| 825 // When typing we check spelling elsewhere, so don't redo it here. |
| 826 // If this is a change in selection resulting from a delete operation, |
| 827 // oldSelection may no longer be in the document. |
| 828 // FIXME(http://crbug.com/382809): if oldSelection is on a textarea |
| 829 // element, we cause synchronous layout. |
| 830 spellCheckOldSelection(oldSelection, newAdjacentWords); |
| 830 } | 831 } |
| 831 | 832 |
| 832 void SpellChecker::removeSpellingMarkers() | 833 void SpellChecker::removeSpellingMarkers() |
| 833 { | 834 { |
| 834 frame().document()->markers().removeMarkers(DocumentMarker::MisspellingMarke
rs()); | 835 frame().document()->markers().removeMarkers(DocumentMarker::MisspellingMarke
rs()); |
| 835 } | 836 } |
| 836 | 837 |
| 837 void SpellChecker::removeSpellingMarkersUnderWords(const Vector<String>& words) | 838 void SpellChecker::removeSpellingMarkersUnderWords(const Vector<String>& words) |
| 838 { | 839 { |
| 839 MarkerRemoverPredicate removerPredicate(words); | 840 MarkerRemoverPredicate removerPredicate(words); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 visitor->trace(m_frame); | 958 visitor->trace(m_frame); |
| 958 visitor->trace(m_spellCheckRequester); | 959 visitor->trace(m_spellCheckRequester); |
| 959 } | 960 } |
| 960 | 961 |
| 961 void SpellChecker::prepareForLeakDetection() | 962 void SpellChecker::prepareForLeakDetection() |
| 962 { | 963 { |
| 963 m_spellCheckRequester->prepareForLeakDetection(); | 964 m_spellCheckRequester->prepareForLeakDetection(); |
| 964 } | 965 } |
| 965 | 966 |
| 966 } // namespace blink | 967 } // namespace blink |
| OLD | NEW |