michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // Enable touch event shim on desktop that translates mouse events michael@0: // into touch ones michael@0: function enableTouch() { michael@0: let require = Cu.import('resource://gre/modules/devtools/Loader.jsm', {}) michael@0: .devtools.require; michael@0: let { TouchEventHandler } = require('devtools/touch-events'); michael@0: let chromeEventHandler = window.QueryInterface(Ci.nsIInterfaceRequestor) michael@0: .getInterface(Ci.nsIWebNavigation) michael@0: .QueryInterface(Ci.nsIDocShell) michael@0: .chromeEventHandler || window; michael@0: let touchEventHandler = new TouchEventHandler(chromeEventHandler); michael@0: touchEventHandler.start(); michael@0: } michael@0: michael@0: function setupButtons() { michael@0: let homeButton = document.getElementById('home-button'); michael@0: if (!homeButton) { michael@0: // The toolbar only exists in b2g desktop build with michael@0: // FXOS_SIMULATOR turned on. michael@0: return; michael@0: } michael@0: // The touch event helper is enabled on shell.html document, michael@0: // so that click events are delayed and it is better to michael@0: // listen for touch events. michael@0: homeButton.addEventListener('touchstart', function() { michael@0: shell.sendChromeEvent({type: 'home-button-press'}); michael@0: homeButton.classList.add('active'); michael@0: }); michael@0: homeButton.addEventListener('touchend', function() { michael@0: shell.sendChromeEvent({type: 'home-button-release'}); michael@0: homeButton.classList.remove('active'); michael@0: }); michael@0: michael@0: Cu.import("resource://gre/modules/GlobalSimulatorScreen.jsm"); michael@0: let rotateButton = document.getElementById('rotate-button'); michael@0: rotateButton.addEventListener('touchstart', function () { michael@0: rotateButton.classList.add('active'); michael@0: }); michael@0: rotateButton.addEventListener('touchend', function() { michael@0: GlobalSimulatorScreen.flipScreen(); michael@0: rotateButton.classList.remove('active'); michael@0: }); michael@0: } michael@0: michael@0: function checkDebuggerPort() { michael@0: // XXX: To be removed once bug 942756 lands. michael@0: // We are hacking 'unix-domain-socket' pref by setting a tcp port (number). michael@0: // DebuggerServer.openListener detects that it isn't a file path (string), michael@0: // and starts listening on the tcp port given here as command line argument. michael@0: michael@0: if (!window.arguments) { michael@0: return; michael@0: } michael@0: michael@0: // Get the command line arguments that were passed to the b2g client michael@0: let args = window.arguments[0].QueryInterface(Ci.nsICommandLine); michael@0: michael@0: let dbgport; michael@0: try { michael@0: dbgport = args.handleFlagWithParam('start-debugger-server', false); michael@0: } catch(e) {} michael@0: michael@0: if (dbgport) { michael@0: dump('Opening debugger server on ' + dbgport + '\n'); michael@0: Services.prefs.setCharPref('devtools.debugger.unix-domain-socket', dbgport); michael@0: navigator.mozSettings.createLock().set( michael@0: {'debugger.remote-mode': 'adb-devtools'}); michael@0: } michael@0: } michael@0: michael@0: window.addEventListener('ContentStart', function() { michael@0: enableTouch(); michael@0: setupButtons(); michael@0: checkDebuggerPort(); michael@0: });