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

Unified Diff: third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp

Issue 1406713002: Make queryCommandSupported(copy|cut|paste) always return true (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2015-10-15T17:15:20 Created 5 years, 2 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
« no previous file with comments | « third_party/WebKit/LayoutTests/editing/pasteboard/copy-cut-paste-supported.html ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp
diff --git a/third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp b/third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp
index 06751912f7b45f7712fb6027065d2bdc52f1f136..29125bddb0493eedf2210e5671ec6adcbb100f47 100644
--- a/third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp
+++ b/third_party/WebKit/Source/core/editing/commands/EditorCommand.cpp
@@ -79,6 +79,8 @@ public:
TriState (*state)(LocalFrame&, Event*);
String (*value)(LocalFrame&, Event*);
bool isTextInsertion;
+ // TODO(yosin) We should have |canExecute()|, which checks clipboard
+ // accessibility to simplify |Editor::Command::execute()|.
bool allowExecutionWhenDisabled;
};
@@ -295,8 +297,24 @@ static bool executeBackColor(LocalFrame& frame, Event*, EditorCommandSource sour
return executeApplyStyle(frame, source, EditActionSetBackgroundColor, CSSPropertyBackgroundColor, value);
}
-static bool executeCopy(LocalFrame& frame, Event*, EditorCommandSource, const String&)
+static bool canWriteClipboard(LocalFrame& frame, EditorCommandSource source)
{
+ if (source == CommandFromMenuOrKeyBinding)
+ return true;
+ Settings* settings = frame.settings();
+ bool defaultValue = (settings && settings->javaScriptCanAccessClipboard()) || UserGestureIndicator::processingUserGesture();
+ return frame.editor().client().canCopyCut(&frame, defaultValue);
+}
+
+static bool executeCopy(LocalFrame& frame, Event*, EditorCommandSource source, const String&)
+{
+ // To support |allowExecutionWhenDisabled|, we need to check clipboard
+ // accessibility here rather than |Editor::Command::execute()|.
+ // TODO(yosin) We should move checking |canWriteClipboard()| to
+ // |Editor::Command::execute()| with introducing appropriate predicate, e.g.
+ // |canExecute()|. See also "Cut", and "Paste" command.
+ if (!canWriteClipboard(frame, source))
+ return false;
frame.editor().copy();
return true;
}
@@ -310,8 +328,15 @@ static bool executeCreateLink(LocalFrame& frame, Event*, EditorCommandSource, co
return true;
}
-static bool executeCut(LocalFrame& frame, Event*, EditorCommandSource, const String&)
+static bool executeCut(LocalFrame& frame, Event*, EditorCommandSource source, const String&)
{
+ // To support |allowExecutionWhenDisabled|, we need to check clipboard
+ // accessibility here rather than |Editor::Command::execute()|.
+ // TODO(yosin) We should move checking |canWriteClipboard()| to
+ // |Editor::Command::execute()| with introducing appropriate predicate, e.g.
+ // |canExecute()|. See also "Copy", and "Paste" command.
+ if (!canWriteClipboard(frame, source))
+ return false;
frame.editor().cut();
return true;
}
@@ -941,14 +966,37 @@ static bool executeToggleOverwrite(LocalFrame& frame, Event*, EditorCommandSourc
return true;
}
-static bool executePaste(LocalFrame& frame, Event*, EditorCommandSource, const String&)
+static bool canReadClipboard(LocalFrame& frame, EditorCommandSource source)
{
+ if (source == CommandFromMenuOrKeyBinding)
+ return true;
+ Settings* settings = frame.settings();
+ bool defaultValue = settings && settings->javaScriptCanAccessClipboard() && settings->DOMPasteAllowed();
+ return frame.editor().client().canPaste(&frame, defaultValue);
+}
+
+static bool executePaste(LocalFrame& frame, Event*, EditorCommandSource source, const String&)
+{
+ // To support |allowExecutionWhenDisabled|, we need to check clipboard
+ // accessibility here rather than |Editor::Command::execute()|.
+ // TODO(yosin) We should move checking |canReadClipboard()| to
+ // |Editor::Command::execute()| with introducing appropriate predicate, e.g.
+ // |canExecute()|. See also "Copy", and "Cut" command.
+ if (!canReadClipboard(frame, source))
+ return false;
frame.editor().paste();
return true;
}
static bool executePasteGlobalSelection(LocalFrame& frame, Event*, EditorCommandSource source, const String&)
{
+ // To support |allowExecutionWhenDisabled|, we need to check clipboard
+ // accessibility here rather than |Editor::Command::execute()|.
+ // TODO(yosin) We should move checking |canReadClipboard()| to
+ // |Editor::Command::execute()| with introducing appropriate predicate, e.g.
+ // |canExecute()|. See also "Copy", and "Cut" command.
+ if (!canReadClipboard(frame, source))
+ return false;
if (!frame.editor().behavior().supportsGlobalSelection())
return false;
ASSERT_UNUSED(source, source == CommandFromMenuOrKeyBinding);
@@ -1170,26 +1218,6 @@ static bool supportedFromMenuOrKeyBinding(LocalFrame*)
return false;
}
-static bool supportedCopyCut(LocalFrame* frame)
-{
- if (!frame)
- return false;
-
- Settings* settings = frame->settings();
- bool defaultValue = (settings && settings->javaScriptCanAccessClipboard()) || UserGestureIndicator::processingUserGesture();
- return frame->editor().client().canCopyCut(frame, defaultValue);
-}
-
-static bool supportedPaste(LocalFrame* frame)
-{
- if (!frame)
- return false;
-
- Settings* settings = frame->settings();
- bool defaultValue = settings && settings->javaScriptCanAccessClipboard() && settings->DOMPasteAllowed();
- return frame->editor().client().canPaste(frame, defaultValue);
-}
-
// Enabled functions
static bool enabled(LocalFrame&, Event*, EditorCommandSource)
@@ -1230,13 +1258,17 @@ static bool enableCaretInEditableText(LocalFrame& frame, Event* event, EditorCom
return selection.isCaret() && selection.isContentEditable();
}
-static bool enabledCopy(LocalFrame& frame, Event*, EditorCommandSource)
+static bool enabledCopy(LocalFrame& frame, Event*, EditorCommandSource source)
{
+ if (!canWriteClipboard(frame, source))
+ return false;
return frame.editor().canDHTMLCopy() || frame.editor().canCopy();
}
-static bool enabledCut(LocalFrame& frame, Event*, EditorCommandSource)
+static bool enabledCut(LocalFrame& frame, Event*, EditorCommandSource source)
{
+ if (!canWriteClipboard(frame, source))
+ return false;
return frame.editor().canDHTMLCut() || frame.editor().canCut();
}
@@ -1270,8 +1302,10 @@ static bool enabledInRichlyEditableText(LocalFrame& frame, Event*, EditorCommand
return frame.selection().isCaretOrRange() && frame.selection().isContentRichlyEditable() && frame.selection().rootEditableElement();
}
-static bool enabledPaste(LocalFrame& frame, Event*, EditorCommandSource)
+static bool enabledPaste(LocalFrame& frame, Event*, EditorCommandSource source)
{
+ if (!canReadClipboard(frame, source))
+ return false;
return frame.editor().canPaste();
}
@@ -1457,9 +1491,9 @@ static const CommandMap& createCommandMap()
{ "BackColor", {4, executeBackColor, supported, enabledInRichlyEditableText, stateNone, valueBackColor, notTextInsertion, doNotAllowExecutionWhenDisabled } },
{ "BackwardDelete", {5, executeDeleteBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } }, // FIXME: remove BackwardDelete when Safari for Windows stops using it.
{ "Bold", {6, executeToggleBold, supported, enabledInRichlyEditableText, stateBold, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
- { "Copy", {7, executeCopy, supportedCopyCut, enabledCopy, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
+ { "Copy", {7, executeCopy, supported, enabledCopy, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
{ "CreateLink", {8, executeCreateLink, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
- { "Cut", {9, executeCut, supportedCopyCut, enabledCut, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
+ { "Cut", {9, executeCut, supported, enabledCut, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
{ "DefaultParagraphSeparator", {10, executeDefaultParagraphSeparator, supported, enabled, stateNone, valueDefaultParagraphSeparator, notTextInsertion, doNotAllowExecutionWhenDisabled} },
{ "Delete", {11, executeDelete, supported, enabledDelete, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
{ "DeleteBackward", {12, executeDeleteBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
@@ -1553,8 +1587,8 @@ static const CommandMap& createCommandMap()
{ "MoveWordRightAndModifySelection", {100, executeMoveWordRightAndModifySelection, supportedFromMenuOrKeyBinding, enabledVisibleSelectionOrCaretBrowsing, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
{ "Outdent", {101, executeOutdent, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
{ "OverWrite", {102, executeToggleOverwrite, supportedFromMenuOrKeyBinding, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
- { "Paste", {103, executePaste, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
- { "PasteAndMatchStyle", {104, executePasteAndMatchStyle, supportedPaste, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
+ { "Paste", {103, executePaste, supported, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
+ { "PasteAndMatchStyle", {104, executePasteAndMatchStyle, supported, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
{ "PasteGlobalSelection", {105, executePasteGlobalSelection, supportedFromMenuOrKeyBinding, enabledPaste, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
{ "Print", {106, executePrint, supported, enabled, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
{ "Redo", {107, executeRedo, supported, enabledRedo, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
@@ -1731,6 +1765,10 @@ Editor::Command::Command(const EditorInternalCommand* command, EditorCommandSour
bool Editor::Command::execute(const String& parameter, Event* triggeringEvent) const
{
+ // TODO(yosin) We should move this logic into |canExecute()| member function
+ // in |EditorInternalCommand| to replace |allowExecutionWhenDisabled|.
+ // |allowExecutionWhenDisabled| is for "Copy", "Cut" and "Paste" commands
+ // only.
if (!isEnabled(triggeringEvent)) {
// Let certain commands be executed when performed explicitly even if they are disabled.
if (!isSupported() || !m_frame || !m_command->allowExecutionWhenDisabled)
« no previous file with comments | « third_party/WebKit/LayoutTests/editing/pasteboard/copy-cut-paste-supported.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698