1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/b2g/chrome/content/desktop.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,79 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +// Enable touch event shim on desktop that translates mouse events 1.9 +// into touch ones 1.10 +function enableTouch() { 1.11 + let require = Cu.import('resource://gre/modules/devtools/Loader.jsm', {}) 1.12 + .devtools.require; 1.13 + let { TouchEventHandler } = require('devtools/touch-events'); 1.14 + let chromeEventHandler = window.QueryInterface(Ci.nsIInterfaceRequestor) 1.15 + .getInterface(Ci.nsIWebNavigation) 1.16 + .QueryInterface(Ci.nsIDocShell) 1.17 + .chromeEventHandler || window; 1.18 + let touchEventHandler = new TouchEventHandler(chromeEventHandler); 1.19 + touchEventHandler.start(); 1.20 +} 1.21 + 1.22 +function setupButtons() { 1.23 + let homeButton = document.getElementById('home-button'); 1.24 + if (!homeButton) { 1.25 + // The toolbar only exists in b2g desktop build with 1.26 + // FXOS_SIMULATOR turned on. 1.27 + return; 1.28 + } 1.29 + // The touch event helper is enabled on shell.html document, 1.30 + // so that click events are delayed and it is better to 1.31 + // listen for touch events. 1.32 + homeButton.addEventListener('touchstart', function() { 1.33 + shell.sendChromeEvent({type: 'home-button-press'}); 1.34 + homeButton.classList.add('active'); 1.35 + }); 1.36 + homeButton.addEventListener('touchend', function() { 1.37 + shell.sendChromeEvent({type: 'home-button-release'}); 1.38 + homeButton.classList.remove('active'); 1.39 + }); 1.40 + 1.41 + Cu.import("resource://gre/modules/GlobalSimulatorScreen.jsm"); 1.42 + let rotateButton = document.getElementById('rotate-button'); 1.43 + rotateButton.addEventListener('touchstart', function () { 1.44 + rotateButton.classList.add('active'); 1.45 + }); 1.46 + rotateButton.addEventListener('touchend', function() { 1.47 + GlobalSimulatorScreen.flipScreen(); 1.48 + rotateButton.classList.remove('active'); 1.49 + }); 1.50 +} 1.51 + 1.52 +function checkDebuggerPort() { 1.53 + // XXX: To be removed once bug 942756 lands. 1.54 + // We are hacking 'unix-domain-socket' pref by setting a tcp port (number). 1.55 + // DebuggerServer.openListener detects that it isn't a file path (string), 1.56 + // and starts listening on the tcp port given here as command line argument. 1.57 + 1.58 + if (!window.arguments) { 1.59 + return; 1.60 + } 1.61 + 1.62 + // Get the command line arguments that were passed to the b2g client 1.63 + let args = window.arguments[0].QueryInterface(Ci.nsICommandLine); 1.64 + 1.65 + let dbgport; 1.66 + try { 1.67 + dbgport = args.handleFlagWithParam('start-debugger-server', false); 1.68 + } catch(e) {} 1.69 + 1.70 + if (dbgport) { 1.71 + dump('Opening debugger server on ' + dbgport + '\n'); 1.72 + Services.prefs.setCharPref('devtools.debugger.unix-domain-socket', dbgport); 1.73 + navigator.mozSettings.createLock().set( 1.74 + {'debugger.remote-mode': 'adb-devtools'}); 1.75 + } 1.76 +} 1.77 + 1.78 +window.addEventListener('ContentStart', function() { 1.79 + enableTouch(); 1.80 + setupButtons(); 1.81 + checkDebuggerPort(); 1.82 +});