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

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

Issue 2258663003: [InputEvent] Support |deleteByCut|&|insertFromPaste| with |dataTransfer| field (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Support cut/paste with |dataTransfer| field and correct event order Created 4 years, 4 months 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 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 return; 535 return;
536 536
537 ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::P reventNesting | ReplaceSelectionCommand::SanitizeFragment; 537 ReplaceSelectionCommand::CommandOptions options = ReplaceSelectionCommand::P reventNesting | ReplaceSelectionCommand::SanitizeFragment;
538 if (selectReplacement) 538 if (selectReplacement)
539 options |= ReplaceSelectionCommand::SelectReplacement; 539 options |= ReplaceSelectionCommand::SelectReplacement;
540 if (smartReplace) 540 if (smartReplace)
541 options |= ReplaceSelectionCommand::SmartReplace; 541 options |= ReplaceSelectionCommand::SmartReplace;
542 if (matchStyle) 542 if (matchStyle)
543 options |= ReplaceSelectionCommand::MatchStyle; 543 options |= ReplaceSelectionCommand::MatchStyle;
544 DCHECK(frame().document()); 544 DCHECK(frame().document());
545 ReplaceSelectionCommand::create(*frame().document(), fragment, options, Inpu tEvent::InputType::Paste)->apply(); 545 ReplaceSelectionCommand::create(*frame().document(), fragment, options, Inpu tEvent::InputType::InsertFromPaste)->apply();
546 revealSelectionAfterEditingOperation(); 546 revealSelectionAfterEditingOperation();
547 } 547 }
548 548
549 void Editor::replaceSelectionWithText(const String& text, bool selectReplacement , bool smartReplace) 549 void Editor::replaceSelectionWithText(const String& text, bool selectReplacement , bool smartReplace)
550 { 550 {
551 replaceSelectionWithFragment(createFragmentFromText(selectedRange(), text), selectReplacement, smartReplace, true); 551 replaceSelectionWithFragment(createFragmentFromText(selectedRange(), text), selectReplacement, smartReplace, true);
552 } 552 }
553 553
554 // TODO(xiaochengh): Merge it with |replaceSelectionWithFragment()|. 554 // TODO(xiaochengh): Merge it with |replaceSelectionWithFragment()|.
555 void Editor::replaceSelectionAfterDragging(DocumentFragment* fragment, bool smar tReplace, bool plainText) 555 void Editor::replaceSelectionAfterDragging(DocumentFragment* fragment, bool smar tReplace, bool plainText)
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 startRoot->dispatchEvent(Event::create(EventTypeNames::webkitEditableCon tentChanged)); 697 startRoot->dispatchEvent(Event::create(EventTypeNames::webkitEditableCon tentChanged));
698 if (endRoot && endRoot != startRoot) 698 if (endRoot && endRoot != startRoot)
699 endRoot->dispatchEvent(Event::create(EventTypeNames::webkitEditableConte ntChanged)); 699 endRoot->dispatchEvent(Event::create(EventTypeNames::webkitEditableConte ntChanged));
700 } 700 }
701 701
702 void Editor::requestSpellcheckingAfterApplyingCommand(CompositeEditCommand* cmd) 702 void Editor::requestSpellcheckingAfterApplyingCommand(CompositeEditCommand* cmd)
703 { 703 {
704 // Note: Request spell checking for and only for |ReplaceSelectionCommand|s 704 // Note: Request spell checking for and only for |ReplaceSelectionCommand|s
705 // created in |Editor::replaceSelectionWithFragment()|. 705 // created in |Editor::replaceSelectionWithFragment()|.
706 // TODO(xiaochengh): May also need to do this after dragging crbug.com/29804 6. 706 // TODO(xiaochengh): May also need to do this after dragging crbug.com/29804 6.
707 if (cmd->inputType() != InputEvent::InputType::Paste) 707 if (cmd->inputType() != InputEvent::InputType::InsertFromPaste)
708 return; 708 return;
709 if (!spellChecker().isSpellCheckingEnabled()) 709 if (!spellChecker().isSpellCheckingEnabled())
710 return; 710 return;
711 if (!SpellChecker::isSpellCheckingEnabledFor(cmd->endingSelection())) 711 if (!SpellChecker::isSpellCheckingEnabledFor(cmd->endingSelection()))
712 return; 712 return;
713 DCHECK(cmd->isReplaceSelectionCommand()); 713 DCHECK(cmd->isReplaceSelectionCommand());
714 const EphemeralRange& insertedRange = toReplaceSelectionCommand(cmd)->insert edRange(); 714 const EphemeralRange& insertedRange = toReplaceSelectionCommand(cmd)->insert edRange();
715 if (insertedRange.isNull()) 715 if (insertedRange.isNull())
716 return; 716 return;
717 // Patch crrev.com/2241293006 assumes the following equality. Revert if it f ails. 717 // Patch crrev.com/2241293006 assumes the following equality. Revert if it f ails.
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
881 bool alignToEdge = isEndOfEditableOrNonEditableContent(caret); 881 bool alignToEdge = isEndOfEditableOrNonEditableContent(caret);
882 DCHECK(frame().document()); 882 DCHECK(frame().document());
883 EditingState editingState; 883 EditingState editingState;
884 if (!TypingCommand::insertParagraphSeparator(*frame().document())) 884 if (!TypingCommand::insertParagraphSeparator(*frame().document()))
885 return false; 885 return false;
886 revealSelectionAfterEditingOperation(alignToEdge ? ScrollAlignment::alignToE dgeIfNeeded : ScrollAlignment::alignCenterIfNeeded); 886 revealSelectionAfterEditingOperation(alignToEdge ? ScrollAlignment::alignToE dgeIfNeeded : ScrollAlignment::alignCenterIfNeeded);
887 887
888 return true; 888 return true;
889 } 889 }
890 890
891 void Editor::cut() 891 void Editor::cut(EditorCommandSource source)
892 { 892 {
893 if (tryDHTMLCut()) 893 if (tryDHTMLCut())
894 return; // DHTML did the whole operation 894 return; // DHTML did the whole operation
895 if (!canCut()) 895 if (!canCut())
896 return; 896 return;
897 // TODO(yosin) We should use early return style here. 897 // TODO(yosin) We should use early return style here.
898 if (shouldDeleteRange(selectedRange())) { 898 if (shouldDeleteRange(selectedRange())) {
899 spellChecker().updateMarkersForWordsAffectedByEditing(true); 899 spellChecker().updateMarkersForWordsAffectedByEditing(true);
900 if (enclosingTextFormControl(frame().selection().start())) { 900 if (enclosingTextFormControl(frame().selection().start())) {
901 String plainText = frame().selectedTextForClipboard(); 901 String plainText = frame().selectedTextForClipboard();
902 Pasteboard::generalPasteboard()->writePlainText(plainText, 902 Pasteboard::generalPasteboard()->writePlainText(plainText,
903 canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace : Pasteboar d::CannotSmartReplace); 903 canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace : Pasteboar d::CannotSmartReplace);
904 } else { 904 } else {
905 writeSelectionToPasteboard(); 905 writeSelectionToPasteboard();
906 } 906 }
907 deleteSelectionWithSmartDelete(canSmartCopyOrDelete(), InputEvent::Input Type::Cut); 907
908 if (source == CommandFromMenuOrKeyBinding) {
909 if (dispatchBeforeInputDataTransfer(findEventTargetFromSelection(), InputEvent::InputType::DeleteByCut, nullptr, nullptr) != DispatchEventResult::No tCanceled)
910 return;
911 // 'beforeinput' event handler might destroy target.
912 if (!m_frame)
yosin_UTC9 2016/08/23 04:23:54 |Editor::m_frame| is never |nullptr|. You can chec
913 return;
914 }
915 deleteSelectionWithSmartDelete(canSmartCopyOrDelete(), InputEvent::Input Type::DeleteByCut);
908 } 916 }
909 } 917 }
910 918
911 void Editor::copy() 919 void Editor::copy()
912 { 920 {
913 if (tryDHTMLCopy()) 921 if (tryDHTMLCopy())
914 return; // DHTML did the whole operation 922 return; // DHTML did the whole operation
915 if (!canCopy()) 923 if (!canCopy())
916 return; 924 return;
917 if (enclosingTextFormControl(frame().selection().start())) { 925 if (enclosingTextFormControl(frame().selection().start())) {
918 Pasteboard::generalPasteboard()->writePlainText(frame().selectedTextForC lipboard(), 926 Pasteboard::generalPasteboard()->writePlainText(frame().selectedTextForC lipboard(),
919 canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace : Pasteboard::C annotSmartReplace); 927 canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace : Pasteboard::C annotSmartReplace);
920 } else { 928 } else {
921 Document* document = frame().document(); 929 Document* document = frame().document();
922 if (HTMLImageElement* imageElement = imageElementFromImageDocument(docum ent)) 930 if (HTMLImageElement* imageElement = imageElementFromImageDocument(docum ent))
923 writeImageNodeToPasteboard(Pasteboard::generalPasteboard(), imageEle ment, document->title()); 931 writeImageNodeToPasteboard(Pasteboard::generalPasteboard(), imageEle ment, document->title());
924 else 932 else
925 writeSelectionToPasteboard(); 933 writeSelectionToPasteboard();
926 } 934 }
927 } 935 }
928 936
929 void Editor::paste() 937 void Editor::paste(EditorCommandSource source)
930 { 938 {
931 DCHECK(frame().document()); 939 DCHECK(frame().document());
932 if (tryDHTMLPaste(AllMimeTypes)) 940 if (tryDHTMLPaste(AllMimeTypes))
933 return; // DHTML did the whole operation 941 return; // DHTML did the whole operation
934 if (!canPaste()) 942 if (!canPaste())
935 return; 943 return;
936 spellChecker().updateMarkersForWordsAffectedByEditing(false); 944 spellChecker().updateMarkersForWordsAffectedByEditing(false);
937 ResourceFetcher* loader = frame().document()->fetcher(); 945 ResourceFetcher* loader = frame().document()->fetcher();
938 ResourceCacheValidationSuppressor validationSuppressor(loader); 946 ResourceCacheValidationSuppressor validationSuppressor(loader);
939 if (frame().selection().isContentRichlyEditable()) 947
948 PasteMode pasteMode = frame().selection().isContentRichlyEditable() ? AllMim eTypes : PlainTextOnly;
949
950 if (source == CommandFromMenuOrKeyBinding) {
951 DataTransfer* dataTransfer = DataTransfer::create(
952 DataTransfer::CopyAndPaste,
953 DataTransferReadable,
954 DataObject::createFromPasteboard(pasteMode));
955
956 if (dispatchBeforeInputDataTransfer(findEventTargetFromSelection(), Inpu tEvent::InputType::InsertFromPaste, dataTransfer, nullptr) != DispatchEventResul t::NotCanceled)
957 return;
958 // 'beforeinput' event handler might destroy target.
959 if (!m_frame)
960 return;
961 }
962
963 if (pasteMode == AllMimeTypes)
940 pasteWithPasteboard(Pasteboard::generalPasteboard()); 964 pasteWithPasteboard(Pasteboard::generalPasteboard());
941 else 965 else
942 pasteAsPlainTextWithPasteboard(Pasteboard::generalPasteboard()); 966 pasteAsPlainTextWithPasteboard(Pasteboard::generalPasteboard());
943 } 967 }
944 968
945 void Editor::pasteAsPlainText() 969 void Editor::pasteAsPlainText(EditorCommandSource source)
946 { 970 {
947 if (tryDHTMLPaste(PlainTextOnly)) 971 if (tryDHTMLPaste(PlainTextOnly))
948 return; 972 return;
949 if (!canPaste()) 973 if (!canPaste())
950 return; 974 return;
951 spellChecker().updateMarkersForWordsAffectedByEditing(false); 975 spellChecker().updateMarkersForWordsAffectedByEditing(false);
952 pasteAsPlainTextWithPasteboard(Pasteboard::generalPasteboard()); 976 pasteAsPlainTextWithPasteboard(Pasteboard::generalPasteboard());
953 } 977 }
954 978
955 void Editor::performDelete() 979 void Editor::performDelete()
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
1408 1432
1409 DEFINE_TRACE(Editor) 1433 DEFINE_TRACE(Editor)
1410 { 1434 {
1411 visitor->trace(m_frame); 1435 visitor->trace(m_frame);
1412 visitor->trace(m_lastEditCommand); 1436 visitor->trace(m_lastEditCommand);
1413 visitor->trace(m_undoStack); 1437 visitor->trace(m_undoStack);
1414 visitor->trace(m_mark); 1438 visitor->trace(m_mark);
1415 } 1439 }
1416 1440
1417 } // namespace blink 1441 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698