Index

HardwareButtons

new HardwareButtons()

Gecko code in b2g/chrome/content/shell.js sends mozChromeEvents
when the user presses or releases a hardware button such as Home, Sleep,
and Volume Up and Down.


This module listens for those low-level mozChromeEvents, processes them
and generates higher-level events to handle autorepeat on the volume keys
long presses on Home and Sleep, and the Home+Sleep key combination.


Other system app modules should listen for the high-level button events
generated by this module.


The low-level input events processed by this module have type set
to mozChromeEvent and detail.type set to one of:



  • home-button-press

  • home-button-release

  • sleep-button-press

  • sleep-button-release

  • volume-up-button-press

  • volume-up-button-release

  • volume-down-button-press

  • volume-down-button-release


The high-level events generated by this module are simple Event objects
that are not cancelable and do not bubble. The are dispatched at the
window object. The type property is set to one of these:











































Event TypeMeaning
homeshort press and release of home button
holdhomelong press and hold of home button
sleepshort press and release of sleep button
wakesleep or home pressed while sleeping
holdsleeplong press and hold of sleep button
volumeupvolume up pressed and released or autorepeated
volumedownvolume down pressed and released or autorepeated
home+sleephome and sleep pressed at same time (used for screenshots)

Because these events are fired at the window object, they cannot be
captured. Many modules listen for the home event. Those that want
to respond to it and prevent others from responding should call
stopImmediatePropagation(). Overlays that want to prevent the window
manager from showing the homescreen on the home event should call that
method. Note, however, that this only works for scripts that run and
register their event handlers before AppWindowManager does.


As of the implementation itself, we process events with a
finite state machine.
Each state object has a process() method for handling events.
And optionally has enter() and exit() methods called when the FSM
enters and exits that state.

Example
var hardwareButtons = new HardwareButtons();
hardwareButtons.start(); // Attach the event listeners.
hardwareButtons.stop();  // Deattach the event listeners.

Members

HOLD_INTERVAL :Number

How long for press and hold Home or Sleep.

REPEAT_DELAY :Number

How long before volume autorepeat begins.

REPEAT_INTERVAL :Number

How fast the autorepeat is.

Methods

handleEvent(evt)

Handle events from Gecko.

Parameters:
Name Type Description
evt Object

Event.

publish(type)

Dispatch a high-level event of the specified type.

Parameters:
Name Type Description
type String

name of the event.

setState(s, type)

Transit the FSM to a new state.

Parameters:
Name Type Description
s String

Keyword of the new state to switch to.

type String

Name of the event to handle

start()

Start listening to events from Gecko and FSM.

stop()

Stop listening to events. Must call before throwing away the instance
to avoid memory leaks.