Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(50)

Side by Side Diff: third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp

Issue 2457523003: Support 'insertReplacementText' for spellcheck (Closed)
Patch Set: fix for chongz's nit Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 10 matching lines...) Expand all
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #include "core/editing/spellcheck/SpellChecker.h" 27 #include "core/editing/spellcheck/SpellChecker.h"
28 28
29 #include "core/HTMLNames.h" 29 #include "core/HTMLNames.h"
30 #include "core/InputTypeNames.h" 30 #include "core/InputTypeNames.h"
31 #include "core/clipboard/DataObject.h"
31 #include "core/dom/Document.h" 32 #include "core/dom/Document.h"
32 #include "core/dom/Element.h" 33 #include "core/dom/Element.h"
33 #include "core/dom/ElementTraversal.h" 34 #include "core/dom/ElementTraversal.h"
34 #include "core/dom/NodeTraversal.h" 35 #include "core/dom/NodeTraversal.h"
36 #include "core/dom/Range.h"
35 #include "core/editing/EditingUtilities.h" 37 #include "core/editing/EditingUtilities.h"
36 #include "core/editing/Editor.h" 38 #include "core/editing/Editor.h"
37 #include "core/editing/EphemeralRange.h" 39 #include "core/editing/EphemeralRange.h"
38 #include "core/editing/VisibleUnits.h" 40 #include "core/editing/VisibleUnits.h"
39 #include "core/editing/commands/CompositeEditCommand.h" 41 #include "core/editing/commands/CompositeEditCommand.h"
40 #include "core/editing/commands/ReplaceSelectionCommand.h" 42 #include "core/editing/commands/ReplaceSelectionCommand.h"
41 #include "core/editing/commands/TypingCommand.h" 43 #include "core/editing/commands/TypingCommand.h"
42 #include "core/editing/iterators/CharacterIterator.h" 44 #include "core/editing/iterators/CharacterIterator.h"
43 #include "core/editing/markers/DocumentMarkerController.h" 45 #include "core/editing/markers/DocumentMarkerController.h"
44 #include "core/editing/spellcheck/SpellCheckRequester.h" 46 #include "core/editing/spellcheck/SpellCheckRequester.h"
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 if (markers.size() < 1 || 813 if (markers.size() < 1 ||
812 markers[0]->startOffset() >= markers[0]->endOffset()) 814 markers[0]->startOffset() >= markers[0]->endOffset())
813 return; 815 return;
814 EphemeralRange markerRange = 816 EphemeralRange markerRange =
815 EphemeralRange(Position(caretRange.startPosition().computeContainerNode(), 817 EphemeralRange(Position(caretRange.startPosition().computeContainerNode(),
816 markers[0]->startOffset()), 818 markers[0]->startOffset()),
817 Position(caretRange.endPosition().computeContainerNode(), 819 Position(caretRange.endPosition().computeContainerNode(),
818 markers[0]->endOffset())); 820 markers[0]->endOffset()));
819 if (markerRange.isNull()) 821 if (markerRange.isNull())
820 return; 822 return;
823
821 frame().selection().setSelection( 824 frame().selection().setSelection(
822 SelectionInDOMTree::Builder().setBaseAndExtent(markerRange).build()); 825 SelectionInDOMTree::Builder().setBaseAndExtent(markerRange).build());
823 826
827 // Dispatch 'beforeinput'.
828 Element* target = frame().editor().findEventTargetFromSelection();
829 RangeVector* ranges = new RangeVector(1, frame().selection().firstRange());
830 DataTransfer* dataTransfer = DataTransfer::create(
831 DataTransfer::DataTransferType::InsertReplacementText,
832 DataTransferAccessPolicy::DataTransferReadable,
833 DataObject::createFromString(text));
834
835 bool cancel = dispatchBeforeInputDataTransfer(
yosin_UTC9 2016/10/28 04:06:14 nit: s/bool/const bool/
836 target, InputEvent::InputType::InsertReplacementText,
837 dataTransfer, ranges) != DispatchEventResult::NotCanceled;
838
839 // 'beforeinput' event handler may destroy target frame.
840 if (frame().document()->frame() != m_frame)
841 return;
842
824 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets 843 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
825 // needs to be audited. See http://crbug.com/590369 for more details. 844 // needs to be audited. See http://crbug.com/590369 for more details.
826 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); 845 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets();
827 846
828 frame().editor().replaceSelectionWithText(text, false, false); 847 if (!cancel) {
yosin_UTC9 2016/10/28 04:06:14 We prefer early-return style.
848 frame().editor().replaceSelectionWithText(
849 text, false, false, InputEvent::InputType::InsertReplacementText);
850 }
829 } 851 }
830 852
831 static bool shouldCheckOldSelection(const Position& oldSelectionStart) { 853 static bool shouldCheckOldSelection(const Position& oldSelectionStart) {
832 if (!oldSelectionStart.isConnected()) 854 if (!oldSelectionStart.isConnected())
833 return false; 855 return false;
834 if (isPositionInTextField(oldSelectionStart)) 856 if (isPositionInTextField(oldSelectionStart))
835 return false; 857 return false;
836 if (isPositionInTextArea(oldSelectionStart)) 858 if (isPositionInTextArea(oldSelectionStart))
837 return true; 859 return true;
838 860
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 startOfNextParagraph(createVisiblePosition(paragraphEnd)); 1163 startOfNextParagraph(createVisiblePosition(paragraphEnd));
1142 paragraphStart = newParagraphStart.toParentAnchoredPosition(); 1164 paragraphStart = newParagraphStart.toParentAnchoredPosition();
1143 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPosition(); 1165 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPosition();
1144 firstIteration = false; 1166 firstIteration = false;
1145 totalLengthProcessed += currentLength; 1167 totalLengthProcessed += currentLength;
1146 } 1168 }
1147 return std::make_pair(firstFoundItem, firstFoundOffset); 1169 return std::make_pair(firstFoundItem, firstFoundOffset);
1148 } 1170 }
1149 1171
1150 } // namespace blink 1172 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698