mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 07:15:46 +00:00
Bug 1305777 - Clean up touch simulator after old RDM removal. r=ochameau
Only `simulator-core` is used by new RDM via the Emulation actor, so I've moved this server side and renamed it to `touch-simulator`. MozReview-Commit-ID: 5YgpYNDwBvw --HG-- rename : devtools/shared/touch/moz.build => devtools/server/actors/emulation/moz.build rename : devtools/shared/touch/simulator-core.js => devtools/server/actors/emulation/touch-simulator.js extra : rebase_source : d38f3fa09c8e187440be716e993d42c88a10da2a
This commit is contained in:
parent
b4ee78b255
commit
efbf4624b2
@ -7,7 +7,7 @@
|
||||
const { Ci } = require("chrome");
|
||||
const protocol = require("devtools/shared/protocol");
|
||||
const { emulationSpec } = require("devtools/shared/specs/emulation");
|
||||
const { SimulatorCore } = require("devtools/shared/touch/simulator-core");
|
||||
const { TouchSimulator } = require("devtools/server/actors/emulation/touch-simulator");
|
||||
|
||||
/**
|
||||
* This actor overrides various browser features to simulate different environments to
|
||||
@ -28,7 +28,7 @@ let EmulationActor = protocol.ActorClassWithSpec(emulationSpec, {
|
||||
protocol.Actor.prototype.initialize.call(this, conn);
|
||||
this.tabActor = tabActor;
|
||||
this.docShell = tabActor.docShell;
|
||||
this.simulatorCore = new SimulatorCore(tabActor.chromeEventHandler);
|
||||
this.touchSimulator = new TouchSimulator(tabActor.chromeEventHandler);
|
||||
},
|
||||
|
||||
destroy() {
|
||||
@ -38,7 +38,7 @@ let EmulationActor = protocol.ActorClassWithSpec(emulationSpec, {
|
||||
this.clearUserAgentOverride();
|
||||
this.tabActor = null;
|
||||
this.docShell = null;
|
||||
this.simulatorCore = null;
|
||||
this.touchSimulator = null;
|
||||
protocol.Actor.prototype.destroy.call(this);
|
||||
},
|
||||
|
||||
@ -186,9 +186,9 @@ let EmulationActor = protocol.ActorClassWithSpec(emulationSpec, {
|
||||
|
||||
// Start or stop the touch simulator depending on the override flag
|
||||
if (flag == Ci.nsIDocShell.TOUCHEVENTS_OVERRIDE_ENABLED) {
|
||||
this.simulatorCore.start();
|
||||
this.touchSimulator.start();
|
||||
} else {
|
||||
this.simulatorCore.stop();
|
||||
this.touchSimulator.stop();
|
||||
}
|
||||
|
||||
this.docShell.touchEventsOverride = flag;
|
||||
|
@ -5,7 +5,5 @@
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
DevToolsModules(
|
||||
'simulator-content.js',
|
||||
'simulator-core.js',
|
||||
'simulator.js',
|
||||
'touch-simulator.js',
|
||||
)
|
@ -24,14 +24,14 @@ var systemAppOrigin = (function () {
|
||||
var threshold = Services.prefs.getIntPref("ui.dragThresholdX", 25);
|
||||
var delay = Services.prefs.getIntPref("ui.click_hold_context_menus.delay", 500);
|
||||
|
||||
function SimulatorCore(simulatorTarget) {
|
||||
function TouchSimulator(simulatorTarget) {
|
||||
this.simulatorTarget = simulatorTarget;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simulate touch events for platforms where they aren't generally available.
|
||||
*/
|
||||
SimulatorCore.prototype = {
|
||||
TouchSimulator.prototype = {
|
||||
events: [
|
||||
"mousedown",
|
||||
"mousemove",
|
||||
@ -354,4 +354,4 @@ SimulatorCore.prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
exports.SimulatorCore = SimulatorCore;
|
||||
exports.TouchSimulator = TouchSimulator;
|
@ -5,6 +5,7 @@
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
DIRS += [
|
||||
'emulation',
|
||||
'highlighters',
|
||||
'utils',
|
||||
'webconsole',
|
||||
|
@ -28,7 +28,6 @@ DIRS += [
|
||||
'sourcemap',
|
||||
'sprintfjs',
|
||||
'specs',
|
||||
'touch',
|
||||
'transport',
|
||||
'webconsole',
|
||||
'worker',
|
||||
|
@ -1,43 +0,0 @@
|
||||
/* 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/. */
|
||||
/* globals addMessageListener, sendAsyncMessage, docShell */
|
||||
"use strict";
|
||||
|
||||
const { utils: Cu } = Components;
|
||||
const { require } = Cu.import("resource://devtools/shared/Loader.jsm", {});
|
||||
const { SimulatorCore } = require("devtools/shared/touch/simulator-core");
|
||||
|
||||
/**
|
||||
* Launches SimulatorCore in the content window to simulate touch events
|
||||
* This frame script is managed by `simulator.js`.
|
||||
*/
|
||||
|
||||
var simulator = {
|
||||
messages: [
|
||||
"TouchEventSimulator:Start",
|
||||
"TouchEventSimulator:Stop",
|
||||
],
|
||||
|
||||
init() {
|
||||
this.simulatorCore = new SimulatorCore(docShell.chromeEventHandler);
|
||||
this.messages.forEach(msgName => {
|
||||
addMessageListener(msgName, this);
|
||||
});
|
||||
},
|
||||
|
||||
receiveMessage(msg) {
|
||||
switch (msg.name) {
|
||||
case "TouchEventSimulator:Start":
|
||||
this.simulatorCore.start();
|
||||
sendAsyncMessage("TouchEventSimulator:Started");
|
||||
break;
|
||||
case "TouchEventSimulator:Stop":
|
||||
this.simulatorCore.stop();
|
||||
sendAsyncMessage("TouchEventSimulator:Stopped");
|
||||
break;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
simulator.init();
|
@ -1,77 +0,0 @@
|
||||
/* 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/. */
|
||||
"use strict";
|
||||
|
||||
var promise = require("promise");
|
||||
var defer = require("devtools/shared/defer");
|
||||
var Services = require("Services");
|
||||
|
||||
const FRAME_SCRIPT =
|
||||
"resource://devtools/shared/touch/simulator-content.js";
|
||||
|
||||
var trackedBrowsers = new WeakMap();
|
||||
var savedTouchEventsEnabled =
|
||||
Services.prefs.getIntPref("dom.w3c_touch_events.enabled");
|
||||
|
||||
/**
|
||||
* Simulate touch events for platforms where they aren't generally available.
|
||||
* Defers to the `simulator-content.js` frame script to perform the real work.
|
||||
*/
|
||||
function TouchEventSimulator(browser) {
|
||||
// Returns an already instantiated simulator for this browser
|
||||
let simulator = trackedBrowsers.get(browser);
|
||||
if (simulator) {
|
||||
return simulator;
|
||||
}
|
||||
|
||||
let mm = browser.frameLoader.messageManager;
|
||||
mm.loadFrameScript(FRAME_SCRIPT, true);
|
||||
|
||||
simulator = {
|
||||
enabled: false,
|
||||
|
||||
start() {
|
||||
if (this.enabled) {
|
||||
return promise.resolve({ isReloadNeeded: false });
|
||||
}
|
||||
this.enabled = true;
|
||||
|
||||
let deferred = defer();
|
||||
let isReloadNeeded =
|
||||
Services.prefs.getIntPref("dom.w3c_touch_events.enabled") != 1;
|
||||
Services.prefs.setIntPref("dom.w3c_touch_events.enabled", 1);
|
||||
let onStarted = () => {
|
||||
mm.removeMessageListener("TouchEventSimulator:Started", onStarted);
|
||||
deferred.resolve({ isReloadNeeded });
|
||||
};
|
||||
mm.addMessageListener("TouchEventSimulator:Started", onStarted);
|
||||
mm.sendAsyncMessage("TouchEventSimulator:Start");
|
||||
return deferred.promise;
|
||||
},
|
||||
|
||||
stop() {
|
||||
if (!this.enabled) {
|
||||
return promise.resolve();
|
||||
}
|
||||
this.enabled = false;
|
||||
|
||||
let deferred = defer();
|
||||
Services.prefs.setIntPref("dom.w3c_touch_events.enabled",
|
||||
savedTouchEventsEnabled);
|
||||
let onStopped = () => {
|
||||
mm.removeMessageListener("TouchEventSimulator:Stopped", onStopped);
|
||||
deferred.resolve();
|
||||
};
|
||||
mm.addMessageListener("TouchEventSimulator:Stopped", onStopped);
|
||||
mm.sendAsyncMessage("TouchEventSimulator:Stop");
|
||||
return deferred.promise;
|
||||
}
|
||||
};
|
||||
|
||||
trackedBrowsers.set(browser, simulator);
|
||||
|
||||
return simulator;
|
||||
}
|
||||
|
||||
exports.TouchEventSimulator = TouchEventSimulator;
|
Loading…
Reference in New Issue
Block a user