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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 using namespace HTMLNames; | 51 using namespace HTMLNames; |
| 52 | 52 |
| 53 namespace { | 53 namespace { |
| 54 | 54 |
| 55 bool isSelectionInTextField(const VisibleSelection& selection) | 55 bool isSelectionInTextField(const VisibleSelection& selection) |
| 56 { | 56 { |
| 57 HTMLTextFormControlElement* textControl = enclosingTextFormControl(selection .start()); | 57 HTMLTextFormControlElement* textControl = enclosingTextFormControl(selection .start()); |
| 58 return isHTMLInputElement(textControl) && toHTMLInputElement(textControl)->i sTextField(); | 58 return isHTMLInputElement(textControl) && toHTMLInputElement(textControl)->i sTextField(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 bool isSelectionInTextArea(const VisibleSelection& selection) | |
| 62 { | |
| 63 HTMLTextFormControlElement* textControl = enclosingTextFormControl(selection .start()); | |
| 64 return isHTMLTextAreaElement(textControl); | |
| 65 } | |
| 66 | |
| 67 bool isSelectionInTextForm(const VisibleSelection& selection) | |
|
yosin_UTC9
2014/07/02 09:44:03
nit: It is better to call |isSelectionInTextFormCo
| |
| 68 { | |
| 69 return !!enclosingTextFormControl(selection.start()); | |
| 70 } | |
| 71 | |
| 61 } // namespace | 72 } // namespace |
| 62 | 73 |
| 63 PassOwnPtr<SpellChecker> SpellChecker::create(LocalFrame& frame) | 74 PassOwnPtr<SpellChecker> SpellChecker::create(LocalFrame& frame) |
| 64 { | 75 { |
| 65 return adoptPtr(new SpellChecker(frame)); | 76 return adoptPtr(new SpellChecker(frame)); |
| 66 } | 77 } |
| 67 | 78 |
| 68 static SpellCheckerClient& emptySpellCheckerClient() | 79 static SpellCheckerClient& emptySpellCheckerClient() |
| 69 { | 80 { |
| 70 DEFINE_STATIC_LOCAL(EmptySpellCheckerClient, client, ()); | 81 DEFINE_STATIC_LOCAL(EmptySpellCheckerClient, client, ()); |
| (...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 752 | 763 |
| 753 void SpellChecker::respondToChangedSelection(const VisibleSelection& oldSelectio n, FrameSelection::SetSelectionOptions options) | 764 void SpellChecker::respondToChangedSelection(const VisibleSelection& oldSelectio n, FrameSelection::SetSelectionOptions options) |
| 754 { | 765 { |
| 755 bool closeTyping = options & FrameSelection::CloseTyping; | 766 bool closeTyping = options & FrameSelection::CloseTyping; |
| 756 bool isContinuousSpellCheckingEnabled = this->isContinuousSpellCheckingEnabl ed(); | 767 bool isContinuousSpellCheckingEnabled = this->isContinuousSpellCheckingEnabl ed(); |
| 757 bool isContinuousGrammarCheckingEnabled = isContinuousSpellCheckingEnabled & & isGrammarCheckingEnabled(); | 768 bool isContinuousGrammarCheckingEnabled = isContinuousSpellCheckingEnabled & & isGrammarCheckingEnabled(); |
| 758 if (isContinuousSpellCheckingEnabled) { | 769 if (isContinuousSpellCheckingEnabled) { |
| 759 VisibleSelection newAdjacentWords; | 770 VisibleSelection newAdjacentWords; |
| 760 VisibleSelection newSelectedSentence; | 771 VisibleSelection newSelectedSentence; |
| 761 bool caretBrowsing = m_frame.settings() && m_frame.settings()->caretBrow singEnabled(); | 772 bool caretBrowsing = m_frame.settings() && m_frame.settings()->caretBrow singEnabled(); |
| 762 if (m_frame.selection().selection().isContentEditable() || caretBrowsing ) { | 773 const VisibleSelection newSelection = m_frame.selection().selection(); |
| 763 VisiblePosition newStart(m_frame.selection().selection().visibleStar t()); | 774 if (isSelectionInTextForm(newSelection)) { |
| 775 Position newStart = newSelection.start(); | |
| 776 newAdjacentWords.setWithoutValidation(HTMLTextFormControlElement::st artOfWord(newStart), HTMLTextFormControlElement::endOfWord(newStart)); | |
| 777 if (isContinuousGrammarCheckingEnabled) | |
| 778 newSelectedSentence.setWithoutValidation(HTMLTextFormControlElem ent::startOfSentence(newStart), HTMLTextFormControlElement::endOfSentence(newSta rt)); | |
| 779 } else if (newSelection.isContentEditable() || caretBrowsing) { | |
| 780 VisiblePosition newStart(newSelection.visibleStart()); | |
| 764 newAdjacentWords = VisibleSelection(startOfWord(newStart, LeftWordIf OnBoundary), endOfWord(newStart, RightWordIfOnBoundary)); | 781 newAdjacentWords = VisibleSelection(startOfWord(newStart, LeftWordIf OnBoundary), endOfWord(newStart, RightWordIfOnBoundary)); |
| 765 if (isContinuousGrammarCheckingEnabled) | 782 if (isContinuousGrammarCheckingEnabled) |
| 766 newSelectedSentence = VisibleSelection(startOfSentence(newStart) , endOfSentence(newStart)); | 783 newSelectedSentence = VisibleSelection(startOfSentence(newStart) , endOfSentence(newStart)); |
| 767 } | 784 } |
| 768 | 785 |
| 769 // Don't check spelling and grammar if the change of selection is trigge red by spelling correction itself. | 786 // Don't check spelling and grammar if the change of selection is trigge red by spelling correction itself. |
| 770 bool shouldCheckSpellingAndGrammar = !(options & FrameSelection::SpellCo rrectionTriggered); | 787 bool shouldCheckSpellingAndGrammar = !(options & FrameSelection::SpellCo rrectionTriggered); |
| 771 | 788 |
| 772 // When typing we check spelling elsewhere, so don't redo it here. | 789 // When typing we check spelling elsewhere, so don't redo it here. |
| 773 // If this is a change in selection resulting from a delete operation, | 790 // If this is a change in selection resulting from a delete operation, |
| 774 // oldSelection may no longer be in the document. | 791 // oldSelection may no longer be in the document. |
| 775 if (shouldCheckSpellingAndGrammar | 792 if (shouldCheckSpellingAndGrammar |
| 776 && closeTyping | 793 && closeTyping |
| 777 && oldSelection.isContentEditable() | 794 && !isSelectionInTextField(oldSelection) |
| 778 && oldSelection.start().inDocument() | 795 && (isSelectionInTextArea(oldSelection) || oldSelection.isContentEdi table()) |
| 779 && !isSelectionInTextField(oldSelection)) { | 796 && oldSelection.start().inDocument()) { |
| 780 spellCheckOldSelection(oldSelection, newAdjacentWords); | 797 spellCheckOldSelection(oldSelection, newAdjacentWords); |
| 781 } | 798 } |
| 782 | 799 |
| 783 if (textChecker().shouldEraseMarkersAfterChangeSelection(TextCheckingTyp eSpelling)) { | 800 if (textChecker().shouldEraseMarkersAfterChangeSelection(TextCheckingTyp eSpelling)) { |
| 784 if (RefPtrWillBeRawPtr<Range> wordRange = newAdjacentWords.toNormali zedRange()) | 801 if (RefPtrWillBeRawPtr<Range> wordRange = newAdjacentWords.toNormali zedRange()) |
| 785 m_frame.document()->markers().removeMarkers(wordRange.get(), Doc umentMarker::Spelling); | 802 m_frame.document()->markers().removeMarkers(wordRange.get(), Doc umentMarker::Spelling); |
| 786 } | 803 } |
| 787 if (textChecker().shouldEraseMarkersAfterChangeSelection(TextCheckingTyp eGrammar)) { | 804 if (textChecker().shouldEraseMarkersAfterChangeSelection(TextCheckingTyp eGrammar)) { |
| 788 if (RefPtrWillBeRawPtr<Range> sentenceRange = newSelectedSentence.to NormalizedRange()) | 805 if (RefPtrWillBeRawPtr<Range> sentenceRange = newSelectedSentence.to NormalizedRange()) |
| 789 m_frame.document()->markers().removeMarkers(sentenceRange.get(), DocumentMarker::Grammar); | 806 m_frame.document()->markers().removeMarkers(sentenceRange.get(), DocumentMarker::Grammar); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 896 } | 913 } |
| 897 | 914 |
| 898 void SpellChecker::requestTextChecking(const Element& element) | 915 void SpellChecker::requestTextChecking(const Element& element) |
| 899 { | 916 { |
| 900 RefPtrWillBeRawPtr<Range> rangeToCheck = rangeOfContents(const_cast<Element* >(&element)); | 917 RefPtrWillBeRawPtr<Range> rangeToCheck = rangeOfContents(const_cast<Element* >(&element)); |
| 901 m_spellCheckRequester->requestCheckingFor(SpellCheckRequest::create(TextChec kingTypeSpelling | TextCheckingTypeGrammar, TextCheckingProcessBatch, rangeToChe ck, rangeToCheck)); | 918 m_spellCheckRequester->requestCheckingFor(SpellCheckRequest::create(TextChec kingTypeSpelling | TextCheckingTypeGrammar, TextCheckingProcessBatch, rangeToChe ck, rangeToCheck)); |
| 902 } | 919 } |
| 903 | 920 |
| 904 | 921 |
| 905 } // namespace WebCore | 922 } // namespace WebCore |
| OLD | NEW |