From 9b02c5402dab38f3a30ff33b149ed70d1ff5364c Mon Sep 17 00:00:00 2001 From: Alexandre Poirot Date: Thu, 20 Nov 2014 10:48:00 -0500 Subject: [PATCH] Bug 1097814 - Fix fake hardware buttons in mulet. r=paul, r=vingtetun --- b2g/components/SystemAppProxy.jsm | 8 ++++- .../responsivedesign/responsivedesign.jsm | 32 +++++++++---------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/b2g/components/SystemAppProxy.jsm b/b2g/components/SystemAppProxy.jsm index 064b0af595f2..eec500de31a7 100644 --- a/b2g/components/SystemAppProxy.jsm +++ b/b2g/components/SystemAppProxy.jsm @@ -89,10 +89,16 @@ let SystemAppProxy = { }, // Now deprecated, use sendCustomEvent with a custom event name - dispatchEvent: function systemApp_sendChromeEvent(details, target) { + dispatchEvent: function systemApp_dispatchEvent(details, target) { return this._sendCustomEvent('mozChromeEvent', details, false, target); }, + dispatchKeyboardEvent: function systemApp_dispatchKeyboardEvent(type, details) { + let content = this._frame ? this._frame.contentWindow : null; + let e = new content.KeyboardEvent(type, details); + content.dispatchEvent(e); + }, + // Listen for dom events on the system app addEventListener: function systemApp_addEventListener() { let content = this._frame ? this._frame.contentWindow : null; diff --git a/browser/devtools/responsivedesign/responsivedesign.jsm b/browser/devtools/responsivedesign/responsivedesign.jsm index 4feb039976d6..9a1d506ca7b1 100644 --- a/browser/devtools/responsivedesign/responsivedesign.jsm +++ b/browser/devtools/responsivedesign/responsivedesign.jsm @@ -482,11 +482,11 @@ ResponsiveUI.prototype = { sleepButton.className = "devtools-responsiveui-sleep-button"; sleepButton.setAttribute("top", 0); sleepButton.setAttribute("right", 0); - sleepButton.addEventListener("mousedown", function() { - SystemAppProxy.dispatchEvent({type: "sleep-button-press"}); + sleepButton.addEventListener("mousedown", () => { + SystemAppProxy.dispatchKeyboardEvent("keydown", {key: "Power"}); }); - sleepButton.addEventListener("mouseup", function() { - SystemAppProxy.dispatchEvent({type: "sleep-button-release"}); + sleepButton.addEventListener("mouseup", () => { + SystemAppProxy.dispatchKeyboardEvent("keyup", {key: "Power"}); }); this.stack.appendChild(sleepButton); @@ -497,20 +497,20 @@ ResponsiveUI.prototype = { let volumeUp = this.chromeDoc.createElement("button"); volumeUp.className = "devtools-responsiveui-volume-up-button"; - volumeUp.addEventListener("mousedown", function() { - SystemAppProxy.dispatchEvent({type: "volume-up-button-press"}); + volumeUp.addEventListener("mousedown", () => { + SystemAppProxy.dispatchKeyboardEvent("keydown", {key: "VolumeUp"}); }); - volumeUp.addEventListener("mouseup", function() { - SystemAppProxy.dispatchEvent({type: "volume-up-button-release"}); + volumeUp.addEventListener("mouseup", () => { + SystemAppProxy.dispatchKeyboardEvent("keyup", {key: "VolumeUp"}); }); let volumeDown = this.chromeDoc.createElement("button"); volumeDown.className = "devtools-responsiveui-volume-down-button"; - volumeDown.addEventListener("mousedown", function() { - SystemAppProxy.dispatchEvent({type: "volume-down-button-press"}); + volumeDown.addEventListener("mousedown", () => { + SystemAppProxy.dispatchKeyboardEvent("keydown", {key: "VolumeDown"}); }); - volumeDown.addEventListener("mouseup", function() { - SystemAppProxy.dispatchEvent({type: "volume-down-button-release"}); + volumeDown.addEventListener("mouseup", () => { + SystemAppProxy.dispatchKeyboardEvent("keyup", {key: "VolumeDown"}); }); volumeButtons.appendChild(volumeUp); @@ -524,11 +524,11 @@ ResponsiveUI.prototype = { let homeButton = this.chromeDoc.createElement("toolbarbutton"); homeButton.className = "devtools-responsiveui-toolbarbutton devtools-responsiveui-home-button"; - homeButton.addEventListener("mousedown", function() { - SystemAppProxy.dispatchEvent({type: "home-button-press"}); + homeButton.addEventListener("mousedown", () => { + SystemAppProxy.dispatchKeyboardEvent("keydown", {key: "Home"}); }); - homeButton.addEventListener("mouseup", function() { - SystemAppProxy.dispatchEvent({type: "home-button-release"}); + homeButton.addEventListener("mouseup", () => { + SystemAppProxy.dispatchKeyboardEvent("keyup", {key: "Home"}); }); bottomToolbar.appendChild(homeButton); this.bottomToolbar = bottomToolbar;