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 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1045 EditingState editingState; | 1045 EditingState editingState; |
1046 if (!TypingCommand::insertParagraphSeparator(*frame().document())) | 1046 if (!TypingCommand::insertParagraphSeparator(*frame().document())) |
1047 return false; | 1047 return false; |
1048 revealSelectionAfterEditingOperation( | 1048 revealSelectionAfterEditingOperation( |
1049 alignToEdge ? ScrollAlignment::alignToEdgeIfNeeded | 1049 alignToEdge ? ScrollAlignment::alignToEdgeIfNeeded |
1050 : ScrollAlignment::alignCenterIfNeeded); | 1050 : ScrollAlignment::alignCenterIfNeeded); |
1051 | 1051 |
1052 return true; | 1052 return true; |
1053 } | 1053 } |
1054 | 1054 |
1055 void Editor::cut(EditCommandSource source) { | 1055 void Editor::cut(EditorCommandSource source) { |
1056 if (tryDHTMLCut()) | 1056 if (tryDHTMLCut()) |
1057 return; // DHTML did the whole operation | 1057 return; // DHTML did the whole operation |
1058 if (!canCut()) | 1058 if (!canCut()) |
1059 return; | 1059 return; |
1060 | 1060 |
1061 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | 1061 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
1062 // needs to be audited. See http://crbug.com/590369 for more details. | 1062 // needs to be audited. See http://crbug.com/590369 for more details. |
1063 // |tryDHTMLCut| dispatches cut event, which may make layout dirty, but we | 1063 // |tryDHTMLCut| dispatches cut event, which may make layout dirty, but we |
1064 // need clean layout to obtain the selected content. | 1064 // need clean layout to obtain the selected content. |
1065 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 1065 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
1066 | 1066 |
1067 // TODO(yosin) We should use early return style here. | 1067 // TODO(yosin) We should use early return style here. |
1068 if (canDeleteRange(selectedRange())) { | 1068 if (canDeleteRange(selectedRange())) { |
1069 spellChecker().updateMarkersForWordsAffectedByEditing(true); | 1069 spellChecker().updateMarkersForWordsAffectedByEditing(true); |
1070 if (enclosingTextControl(frame().selection().start())) { | 1070 if (enclosingTextControl(frame().selection().start())) { |
1071 String plainText = frame().selectedTextForClipboard(); | 1071 String plainText = frame().selectedTextForClipboard(); |
1072 Pasteboard::generalPasteboard()->writePlainText( | 1072 Pasteboard::generalPasteboard()->writePlainText( |
1073 plainText, canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace | 1073 plainText, canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace |
1074 : Pasteboard::CannotSmartReplace); | 1074 : Pasteboard::CannotSmartReplace); |
1075 } else { | 1075 } else { |
1076 writeSelectionToPasteboard(); | 1076 writeSelectionToPasteboard(); |
1077 } | 1077 } |
1078 | 1078 |
1079 if (source == EditCommandSource::kMenuOrKeyBinding) { | 1079 if (source == CommandFromMenuOrKeyBinding) { |
1080 if (dispatchBeforeInputDataTransfer(findEventTargetFromSelection(), | 1080 if (dispatchBeforeInputDataTransfer(findEventTargetFromSelection(), |
1081 InputEvent::InputType::DeleteByCut, | 1081 InputEvent::InputType::DeleteByCut, |
1082 nullptr, nullptr) != | 1082 nullptr, nullptr) != |
1083 DispatchEventResult::NotCanceled) | 1083 DispatchEventResult::NotCanceled) |
1084 return; | 1084 return; |
1085 // 'beforeinput' event handler may destroy target frame. | 1085 // 'beforeinput' event handler may destroy target frame. |
1086 if (m_frame->document()->frame() != m_frame) | 1086 if (m_frame->document()->frame() != m_frame) |
1087 return; | 1087 return; |
1088 } | 1088 } |
1089 deleteSelectionWithSmartDelete( | 1089 deleteSelectionWithSmartDelete( |
(...skipping 23 matching lines...) Expand all Loading... |
1113 Document* document = frame().document(); | 1113 Document* document = frame().document(); |
1114 if (HTMLImageElement* imageElement = | 1114 if (HTMLImageElement* imageElement = |
1115 imageElementFromImageDocument(document)) | 1115 imageElementFromImageDocument(document)) |
1116 writeImageNodeToPasteboard(Pasteboard::generalPasteboard(), imageElement, | 1116 writeImageNodeToPasteboard(Pasteboard::generalPasteboard(), imageElement, |
1117 document->title()); | 1117 document->title()); |
1118 else | 1118 else |
1119 writeSelectionToPasteboard(); | 1119 writeSelectionToPasteboard(); |
1120 } | 1120 } |
1121 } | 1121 } |
1122 | 1122 |
1123 void Editor::paste(EditCommandSource source) { | 1123 void Editor::paste(EditorCommandSource source) { |
1124 DCHECK(frame().document()); | 1124 DCHECK(frame().document()); |
1125 if (tryDHTMLPaste(AllMimeTypes)) | 1125 if (tryDHTMLPaste(AllMimeTypes)) |
1126 return; // DHTML did the whole operation | 1126 return; // DHTML did the whole operation |
1127 if (!canPaste()) | 1127 if (!canPaste()) |
1128 return; | 1128 return; |
1129 spellChecker().updateMarkersForWordsAffectedByEditing(false); | 1129 spellChecker().updateMarkersForWordsAffectedByEditing(false); |
1130 ResourceFetcher* loader = frame().document()->fetcher(); | 1130 ResourceFetcher* loader = frame().document()->fetcher(); |
1131 ResourceCacheValidationSuppressor validationSuppressor(loader); | 1131 ResourceCacheValidationSuppressor validationSuppressor(loader); |
1132 | 1132 |
1133 PasteMode pasteMode = frame().selection().isContentRichlyEditable() | 1133 PasteMode pasteMode = frame().selection().isContentRichlyEditable() |
1134 ? AllMimeTypes | 1134 ? AllMimeTypes |
1135 : PlainTextOnly; | 1135 : PlainTextOnly; |
1136 | 1136 |
1137 if (source == EditCommandSource::kMenuOrKeyBinding) { | 1137 if (source == CommandFromMenuOrKeyBinding) { |
1138 DataTransfer* dataTransfer = | 1138 DataTransfer* dataTransfer = |
1139 DataTransfer::create(DataTransfer::CopyAndPaste, DataTransferReadable, | 1139 DataTransfer::create(DataTransfer::CopyAndPaste, DataTransferReadable, |
1140 DataObject::createFromPasteboard(pasteMode)); | 1140 DataObject::createFromPasteboard(pasteMode)); |
1141 | 1141 |
1142 if (dispatchBeforeInputDataTransfer(findEventTargetFromSelection(), | 1142 if (dispatchBeforeInputDataTransfer(findEventTargetFromSelection(), |
1143 InputEvent::InputType::InsertFromPaste, | 1143 InputEvent::InputType::InsertFromPaste, |
1144 dataTransfer, nullptr) != | 1144 dataTransfer, nullptr) != |
1145 DispatchEventResult::NotCanceled) | 1145 DispatchEventResult::NotCanceled) |
1146 return; | 1146 return; |
1147 // 'beforeinput' event handler may destroy target frame. | 1147 // 'beforeinput' event handler may destroy target frame. |
1148 if (m_frame->document()->frame() != m_frame) | 1148 if (m_frame->document()->frame() != m_frame) |
1149 return; | 1149 return; |
1150 } | 1150 } |
1151 | 1151 |
1152 if (pasteMode == AllMimeTypes) | 1152 if (pasteMode == AllMimeTypes) |
1153 pasteWithPasteboard(Pasteboard::generalPasteboard()); | 1153 pasteWithPasteboard(Pasteboard::generalPasteboard()); |
1154 else | 1154 else |
1155 pasteAsPlainTextWithPasteboard(Pasteboard::generalPasteboard()); | 1155 pasteAsPlainTextWithPasteboard(Pasteboard::generalPasteboard()); |
1156 } | 1156 } |
1157 | 1157 |
1158 void Editor::pasteAsPlainText(EditCommandSource source) { | 1158 void Editor::pasteAsPlainText(EditorCommandSource source) { |
1159 if (tryDHTMLPaste(PlainTextOnly)) | 1159 if (tryDHTMLPaste(PlainTextOnly)) |
1160 return; | 1160 return; |
1161 if (!canPaste()) | 1161 if (!canPaste()) |
1162 return; | 1162 return; |
1163 spellChecker().updateMarkersForWordsAffectedByEditing(false); | 1163 spellChecker().updateMarkersForWordsAffectedByEditing(false); |
1164 pasteAsPlainTextWithPasteboard(Pasteboard::generalPasteboard()); | 1164 pasteAsPlainTextWithPasteboard(Pasteboard::generalPasteboard()); |
1165 } | 1165 } |
1166 | 1166 |
1167 void Editor::performDelete() { | 1167 void Editor::performDelete() { |
1168 if (!canDelete()) | 1168 if (!canDelete()) |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1702 } | 1702 } |
1703 | 1703 |
1704 DEFINE_TRACE(Editor) { | 1704 DEFINE_TRACE(Editor) { |
1705 visitor->trace(m_frame); | 1705 visitor->trace(m_frame); |
1706 visitor->trace(m_lastEditCommand); | 1706 visitor->trace(m_lastEditCommand); |
1707 visitor->trace(m_undoStack); | 1707 visitor->trace(m_undoStack); |
1708 visitor->trace(m_mark); | 1708 visitor->trace(m_mark); |
1709 } | 1709 } |
1710 | 1710 |
1711 } // namespace blink | 1711 } // namespace blink |
OLD | NEW |