<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[198354] trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/198354">198354</a></dd>
<dt>Author</dt> <dd>weinig@apple.com</dd>
<dt>Date</dt> <dd>2016-03-17 14:04:49 -0700 (Thu, 17 Mar 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Implement document.queryCommandSupported("copy")
https://bugs.webkit.org/show_bug.cgi?id=155548
<rdar://problem/25195295>
Reviewed by Enrica Casucci.
Source/WebCore:
- document.queryCommandSupported("copy") and document.queryCommandSupported("cut") need
to return true if the ClipboardAccessPolicy is either Allow or RequiresUserGesture.
But, document.queryCommandEnabled("copy") and document.queryCommandEnabled("cut")
should still return false when there is no user gesture. I also had to maintain a weird
quirk that copy and cut should be allowed to execute, and thus fire the oncopy and oncut
events, even when disabled, if coming from a "MenuOrKeyBinding" source. To do this, I
upgraded the allowExecutionWhenDisabled bit to a function taking a source, and return true
only when the correct source is specified.
* editing/Editor.h:
* editing/EditorCommand.cpp:
(WebCore::defaultValueForSupportedCopyCut):
(WebCore::allowCopyCutFromDOM):
(WebCore::enabledCopy):
(WebCore::enabledCut):
(WebCore::allowExecutionWhenDisabled):
(WebCore::doNotAllowExecutionWhenDisabled):
(WebCore::allowExecutionWhenDisabledCopyCut):
(WebCore::Editor::Command::execute):
(WebCore::Editor::Command::allowExecutionWhenDisabled):
LayoutTests:
* editing/execCommand/clipboard-access-with-user-gesture-expected.txt:
* editing/execCommand/clipboard-access-with-user-gesture.html:
document.queryCommandSupported('copy') should be returning true.
* editing/pasteboard/can-read-in-copy-and-cut-events.html:
* editing/pasteboard/copy-cut-paste-events-fired-when-disabled.html:
* editing/pasteboard/pasting-empty-html-falls-back-to-text.html:
* editing/pasteboard/set_data_typeof_return.html:
Use testRunner.execCommand() to test the behavior of a user.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestseditingexecCommandclipboardaccesswithusergestureexpectedtxt">trunk/LayoutTests/editing/execCommand/clipboard-access-with-user-gesture-expected.txt</a></li>
<li><a href="#trunkLayoutTestseditingexecCommandclipboardaccesswithusergesturehtml">trunk/LayoutTests/editing/execCommand/clipboard-access-with-user-gesture.html</a></li>
<li><a href="#trunkLayoutTestseditingmacpasteboardtextprecomposedhtml">trunk/LayoutTests/editing/mac/pasteboard/text-precomposed.html</a></li>
<li><a href="#trunkLayoutTestseditingpasteboardcanreadincopyandcuteventshtml">trunk/LayoutTests/editing/pasteboard/can-read-in-copy-and-cut-events.html</a></li>
<li><a href="#trunkLayoutTestseditingpasteboardcopycutpasteeventsfiredwhendisabledhtml">trunk/LayoutTests/editing/pasteboard/copy-cut-paste-events-fired-when-disabled.html</a></li>
<li><a href="#trunkLayoutTestseditingpasteboardpastingemptyhtmlfallsbacktotexthtml">trunk/LayoutTests/editing/pasteboard/pasting-empty-html-falls-back-to-text.html</a></li>
<li><a href="#trunkLayoutTestseditingpasteboardset_data_typeof_returnhtml">trunk/LayoutTests/editing/pasteboard/set_data_typeof_return.html</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreeditingEditorh">trunk/Source/WebCore/editing/Editor.h</a></li>
<li><a href="#trunkSourceWebCoreeditingEditorCommandcpp">trunk/Source/WebCore/editing/EditorCommand.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (198353 => 198354)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2016-03-17 21:02:07 UTC (rev 198353)
+++ trunk/LayoutTests/ChangeLog        2016-03-17 21:04:49 UTC (rev 198354)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2016-03-17 Sam Weinig <sam@webkit.org>
+
+ Implement document.queryCommandSupported("copy")
+ https://bugs.webkit.org/show_bug.cgi?id=155548
+ <rdar://problem/25195295>
+
+ Reviewed by Enrica Casucci.
+
+ * editing/execCommand/clipboard-access-with-user-gesture-expected.txt:
+ * editing/execCommand/clipboard-access-with-user-gesture.html:
+ document.queryCommandSupported('copy') should be returning true.
+
+ * editing/pasteboard/can-read-in-copy-and-cut-events.html:
+ * editing/pasteboard/copy-cut-paste-events-fired-when-disabled.html:
+ * editing/pasteboard/pasting-empty-html-falls-back-to-text.html:
+ * editing/pasteboard/set_data_typeof_return.html:
+ Use testRunner.execCommand() to test the behavior of a user.
+
</ins><span class="cx"> 2016-03-17 Joseph Pecoraro <pecoraro@apple.com>
</span><span class="cx">
</span><span class="cx"> Web Inspector: HeapSnapshots are slow and use too much memory
</span></span></pre></div>
<a id="trunkLayoutTestseditingexecCommandclipboardaccesswithusergestureexpectedtxt"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/editing/execCommand/clipboard-access-with-user-gesture-expected.txt (198353 => 198354)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/execCommand/clipboard-access-with-user-gesture-expected.txt        2016-03-17 21:02:07 UTC (rev 198353)
+++ trunk/LayoutTests/editing/execCommand/clipboard-access-with-user-gesture-expected.txt        2016-03-17 21:04:49 UTC (rev 198354)
</span><span class="lines">@@ -7,7 +7,7 @@
</span><span class="cx"> Testing copying an editableParagraph range without a user gesture.
</span><span class="cx"> PASS document.queryCommandEnabled('copy') is false
</span><span class="cx"> PASS eventSeen['copy'] is false
</span><del>-PASS document.queryCommandSupported('copy') is false
</del><ins>+PASS document.queryCommandSupported('copy') is true
</ins><span class="cx"> PASS eventSeen['copy'] is false
</span><span class="cx"> PASS document.execCommand('copy') is false
</span><span class="cx"> PASS eventSeen['copy'] is false
</span><span class="lines">@@ -15,7 +15,7 @@
</span><span class="cx"> Testing copying an editableParagraph caret without a user gesture.
</span><span class="cx"> PASS document.queryCommandEnabled('copy') is false
</span><span class="cx"> PASS eventSeen['copy'] is false
</span><del>-PASS document.queryCommandSupported('copy') is false
</del><ins>+PASS document.queryCommandSupported('copy') is true
</ins><span class="cx"> PASS eventSeen['copy'] is false
</span><span class="cx"> PASS document.execCommand('copy') is false
</span><span class="cx"> PASS eventSeen['copy'] is false
</span><span class="lines">@@ -23,7 +23,7 @@
</span><span class="cx"> Testing copying an non-editable range without a user gesture.
</span><span class="cx"> PASS document.queryCommandEnabled('copy') is false
</span><span class="cx"> PASS eventSeen['copy'] is false
</span><del>-PASS document.queryCommandSupported('copy') is false
</del><ins>+PASS document.queryCommandSupported('copy') is true
</ins><span class="cx"> PASS eventSeen['copy'] is false
</span><span class="cx"> PASS document.execCommand('copy') is false
</span><span class="cx"> PASS eventSeen['copy'] is false
</span><span class="lines">@@ -31,7 +31,7 @@
</span><span class="cx"> Testing copying an non-editable caret without a user gesture.
</span><span class="cx"> PASS document.queryCommandEnabled('copy') is false
</span><span class="cx"> PASS eventSeen['copy'] is false
</span><del>-PASS document.queryCommandSupported('copy') is false
</del><ins>+PASS document.queryCommandSupported('copy') is true
</ins><span class="cx"> PASS eventSeen['copy'] is false
</span><span class="cx"> PASS document.execCommand('copy') is false
</span><span class="cx"> PASS eventSeen['copy'] is false
</span><span class="lines">@@ -39,7 +39,7 @@
</span><span class="cx"> Testing copying an editable plaint-text range without a user gesture.
</span><span class="cx"> PASS document.queryCommandEnabled('copy') is false
</span><span class="cx"> PASS eventSeen['copy'] is false
</span><del>-PASS document.queryCommandSupported('copy') is false
</del><ins>+PASS document.queryCommandSupported('copy') is true
</ins><span class="cx"> PASS eventSeen['copy'] is false
</span><span class="cx"> PASS document.execCommand('copy') is false
</span><span class="cx"> PASS eventSeen['copy'] is false
</span><span class="lines">@@ -47,7 +47,7 @@
</span><span class="cx"> Testing copying an editable plaint-text caret without a user gesture.
</span><span class="cx"> PASS document.queryCommandEnabled('copy') is false
</span><span class="cx"> PASS eventSeen['copy'] is false
</span><del>-PASS document.queryCommandSupported('copy') is false
</del><ins>+PASS document.queryCommandSupported('copy') is true
</ins><span class="cx"> PASS eventSeen['copy'] is false
</span><span class="cx"> PASS document.execCommand('copy') is false
</span><span class="cx"> PASS eventSeen['copy'] is false
</span><span class="lines">@@ -55,7 +55,7 @@
</span><span class="cx"> Testing copying when there is no selection without a user gesture.
</span><span class="cx"> PASS document.queryCommandEnabled('copy') is false
</span><span class="cx"> PASS eventSeen['copy'] is false
</span><del>-PASS document.queryCommandSupported('copy') is false
</del><ins>+PASS document.queryCommandSupported('copy') is true
</ins><span class="cx"> PASS eventSeen['copy'] is false
</span><span class="cx"> PASS document.execCommand('copy') is false
</span><span class="cx"> PASS eventSeen['copy'] is false
</span><span class="lines">@@ -63,7 +63,7 @@
</span><span class="cx"> Testing cutting an editableParagraph range without a user gesture.
</span><span class="cx"> PASS document.queryCommandEnabled('cut') is false
</span><span class="cx"> PASS eventSeen['cut'] is false
</span><del>-PASS document.queryCommandSupported('cut') is false
</del><ins>+PASS document.queryCommandSupported('cut') is true
</ins><span class="cx"> PASS eventSeen['cut'] is false
</span><span class="cx"> PASS document.execCommand('cut') is false
</span><span class="cx"> PASS eventSeen['cut'] is false
</span><span class="lines">@@ -71,7 +71,7 @@
</span><span class="cx"> Testing cutting an editableParagraph caret without a user gesture.
</span><span class="cx"> PASS document.queryCommandEnabled('cut') is false
</span><span class="cx"> PASS eventSeen['cut'] is false
</span><del>-PASS document.queryCommandSupported('cut') is false
</del><ins>+PASS document.queryCommandSupported('cut') is true
</ins><span class="cx"> PASS eventSeen['cut'] is false
</span><span class="cx"> PASS document.execCommand('cut') is false
</span><span class="cx"> PASS eventSeen['cut'] is false
</span><span class="lines">@@ -79,7 +79,7 @@
</span><span class="cx"> Testing cutting an non-editable range without a user gesture.
</span><span class="cx"> PASS document.queryCommandEnabled('cut') is false
</span><span class="cx"> PASS eventSeen['cut'] is false
</span><del>-PASS document.queryCommandSupported('cut') is false
</del><ins>+PASS document.queryCommandSupported('cut') is true
</ins><span class="cx"> PASS eventSeen['cut'] is false
</span><span class="cx"> PASS document.execCommand('cut') is false
</span><span class="cx"> PASS eventSeen['cut'] is false
</span><span class="lines">@@ -87,7 +87,7 @@
</span><span class="cx"> Testing cutting an non-editable caret without a user gesture.
</span><span class="cx"> PASS document.queryCommandEnabled('cut') is false
</span><span class="cx"> PASS eventSeen['cut'] is false
</span><del>-PASS document.queryCommandSupported('cut') is false
</del><ins>+PASS document.queryCommandSupported('cut') is true
</ins><span class="cx"> PASS eventSeen['cut'] is false
</span><span class="cx"> PASS document.execCommand('cut') is false
</span><span class="cx"> PASS eventSeen['cut'] is false
</span><span class="lines">@@ -95,7 +95,7 @@
</span><span class="cx"> Testing cutting an editable plaint-text range without a user gesture.
</span><span class="cx"> PASS document.queryCommandEnabled('cut') is false
</span><span class="cx"> PASS eventSeen['cut'] is false
</span><del>-PASS document.queryCommandSupported('cut') is false
</del><ins>+PASS document.queryCommandSupported('cut') is true
</ins><span class="cx"> PASS eventSeen['cut'] is false
</span><span class="cx"> PASS document.execCommand('cut') is false
</span><span class="cx"> PASS eventSeen['cut'] is false
</span><span class="lines">@@ -103,7 +103,7 @@
</span><span class="cx"> Testing cutting an editable plaint-text caret without a user gesture.
</span><span class="cx"> PASS document.queryCommandEnabled('cut') is false
</span><span class="cx"> PASS eventSeen['cut'] is false
</span><del>-PASS document.queryCommandSupported('cut') is false
</del><ins>+PASS document.queryCommandSupported('cut') is true
</ins><span class="cx"> PASS eventSeen['cut'] is false
</span><span class="cx"> PASS document.execCommand('cut') is false
</span><span class="cx"> PASS eventSeen['cut'] is false
</span><span class="lines">@@ -111,7 +111,7 @@
</span><span class="cx"> Testing cutting when there is no selection without a user gesture.
</span><span class="cx"> PASS document.queryCommandEnabled('cut') is false
</span><span class="cx"> PASS eventSeen['cut'] is false
</span><del>-PASS document.queryCommandSupported('cut') is false
</del><ins>+PASS document.queryCommandSupported('cut') is true
</ins><span class="cx"> PASS eventSeen['cut'] is false
</span><span class="cx"> PASS document.execCommand('cut') is false
</span><span class="cx"> PASS eventSeen['cut'] is false
</span></span></pre></div>
<a id="trunkLayoutTestseditingexecCommandclipboardaccesswithusergesturehtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/editing/execCommand/clipboard-access-with-user-gesture.html (198353 => 198354)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/execCommand/clipboard-access-with-user-gesture.html        2016-03-17 21:02:07 UTC (rev 198353)
+++ trunk/LayoutTests/editing/execCommand/clipboard-access-with-user-gesture.html        2016-03-17 21:04:49 UTC (rev 198354)
</span><span class="lines">@@ -196,61 +196,61 @@
</span><span class="cx"> // First test copy/cut without user gestures.
</span><span class="cx"> header("Testing copying an editableParagraph range without a user gesture.")
</span><span class="cx"> makeSelection("editableParagraph", 0, 1);
</span><del>-test("copy", false, false, false);
</del><ins>+test("copy", false, true, false);
</ins><span class="cx">
</span><span class="cx"> header("Testing copying an editableParagraph caret without a user gesture.")
</span><span class="cx"> makeSelection("editableParagraph", 0, 0);
</span><del>-test("copy", false, false, false);
</del><ins>+test("copy", false, true, false);
</ins><span class="cx">
</span><span class="cx"> header("Testing copying an non-editable range without a user gesture.")
</span><span class="cx"> makeSelection("nonEditableParagraph", 0, 1);
</span><del>-test("copy", false, false, false);
</del><ins>+test("copy", false, true, false);
</ins><span class="cx">
</span><span class="cx"> header("Testing copying an non-editable caret without a user gesture.")
</span><span class="cx"> makeSelection("nonEditableParagraph", 0, 0);
</span><del>-test("copy", false, false, false);
</del><ins>+test("copy", false, true, false);
</ins><span class="cx">
</span><span class="cx"> header("Testing copying an editable plaint-text range without a user gesture.")
</span><span class="cx"> makeSelection("editablePlainTextParagraph", 0, 1);
</span><del>-test("copy", false, false, false);
</del><ins>+test("copy", false, true, false);
</ins><span class="cx">
</span><span class="cx"> header("Testing copying an editable plaint-text caret without a user gesture.")
</span><span class="cx"> makeSelection("editablePlainTextParagraph", 0, 0);
</span><del>-test("copy", false, false, false);
</del><ins>+test("copy", false, true, false);
</ins><span class="cx">
</span><span class="cx"> header("Testing copying when there is no selection without a user gesture.")
</span><span class="cx"> window.getSelection().removeAllRanges();
</span><del>-test("copy", false, false, false);
</del><ins>+test("copy", false, true, false);
</ins><span class="cx">
</span><span class="cx"> clearSelectionContainer();
</span><span class="cx">
</span><span class="cx"> header("Testing cutting an editableParagraph range without a user gesture.")
</span><span class="cx"> makeSelection("editableParagraph", 0, 1);
</span><del>-test("cut", false, false, false);
</del><ins>+test("cut", false, true, false);
</ins><span class="cx">
</span><span class="cx"> header("Testing cutting an editableParagraph caret without a user gesture.")
</span><span class="cx"> makeSelection("editableParagraph", 0, 0);
</span><del>-test("cut", false, false, false);
</del><ins>+test("cut", false, true, false);
</ins><span class="cx">
</span><span class="cx"> header("Testing cutting an non-editable range without a user gesture.")
</span><span class="cx"> makeSelection("nonEditableParagraph", 0, 1);
</span><del>-test("cut", false, false, false);
</del><ins>+test("cut", false, true, false);
</ins><span class="cx">
</span><span class="cx"> header("Testing cutting an non-editable caret without a user gesture.")
</span><span class="cx"> makeSelection("nonEditableParagraph", 0, 0);
</span><del>-test("cut", false, false, false);
</del><ins>+test("cut", false, true, false);
</ins><span class="cx">
</span><span class="cx"> header("Testing cutting an editable plaint-text range without a user gesture.")
</span><span class="cx"> makeSelection("editablePlainTextParagraph", 0, 1);
</span><del>-test("cut", false, false, false);
</del><ins>+test("cut", false, true, false);
</ins><span class="cx">
</span><span class="cx"> header("Testing cutting an editable plaint-text caret without a user gesture.")
</span><span class="cx"> makeSelection("editablePlainTextParagraph", 0, 0);
</span><del>-test("cut", false, false, false);
</del><ins>+test("cut", false, true, false);
</ins><span class="cx">
</span><span class="cx"> header("Testing cutting when there is no selection without a user gesture.")
</span><span class="cx"> window.getSelection().removeAllRanges();
</span><del>-test("cut", false, false, false);
</del><ins>+test("cut", false, true, false);
</ins><span class="cx">
</span><span class="cx"> clearSelectionContainer();
</span><span class="cx">
</span></span></pre></div>
<a id="trunkLayoutTestseditingmacpasteboardtextprecomposedhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/editing/mac/pasteboard/text-precomposed.html (198353 => 198354)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/mac/pasteboard/text-precomposed.html        2016-03-17 21:02:07 UTC (rev 198353)
+++ trunk/LayoutTests/editing/mac/pasteboard/text-precomposed.html        2016-03-17 21:04:49 UTC (rev 198354)
</span><span class="lines">@@ -26,11 +26,11 @@
</span><span class="cx"> log("FAIL: text/plain data on the clipboard is \"" + data + "\"");
</span><span class="cx"> }, true);
</span><span class="cx">
</span><del>- document.execCommand("Copy");
</del><ins>+ window.testRunner.execCommand("Copy");
</ins><span class="cx">
</span><span class="cx"> var target = document.getElementById("paste-target");
</span><span class="cx"> target.focus();
</span><del>- document.execCommand("Paste");
</del><ins>+ window.testRunner.execCommand("Paste");
</ins><span class="cx"> var data = target.firstChild.data;
</span><span class="cx"> if (data === "\u00e9")
</span><span class="cx"> log("PASS: pasted text is precomposed");
</span></span></pre></div>
<a id="trunkLayoutTestseditingpasteboardcanreadincopyandcuteventshtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/editing/pasteboard/can-read-in-copy-and-cut-events.html (198353 => 198354)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/pasteboard/can-read-in-copy-and-cut-events.html        2016-03-17 21:02:07 UTC (rev 198353)
+++ trunk/LayoutTests/editing/pasteboard/can-read-in-copy-and-cut-events.html        2016-03-17 21:04:49 UTC (rev 198354)
</span><span class="lines">@@ -30,8 +30,8 @@
</span><span class="cx"> if (!window.testRunner)
</span><span class="cx"> return;
</span><span class="cx"> testRunner.dumpAsText();
</span><del>- document.execCommand('copy');
- document.execCommand('cut');
</del><ins>+ testRunner.execCommand('copy');
+ testRunner.execCommand('cut');
</ins><span class="cx"> }
</span><span class="cx"> </script>
</span><span class="cx"> </head>
</span></span></pre></div>
<a id="trunkLayoutTestseditingpasteboardcopycutpasteeventsfiredwhendisabledhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/editing/pasteboard/copy-cut-paste-events-fired-when-disabled.html (198353 => 198354)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/pasteboard/copy-cut-paste-events-fired-when-disabled.html        2016-03-17 21:02:07 UTC (rev 198353)
+++ trunk/LayoutTests/editing/pasteboard/copy-cut-paste-events-fired-when-disabled.html        2016-03-17 21:04:49 UTC (rev 198354)
</span><span class="lines">@@ -9,10 +9,11 @@
</span><span class="cx"> console.appendChild(li);
</span><span class="cx"> li.appendChild(text);
</span><span class="cx"> }
</span><del>-if (window.testRunner)
</del><ins>+if (window.testRunner) {
</ins><span class="cx"> window.testRunner.dumpAsText();
</span><del>-document.execCommand("Copy");
-document.execCommand("Cut");
-document.execCommand("Paste");
</del><ins>+ window.testRunner.execCommand("Copy");
+ window.testRunner.execCommand("Cut");
+ window.testRunner.execCommand("Paste");
+}
</ins><span class="cx"> </script>
</span><span class="cx"> </body>
</span></span></pre></div>
<a id="trunkLayoutTestseditingpasteboardpastingemptyhtmlfallsbacktotexthtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/editing/pasteboard/pasting-empty-html-falls-back-to-text.html (198353 => 198354)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/pasteboard/pasting-empty-html-falls-back-to-text.html        2016-03-17 21:02:07 UTC (rev 198353)
+++ trunk/LayoutTests/editing/pasteboard/pasting-empty-html-falls-back-to-text.html        2016-03-17 21:04:49 UTC (rev 198354)
</span><span class="lines">@@ -15,13 +15,13 @@
</span><span class="cx"> testRunner.dumpAsText();
</span><span class="cx">
</span><span class="cx"> document.body.addEventListener('copy', handleCopy);
</span><del>- document.execCommand('copy');
</del><ins>+ testRunner.execCommand('copy');
</ins><span class="cx"> var selection = window.getSelection();
</span><span class="cx"> var range = document.createRange();
</span><span class="cx"> range.selectNode(document.getElementById('description'));
</span><span class="cx"> selection.addRange(range);
</span><span class="cx"> selection.collapseToEnd();
</span><del>- document.execCommand('paste');
</del><ins>+ testRunner.execCommand('paste');
</ins><span class="cx"> }
</span><span class="cx"> </script>
</span><span class="cx"> <body onload="runTest()" contenteditable="true">
</span></span></pre></div>
<a id="trunkLayoutTestseditingpasteboardset_data_typeof_returnhtml"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/editing/pasteboard/set_data_typeof_return.html (198353 => 198354)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/editing/pasteboard/set_data_typeof_return.html        2016-03-17 21:02:07 UTC (rev 198353)
+++ trunk/LayoutTests/editing/pasteboard/set_data_typeof_return.html        2016-03-17 21:04:49 UTC (rev 198354)
</span><span class="lines">@@ -13,7 +13,8 @@
</span><span class="cx"> <script>
</span><span class="cx"> description("Simple test to validate the return type of setData(). To run the test manually, simply select any text and initiate a copy operation.");
</span><span class="cx">
</span><del>-document.execCommand('copy');
</del><ins>+if (window.testRunner)
+ window.testRunner.execCommand('copy');
</ins><span class="cx"> </script>
</span><span class="cx"> <script src="../../resources/js-test-post.js"></script>
</span><span class="cx"> </body>
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (198353 => 198354)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-03-17 21:02:07 UTC (rev 198353)
+++ trunk/Source/WebCore/ChangeLog        2016-03-17 21:04:49 UTC (rev 198354)
</span><span class="lines">@@ -1,3 +1,32 @@
</span><ins>+2016-03-17 Sam Weinig <sam@webkit.org>
+
+ Implement document.queryCommandSupported("copy")
+ https://bugs.webkit.org/show_bug.cgi?id=155548
+ <rdar://problem/25195295>
+
+ Reviewed by Enrica Casucci.
+
+ - document.queryCommandSupported("copy") and document.queryCommandSupported("cut") need
+ to return true if the ClipboardAccessPolicy is either Allow or RequiresUserGesture.
+ But, document.queryCommandEnabled("copy") and document.queryCommandEnabled("cut")
+ should still return false when there is no user gesture. I also had to maintain a weird
+ quirk that copy and cut should be allowed to execute, and thus fire the oncopy and oncut
+ events, even when disabled, if coming from a "MenuOrKeyBinding" source. To do this, I
+ upgraded the allowExecutionWhenDisabled bit to a function taking a source, and return true
+ only when the correct source is specified.
+
+ * editing/Editor.h:
+ * editing/EditorCommand.cpp:
+ (WebCore::defaultValueForSupportedCopyCut):
+ (WebCore::allowCopyCutFromDOM):
+ (WebCore::enabledCopy):
+ (WebCore::enabledCut):
+ (WebCore::allowExecutionWhenDisabled):
+ (WebCore::doNotAllowExecutionWhenDisabled):
+ (WebCore::allowExecutionWhenDisabledCopyCut):
+ (WebCore::Editor::Command::execute):
+ (WebCore::Editor::Command::allowExecutionWhenDisabled):
+
</ins><span class="cx"> 2016-03-17 Antti Koivisto <antti@apple.com>
</span><span class="cx">
</span><span class="cx"> DataURLDecoder::DecodingResultDispatcher may get deleted outside main thread
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingEditorh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/Editor.h (198353 => 198354)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/Editor.h        2016-03-17 21:02:07 UTC (rev 198353)
+++ trunk/Source/WebCore/editing/Editor.h        2016-03-17 21:04:49 UTC (rev 198354)
</span><span class="lines">@@ -215,6 +215,7 @@
</span><span class="cx"> String value(Event* triggeringEvent = nullptr) const;
</span><span class="cx">
</span><span class="cx"> WEBCORE_EXPORT bool isTextInsertion() const;
</span><ins>+ WEBCORE_EXPORT bool allowExecutionWhenDisabled() const;
</ins><span class="cx">
</span><span class="cx"> private:
</span><span class="cx"> const EditorInternalCommand* m_command { nullptr };
</span></span></pre></div>
<a id="trunkSourceWebCoreeditingEditorCommandcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/editing/EditorCommand.cpp (198353 => 198354)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/editing/EditorCommand.cpp        2016-03-17 21:02:07 UTC (rev 198353)
+++ trunk/Source/WebCore/editing/EditorCommand.cpp        2016-03-17 21:04:49 UTC (rev 198354)
</span><span class="lines">@@ -75,7 +75,7 @@
</span><span class="cx"> TriState (*state)(Frame&, Event*);
</span><span class="cx"> String (*value)(Frame&, Event*);
</span><span class="cx"> bool isTextInsertion;
</span><del>- bool allowExecutionWhenDisabled;
</del><ins>+ bool (*allowExecutionWhenDisabled)(EditorCommandSource);
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> typedef HashMap<String, const EditorInternalCommand*, ASCIICaseInsensitiveHash> CommandMap;
</span><span class="lines">@@ -83,9 +83,6 @@
</span><span class="cx"> static const bool notTextInsertion = false;
</span><span class="cx"> static const bool isTextInsertion = true;
</span><span class="cx">
</span><del>-static const bool allowExecutionWhenDisabled = true;
-static const bool doNotAllowExecutionWhenDisabled = false;
-
</del><span class="cx"> // Related to Editor::selectionForCommand.
</span><span class="cx"> // Certain operations continue to use the target control's selection even if the event handler
</span><span class="cx"> // already moved the selection outside of the text control.
</span><span class="lines">@@ -1166,11 +1163,10 @@
</span><span class="cx">
</span><span class="cx"> switch (settings.clipboardAccessPolicy()) {
</span><span class="cx"> case ClipboardAccessPolicy::Allow:
</span><ins>+ case ClipboardAccessPolicy::RequiresUserGesture:
</ins><span class="cx"> return true;
</span><span class="cx"> case ClipboardAccessPolicy::Deny:
</span><span class="cx"> return false;
</span><del>- case ClipboardAccessPolicy::RequiresUserGesture:
- return UserGestureIndicator::processingUserGesture();
</del><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> ASSERT_NOT_REACHED();
</span><span class="lines">@@ -1239,16 +1235,51 @@
</span><span class="cx"> return selection.isCaret() && selection.isContentEditable();
</span><span class="cx"> }
</span><span class="cx">
</span><del>-static bool enabledCopy(Frame& frame, Event*, EditorCommandSource)
</del><ins>+static bool allowCopyCutFromDOM(Frame& frame)
</ins><span class="cx"> {
</span><del>- return frame.editor().canDHTMLCopy() || frame.editor().canCopy();
</del><ins>+ auto& settings = frame.settings();
+ if (settings.javaScriptCanAccessClipboard())
+ return true;
+
+ switch (settings.clipboardAccessPolicy()) {
+ case ClipboardAccessPolicy::Allow:
+ return true;
+ case ClipboardAccessPolicy::Deny:
+ return false;
+ case ClipboardAccessPolicy::RequiresUserGesture:
+ return UserGestureIndicator::processingUserGesture();
+ }
+
+ ASSERT_NOT_REACHED();
+ return false;
</ins><span class="cx"> }
</span><span class="cx">
</span><del>-static bool enabledCut(Frame& frame, Event*, EditorCommandSource)
</del><ins>+static bool enabledCopy(Frame& frame, Event*, EditorCommandSource source)
</ins><span class="cx"> {
</span><del>- return frame.editor().canDHTMLCut() || frame.editor().canCut();
</del><ins>+ switch (source) {
+ case CommandFromMenuOrKeyBinding:
+ return frame.editor().canDHTMLCopy() || frame.editor().canCopy();
+ case CommandFromDOM:
+ case CommandFromDOMWithUserInterface:
+ return allowCopyCutFromDOM(frame) && (frame.editor().canDHTMLCopy() || frame.editor().canCopy());
+ }
+ ASSERT_NOT_REACHED();
+ return false;
</ins><span class="cx"> }
</span><span class="cx">
</span><ins>+static bool enabledCut(Frame& frame, Event*, EditorCommandSource source)
+{
+ switch (source) {
+ case CommandFromMenuOrKeyBinding:
+ return frame.editor().canDHTMLCut() || frame.editor().canCut();
+ case CommandFromDOM:
+ case CommandFromDOMWithUserInterface:
+ return allowCopyCutFromDOM(frame) && (frame.editor().canDHTMLCut() || frame.editor().canCut());
+ }
+ ASSERT_NOT_REACHED();
+ return false;
+}
+
</ins><span class="cx"> static bool enabledClearText(Frame& frame, Event*, EditorCommandSource)
</span><span class="cx"> {
</span><span class="cx"> UNUSED_PARAM(frame);
</span><span class="lines">@@ -1462,6 +1493,32 @@
</span><span class="cx"> return formatBlockElement->localName();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+// allowExecutionWhenDisabled functions
+
+static bool allowExecutionWhenDisabled(EditorCommandSource)
+{
+ return true;
+}
+
+static bool doNotAllowExecutionWhenDisabled(EditorCommandSource)
+{
+ return false;
+}
+
+static bool allowExecutionWhenDisabledCopyCut(EditorCommandSource source)
+{
+ switch (source) {
+ case CommandFromMenuOrKeyBinding:
+ return true;
+ case CommandFromDOM:
+ case CommandFromDOMWithUserInterface:
+ return false;
+ }
+
+ ASSERT_NOT_REACHED();
+ return false;
+}
+
</ins><span class="cx"> // Map of functions
</span><span class="cx">
</span><span class="cx"> struct CommandEntry {
</span><span class="lines">@@ -1479,9 +1536,9 @@
</span><span class="cx"> { "BackColor", { executeBackColor, supported, enabledInRichlyEditableText, stateNone, valueBackColor, notTextInsertion, doNotAllowExecutionWhenDisabled } },
</span><span class="cx"> { "Bold", { executeToggleBold, supported, enabledInRichlyEditableText, stateBold, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
</span><span class="cx"> { "ClearText", { executeClearText, supported, enabledClearText, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
</span><del>- { "Copy", { executeCopy, supportedCopyCut, enabledCopy, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
</del><ins>+ { "Copy", { executeCopy, supportedCopyCut, enabledCopy, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabledCopyCut } },
</ins><span class="cx"> { "CreateLink", { executeCreateLink, supported, enabledInRichlyEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
</span><del>- { "Cut", { executeCut, supportedCopyCut, enabledCut, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabled } },
</del><ins>+ { "Cut", { executeCut, supportedCopyCut, enabledCut, stateNone, valueNull, notTextInsertion, allowExecutionWhenDisabledCopyCut } },
</ins><span class="cx"> { "DefaultParagraphSeparator", { executeDefaultParagraphSeparator, supported, enabled, stateNone, valueDefaultParagraphSeparator, notTextInsertion, doNotAllowExecutionWhenDisabled} },
</span><span class="cx"> { "Delete", { executeDelete, supported, enabledDelete, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
</span><span class="cx"> { "DeleteBackward", { executeDeleteBackward, supportedFromMenuOrKeyBinding, enabledInEditableText, stateNone, valueNull, notTextInsertion, doNotAllowExecutionWhenDisabled } },
</span><span class="lines">@@ -1716,7 +1773,7 @@
</span><span class="cx"> {
</span><span class="cx"> if (!isEnabled(triggeringEvent)) {
</span><span class="cx"> // Let certain commands be executed when performed explicitly even if they are disabled.
</span><del>- if (!isSupported() || !m_frame || !m_command->allowExecutionWhenDisabled)
</del><ins>+ if (!allowExecutionWhenDisabled())
</ins><span class="cx"> return false;
</span><span class="cx"> }
</span><span class="cx"> m_frame->document()->updateLayoutIgnorePendingStylesheets();
</span><span class="lines">@@ -1771,4 +1828,11 @@
</span><span class="cx"> return m_command && m_command->isTextInsertion;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+bool Editor::Command::allowExecutionWhenDisabled() const
+{
+ if (!isSupported() || !m_frame)
+ return false;
+ return m_command->allowExecutionWhenDisabled(m_source);
+}
+
</ins><span class="cx"> } // namespace WebCore
</span></span></pre>
</div>
</div>
</body>
</html>