зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1208217 - Enable paste event listener in documents with no editor component, r=enndeakin
This commit is contained in:
Родитель
fe5c0e702f
Коммит
d09810392d
|
@ -484,7 +484,8 @@ nsClipboardCommand::IsCommandEnabled(const char* aCommandName, nsISupports *aCon
|
||||||
|
|
||||||
if (strcmp(aCommandName, "cmd_copy") &&
|
if (strcmp(aCommandName, "cmd_copy") &&
|
||||||
strcmp(aCommandName, "cmd_copyAndCollapseToEnd") &&
|
strcmp(aCommandName, "cmd_copyAndCollapseToEnd") &&
|
||||||
strcmp(aCommandName, "cmd_cut"))
|
strcmp(aCommandName, "cmd_cut") &&
|
||||||
|
strcmp(aCommandName, "cmd_paste"))
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
||||||
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryInterface(aContext);
|
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryInterface(aContext);
|
||||||
|
@ -492,11 +493,13 @@ nsClipboardCommand::IsCommandEnabled(const char* aCommandName, nsISupports *aCon
|
||||||
|
|
||||||
nsCOMPtr<nsIDocument> doc = window->GetExtantDoc();
|
nsCOMPtr<nsIDocument> doc = window->GetExtantDoc();
|
||||||
if (doc->IsHTMLOrXHTML()) {
|
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;
|
*outCmdEnabled = true;
|
||||||
} else {
|
} else {
|
||||||
// Cut isn't enabled in xul documents which use nsClipboardCommand
|
// 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);
|
*outCmdEnabled = nsCopySupport::CanCopy(doc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -508,7 +511,8 @@ nsClipboardCommand::DoCommand(const char *aCommandName, nsISupports *aContext)
|
||||||
{
|
{
|
||||||
if (strcmp(aCommandName, "cmd_cut") &&
|
if (strcmp(aCommandName, "cmd_cut") &&
|
||||||
strcmp(aCommandName, "cmd_copy") &&
|
strcmp(aCommandName, "cmd_copy") &&
|
||||||
strcmp(aCommandName, "cmd_copyAndCollapseToEnd"))
|
strcmp(aCommandName, "cmd_copyAndCollapseToEnd") &&
|
||||||
|
strcmp(aCommandName, "cmd_paste"))
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|
||||||
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryInterface(aContext);
|
nsCOMPtr<nsPIDOMWindowOuter> window = do_QueryInterface(aContext);
|
||||||
|
@ -523,14 +527,17 @@ nsClipboardCommand::DoCommand(const char *aCommandName, nsISupports *aContext)
|
||||||
EventMessage eventMessage = eCopy;
|
EventMessage eventMessage = eCopy;
|
||||||
if (strcmp(aCommandName, "cmd_cut") == 0) {
|
if (strcmp(aCommandName, "cmd_cut") == 0) {
|
||||||
eventMessage = eCut;
|
eventMessage = eCut;
|
||||||
|
} else if (strcmp(aCommandName, "cmd_paste") == 0) {
|
||||||
|
eventMessage = ePaste;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool actionTaken = false;
|
bool actionTaken = false;
|
||||||
nsCopySupport::FireClipboardEvent(eventMessage,
|
bool notCancelled =
|
||||||
nsIClipboard::kGlobalClipboard,
|
nsCopySupport::FireClipboardEvent(eventMessage,
|
||||||
presShell, nullptr, &actionTaken);
|
nsIClipboard::kGlobalClipboard,
|
||||||
|
presShell, nullptr, &actionTaken);
|
||||||
|
|
||||||
if (!strcmp(aCommandName, "cmd_copyAndCollapseToEnd")) {
|
if (notCancelled && !strcmp(aCommandName, "cmd_copyAndCollapseToEnd")) {
|
||||||
dom::Selection *sel =
|
dom::Selection *sel =
|
||||||
presShell->GetCurrentSelection(nsISelectionController::SELECTION_NORMAL);
|
presShell->GetCurrentSelection(nsISelectionController::SELECTION_NORMAL);
|
||||||
NS_ENSURE_TRUE(sel, NS_ERROR_FAILURE);
|
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
|
# Disabled on Android, see bug 1230232
|
||||||
[test_WebKitCSSMatrix.html]
|
[test_WebKitCSSMatrix.html]
|
||||||
[test_resource_timing_frameset.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; };
|
content.onpaste = function() { onpaste_fired = true; };
|
||||||
try {
|
try {
|
||||||
synthesizeKey("v", {accelKey: 1});
|
synthesizeKey("v", {accelKey: 1});
|
||||||
ok(!onpaste_fired, "paste event firing on DOM element");
|
ok(onpaste_fired, "paste event firing on DOM element");
|
||||||
} finally {
|
} finally {
|
||||||
content.onpaste = null;
|
content.onpaste = null;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче