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

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

Issue 2457523003: Support 'insertReplacementText' for spellcheck (Closed)
Patch Set: dtapuska's comment addressed 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 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 if (markers.size() < 1 || 812 if (markers.size() < 1 ||
811 markers[0]->startOffset() >= markers[0]->endOffset()) 813 markers[0]->startOffset() >= markers[0]->endOffset())
812 return; 814 return;
813 EphemeralRange markerRange = 815 EphemeralRange markerRange =
814 EphemeralRange(Position(caretRange.startPosition().computeContainerNode(), 816 EphemeralRange(Position(caretRange.startPosition().computeContainerNode(),
815 markers[0]->startOffset()), 817 markers[0]->startOffset()),
816 Position(caretRange.endPosition().computeContainerNode(), 818 Position(caretRange.endPosition().computeContainerNode(),
817 markers[0]->endOffset())); 819 markers[0]->endOffset()));
818 if (markerRange.isNull()) 820 if (markerRange.isNull())
819 return; 821 return;
822
820 frame().selection().setSelection( 823 frame().selection().setSelection(
821 SelectionInDOMTree::Builder().setBaseAndExtent(markerRange).build()); 824 SelectionInDOMTree::Builder().setBaseAndExtent(markerRange).build());
822 825
826 // Dispatch 'beforeinput'.
827 Element* target = frame().editor().findEventTargetFromSelection();
828 RangeVector* ranges = new RangeVector(1, frame().selection().firstRange());
yosin_UTC9 2016/11/10 01:49:52 Is this work if |FrameSelection::firstRange()| ret
Xiaocheng 2016/11/10 02:35:53 This seems to be a bug that we introduced. When ho
829 DataTransfer* dataTransfer = DataTransfer::create(
830 DataTransfer::DataTransferType::InsertReplacementText,
831 DataTransferAccessPolicy::DataTransferReadable,
832 DataObject::createFromString(text));
833
834 const bool cancel =
835 dispatchBeforeInputDataTransfer(
836 target, InputEvent::InputType::InsertReplacementText, dataTransfer,
837 ranges) != DispatchEventResult::NotCanceled;
838
839 // 'beforeinput' event handler may destroy target frame.
840 if (frame().document()->frame() != m_frame)
841 return;
842
823 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets 843 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
824 // 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.
825 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); 845 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets();
826 846
827 frame().editor().replaceSelectionWithText(text, false, false); 847 if (cancel)
Xiaocheng 2016/11/10 02:35:53 Let's move this return to be before updateStyleAnd
848 return;
849 frame().editor().replaceSelectionWithText(
850 text, false, false, InputEvent::InputType::InsertReplacementText);
828 } 851 }
829 852
830 static bool shouldCheckOldSelection(const Position& oldSelectionStart) { 853 static bool shouldCheckOldSelection(const Position& oldSelectionStart) {
831 if (!oldSelectionStart.isConnected()) 854 if (!oldSelectionStart.isConnected())
832 return false; 855 return false;
833 if (isPositionInTextField(oldSelectionStart)) 856 if (isPositionInTextField(oldSelectionStart))
834 return false; 857 return false;
835 if (isPositionInTextArea(oldSelectionStart)) 858 if (isPositionInTextArea(oldSelectionStart))
836 return true; 859 return true;
837 860
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1140 startOfNextParagraph(createVisiblePosition(paragraphEnd)); 1163 startOfNextParagraph(createVisiblePosition(paragraphEnd));
1141 paragraphStart = newParagraphStart.toParentAnchoredPosition(); 1164 paragraphStart = newParagraphStart.toParentAnchoredPosition();
1142 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPosition(); 1165 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPosition();
1143 firstIteration = false; 1166 firstIteration = false;
1144 totalLengthProcessed += currentLength; 1167 totalLengthProcessed += currentLength;
1145 } 1168 }
1146 return std::make_pair(firstFoundItem, firstFoundOffset); 1169 return std::make_pair(firstFoundItem, firstFoundOffset);
1147 } 1170 }
1148 1171
1149 } // namespace blink 1172 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698