2014-01-22 19:06:46 +00:00
|
|
|
/* 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/. */
|
2014-01-15 14:28:04 +00:00
|
|
|
|
2014-03-19 12:38:59 +00:00
|
|
|
// Enable touch event shim on desktop that translates mouse events
|
|
|
|
// into touch ones
|
|
|
|
function enableTouch() {
|
|
|
|
let require = Cu.import('resource://gre/modules/devtools/Loader.jsm', {})
|
2014-01-15 14:28:04 +00:00
|
|
|
.devtools.require;
|
2014-03-19 12:38:59 +00:00
|
|
|
let { TouchEventHandler } = require('devtools/touch-events');
|
2014-01-22 19:06:46 +00:00
|
|
|
let chromeEventHandler = window.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(Ci.nsIDocShell)
|
|
|
|
.chromeEventHandler || window;
|
|
|
|
let touchEventHandler = new TouchEventHandler(chromeEventHandler);
|
2014-01-15 14:28:04 +00:00
|
|
|
touchEventHandler.start();
|
2014-03-19 12:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function setupHomeButton() {
|
|
|
|
let homeButton = document.getElementById('home-button');
|
|
|
|
if (!homeButton) {
|
|
|
|
// The toolbar only exists in b2g desktop build with
|
|
|
|
// FXOS_SIMULATOR turned on.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// The touch event helper is enabled on shell.html document,
|
|
|
|
// so that click events are delayed and it is better to
|
|
|
|
// listen for touch events.
|
|
|
|
homeButton.addEventListener('touchstart', function() {
|
|
|
|
shell.sendChromeEvent({type: 'home-button-press'});
|
|
|
|
homeButton.classList.add('active');
|
|
|
|
});
|
|
|
|
homeButton.addEventListener('touchend', function() {
|
|
|
|
shell.sendChromeEvent({type: 'home-button-release'});
|
|
|
|
homeButton.classList.remove('active');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener('ContentStart', function() {
|
|
|
|
enableTouch();
|
|
|
|
setupHomeButton();
|
2014-01-15 14:28:04 +00:00
|
|
|
});
|