Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 // Enable touch event shim on desktop that translates mouse events
6 // into touch ones
7 function enableTouch() {
8 let require = Cu.import('resource://gre/modules/devtools/Loader.jsm', {})
9 .devtools.require;
10 let { TouchEventHandler } = require('devtools/touch-events');
11 let chromeEventHandler = window.QueryInterface(Ci.nsIInterfaceRequestor)
12 .getInterface(Ci.nsIWebNavigation)
13 .QueryInterface(Ci.nsIDocShell)
14 .chromeEventHandler || window;
15 let touchEventHandler = new TouchEventHandler(chromeEventHandler);
16 touchEventHandler.start();
17 }
19 function setupButtons() {
20 let homeButton = document.getElementById('home-button');
21 if (!homeButton) {
22 // The toolbar only exists in b2g desktop build with
23 // FXOS_SIMULATOR turned on.
24 return;
25 }
26 // The touch event helper is enabled on shell.html document,
27 // so that click events are delayed and it is better to
28 // listen for touch events.
29 homeButton.addEventListener('touchstart', function() {
30 shell.sendChromeEvent({type: 'home-button-press'});
31 homeButton.classList.add('active');
32 });
33 homeButton.addEventListener('touchend', function() {
34 shell.sendChromeEvent({type: 'home-button-release'});
35 homeButton.classList.remove('active');
36 });
38 Cu.import("resource://gre/modules/GlobalSimulatorScreen.jsm");
39 let rotateButton = document.getElementById('rotate-button');
40 rotateButton.addEventListener('touchstart', function () {
41 rotateButton.classList.add('active');
42 });
43 rotateButton.addEventListener('touchend', function() {
44 GlobalSimulatorScreen.flipScreen();
45 rotateButton.classList.remove('active');
46 });
47 }
49 function checkDebuggerPort() {
50 // XXX: To be removed once bug 942756 lands.
51 // We are hacking 'unix-domain-socket' pref by setting a tcp port (number).
52 // DebuggerServer.openListener detects that it isn't a file path (string),
53 // and starts listening on the tcp port given here as command line argument.
55 if (!window.arguments) {
56 return;
57 }
59 // Get the command line arguments that were passed to the b2g client
60 let args = window.arguments[0].QueryInterface(Ci.nsICommandLine);
62 let dbgport;
63 try {
64 dbgport = args.handleFlagWithParam('start-debugger-server', false);
65 } catch(e) {}
67 if (dbgport) {
68 dump('Opening debugger server on ' + dbgport + '\n');
69 Services.prefs.setCharPref('devtools.debugger.unix-domain-socket', dbgport);
70 navigator.mozSettings.createLock().set(
71 {'debugger.remote-mode': 'adb-devtools'});
72 }
73 }
75 window.addEventListener('ContentStart', function() {
76 enableTouch();
77 setupButtons();
78 checkDebuggerPort();
79 });