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 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 2178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2278 if (!isContinuousSpellCheckingEnabled) | 2289 if (!isContinuousSpellCheckingEnabled) |
| 2279 m_frame->document()->markers()->removeMarkers(DocumentMarker::Spelling); | 2290 m_frame->document()->markers()->removeMarkers(DocumentMarker::Spelling); |
| 2280 if (!isContinuousGrammarCheckingEnabled) | 2291 if (!isContinuousGrammarCheckingEnabled) |
| 2281 m_frame->document()->markers()->removeMarkers(DocumentMarker::Grammar); | 2292 m_frame->document()->markers()->removeMarkers(DocumentMarker::Grammar); |
| 2282 | 2293 |
| 2283 cancelCompositionIfSelectionIsInvalid(); | 2294 cancelCompositionIfSelectionIsInvalid(); |
| 2284 | 2295 |
| 2285 notifyComponentsOnChangedSelection(oldSelection, options); | 2296 notifyComponentsOnChangedSelection(oldSelection, options); |
| 2286 } | 2297 } |
| 2287 | 2298 |
| 2299 void Editor::respondToChangedFocusedOrActiveState(bool activeAndFocused) | |
| 2300 { | |
| 2301 if (!activeAndFocused) { | |
|
tony
2013/08/02 20:35:03
Nit: It's a little easier to read if you early ret
| |
| 2302 if (!m_frame->selection()->selection().isContentEditable()) | |
| 2303 return; | |
| 2304 | |
| 2305 if (isSelectionInTextField(m_frame->selection()->selection())) { | |
| 2306 // textFieldDidEndEditing() and textFieldDidBeginEditing() handle th is. | |
| 2307 return; | |
| 2308 } | |
| 2309 | |
| 2310 // Make sure a current selection gets spell checked when unfocusing an e ditable element | |
| 2311 // by activating different frame. | |
|
tony
2013/08/02 20:35:03
This is a 'what' comment, which we normally avoid
| |
| 2312 VisiblePosition start(m_frame->selection()->selection().visibleStart()); | |
|
tony
2013/08/02 20:35:03
This code seems similar to the code in respondToCh
| |
| 2313 VisibleSelection adjacentWords = VisibleSelection(startOfWord(start, Lef tWordIfOnBoundary), endOfWord(start, RightWordIfOnBoundary)); | |
| 2314 if (isContinuousSpellCheckingEnabled() && isGrammarCheckingEnabled()) { | |
| 2315 VisibleSelection selectedSentence = VisibleSelection(startOfSentence (start), endOfSentence(start)); | |
| 2316 markMisspellingsAndBadGrammar(adjacentWords, true, selectedSentence) ; | |
|
tony
2013/08/02 20:35:03
A good cleanup change would be converting the bool
pstanek
2013/08/04 00:00:06
Sure but note I'm not doing this within this bug f
| |
| 2317 } else { | |
| 2318 markMisspellingsAndBadGrammar(adjacentWords, false, adjacentWords); | |
| 2319 } | |
| 2320 } | |
| 2321 } | |
| 2322 | |
| 2288 static Node* findFirstMarkable(Node* node) | 2323 static Node* findFirstMarkable(Node* node) |
| 2289 { | 2324 { |
| 2290 while (node) { | 2325 while (node) { |
| 2291 if (!node->renderer()) | 2326 if (!node->renderer()) |
| 2292 return 0; | 2327 return 0; |
| 2293 if (node->renderer()->isText()) | 2328 if (node->renderer()->isText()) |
| 2294 return node; | 2329 return node; |
| 2295 if (node->renderer()->isTextControl()) | 2330 if (node->renderer()->isTextControl()) |
| 2296 node = toRenderTextControl(node->renderer())->textFormControlElement ()->visiblePositionForIndex(1).deepEquivalent().deprecatedNode(); | 2331 node = toRenderTextControl(node->renderer())->textFormControlElement ()->visiblePositionForIndex(1).deepEquivalent().deprecatedNode(); |
| 2297 else if (node->firstChild()) | 2332 else if (node->firstChild()) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2340 return WebCore::unifiedTextCheckerEnabled(m_frame); | 2375 return WebCore::unifiedTextCheckerEnabled(m_frame); |
| 2341 } | 2376 } |
| 2342 | 2377 |
| 2343 void Editor::toggleOverwriteModeEnabled() | 2378 void Editor::toggleOverwriteModeEnabled() |
| 2344 { | 2379 { |
| 2345 m_overwriteModeEnabled = !m_overwriteModeEnabled; | 2380 m_overwriteModeEnabled = !m_overwriteModeEnabled; |
| 2346 frame()->selection()->setShouldShowBlockCursor(m_overwriteModeEnabled); | 2381 frame()->selection()->setShouldShowBlockCursor(m_overwriteModeEnabled); |
| 2347 }; | 2382 }; |
| 2348 | 2383 |
| 2349 } // namespace WebCore | 2384 } // namespace WebCore |
| OLD | NEW |