2014-06-25 09:12:07 +04:00
|
|
|
// -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
|
2013-08-21 21:24:53 +04: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/.
|
|
|
|
|
2016-12-31 05:47:25 +03:00
|
|
|
function RemoteController(browser) {
|
2013-08-21 21:24:53 +04:00
|
|
|
this._browser = browser;
|
2014-12-09 18:48:27 +03:00
|
|
|
|
|
|
|
// A map of commands that have had their enabled/disabled state assigned. The
|
|
|
|
// value of each key will be true if enabled, and false if disabled.
|
|
|
|
this._supportedCommands = { };
|
2013-08-21 21:24:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
RemoteController.prototype = {
|
2018-04-23 06:55:06 +03:00
|
|
|
QueryInterface: ChromeUtils.generateQI([Ci.nsIController,
|
|
|
|
Ci.nsICommandController]),
|
2013-08-21 21:24:53 +04:00
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
isCommandEnabled(aCommand) {
|
2014-12-09 18:48:27 +03:00
|
|
|
return this._supportedCommands[aCommand] || false;
|
2013-08-21 21:24:53 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
supportsCommand(aCommand) {
|
2014-12-09 18:48:27 +03:00
|
|
|
return aCommand in this._supportedCommands;
|
2013-08-21 21:24:53 +04:00
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
doCommand(aCommand) {
|
2013-08-21 21:24:53 +04:00
|
|
|
this._browser.messageManager.sendAsyncMessage("ControllerCommands:Do", aCommand);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
getCommandStateWithParams(aCommand, aCommandParams) {
|
2016-04-20 13:12:27 +03:00
|
|
|
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
doCommandWithParams(aCommand, aCommandParams) {
|
2016-04-20 13:12:27 +03:00
|
|
|
let cmd = {
|
|
|
|
cmd: aCommand,
|
2018-08-31 08:59:17 +03:00
|
|
|
params: null,
|
2016-04-20 13:12:27 +03:00
|
|
|
};
|
|
|
|
if (aCommand == "cmd_lookUpDictionary") {
|
2016-05-23 10:47:48 +03:00
|
|
|
// Although getBoundingClientRect of the element is logical pixel, but
|
|
|
|
// x and y parameter of cmd_lookUpDictionary are device pixel.
|
|
|
|
// So we need calculate child process's coordinate using correct unit.
|
2016-04-20 13:12:27 +03:00
|
|
|
let rect = this._browser.getBoundingClientRect();
|
2017-01-27 12:51:03 +03:00
|
|
|
let scale = this._browser.ownerGlobal.devicePixelRatio;
|
2016-04-20 13:12:27 +03:00
|
|
|
cmd.params = {
|
|
|
|
x: {
|
|
|
|
type: "long",
|
2018-08-31 08:59:17 +03:00
|
|
|
value: aCommandParams.getLongValue("x") - rect.left * scale,
|
2016-04-20 13:12:27 +03:00
|
|
|
},
|
|
|
|
y: {
|
|
|
|
type: "long",
|
2018-08-31 08:59:17 +03:00
|
|
|
value: aCommandParams.getLongValue("y") - rect.top * scale,
|
|
|
|
},
|
2016-04-20 13:12:27 +03:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
this._browser.messageManager.sendAsyncMessage(
|
|
|
|
"ControllerCommands:DoWithParams", cmd);
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
getSupportedCommands(aCount, aCommands) {
|
2016-04-20 13:12:27 +03:00
|
|
|
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
},
|
|
|
|
|
2016-12-30 02:34:54 +03:00
|
|
|
onEvent() {},
|
2014-12-09 18:48:27 +03:00
|
|
|
|
2018-09-24 19:24:04 +03:00
|
|
|
// This is intended to be called from the browser binding to update
|
2014-12-09 18:48:27 +03:00
|
|
|
// the enabled and disabled commands.
|
2016-12-30 02:34:54 +03:00
|
|
|
enableDisableCommands(aAction,
|
2014-12-09 18:48:27 +03:00
|
|
|
aEnabledLength, aEnabledCommands,
|
|
|
|
aDisabledLength, aDisabledCommands) {
|
|
|
|
// Clear the list first
|
|
|
|
this._supportedCommands = { };
|
|
|
|
|
|
|
|
for (let c = 0; c < aEnabledLength; c++) {
|
|
|
|
this._supportedCommands[aEnabledCommands[c]] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let c = 0; c < aDisabledLength; c++) {
|
|
|
|
this._supportedCommands[aDisabledCommands[c]] = false;
|
|
|
|
}
|
|
|
|
|
2019-01-16 19:20:43 +03:00
|
|
|
// Don't update anything if we're not the active element
|
|
|
|
if (this._browser != this._browser.ownerDocument.activeElement) {
|
|
|
|
return;
|
|
|
|
}
|
2017-01-27 12:51:03 +03:00
|
|
|
this._browser.ownerGlobal.updateCommands(aAction);
|
2018-08-31 08:59:17 +03:00
|
|
|
},
|
2013-08-21 21:24:53 +04:00
|
|
|
};
|