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

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

Issue 2457523003: Support 'insertReplacementText' for spellcheck (Closed)
Patch Set: add null check Created 4 years 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 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 if (markers.size() < 1 || 811 if (markers.size() < 1 ||
810 markers[0]->startOffset() >= markers[0]->endOffset()) 812 markers[0]->startOffset() >= markers[0]->endOffset())
811 return; 813 return;
812 EphemeralRange markerRange = 814 EphemeralRange markerRange =
813 EphemeralRange(Position(caretRange.startPosition().computeContainerNode(), 815 EphemeralRange(Position(caretRange.startPosition().computeContainerNode(),
814 markers[0]->startOffset()), 816 markers[0]->startOffset()),
815 Position(caretRange.endPosition().computeContainerNode(), 817 Position(caretRange.endPosition().computeContainerNode(),
816 markers[0]->endOffset())); 818 markers[0]->endOffset()));
817 if (markerRange.isNull()) 819 if (markerRange.isNull())
818 return; 820 return;
821
819 frame().selection().setSelection( 822 frame().selection().setSelection(
820 SelectionInDOMTree::Builder().setBaseAndExtent(markerRange).build()); 823 SelectionInDOMTree::Builder().setBaseAndExtent(markerRange).build());
821 824
825 // Dispatch 'beforeinput'.
826 Element* const target = frame().editor().findEventTargetFromSelection();
827 RangeVector* const ranges =
828 new RangeVector(1, frame().selection().firstRange());
829 DataTransfer* const 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)
yosin_UTC9 2016/11/22 01:23:47 This if-condition always true. frame() == m_frame.
841 return;
842
822 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets 843 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
823 // 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.
824 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); 845 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets();
825 846
826 frame().editor().replaceSelectionWithText(text, false, false); 847 if (cancel)
848 return;
849 frame().editor().replaceSelectionWithText(
850 text, false, false, InputEvent::InputType::InsertReplacementText);
827 } 851 }
828 852
829 static bool shouldCheckOldSelection(const Position& oldSelectionStart) { 853 static bool shouldCheckOldSelection(const Position& oldSelectionStart) {
830 if (!oldSelectionStart.isConnected()) 854 if (!oldSelectionStart.isConnected())
831 return false; 855 return false;
832 if (isPositionInTextField(oldSelectionStart)) 856 if (isPositionInTextField(oldSelectionStart))
833 return false; 857 return false;
834 if (isPositionInTextArea(oldSelectionStart)) 858 if (isPositionInTextArea(oldSelectionStart))
835 return true; 859 return true;
836 860
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1139 startOfNextParagraph(createVisiblePosition(paragraphEnd)); 1163 startOfNextParagraph(createVisiblePosition(paragraphEnd));
1140 paragraphStart = newParagraphStart.toParentAnchoredPosition(); 1164 paragraphStart = newParagraphStart.toParentAnchoredPosition();
1141 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPosition(); 1165 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPosition();
1142 firstIteration = false; 1166 firstIteration = false;
1143 totalLengthProcessed += currentLength; 1167 totalLengthProcessed += currentLength;
1144 } 1168 }
1145 return std::make_pair(firstFoundItem, firstFoundOffset); 1169 return std::make_pair(firstFoundItem, firstFoundOffset);
1146 } 1170 }
1147 1171
1148 } // namespace blink 1172 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698