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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 #include "core/editing/ReplaceSelectionCommand.h" | 55 #include "core/editing/ReplaceSelectionCommand.h" |
56 #include "core/editing/SimplifyMarkupCommand.h" | 56 #include "core/editing/SimplifyMarkupCommand.h" |
57 #include "core/editing/SpellChecker.h" | 57 #include "core/editing/SpellChecker.h" |
58 #include "core/editing/TextCheckingHelper.h" | 58 #include "core/editing/TextCheckingHelper.h" |
59 #include "core/editing/TextIterator.h" | 59 #include "core/editing/TextIterator.h" |
60 #include "core/editing/TypingCommand.h" | 60 #include "core/editing/TypingCommand.h" |
61 #include "core/editing/VisibleUnits.h" | 61 #include "core/editing/VisibleUnits.h" |
62 #include "core/editing/htmlediting.h" | 62 #include "core/editing/htmlediting.h" |
63 #include "core/editing/markup.h" | 63 #include "core/editing/markup.h" |
64 #include "core/html/HTMLImageElement.h" | 64 #include "core/html/HTMLImageElement.h" |
65 #include "core/html/HTMLInputElement.h" | |
65 #include "core/html/HTMLTextAreaElement.h" | 66 #include "core/html/HTMLTextAreaElement.h" |
66 #include "core/loader/cache/ResourceFetcher.h" | 67 #include "core/loader/cache/ResourceFetcher.h" |
67 #include "core/page/EditorClient.h" | 68 #include "core/page/EditorClient.h" |
68 #include "core/page/EventHandler.h" | 69 #include "core/page/EventHandler.h" |
69 #include "core/page/FocusController.h" | 70 #include "core/page/FocusController.h" |
70 #include "core/page/Frame.h" | 71 #include "core/page/Frame.h" |
71 #include "core/page/FrameView.h" | 72 #include "core/page/FrameView.h" |
72 #include "core/page/Page.h" | 73 #include "core/page/Page.h" |
73 #include "core/page/Settings.h" | 74 #include "core/page/Settings.h" |
74 #include "core/platform/KillRing.h" | 75 #include "core/platform/KillRing.h" |
75 #include "core/platform/Pasteboard.h" | 76 #include "core/platform/Pasteboard.h" |
76 #include "core/platform/Sound.h" | 77 #include "core/platform/Sound.h" |
77 #include "core/platform/text/TextCheckerClient.h" | 78 #include "core/platform/text/TextCheckerClient.h" |
78 #include "core/rendering/HitTestResult.h" | 79 #include "core/rendering/HitTestResult.h" |
79 #include "core/rendering/RenderBlock.h" | 80 #include "core/rendering/RenderBlock.h" |
80 #include "core/rendering/RenderTextControl.h" | 81 #include "core/rendering/RenderTextControl.h" |
81 #include "wtf/unicode/CharacterNames.h" | 82 #include "wtf/unicode/CharacterNames.h" |
82 | 83 |
83 namespace WebCore { | 84 namespace WebCore { |
84 | 85 |
85 using namespace std; | 86 using namespace std; |
86 using namespace HTMLNames; | 87 using namespace HTMLNames; |
87 using namespace WTF; | 88 using namespace WTF; |
88 using namespace Unicode; | 89 using namespace Unicode; |
89 | 90 |
91 namespace { | |
92 | |
93 bool isSelectionInTextField(const VisibleSelection& selection) | |
94 { | |
95 HTMLTextFormControlElement* textControl = enclosingTextFormControl(selection .start()); | |
96 return textControl && textControl->hasTagName(inputTag) && toHTMLInputElemen t(textControl)->isTextField(); | |
97 } | |
98 | |
99 } // namespace | |
100 | |
90 // When an event handler has moved the selection outside of a text control | 101 // When an event handler has moved the selection outside of a text control |
91 // we should use the target control's selection for this editing operation. | 102 // we should use the target control's selection for this editing operation. |
92 VisibleSelection Editor::selectionForCommand(Event* event) | 103 VisibleSelection Editor::selectionForCommand(Event* event) |
93 { | 104 { |
94 VisibleSelection selection = m_frame->selection()->selection(); | 105 VisibleSelection selection = m_frame->selection()->selection(); |
95 if (!event) | 106 if (!event) |
96 return selection; | 107 return selection; |
97 // If the target is a text control, and the current selection is outside of its shadow tree, | 108 // If the target is a text control, and the current selection is outside of its shadow tree, |
98 // then use the saved selection for that text control. | 109 // then use the saved selection for that text control. |
99 HTMLTextFormControlElement* textFormControlOfSelectionStart = enclosingTextF ormControl(selection.start()); | 110 HTMLTextFormControlElement* textFormControlOfSelectionStart = enclosingTextF ormControl(selection.start()); |
(...skipping 1968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2068 | 2079 |
2069 // Handle block styles, substracting these from the typing style. | 2080 // Handle block styles, substracting these from the typing style. |
2070 RefPtr<EditingStyle> blockStyle = typingStyle->extractAndRemoveBlockProperti es(); | 2081 RefPtr<EditingStyle> blockStyle = typingStyle->extractAndRemoveBlockProperti es(); |
2071 if (!blockStyle->isEmpty()) | 2082 if (!blockStyle->isEmpty()) |
2072 applyCommand(ApplyStyleCommand::create(m_frame->document(), blockStyle.g et(), editingAction)); | 2083 applyCommand(ApplyStyleCommand::create(m_frame->document(), blockStyle.g et(), editingAction)); |
2073 | 2084 |
2074 // Set the remaining style as the typing style. | 2085 // Set the remaining style as the typing style. |
2075 m_frame->selection()->setTypingStyle(typingStyle); | 2086 m_frame->selection()->setTypingStyle(typingStyle); |
2076 } | 2087 } |
2077 | 2088 |
2089 | |
2090 void Editor::textFieldDidBeginEditing(Element* e) | |
2091 { | |
2092 if (isContinuousSpellCheckingEnabled()) { | |
2093 Element* element = toHTMLTextFormControlElement(e)->innerTextElement(); | |
2094 VisibleSelection selection = VisibleSelection::selectionFromContentsOfNo de(element); | |
2095 markMisspellingsAndBadGrammar(selection); | |
2096 } | |
2097 } | |
2098 | |
2078 void Editor::textFieldDidEndEditing(Element* e) | 2099 void Editor::textFieldDidEndEditing(Element* e) |
2079 { | 2100 { |
2101 // Remove markers when deactivating a selection in an <input type="text"/>. | |
2102 // Prevent new ones from appearing too. | |
2103 m_spellChecker->cancelProcessingRequest(); | |
2104 HTMLTextFormControlElement* textFormControlElement = toHTMLTextFormControlEl ement(e); | |
2105 HTMLElement* innerText = textFormControlElement->innerTextElement(); | |
2106 DocumentMarker::MarkerTypes markerTypes(DocumentMarker::Spelling); | |
2107 if (isGrammarCheckingEnabled()) | |
please use gerrit instead
2013/07/30 21:32:00
Also check for unified spellchecker setting. If un
| |
2108 markerTypes.add(DocumentMarker::Grammar); | |
2109 for (Node* node = innerText; node; node = NodeTraversal::next(node, innerTex t)) { | |
2110 m_frame->document()->markers()->removeMarkers(node, markerTypes); | |
2111 } | |
2112 | |
2080 if (client()) | 2113 if (client()) |
2081 client()->textFieldDidEndEditing(e); | 2114 client()->textFieldDidEndEditing(e); |
2082 } | 2115 } |
2083 | 2116 |
2084 void Editor::textDidChangeInTextField(Element* e) | 2117 void Editor::textDidChangeInTextField(Element* e) |
2085 { | 2118 { |
2086 if (client()) | 2119 if (client()) |
2087 client()->textDidChangeInTextField(e); | 2120 client()->textDidChangeInTextField(e); |
2088 } | 2121 } |
2089 | 2122 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2245 if (isContinuousGrammarCheckingEnabled) | 2278 if (isContinuousGrammarCheckingEnabled) |
2246 newSelectedSentence = VisibleSelection(startOfSentence(newStart) , endOfSentence(newStart)); | 2279 newSelectedSentence = VisibleSelection(startOfSentence(newStart) , endOfSentence(newStart)); |
2247 } | 2280 } |
2248 | 2281 |
2249 // Don't check spelling and grammar if the change of selection is trigge red by spelling correction itself. | 2282 // Don't check spelling and grammar if the change of selection is trigge red by spelling correction itself. |
2250 bool shouldCheckSpellingAndGrammar = !(options & FrameSelection::SpellCo rrectionTriggered); | 2283 bool shouldCheckSpellingAndGrammar = !(options & FrameSelection::SpellCo rrectionTriggered); |
2251 | 2284 |
2252 // When typing we check spelling elsewhere, so don't redo it here. | 2285 // When typing we check spelling elsewhere, so don't redo it here. |
2253 // If this is a change in selection resulting from a delete operation, | 2286 // If this is a change in selection resulting from a delete operation, |
2254 // oldSelection may no longer be in the document. | 2287 // oldSelection may no longer be in the document. |
2255 if (shouldCheckSpellingAndGrammar && closeTyping && oldSelection.isConte ntEditable() && oldSelection.start().deprecatedNode() && oldSelection.start().an chorNode()->inDocument()) { | 2288 if (shouldCheckSpellingAndGrammar && closeTyping && oldSelection.isConte ntEditable() && oldSelection.start().deprecatedNode() && oldSelection.start().an chorNode()->inDocument() |
2289 && !isSelectionInTextField(oldSelection)) { | |
please use gerrit instead
2013/07/30 21:32:00
We don't go through code looking for style violati
pstanek
2013/07/30 21:50:39
Been there. && and || on the right is something pr
please use gerrit instead
2013/07/30 21:57:01
Presubmit checks are usually correct. Do what they
| |
2256 VisiblePosition oldStart(oldSelection.visibleStart()); | 2290 VisiblePosition oldStart(oldSelection.visibleStart()); |
2257 VisibleSelection oldAdjacentWords = VisibleSelection(startOfWord(old Start, LeftWordIfOnBoundary), endOfWord(oldStart, RightWordIfOnBoundary)); | 2291 VisibleSelection oldAdjacentWords = VisibleSelection(startOfWord(old Start, LeftWordIfOnBoundary), endOfWord(oldStart, RightWordIfOnBoundary)); |
2258 if (oldAdjacentWords != newAdjacentWords) { | 2292 if (oldAdjacentWords != newAdjacentWords) { |
2259 if (isContinuousGrammarCheckingEnabled) { | 2293 if (isContinuousGrammarCheckingEnabled) { |
2260 VisibleSelection oldSelectedSentence = VisibleSelection(star tOfSentence(oldStart), endOfSentence(oldStart)); | 2294 VisibleSelection oldSelectedSentence = VisibleSelection(star tOfSentence(oldStart), endOfSentence(oldStart)); |
2261 markMisspellingsAndBadGrammar(oldAdjacentWords, oldSelectedS entence != newSelectedSentence, oldSelectedSentence); | 2295 markMisspellingsAndBadGrammar(oldAdjacentWords, oldSelectedS entence != newSelectedSentence, oldSelectedSentence); |
2262 } else | 2296 } else |
2263 markMisspellingsAndBadGrammar(oldAdjacentWords, false, oldAd jacentWords); | 2297 markMisspellingsAndBadGrammar(oldAdjacentWords, false, oldAd jacentWords); |
2264 } | 2298 } |
2265 } | 2299 } |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2340 return WebCore::unifiedTextCheckerEnabled(m_frame); | 2374 return WebCore::unifiedTextCheckerEnabled(m_frame); |
2341 } | 2375 } |
2342 | 2376 |
2343 void Editor::toggleOverwriteModeEnabled() | 2377 void Editor::toggleOverwriteModeEnabled() |
2344 { | 2378 { |
2345 m_overwriteModeEnabled = !m_overwriteModeEnabled; | 2379 m_overwriteModeEnabled = !m_overwriteModeEnabled; |
2346 frame()->selection()->setShouldShowBlockCursor(m_overwriteModeEnabled); | 2380 frame()->selection()->setShouldShowBlockCursor(m_overwriteModeEnabled); |
2347 }; | 2381 }; |
2348 | 2382 |
2349 } // namespace WebCore | 2383 } // namespace WebCore |
OLD | NEW |