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

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

Issue 2894473003: Fix behavior of clipboard commands when there is unfocused selection (Closed)
Patch Set: Fix UnsafeSVGAttributeSanitizationTest Created 3 years, 7 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 1122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 return; // DHTML did the whole operation 1133 return; // DHTML did the whole operation
1134 if (!CanCut()) 1134 if (!CanCut())
1135 return; 1135 return;
1136 1136
1137 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets 1137 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets
1138 // needs to be audited. See http://crbug.com/590369 for more details. 1138 // needs to be audited. See http://crbug.com/590369 for more details.
1139 // |tryDHTMLCut| dispatches cut event, which may make layout dirty, but we 1139 // |tryDHTMLCut| dispatches cut event, which may make layout dirty, but we
1140 // need clean layout to obtain the selected content. 1140 // need clean layout to obtain the selected content.
1141 GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); 1141 GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
1142 1142
1143 if (source == kCommandFromMenuOrKeyBinding &&
1144 !GetFrame().Selection().SelectionHasFocus())
1145 return;
1146
1143 // TODO(yosin) We should use early return style here. 1147 // TODO(yosin) We should use early return style here.
1144 if (CanDeleteRange(SelectedRange())) { 1148 if (CanDeleteRange(SelectedRange())) {
1145 GetSpellChecker().UpdateMarkersForWordsAffectedByEditing(true); 1149 GetSpellChecker().UpdateMarkersForWordsAffectedByEditing(true);
1146 if (EnclosingTextControl(GetFrame() 1150 if (EnclosingTextControl(GetFrame()
1147 .Selection() 1151 .Selection()
1148 .ComputeVisibleSelectionInDOMTree() 1152 .ComputeVisibleSelectionInDOMTree()
1149 .Start())) { 1153 .Start())) {
1150 String plain_text = GetFrame().SelectedTextForClipboard(); 1154 String plain_text = GetFrame().SelectedTextForClipboard();
1151 Pasteboard::GeneralPasteboard()->WritePlainText( 1155 Pasteboard::GeneralPasteboard()->WritePlainText(
1152 plain_text, CanSmartCopyOrDelete() ? Pasteboard::kCanSmartReplace 1156 plain_text, CanSmartCopyOrDelete() ? Pasteboard::kCanSmartReplace
(...skipping 11 matching lines...) Expand all
1164 // 'beforeinput' event handler may destroy target frame. 1168 // 'beforeinput' event handler may destroy target frame.
1165 if (frame_->GetDocument()->GetFrame() != frame_) 1169 if (frame_->GetDocument()->GetFrame() != frame_)
1166 return; 1170 return;
1167 } 1171 }
1168 DeleteSelectionWithSmartDelete( 1172 DeleteSelectionWithSmartDelete(
1169 CanSmartCopyOrDelete() ? DeleteMode::kSmart : DeleteMode::kSimple, 1173 CanSmartCopyOrDelete() ? DeleteMode::kSmart : DeleteMode::kSimple,
1170 InputEvent::InputType::kDeleteByCut); 1174 InputEvent::InputType::kDeleteByCut);
1171 } 1175 }
1172 } 1176 }
1173 1177
1174 void Editor::Copy() { 1178 void Editor::Copy(EditorCommandSource source) {
1175 if (TryDHTMLCopy()) 1179 if (TryDHTMLCopy())
1176 return; // DHTML did the whole operation 1180 return; // DHTML did the whole operation
1177 if (!CanCopy()) 1181 if (!CanCopy())
1178 return; 1182 return;
1179 1183
1180 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets 1184 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets
1181 // needs to be audited. See http://crbug.com/590369 for more details. 1185 // needs to be audited. See http://crbug.com/590369 for more details.
1182 // |tryDHTMLCopy| dispatches copy event, which may make layout dirty, but 1186 // |tryDHTMLCopy| dispatches copy event, which may make layout dirty, but
1183 // we need clean layout to obtain the selected content. 1187 // we need clean layout to obtain the selected content.
1184 GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); 1188 GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
1185 1189
1190 if (source == kCommandFromMenuOrKeyBinding &&
1191 !GetFrame().Selection().SelectionHasFocus())
1192 return;
1193
1186 if (EnclosingTextControl( 1194 if (EnclosingTextControl(
1187 GetFrame().Selection().ComputeVisibleSelectionInDOMTree().Start())) { 1195 GetFrame().Selection().ComputeVisibleSelectionInDOMTree().Start())) {
1188 Pasteboard::GeneralPasteboard()->WritePlainText( 1196 Pasteboard::GeneralPasteboard()->WritePlainText(
1189 GetFrame().SelectedTextForClipboard(), 1197 GetFrame().SelectedTextForClipboard(),
1190 CanSmartCopyOrDelete() ? Pasteboard::kCanSmartReplace 1198 CanSmartCopyOrDelete() ? Pasteboard::kCanSmartReplace
1191 : Pasteboard::kCannotSmartReplace); 1199 : Pasteboard::kCannotSmartReplace);
1192 } else { 1200 } else {
1193 Document* document = GetFrame().GetDocument(); 1201 Document* document = GetFrame().GetDocument();
1194 if (HTMLImageElement* image_element = 1202 if (HTMLImageElement* image_element =
1195 ImageElementFromImageDocument(document)) 1203 ImageElementFromImageDocument(document))
1196 WriteImageNodeToPasteboard(Pasteboard::GeneralPasteboard(), image_element, 1204 WriteImageNodeToPasteboard(Pasteboard::GeneralPasteboard(), image_element,
1197 document->title()); 1205 document->title());
1198 else 1206 else
1199 WriteSelectionToPasteboard(); 1207 WriteSelectionToPasteboard();
1200 } 1208 }
1201 } 1209 }
1202 1210
1203 void Editor::Paste(EditorCommandSource source) { 1211 void Editor::Paste(EditorCommandSource source) {
1204 DCHECK(GetFrame().GetDocument()); 1212 DCHECK(GetFrame().GetDocument());
1205 if (TryDHTMLPaste(kAllMimeTypes)) 1213 if (TryDHTMLPaste(kAllMimeTypes))
1206 return; // DHTML did the whole operation 1214 return; // DHTML did the whole operation
1207 if (!CanPaste()) 1215 if (!CanPaste())
1208 return; 1216 return;
1217
1218 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets
1219 // needs to be audited. See http://crbug.com/590369 for more details.
1220 // |tryDHTMLPaste| dispatches copy event, which may make layout dirty, but
1221 // we need clean layout to obtain the selected content.
1222 GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
1223
1224 if (source == kCommandFromMenuOrKeyBinding &&
1225 !GetFrame().Selection().SelectionHasFocus())
1226 return;
1227
1209 GetSpellChecker().UpdateMarkersForWordsAffectedByEditing(false); 1228 GetSpellChecker().UpdateMarkersForWordsAffectedByEditing(false);
1210 ResourceFetcher* loader = GetFrame().GetDocument()->Fetcher(); 1229 ResourceFetcher* loader = GetFrame().GetDocument()->Fetcher();
1211 ResourceCacheValidationSuppressor validation_suppressor(loader); 1230 ResourceCacheValidationSuppressor validation_suppressor(loader);
1212 1231
1213 PasteMode paste_mode = GetFrame() 1232 PasteMode paste_mode = GetFrame()
1214 .Selection() 1233 .Selection()
1215 .ComputeVisibleSelectionInDOMTree() 1234 .ComputeVisibleSelectionInDOMTree()
1216 .IsContentRichlyEditable() 1235 .IsContentRichlyEditable()
1217 ? kAllMimeTypes 1236 ? kAllMimeTypes
1218 : kPlainTextOnly; 1237 : kPlainTextOnly;
(...skipping 17 matching lines...) Expand all
1236 PasteWithPasteboard(Pasteboard::GeneralPasteboard()); 1255 PasteWithPasteboard(Pasteboard::GeneralPasteboard());
1237 else 1256 else
1238 PasteAsPlainTextWithPasteboard(Pasteboard::GeneralPasteboard()); 1257 PasteAsPlainTextWithPasteboard(Pasteboard::GeneralPasteboard());
1239 } 1258 }
1240 1259
1241 void Editor::PasteAsPlainText(EditorCommandSource source) { 1260 void Editor::PasteAsPlainText(EditorCommandSource source) {
1242 if (TryDHTMLPaste(kPlainTextOnly)) 1261 if (TryDHTMLPaste(kPlainTextOnly))
1243 return; 1262 return;
1244 if (!CanPaste()) 1263 if (!CanPaste())
1245 return; 1264 return;
1265
1266 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets
1267 // needs to be audited. See http://crbug.com/590369 for more details.
1268 // |tryDHTMLPaste| dispatches copy event, which may make layout dirty, but
1269 // we need clean layout to obtain the selected content.
1270 GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
1271
1272 if (source == kCommandFromMenuOrKeyBinding &&
1273 !GetFrame().Selection().SelectionHasFocus())
1274 return;
1275
1246 GetSpellChecker().UpdateMarkersForWordsAffectedByEditing(false); 1276 GetSpellChecker().UpdateMarkersForWordsAffectedByEditing(false);
1247 PasteAsPlainTextWithPasteboard(Pasteboard::GeneralPasteboard()); 1277 PasteAsPlainTextWithPasteboard(Pasteboard::GeneralPasteboard());
1248 } 1278 }
1249 1279
1250 void Editor::PerformDelete() { 1280 void Editor::PerformDelete() {
1251 if (!CanDelete()) 1281 if (!CanDelete())
1252 return; 1282 return;
1253 1283
1254 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets 1284 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets
1255 // needs to be audited. See http://crbug.com/590369 for more details. 1285 // needs to be audited. See http://crbug.com/590369 for more details.
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
1818 1848
1819 DEFINE_TRACE(Editor) { 1849 DEFINE_TRACE(Editor) {
1820 visitor->Trace(frame_); 1850 visitor->Trace(frame_);
1821 visitor->Trace(last_edit_command_); 1851 visitor->Trace(last_edit_command_);
1822 visitor->Trace(undo_stack_); 1852 visitor->Trace(undo_stack_);
1823 visitor->Trace(mark_); 1853 visitor->Trace(mark_);
1824 visitor->Trace(typing_style_); 1854 visitor->Trace(typing_style_);
1825 } 1855 }
1826 1856
1827 } // namespace blink 1857 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/Editor.h ('k') | third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698