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

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

Issue 2558643003: [InputEvent] Move 'beforeinput' logic into |CompositeEditCommand::willApplyEditing()| (3/3) (Closed)
Patch Set: 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 800 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 EphemeralRange(Position(caretRange.startPosition().computeContainerNode(), 811 EphemeralRange(Position(caretRange.startPosition().computeContainerNode(),
812 markers[0]->startOffset()), 812 markers[0]->startOffset()),
813 Position(caretRange.endPosition().computeContainerNode(), 813 Position(caretRange.endPosition().computeContainerNode(),
814 markers[0]->endOffset())); 814 markers[0]->endOffset()));
815 if (markerRange.isNull()) 815 if (markerRange.isNull())
816 return; 816 return;
817 817
818 frame().selection().setSelection( 818 frame().selection().setSelection(
819 SelectionInDOMTree::Builder().setBaseAndExtent(markerRange).build()); 819 SelectionInDOMTree::Builder().setBaseAndExtent(markerRange).build());
820 820
821 Document& currentDocument = *frame().document();
822
823 // Dispatch 'beforeinput'.
824 Element* const target = frame().editor().findEventTargetFromSelection();
825 RangeVector* const ranges =
826 new RangeVector(1, frame().selection().firstRange());
827 DataTransfer* const dataTransfer = DataTransfer::create(
828 DataTransfer::DataTransferType::InsertReplacementText,
829 DataTransferAccessPolicy::DataTransferReadable,
830 DataObject::createFromString(text));
831
832 const bool cancel =
833 dispatchBeforeInputDataTransfer(
834 target, InputEvent::InputType::InsertReplacementText, dataTransfer,
835 ranges) != DispatchEventResult::NotCanceled;
836
837 // 'beforeinput' event handler may destroy target frame.
838 if (currentDocument != frame().document())
839 return;
840
841 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets 821 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
842 // needs to be audited. See http://crbug.com/590369 for more details. 822 // needs to be audited. See http://crbug.com/590369 for more details.
843 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); 823 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets();
844
845 if (cancel)
846 return;
847 frame().editor().replaceSelectionWithText( 824 frame().editor().replaceSelectionWithText(
848 text, false, false, InputEvent::InputType::InsertReplacementText); 825 text, false, false, InputEvent::InputType::InsertReplacementText);
849 } 826 }
850 827
851 static bool shouldCheckOldSelection(const Position& oldSelectionStart) { 828 static bool shouldCheckOldSelection(const Position& oldSelectionStart) {
852 if (!oldSelectionStart.isConnected()) 829 if (!oldSelectionStart.isConnected())
853 return false; 830 return false;
854 if (isPositionInTextField(oldSelectionStart)) 831 if (isPositionInTextField(oldSelectionStart))
855 return false; 832 return false;
856 if (isPositionInTextArea(oldSelectionStart)) 833 if (isPositionInTextArea(oldSelectionStart))
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 startOfNextParagraph(createVisiblePosition(paragraphEnd)); 1131 startOfNextParagraph(createVisiblePosition(paragraphEnd));
1155 paragraphStart = newParagraphStart.toParentAnchoredPosition(); 1132 paragraphStart = newParagraphStart.toParentAnchoredPosition();
1156 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPosition(); 1133 paragraphEnd = endOfParagraph(newParagraphStart).toParentAnchoredPosition();
1157 firstIteration = false; 1134 firstIteration = false;
1158 totalLengthProcessed += currentLength; 1135 totalLengthProcessed += currentLength;
1159 } 1136 }
1160 return std::make_pair(firstFoundItem, firstFoundOffset); 1137 return std::make_pair(firstFoundItem, firstFoundOffset);
1161 } 1138 }
1162 1139
1163 } // namespace blink 1140 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698