Bug 960695 - Focus Input line when clicking anywhere in the console; r=msucan
authorRob Campbell <rcampbell@mozilla.com>
Thu, 16 Jan 2014 11:57:00 -0500
changeset 164529 f5fb918f295fdfe623accce4044fcf280d54a53e
parent 164528 2f002462b96d7fdbdd739251fe55316852e7526b
child 164530 31dca1ad8cfb22f3e15365c4dedb7399f459f7c4
push id26050
push userkwierso@gmail.com
push dateWed, 22 Jan 2014 01:28:12 +0000
treeherdermozilla-central@8f4ecbf938cd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmsucan
bugs960695
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 960695 - Focus Input line when clicking anywhere in the console; r=msucan
browser/devtools/webconsole/test/browser.ini
browser/devtools/webconsole/test/browser_console_click_focus.js
browser/devtools/webconsole/webconsole.js
--- a/browser/devtools/webconsole/test/browser.ini
+++ b/browser/devtools/webconsole/test/browser.ini
@@ -110,16 +110,17 @@ support-files =
 [browser_bug_865288_repeat_different_objects.js]
 [browser_bug_865871_variables_view_close_on_esc_key.js]
 [browser_bug_869003_inspect_cross_domain_object.js]
 [browser_bug_871156_ctrlw_close_tab.js]
 [browser_cached_messages.js]
 [browser_console.js]
 [browser_console_addonsdk_loader_exception.js]
 [browser_console_clear_on_reload.js]
+[browser_console_click_focus.js]
 [browser_console_consolejsm_output.js]
 [browser_console_dead_objects.js]
 [browser_console_error_source_click.js]
 [browser_console_filters.js]
 [browser_console_iframe_messages.js]
 [browser_console_keyboard_accessibility.js]
 [browser_console_log_inspectable_object.js]
 [browser_console_native_getters.js]
new file mode 100644
--- /dev/null
+++ b/browser/devtools/webconsole/test/browser_console_click_focus.js
@@ -0,0 +1,40 @@
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// Tests that the input field is focused when the console is opened.
+
+const TEST_URI = "http://example.com/browser/browser/devtools/webconsole/test/test-console.html";
+
+function test() {
+  addTab(TEST_URI);
+  browser.addEventListener("DOMContentLoaded", testInputFocus, false);
+}
+
+function testInputFocus() {
+  browser.removeEventListener("DOMContentLoaded", testInputFocus, false);
+
+  openConsole().then((hud) => {
+    let inputNode = hud.jsterm.inputNode;
+    ok(inputNode.getAttribute("focused"), "input node is focused");
+
+    let lostFocus = () => {
+      inputNode.removeEventListener("blur", lostFocus);
+      info("input node lost focus");
+    }
+
+   	inputNode.addEventListener("blur", lostFocus);
+
+   	browser.ownerDocument.getElementById("urlbar").click();
+
+  	ok(!inputNode.getAttribute("focused"), "input node is not focused");
+
+   	hud.outputNode.click();
+
+   	ok(inputNode.getAttribute("focused"), "input node is focused");
+
+      finishTest();
+  });
+}
+
--- a/browser/devtools/webconsole/webconsole.js
+++ b/browser/devtools/webconsole/webconsole.js
@@ -564,16 +564,29 @@ WebConsoleFrame.prototype = {
     this.jsterm.init();
     this.jsterm.inputNode.focus();
 
     let toolbox = gDevTools.getToolbox(this.owner.target);
     if (toolbox) {
       toolbox.on("webconsole-selected", this._onPanelSelected);
     }
 
+    /*
+     * Focus input line whenever the output area is clicked.
+     * Only focus when the target node (or parent, as in source links) is
+     * not an anchor.
+     */
+    this.outputNode.addEventListener("click", (e) => {
+      if ((e.button == 0) &&
+          (e.target.nodeName.toLowerCase() != "a") &&
+          (e.target.parentNode.nodeName.toLowerCase() != "a")) {
+        this.jsterm.inputNode.focus();
+      }
+    });
+
     // Toggle the timestamp on preference change
     gDevTools.on("pref-changed", this._onToolboxPrefChanged);
     this._onToolboxPrefChanged("pref-changed", {
       pref: PREF_MESSAGE_TIMESTAMP,
       newValue: Services.prefs.getBoolPref(PREF_MESSAGE_TIMESTAMP),
     });
   },