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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/editing/Editor.cpp
diff --git a/third_party/WebKit/Source/core/editing/Editor.cpp b/third_party/WebKit/Source/core/editing/Editor.cpp
index 2fc9b42fc338aee591b90e97681a6c6115edeaa3..9072cf77cbb360182aaaab8b6c64f025dfacf0ed 100644
--- a/third_party/WebKit/Source/core/editing/Editor.cpp
+++ b/third_party/WebKit/Source/core/editing/Editor.cpp
@@ -1140,6 +1140,10 @@ void Editor::Cut(EditorCommandSource source) {
// need clean layout to obtain the selected content.
GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
+ if (source == kCommandFromMenuOrKeyBinding &&
+ !GetFrame().Selection().SelectionHasFocus())
+ return;
+
// TODO(yosin) We should use early return style here.
if (CanDeleteRange(SelectedRange())) {
GetSpellChecker().UpdateMarkersForWordsAffectedByEditing(true);
@@ -1171,7 +1175,7 @@ void Editor::Cut(EditorCommandSource source) {
}
}
-void Editor::Copy() {
+void Editor::Copy(EditorCommandSource source) {
if (TryDHTMLCopy())
return; // DHTML did the whole operation
if (!CanCopy())
@@ -1183,6 +1187,10 @@ void Editor::Copy() {
// we need clean layout to obtain the selected content.
GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
+ if (source == kCommandFromMenuOrKeyBinding &&
+ !GetFrame().Selection().SelectionHasFocus())
+ return;
+
if (EnclosingTextControl(
GetFrame().Selection().ComputeVisibleSelectionInDOMTree().Start())) {
Pasteboard::GeneralPasteboard()->WritePlainText(
@@ -1206,6 +1214,17 @@ void Editor::Paste(EditorCommandSource source) {
return; // DHTML did the whole operation
if (!CanPaste())
return;
+
+ // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets
+ // needs to be audited. See http://crbug.com/590369 for more details.
+ // |tryDHTMLPaste| dispatches copy event, which may make layout dirty, but
+ // we need clean layout to obtain the selected content.
+ GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
+
+ if (source == kCommandFromMenuOrKeyBinding &&
+ !GetFrame().Selection().SelectionHasFocus())
+ return;
+
GetSpellChecker().UpdateMarkersForWordsAffectedByEditing(false);
ResourceFetcher* loader = GetFrame().GetDocument()->Fetcher();
ResourceCacheValidationSuppressor validation_suppressor(loader);
@@ -1243,6 +1262,17 @@ void Editor::PasteAsPlainText(EditorCommandSource source) {
return;
if (!CanPaste())
return;
+
+ // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets
+ // needs to be audited. See http://crbug.com/590369 for more details.
+ // |tryDHTMLPaste| dispatches copy event, which may make layout dirty, but
+ // we need clean layout to obtain the selected content.
+ GetFrame().GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
+
+ if (source == kCommandFromMenuOrKeyBinding &&
+ !GetFrame().Selection().SelectionHasFocus())
+ return;
+
GetSpellChecker().UpdateMarkersForWordsAffectedByEditing(false);
PasteAsPlainTextWithPasteboard(Pasteboard::GeneralPasteboard());
}
« 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