Bug 1208217 - Enable paste event listener in documents with no editor component, r=enndeakin

This commit is contained in:
Michael Layzell 2016-05-13 11:16:30 -07:00
Родитель fe5c0e702f
Коммит d09810392d
4 изменённых файлов: 49 добавлений и 9 удалений

Просмотреть файл

@ -484,7 +484,8 @@ nsClipboardCommand::IsCommandEnabled(const char* aCommandName, nsISupports *aCon
if (strcmp(aCommandName, "cmd_copy") &&
strcmp(aCommandName, "cmd_copyAndCollapseToEnd") &&
strcmp(aCommandName, "cmd_cut"))
strcmp(aCommandName, "cmd_cut") &&
strcmp(aCommandName, "cmd_paste"))
return NS_OK;
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryInterface(aContext);
@ -492,11 +493,13 @@ nsClipboardCommand::IsCommandEnabled(const char* aCommandName, nsISupports *aCon
nsCOMPtr<nsIDocument> doc = window->GetExtantDoc();
if (doc->IsHTMLOrXHTML()) {
// In HTML and XHTML documents, we always want cut and copy commands to be enabled.
// In HTML and XHTML documents, we always want the cut, copy and paste
// commands to be enabled.
*outCmdEnabled = true;
} else {
// Cut isn't enabled in xul documents which use nsClipboardCommand
if (strcmp(aCommandName, "cmd_cut")) {
if (strcmp(aCommandName, "cmd_copy") == 0 ||
strcmp(aCommandName, "cmd_copyAndCollapseToEnd") == 0) {
*outCmdEnabled = nsCopySupport::CanCopy(doc);
}
}
@ -508,7 +511,8 @@ nsClipboardCommand::DoCommand(const char *aCommandName, nsISupports *aContext)
{
if (strcmp(aCommandName, "cmd_cut") &&
strcmp(aCommandName, "cmd_copy") &&
strcmp(aCommandName, "cmd_copyAndCollapseToEnd"))
strcmp(aCommandName, "cmd_copyAndCollapseToEnd") &&
strcmp(aCommandName, "cmd_paste"))
return NS_OK;
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryInterface(aContext);
@ -523,14 +527,17 @@ nsClipboardCommand::DoCommand(const char *aCommandName, nsISupports *aContext)
EventMessage eventMessage = eCopy;
if (strcmp(aCommandName, "cmd_cut") == 0) {
eventMessage = eCut;
} else if (strcmp(aCommandName, "cmd_paste") == 0) {
eventMessage = ePaste;
}
bool actionTaken = false;
nsCopySupport::FireClipboardEvent(eventMessage,
nsIClipboard::kGlobalClipboard,
presShell, nullptr, &actionTaken);
bool notCancelled =
nsCopySupport::FireClipboardEvent(eventMessage,
nsIClipboard::kGlobalClipboard,
presShell, nullptr, &actionTaken);
if (!strcmp(aCommandName, "cmd_copyAndCollapseToEnd")) {
if (notCancelled && !strcmp(aCommandName, "cmd_copyAndCollapseToEnd")) {
dom::Selection *sel =
presShell->GetCurrentSelection(nsISelectionController::SELECTION_NORMAL);
NS_ENSURE_TRUE(sel, NS_ERROR_FAILURE);

Просмотреть файл

@ -137,3 +137,4 @@ skip-if = buildapp == 'b2g' || buildapp == 'mulet' || toolkit == 'android' # Mou
# Disabled on Android, see bug 1230232
[test_WebKitCSSMatrix.html]
[test_resource_timing_frameset.html]
[test_bug1208217.html]

Просмотреть файл

@ -0,0 +1,32 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=1208217
-->
<head>
<title>Test for Bug 1208217</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1208217">Mozilla Bug 1208217</a>
<script type="application/javascript">
add_task(function*() {
let pasteCount = 0;
document.addEventListener('paste', function() {
pasteCount++;
});
is(pasteCount, 0);
synthesizeKey("V", {accelKey: true});
is(pasteCount, 1);
});
</script>
</body>
</html>

Просмотреть файл

@ -157,7 +157,7 @@ function test_dom_onpaste() {
content.onpaste = function() { onpaste_fired = true; };
try {
synthesizeKey("v", {accelKey: 1});
ok(!onpaste_fired, "paste event firing on DOM element");
ok(onpaste_fired, "paste event firing on DOM element");
} finally {
content.onpaste = null;
}