зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1170531 - Disable clipboard menu commands correctly in non-(X)HTML documents; r=ehsan
This commit is contained in:
Родитель
1869f54deb
Коммит
0f9ea8b283
|
@ -19,7 +19,7 @@ add_task(function() {
|
|||
|
||||
let copyButton = document.getElementById("copy-button");
|
||||
ok(copyButton, "Copy button exists in Panel Menu");
|
||||
ok(!copyButton.getAttribute("disabled"), "Copy button is initially enabled");
|
||||
ok(copyButton.getAttribute("disabled"), "Copy button is initially disabled");
|
||||
|
||||
// copy text from URL bar
|
||||
gURLBar.value = testText;
|
||||
|
|
|
@ -18,7 +18,7 @@ add_task(function() {
|
|||
|
||||
let cutButton = document.getElementById("cut-button");
|
||||
ok(cutButton, "Cut button exists in Panel Menu");
|
||||
ok(!cutButton.hasAttribute("disabled"), "Cut button is enabled");
|
||||
ok(cutButton.hasAttribute("disabled"), "Cut button is disabled");
|
||||
|
||||
// cut text from URL bar
|
||||
gURLBar.value = testText;
|
||||
|
|
|
@ -39,8 +39,8 @@ add_task(function*() {
|
|||
is(cmdUndo.getAttribute("disabled"), "true", "cmdUndo is disabled");
|
||||
is(cmdDelete.getAttribute("disabled"), "true", "cmdDelete is disabled");
|
||||
is(cmdSelectAll.getAttribute("disabled"), "", "cmdSelectAll is enabled");
|
||||
is(cmdCut.getAttribute("disabled"), "true", "cmdCut is disabled");
|
||||
is(cmdCopy.getAttribute("disabled"), "true", "cmdCopy is disabled");
|
||||
is(cmdCut.getAttribute("disabled"), "", "cmdCut is enabled");
|
||||
is(cmdCopy.getAttribute("disabled"), "", "cmdCopy is enabled");
|
||||
is(cmdPaste.getAttribute("disabled"), "true", "cmdPaste is disabled");
|
||||
|
||||
info("Closing context menu");
|
||||
|
|
|
@ -39,8 +39,8 @@ add_task(function*() {
|
|||
is(cmdUndo.getAttribute("disabled"), "true", "cmdUndo is disabled");
|
||||
is(cmdDelete.getAttribute("disabled"), "true", "cmdDelete is disabled");
|
||||
is(cmdSelectAll.getAttribute("disabled"), "", "cmdSelectAll is enabled");
|
||||
is(cmdCut.getAttribute("disabled"), "true", "cmdCut is disabled");
|
||||
is(cmdCopy.getAttribute("disabled"), "true", "cmdCopy is disabled");
|
||||
is(cmdCut.getAttribute("disabled"), "", "cmdCut is enabled");
|
||||
is(cmdCopy.getAttribute("disabled"), "", "cmdCopy is enabled");
|
||||
is(cmdPaste.getAttribute("disabled"), "true", "cmdPaste is disabled");
|
||||
|
||||
info("Closing context menu");
|
||||
|
|
|
@ -486,14 +486,23 @@ nsClipboardCommand::IsCommandEnabled(const char* aCommandName, nsISupports *aCon
|
|||
*outCmdEnabled = false;
|
||||
|
||||
if (strcmp(aCommandName, "cmd_copy") &&
|
||||
strcmp(aCommandName, "cmd_copyAndCollapseToEnd"))
|
||||
strcmp(aCommandName, "cmd_copyAndCollapseToEnd") &&
|
||||
strcmp(aCommandName, "cmd_cut"))
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(aContext);
|
||||
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
|
||||
|
||||
nsCOMPtr<nsIDocument> doc = window->GetExtantDoc();
|
||||
*outCmdEnabled = nsCopySupport::CanCopy(doc);
|
||||
if (doc->IsHTMLOrXHTML()) {
|
||||
// In HTML and XHTML documents, we always want cut and copy commands to be enabled.
|
||||
*outCmdEnabled = true;
|
||||
} else {
|
||||
// Cut isn't enabled in xul documents which use nsClipboardCommand
|
||||
if (strcmp(aCommandName, "cmd_cut")) {
|
||||
*outCmdEnabled = nsCopySupport::CanCopy(doc);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -1201,7 +1201,10 @@ NS_IMETHODIMP nsPlaintextEditor::Cut()
|
|||
NS_IMETHODIMP nsPlaintextEditor::CanCut(bool *aCanCut)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aCanCut);
|
||||
*aCanCut = IsModifiable() && CanCutOrCopy(ePasswordFieldNotAllowed);
|
||||
// Cut is always enabled in HTML documents
|
||||
nsCOMPtr<nsIDocument> doc = GetDocument();
|
||||
*aCanCut = (doc && doc->IsHTMLOrXHTML()) ||
|
||||
(IsModifiable() && CanCutOrCopy(ePasswordFieldNotAllowed));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1216,7 +1219,10 @@ NS_IMETHODIMP nsPlaintextEditor::Copy()
|
|||
NS_IMETHODIMP nsPlaintextEditor::CanCopy(bool *aCanCopy)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aCanCopy);
|
||||
*aCanCopy = CanCutOrCopy(ePasswordFieldNotAllowed);
|
||||
// Copy is always enabled in HTML documents
|
||||
nsCOMPtr<nsIDocument> doc = GetDocument();
|
||||
*aCanCopy = (doc && doc->IsHTMLOrXHTML()) ||
|
||||
CanCutOrCopy(ePasswordFieldNotAllowed);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,9 +39,12 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1067255
|
|||
password.focus();
|
||||
password.select();
|
||||
|
||||
ok(!editor2.canCopy(), "can copy, password");
|
||||
ok(!editor2.canCut(), "can cut, password");
|
||||
ok(editor1.canDelete(), "can delete, password");
|
||||
// Copy and cut commands don't do anything on passoword fields by default,
|
||||
// but webpages can hook up event handlers to the event, and thus, we have to
|
||||
// always keep the cut and copy event enabled in HTML/XHTML documents.
|
||||
ok(editor2.canCopy(), "can copy, password");
|
||||
ok(editor2.canCut(), "can cut, password");
|
||||
ok(editor2.canDelete(), "can delete, password");
|
||||
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
|
|
@ -17,7 +17,8 @@ function goUpdateGlobalEditMenuItems()
|
|||
|
||||
goUpdateCommand("cmd_undo");
|
||||
goUpdateCommand("cmd_redo");
|
||||
// don't update the cmd_cut or cmd_copy items - as we want them to always be enabled
|
||||
goUpdateCommand("cmd_cut");
|
||||
goUpdateCommand("cmd_copy");
|
||||
goUpdateCommand("cmd_paste");
|
||||
goUpdateCommand("cmd_selectAll");
|
||||
goUpdateCommand("cmd_delete");
|
||||
|
|
|
@ -93,7 +93,7 @@ function goDoCommand(aCommand)
|
|||
try {
|
||||
var controller = top.document.commandDispatcher
|
||||
.getControllerForCommand(aCommand);
|
||||
if (controller)
|
||||
if (controller && controller.isCommandEnabled(aCommand))
|
||||
controller.doCommand(aCommand);
|
||||
}
|
||||
catch (e) {
|
||||
|
|
|
@ -36,3 +36,4 @@ skip-if = !e10s || !crashreporter
|
|||
support-files =
|
||||
file_redirect.html
|
||||
file_redirect_to.html
|
||||
[browser_bug1170531.js]
|
|
@ -0,0 +1,89 @@
|
|||
// Test for bug 1170531
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1170531
|
||||
|
||||
add_task(function* () {
|
||||
// Get a bunch of DOM nodes
|
||||
let winUtils = window.QueryInterface(Ci.nsIInterfaceRequestor).
|
||||
getInterface(Ci.nsIDOMWindowUtils);
|
||||
|
||||
let editMenu = document.getElementById("edit-menu");
|
||||
let menubar = editMenu.parentNode;
|
||||
let menuPopup = editMenu.menupopup;
|
||||
let editMenuIndex = -1;
|
||||
for (let i = 0; i < menubar.children.length; i++) {
|
||||
if (menubar.children[i] === editMenu) {
|
||||
editMenuIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let closeMenu = function(aCallback) {
|
||||
if (OS.Constants.Sys.Name == "Darwin") {
|
||||
executeSoon(aCallback);
|
||||
return;
|
||||
}
|
||||
|
||||
menuPopup.addEventListener("popuphidden", function onPopupHidden() {
|
||||
menuPopup.removeEventListener("popuphidden", onPopupHidden, false);
|
||||
executeSoon(aCallback);
|
||||
}, false);
|
||||
|
||||
executeSoon(function() {
|
||||
editMenu.open = false;
|
||||
});
|
||||
};
|
||||
|
||||
let openMenu = function(aCallback) {
|
||||
if (OS.Constants.Sys.Name == "Darwin") {
|
||||
goUpdateGlobalEditMenuItems();
|
||||
// On OSX, we have a native menu, so it has to be updated. In single process browsers,
|
||||
// this happens synchronously, but in e10s, we have to wait for the main thread
|
||||
// to deal with it for us. 1 second should be plenty of time.
|
||||
setTimeout(aCallback, 1000);
|
||||
return;
|
||||
}
|
||||
|
||||
menuPopup.addEventListener("popupshown", function onPopupShown() {
|
||||
menuPopup.removeEventListener("popupshown", onPopupShown, false);
|
||||
executeSoon(aCallback);
|
||||
}, false);
|
||||
|
||||
executeSoon(function() {
|
||||
editMenu.open = true;
|
||||
});
|
||||
};
|
||||
|
||||
yield BrowserTestUtils.withNewTab({ gBrowser: gBrowser, url: "about:blank" }, function* (browser) {
|
||||
let menu_cut_disabled, menu_copy_disabled;
|
||||
|
||||
yield BrowserTestUtils.loadURI(browser, "data:text/html,<div>hello!</div>");
|
||||
browser.focus();
|
||||
yield new Promise(resolve => waitForFocus(resolve, window));
|
||||
yield new Promise(openMenu);
|
||||
menu_cut_disabled = menuPopup.querySelector("#menu_cut").getAttribute('disabled') == "true";
|
||||
is(menu_cut_disabled, false, "menu_cut should be enabled");
|
||||
menu_copy_disabled = menuPopup.querySelector("#menu_copy").getAttribute('disabled') == "true";
|
||||
is(menu_copy_disabled, false, "menu_copy should be enabled");
|
||||
yield new Promise(closeMenu);
|
||||
|
||||
yield BrowserTestUtils.loadURI(browser, "data:text/html,<div contentEditable='true'>hello!</div>");
|
||||
browser.focus();
|
||||
yield new Promise(resolve => waitForFocus(resolve, window));
|
||||
yield new Promise(openMenu);
|
||||
menu_cut_disabled = menuPopup.querySelector("#menu_cut").getAttribute('disabled') == "true";
|
||||
is(menu_cut_disabled, false, "menu_cut should be enabled");
|
||||
menu_copy_disabled = menuPopup.querySelector("#menu_copy").getAttribute('disabled') == "true";
|
||||
is(menu_copy_disabled, false, "menu_copy should be enabled");
|
||||
yield new Promise(closeMenu);
|
||||
|
||||
yield BrowserTestUtils.loadURI(browser, "about:preferences");
|
||||
browser.focus();
|
||||
yield new Promise(resolve => waitForFocus(resolve, window));
|
||||
yield new Promise(openMenu);
|
||||
menu_cut_disabled = menuPopup.querySelector("#menu_cut").getAttribute('disabled') == "true";
|
||||
is(menu_cut_disabled, true, "menu_cut should be disabled");
|
||||
menu_copy_disabled = menuPopup.querySelector("#menu_copy").getAttribute('disabled') == "true";
|
||||
is(menu_copy_disabled, true, "menu_copy should be disabled");
|
||||
yield new Promise(closeMenu);
|
||||
});
|
||||
});
|
Загрузка…
Ссылка в новой задаче