Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 861 bool alignToEdge = isEndOfEditableOrNonEditableContent(caret); | 861 bool alignToEdge = isEndOfEditableOrNonEditableContent(caret); |
| 862 DCHECK(frame().document()); | 862 DCHECK(frame().document()); |
| 863 EditingState editingState; | 863 EditingState editingState; |
| 864 if (!TypingCommand::insertParagraphSeparator(*frame().document())) | 864 if (!TypingCommand::insertParagraphSeparator(*frame().document())) |
| 865 return false; | 865 return false; |
| 866 revealSelectionAfterEditingOperation(alignToEdge ? ScrollAlignment::alignToE dgeIfNeeded : ScrollAlignment::alignCenterIfNeeded); | 866 revealSelectionAfterEditingOperation(alignToEdge ? ScrollAlignment::alignToE dgeIfNeeded : ScrollAlignment::alignCenterIfNeeded); |
| 867 | 867 |
| 868 return true; | 868 return true; |
| 869 } | 869 } |
| 870 | 870 |
| 871 void Editor::cut() | 871 void Editor::cut(EditorCommandSource source) |
| 872 { | 872 { |
| 873 if (tryDHTMLCut()) | 873 if (tryDHTMLCut()) |
| 874 return; // DHTML did the whole operation | 874 return; // DHTML did the whole operation |
| 875 if (!canCut()) | 875 if (!canCut()) |
| 876 return; | 876 return; |
| 877 // TODO(yosin) We should use early return style here. | 877 // TODO(yosin) We should use early return style here. |
| 878 if (shouldDeleteRange(selectedRange())) { | 878 if (shouldDeleteRange(selectedRange())) { |
| 879 spellChecker().updateMarkersForWordsAffectedByEditing(true); | 879 spellChecker().updateMarkersForWordsAffectedByEditing(true); |
| 880 if (enclosingTextFormControl(frame().selection().start())) { | 880 if (enclosingTextFormControl(frame().selection().start())) { |
| 881 String plainText = frame().selectedTextForClipboard(); | 881 String plainText = frame().selectedTextForClipboard(); |
| 882 Pasteboard::generalPasteboard()->writePlainText(plainText, | 882 Pasteboard::generalPasteboard()->writePlainText(plainText, |
| 883 canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace : Pasteboar d::CannotSmartReplace); | 883 canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace : Pasteboar d::CannotSmartReplace); |
| 884 } else { | 884 } else { |
| 885 writeSelectionToPasteboard(); | 885 writeSelectionToPasteboard(); |
| 886 } | 886 } |
| 887 deleteSelectionWithSmartDelete(canSmartCopyOrDelete(), InputEvent::Input Type::Cut); | 887 |
| 888 if (source == CommandFromMenuOrKeyBinding) { | |
| 889 if (dispatchBeforeInputDataTransfer(findEventTargetFromSelection(), InputEvent::InputType::DeleteByCut, nullptr, nullptr) != DispatchEventResult::No tCanceled) | |
| 890 return; | |
| 891 // 'beforeinput' event handler may destroy target frame. | |
| 892 if (!m_frame->document()->frame()) | |
| 893 return; | |
|
chongz
2016/08/24 01:43:27
Compare document won't work, have to do this...
yosin_UTC9
2016/08/24 02:11:44
How about
|m_frame->document()->frame() != m_fram
chongz
2016/08/24 02:42:01
Done.
| |
| 894 } | |
| 895 deleteSelectionWithSmartDelete(canSmartCopyOrDelete(), InputEvent::Input Type::DeleteByCut); | |
| 888 } | 896 } |
| 889 } | 897 } |
| 890 | 898 |
| 891 void Editor::copy() | 899 void Editor::copy() |
| 892 { | 900 { |
| 893 if (tryDHTMLCopy()) | 901 if (tryDHTMLCopy()) |
| 894 return; // DHTML did the whole operation | 902 return; // DHTML did the whole operation |
| 895 if (!canCopy()) | 903 if (!canCopy()) |
| 896 return; | 904 return; |
| 897 if (enclosingTextFormControl(frame().selection().start())) { | 905 if (enclosingTextFormControl(frame().selection().start())) { |
| 898 Pasteboard::generalPasteboard()->writePlainText(frame().selectedTextForC lipboard(), | 906 Pasteboard::generalPasteboard()->writePlainText(frame().selectedTextForC lipboard(), |
| 899 canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace : Pasteboard::C annotSmartReplace); | 907 canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace : Pasteboard::C annotSmartReplace); |
| 900 } else { | 908 } else { |
| 901 Document* document = frame().document(); | 909 Document* document = frame().document(); |
| 902 if (HTMLImageElement* imageElement = imageElementFromImageDocument(docum ent)) | 910 if (HTMLImageElement* imageElement = imageElementFromImageDocument(docum ent)) |
| 903 writeImageNodeToPasteboard(Pasteboard::generalPasteboard(), imageEle ment, document->title()); | 911 writeImageNodeToPasteboard(Pasteboard::generalPasteboard(), imageEle ment, document->title()); |
| 904 else | 912 else |
| 905 writeSelectionToPasteboard(); | 913 writeSelectionToPasteboard(); |
| 906 } | 914 } |
| 907 } | 915 } |
| 908 | 916 |
| 909 void Editor::paste() | 917 void Editor::paste(EditorCommandSource source) |
| 910 { | 918 { |
| 911 DCHECK(frame().document()); | 919 DCHECK(frame().document()); |
| 912 if (tryDHTMLPaste(AllMimeTypes)) | 920 if (tryDHTMLPaste(AllMimeTypes)) |
| 913 return; // DHTML did the whole operation | 921 return; // DHTML did the whole operation |
| 914 if (!canPaste()) | 922 if (!canPaste()) |
| 915 return; | 923 return; |
| 916 spellChecker().updateMarkersForWordsAffectedByEditing(false); | 924 spellChecker().updateMarkersForWordsAffectedByEditing(false); |
| 917 ResourceFetcher* loader = frame().document()->fetcher(); | 925 ResourceFetcher* loader = frame().document()->fetcher(); |
| 918 ResourceCacheValidationSuppressor validationSuppressor(loader); | 926 ResourceCacheValidationSuppressor validationSuppressor(loader); |
| 919 if (frame().selection().isContentRichlyEditable()) | 927 |
| 928 PasteMode pasteMode = frame().selection().isContentRichlyEditable() ? AllMim eTypes : PlainTextOnly; | |
| 929 | |
| 930 if (source == CommandFromMenuOrKeyBinding) { | |
| 931 DataTransfer* dataTransfer = DataTransfer::create( | |
| 932 DataTransfer::CopyAndPaste, | |
| 933 DataTransferReadable, | |
| 934 DataObject::createFromPasteboard(pasteMode)); | |
| 935 | |
| 936 if (dispatchBeforeInputDataTransfer(findEventTargetFromSelection(), Inpu tEvent::InputType::InsertFromPaste, dataTransfer, nullptr) != DispatchEventResul t::NotCanceled) | |
| 937 return; | |
| 938 // 'beforeinput' event handler may destroy target frame. | |
| 939 if (!m_frame->document()->frame()) | |
| 940 return; | |
| 941 } | |
| 942 | |
| 943 if (pasteMode == AllMimeTypes) | |
| 920 pasteWithPasteboard(Pasteboard::generalPasteboard()); | 944 pasteWithPasteboard(Pasteboard::generalPasteboard()); |
| 921 else | 945 else |
| 922 pasteAsPlainTextWithPasteboard(Pasteboard::generalPasteboard()); | 946 pasteAsPlainTextWithPasteboard(Pasteboard::generalPasteboard()); |
| 923 } | 947 } |
| 924 | 948 |
| 925 void Editor::pasteAsPlainText() | 949 void Editor::pasteAsPlainText(EditorCommandSource source) |
| 926 { | 950 { |
| 927 if (tryDHTMLPaste(PlainTextOnly)) | 951 if (tryDHTMLPaste(PlainTextOnly)) |
| 928 return; | 952 return; |
| 929 if (!canPaste()) | 953 if (!canPaste()) |
| 930 return; | 954 return; |
| 931 spellChecker().updateMarkersForWordsAffectedByEditing(false); | 955 spellChecker().updateMarkersForWordsAffectedByEditing(false); |
| 932 pasteAsPlainTextWithPasteboard(Pasteboard::generalPasteboard()); | 956 pasteAsPlainTextWithPasteboard(Pasteboard::generalPasteboard()); |
| 933 } | 957 } |
| 934 | 958 |
| 935 void Editor::performDelete() | 959 void Editor::performDelete() |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1388 | 1412 |
| 1389 DEFINE_TRACE(Editor) | 1413 DEFINE_TRACE(Editor) |
| 1390 { | 1414 { |
| 1391 visitor->trace(m_frame); | 1415 visitor->trace(m_frame); |
| 1392 visitor->trace(m_lastEditCommand); | 1416 visitor->trace(m_lastEditCommand); |
| 1393 visitor->trace(m_undoStack); | 1417 visitor->trace(m_undoStack); |
| 1394 visitor->trace(m_mark); | 1418 visitor->trace(m_mark); |
| 1395 } | 1419 } |
| 1396 | 1420 |
| 1397 } // namespace blink | 1421 } // namespace blink |
| OLD | NEW |