Closed Bug 1097814 Opened 5 years ago Closed 5 years ago

Software buttons are broken in mulet and simulator

Categories

(Firefox OS Graveyard :: Simulator, defect)

defect
Not set

Tracking

(Not tracked)

RESOLVED FIXED
2.2 S1 (5dec)

People

(Reporter: ochameau, Assigned: ochameau)

References

Details

Attachments

(2 files, 3 obsolete files)

Bug 1014418 most likely regressed these features. It looks like we need to send other kinds of events to gaia now (don't know yet what?).
We used to send mozChromeEvent to the system app.
Hi Alexandre,

Did you mean software home buttons or software buttons you simulate in mulet and simulator?

If you mean the latter, this is because after bug 1014418 landed, system app no longer listens to mozChromeEvent.
Bug 989198 made KeyboardEvents dispatched across browser elements. System app now listens to KeyboardEvent and BeforeAfterKeyboardEvent introduced in bug 989198.

This page describe the whole scenario:   https://wiki.mozilla.org/WebAPI/BrowserAPI/KeyboardEvent#Dispatch_KeyboardEvent_across_BrowserElements

BeforeAfterKeyboardEvent is currently enabled in b2g only, with the pref 'dom.beforeAfterKeyboardEvent.enabled' set to true.
(In reply to Tzu-Lin Huang [:dwi2][:tzhuang] from comment #1)
> Did you mean software home buttons or software buttons you simulate in mulet
> and simulator?

Yes, the ones in mulet, simulator and fx nightly mode.
It's not really clear how we can implement software buttons now.
Before all these patches, pressing the HOME or END key of your keyboard was like pressing your home button and power button of your device.
Now it no longer works.

We used to send mozChromeEvent.
I tried dispatching fake KeyboardEvent and/or BeforeAfterKeyboardEvent, but nothing appear to work.
What precise kind of event should I dispatch on the system app to make it work??

Here is what I tried:
  let systemAppContentWindow;
  let KeyEvent = systemAppContentWindow.KeyEvent;
  var e = new systemAppContentWindow.KeyboardEvent("keydown", {keyCode: KeyEvent.DOM_VK_HOME});
  // Replacing KeyboardEvent with BeforeAfterKeyboardEvent doesn't change anything
  // Dispatching keydown, keyup or keypress doesn't work
  systemAppContentWindow.dispatchEvent(e); 

Or should I directly fake some mozbrowserbeforekeydown events?!
Flags: needinfo?(tzhuang)
Hi Alexandre, 

What you tried is almost right, except that you need to change {keyCode: KeyEvent.DOM_VK_HOME} to {key: 'Home'}. This is because we try to follow DOM level 3 definition.

Here is the key mapping:
  Home key: 'Home'
  Power key: 'Power'
  Volume up key: 'VolumeUp'
  Volume down key: 'VolumeDown'

I tried your code snippet with key definition above. And it works on mulet.

  let systemAppContentWindow;
  let KeyEvent = systemAppContentWindow.KeyEvent;
  var e = new systemAppContentWindow.KeyboardEvent("keydown", {key: "Home"});
  systemAppContentWindow.dispatchEvent(e); 

Also I press the HOME key on my physical keyboard when I use mulet, it also works.
Flags: needinfo?(tzhuang)
Assignee: nobody → poirot.alex
Summary: Sofware buttons are broken in mulet and simulator → Software buttons are broken in mulet and simulator
Comment on attachment 8524143 [details] [diff] [review]
b2g desktop patch

Review of attachment 8524143 [details] [diff] [review]:
-----------------------------------------------------------------

::: b2g/chrome/content/desktop.js
@@ +30,5 @@
>    // so that click events are delayed and it is better to
>    // listen for touch events.
>    homeButton.addEventListener('touchstart', function() {
> +    let window = shell.contentBrowser.contentWindow;
> +    let e = new window.KeyboardEvent("keydown", {key: "Home"});

As much as I prefer double quotes for strings, it looks like this file foolishly mixes quote style but uses single quotes in the functions touched by this patch.
Attachment #8524143 - Flags: review?(fabrice) → review+
I had to expose the system app frame from SystemAppProxy
in order to dispatch the KeyboardEvents... (instead of mozChromeEvent)
Attachment #8524396 - Flags: review?(paul)
Attachment #8524396 - Flags: review?(21)
Attached patch b2g desktop patch (obsolete) — Splinter Review
Fixed quotes.
Attachment #8524143 - Attachment is obsolete: true
Attachment #8524507 - Flags: review+
Really fix them...
Attachment #8524507 - Attachment is obsolete: true
Attachment #8524567 - Flags: review+
Attachment #8524396 - Flags: review?(paul) → review+
No longer expose system app frame.
Exposes a helper on SystemAppProxy instead.
Attachment #8524396 - Attachment is obsolete: true
Attachment #8524396 - Flags: review?(21)
Attachment #8526178 - Flags: review?(21)
Comment on attachment 8526178 [details] [diff] [review]
responsive design patch for mulet

Review of attachment 8526178 [details] [diff] [review]:
-----------------------------------------------------------------

Carry over review from paul and got offline r+ from vivien.
Attachment #8526178 - Flags: review?(21) → review+
Checking needed for the second patch.
https://hg.mozilla.org/mozilla-central/rev/dcdd75b0017f
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → 2.2 S1 (5dec)
You need to log in before you can comment on or make changes to this bug.