Bug 574036 - HUD Console should allow copying text, r=sdwilsh

This commit is contained in:
Mihai Sucan 2010-08-10 09:37:29 -03:00
Родитель 9d74affc33
Коммит b59d45daec
5 изменённых файлов: 92 добавлений и 2 удалений

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

@ -1675,6 +1675,8 @@ function HeadsUpDisplay(aConfig)
this.XULFactory = NodeFactory("xul", "xul", this.chromeDocument); this.XULFactory = NodeFactory("xul", "xul", this.chromeDocument);
this.textFactory = NodeFactory("text", "xul", this.chromeDocument); this.textFactory = NodeFactory("text", "xul", this.chromeDocument);
this.chromeWindow = HUDService.getChromeWindowFromContentWindow(this.contentWindow);
// create a panel dynamically and attach to the parentNode // create a panel dynamically and attach to the parentNode
let hudBox = this.createHUD(); let hudBox = this.createHUD();
@ -1760,9 +1762,15 @@ HeadsUpDisplay.prototype = {
{ {
this.hudId = this.HUDBox.getAttribute("id"); this.hudId = this.HUDBox.getAttribute("id");
// set outputNode
this.outputNode = this.HUDBox.querySelectorAll(".hud-output-node")[0]; this.outputNode = this.HUDBox.querySelectorAll(".hud-output-node")[0];
this.contextMenu = this.HUDBox.querySelector("#" + this.hudId +
"-output-contextmenu");
this.copyOutputMenuItem = this.HUDBox.
querySelector("menuitem[command=cmd_copy]");
this.chromeWindow = HUDService.
getChromeWindowFromContentWindow(this.contentWindow);
this.chromeDocument = this.HUDBox.ownerDocument; this.chromeDocument = this.HUDBox.ownerDocument;
if (this.outputNode) { if (this.outputNode) {
@ -1867,6 +1875,7 @@ HeadsUpDisplay.prototype = {
this.outputNode = this.makeXULNode("vbox"); this.outputNode = this.makeXULNode("vbox");
this.outputNode.setAttribute("class", "hud-output-node"); this.outputNode.setAttribute("class", "hud-output-node");
this.outputNode.setAttribute("flex", "1"); this.outputNode.setAttribute("flex", "1");
this.outputNode.setAttribute("context", this.hudId + "-output-contextmenu");
this.filterSpacer = this.makeXULNode("spacer"); this.filterSpacer = this.makeXULNode("spacer");
this.filterSpacer.setAttribute("flex", "1"); this.filterSpacer.setAttribute("flex", "1");
@ -1887,6 +1896,16 @@ HeadsUpDisplay.prototype = {
var command = "HUDConsoleUI.command(this)"; var command = "HUDConsoleUI.command(this)";
this.consoleClearButton.setAttribute("oncommand", command); this.consoleClearButton.setAttribute("oncommand", command);
this.copyOutputMenuItem = this.makeXULNode("menuitem");
this.copyOutputMenuItem.setAttribute("label", this.getStr("copyCmd.label"));
this.copyOutputMenuItem.setAttribute("accesskey", this.getStr("copyCmd.accesskey"));
this.copyOutputMenuItem.setAttribute("key", "key_copy");
this.copyOutputMenuItem.setAttribute("command", "cmd_copy");
this.contextMenu = this.makeXULNode("menupopup");
this.contextMenu.setAttribute("id", this.hudId + "-output-contextmenu");
this.contextMenu.appendChild(this.copyOutputMenuItem);
this.filterPrefs = HUDService.getDefaultFilterPrefs(this.hudId); this.filterPrefs = HUDService.getDefaultFilterPrefs(this.hudId);
let consoleFilterToolbar = this.makeFilterToolbar(); let consoleFilterToolbar = this.makeFilterToolbar();
@ -1895,6 +1914,11 @@ HeadsUpDisplay.prototype = {
consoleWrap.appendChild(consoleFilterToolbar); consoleWrap.appendChild(consoleFilterToolbar);
consoleWrap.appendChild(this.outputNode); consoleWrap.appendChild(this.outputNode);
// We want the context menu inside the console wrapper, but outside the
// outputNode.
outerWrap.appendChild(this.contextMenu);
outerWrap.appendChild(consoleWrap); outerWrap.appendChild(consoleWrap);
this.HUDBox.lastTimestamp = 0; this.HUDBox.lastTimestamp = 0;

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

@ -747,7 +747,7 @@ function testDuplicateError() {
"found test-duplicate-error.html"); "found test-duplicate-error.html");
text = null; text = null;
testWebConsoleClose(); testCopyOutputMenuItem();
}); });
} }
}; };
@ -756,6 +756,68 @@ function testDuplicateError() {
content.location = TEST_DUPLICATE_ERROR_URI; content.location = TEST_DUPLICATE_ERROR_URI;
} }
function testCopyOutputMenuItem()
{
// See bug 574036 - HUD Console should allow copying text.
// https://bugzilla.mozilla.org/show_bug.cgi?id=574036
var HUD = HUDService.hudWeakReferences[hudId].get();
var selection = getSelection();
var console = content.wrappedJSObject.console;
if (selection.rangeCount > 0) {
selection.removeAllRanges();
}
// Test 1: check that the copyOutputMenuItem is disabled
HUD.contextMenu.addEventListener("popupshown", function () {
HUD.contextMenu.removeEventListener("popupshown", arguments.callee, false);
// Skip the test on Linux, because the menu is always enabled.
// See bug 584972 - https://bugzilla.mozilla.org/show_bug.cgi?id=584972
if (navigator.platform.indexOf("Linux") == -1) {
ok(HUD.copyOutputMenuItem.disabled, "HUD.copyOutputMenuItem is disabled");
}
console.log("Hello world!");
var range = HUD.chromeDocument.createRange();
range.selectNode(HUD.outputNode.firstChild);
selection.addRange(range);
// Test 2: check that the copyOutputMenuItem is enabled, because a node is
// selected.
HUD.contextMenu.addEventListener("popupshown", function () {
HUD.contextMenu.removeEventListener("popupshown", arguments.callee,
false);
ok(!HUD.copyOutputMenuItem.disabled, "HUD.copyOutputMenuItem is enabled");
selection.removeAllRanges();
// We are done, close the contextmenu now.
EventUtils.synthesizeKey("VK_ESCAPE", {});
testWebConsoleClose();
}, false);
HUD.contextMenu.addEventListener("popuphidden", function () {
HUD.contextMenu.removeEventListener("popuphidden", arguments.callee,
false);
// Show the context menu again.
EventUtils.synthesizeMouse(HUD.outputNode, 2, 2, {type: "contextmenu",
button: 2});
}, false);
// We need to hide the context menu, before we can show it again.
EventUtils.synthesizeKey("VK_ESCAPE", {});
}, false);
EventUtils.synthesizeMouse(HUD.outputNode, 1, 1, {type: "contextmenu",
button: 2});
}
/** /**
* Unit test for bug 580001: * Unit test for bug 580001:
* 'Close console after completion causes error "inputValue is undefined"' * 'Close console after completion causes error "inputValue is undefined"'

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

@ -36,3 +36,5 @@ localConsole=Local Console
btnClear=Clear Console btnClear=Clear Console
tipClear=Clear the console output tipClear=Clear the console output
stringFilter=Filter stringFilter=Filter
copyCmd.label=Copy
copyCmd.accesskey=C

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

@ -58,6 +58,7 @@
.hud-output-node div { .hud-output-node div {
-moz-user-select: text; -moz-user-select: text;
white-space: pre-wrap; white-space: pre-wrap;
-moz-user-focus: normal;
} }
.hud-output-node .hud-network { .hud-output-node .hud-network {

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

@ -59,6 +59,7 @@
.hud-output-node div { .hud-output-node div {
-moz-user-select: text; -moz-user-select: text;
white-space: pre-wrap; white-space: pre-wrap;
-moz-user-focus: normal;
} }
.hud-output-node .hud-network { .hud-output-node .hud-network {