Bug 1342297 - Propagate keypress events from the child frames to the toolbox. r=ochameau
MozReview-Commit-ID: 3u17W167bdi
--- a/devtools/client/framework/toolbox.js
+++ b/devtools/client/framework/toolbox.js
@@ -1423,16 +1423,19 @@ Toolbox.prototype = {
let onLoad = () => {
// Prevent flicker while loading by waiting to make visible until now.
iframe.style.visibility = "visible";
// Try to set the dir attribute as early as possible.
this.setIframeDocumentDir(iframe);
+ // Propagate keypress event from frame to toolbox
+ this.setIframeKeypressListener(iframe);
+
// The build method should return a panel instance, so events can
// be fired with the panel as an argument. However, in order to keep
// backward compatibility with existing extensions do a check
// for a promise return value.
let built = definition.build(iframe.contentWindow, this);
if (!(typeof built.then == "function")) {
let panel = built;
@@ -1524,16 +1527,31 @@ Toolbox.prototype = {
let top = this.win.top;
let topDocEl = top.document.documentElement;
let isRtl = top.getComputedStyle(topDocEl).direction === "rtl";
docEl.setAttribute("dir", isRtl ? "rtl" : "ltr");
}
},
/**
+ * Due to the use of content event handling, keypress events in the child iframes
+ * are not propagated to the toolbox window
+ *
+ * @param {IframeElement} iframe
+ */
+ setIframeKeypressListener: function (iframe) {
+ iframe.contentWindow.addEventListener("keypress", (e) => {
+ for (let eventName of ["keypress", "keydown", "keyup"]) {
+ let event = new this.win.KeyboardEvent(eventName, e);
+ this.doc.dispatchEvent(event);
+ }
+ });
+ },
+
+ /**
* Mark all in collection as unselected; and id as selected
* @param {string} collection
* DOM collection of items
* @param {string} id
* The Id of the item within the collection to select
*/
selectSingleNode: function (collection, id) {
[...collection].forEach(node => {