Bug 692153 Make Copy and Select All always work even when contenteditable areas are present r=ehsan

This commit is contained in:
Neil Rashbrook 2011-12-30 17:42:04 +00:00
parent a9fa22ee9c
commit 02c6a3f7d4
2 changed files with 12 additions and 23 deletions

View File

@ -320,13 +320,7 @@ nsCopyCommand::IsCommandEnabled(const char * aCommandName,
NS_ENSURE_ARG_POINTER(outCmdEnabled);
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
if (editor)
{
bool isEditable = false;
nsresult rv = editor->GetIsSelectionEditable(&isEditable);
NS_ENSURE_SUCCESS(rv, rv);
if (isEditable)
return editor->CanCopy(outCmdEnabled);
}
return editor->CanCopy(outCmdEnabled);
*outCmdEnabled = false;
return NS_OK;
@ -663,19 +657,14 @@ nsSelectAllCommand::IsCommandEnabled(const char * aCommandName,
nsresult rv = NS_OK;
*outCmdEnabled = false;
bool docIsEmpty, selectionIsEditable;
bool docIsEmpty;
// you can select all if there is an editor which is non-empty
nsCOMPtr<nsIEditor> editor = do_QueryInterface(aCommandRefCon);
if (editor) {
rv = editor->GetIsSelectionEditable(&selectionIsEditable);
rv = editor->GetDocumentIsEmpty(&docIsEmpty);
NS_ENSURE_SUCCESS(rv, rv);
if (selectionIsEditable) {
rv = editor->GetDocumentIsEmpty(&docIsEmpty);
NS_ENSURE_SUCCESS(rv, rv);
*outCmdEnabled = !docIsEmpty;
}
*outCmdEnabled = !docIsEmpty;
}
return rv;

View File

@ -32,13 +32,13 @@ SimpleTest.waitForFocus(runTests);
var gBlock1, gBlock2;
function IsCommandEnabled(command) {
function IsCommandEnabled(command, alwaysEnabled) {
var enabled;
// non-editable div: should return false
// non-editable div: should return false unless alwaysEnabled
window.getSelection().selectAllChildren(gBlock1);
enabled = document.queryCommandEnabled(command);
is(enabled, false, "'" + command + "' should not be enabled on a non-editable block.");
is(enabled, alwaysEnabled, "'" + command + "' should not be enabled on a non-editable block.");
// editable div: should return true
window.getSelection().selectAllChildren(gBlock2);
@ -67,15 +67,15 @@ function runTests() {
];
document.execCommand("styleWithCSS", false, false);
for (i = 0; i < commands.length; i++)
IsCommandEnabled(commands[i]);
IsCommandEnabled(commands[i], commands[i] == "selectAll");
document.execCommand("styleWithCSS", false, true);
for (i = 0; i < commands.length; i++)
IsCommandEnabled(commands[i]);
IsCommandEnabled(commands[i], commands[i] == "selectAll");
// Mozilla-specific stuff
commands = ["enableInlineTableEditing", "enableObjectResizing", "insertBrOnReturn"];
for (i = 0; i < commands.length; i++)
IsCommandEnabled(commands[i]);
IsCommandEnabled(commands[i], false);
// cut/copy/paste -- SpecialPowers required
SpecialPowers.setCharPref("capability.policy.policynames", "allowclipboard");
@ -84,7 +84,7 @@ function runTests() {
SpecialPowers.setCharPref("capability.policy.allowclipboard.Clipboard.paste", "allAccess");
commands = ["cut", "paste", "copy"];
for (i = 0; i < commands.length; i++) {
IsCommandEnabled(commands[i]);
IsCommandEnabled(commands[i], commands[i] == "copy");
document.execCommand(commands[i], false, false);
}
SpecialPowers.clearUserPref("capability.policy.policynames");
@ -97,7 +97,7 @@ function runTests() {
// * there's nothing to redo if we haven't undone something first
commands = ["delete", "undo", "redo"];
for (i = 0; i < commands.length; i++) {
IsCommandEnabled(commands[i]);
IsCommandEnabled(commands[i], false);
document.execCommand(commands[i], false, false);
}