Bug 1586801 - Use the contextual WalkerFront in _duplicateNode(). r=pbro
[gecko.git] / toolkit / modules / RemoteController.js
bloba133fe66144552a14e22d08085b362015cc47429
1 // -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
2 // This Source Code Form is subject to the terms of the Mozilla Public
3 // License, v. 2.0. If a copy of the MPL was not distributed with this
4 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 function RemoteController(browser) {
7   this._browser = browser;
9   // A map of commands that have had their enabled/disabled state assigned. The
10   // value of each key will be true if enabled, and false if disabled.
11   this._supportedCommands = {};
14 RemoteController.prototype = {
15   QueryInterface: ChromeUtils.generateQI([
16     Ci.nsIController,
17     Ci.nsICommandController,
18   ]),
20   isCommandEnabled(aCommand) {
21     return this._supportedCommands[aCommand] || false;
22   },
24   supportsCommand(aCommand) {
25     return aCommand in this._supportedCommands;
26   },
28   doCommand(aCommand) {
29     this._browser.messageManager.sendAsyncMessage(
30       "ControllerCommands:Do",
31       aCommand
32     );
33   },
35   getCommandStateWithParams(aCommand, aCommandParams) {
36     throw Cr.NS_ERROR_NOT_IMPLEMENTED;
37   },
39   doCommandWithParams(aCommand, aCommandParams) {
40     let cmd = {
41       cmd: aCommand,
42       params: null,
43     };
44     if (aCommand == "cmd_lookUpDictionary") {
45       // Although getBoundingClientRect of the element is logical pixel, but
46       // x and y parameter of cmd_lookUpDictionary are device pixel.
47       // So we need calculate child process's coordinate using correct unit.
48       let rect = this._browser.getBoundingClientRect();
49       let scale = this._browser.ownerGlobal.devicePixelRatio;
50       cmd.params = {
51         x: {
52           type: "long",
53           value: aCommandParams.getLongValue("x") - rect.left * scale,
54         },
55         y: {
56           type: "long",
57           value: aCommandParams.getLongValue("y") - rect.top * scale,
58         },
59       };
60     } else {
61       throw Cr.NS_ERROR_NOT_IMPLEMENTED;
62     }
63     this._browser.messageManager.sendAsyncMessage(
64       "ControllerCommands:DoWithParams",
65       cmd
66     );
67   },
69   getSupportedCommands() {
70     throw Cr.NS_ERROR_NOT_IMPLEMENTED;
71   },
73   onEvent() {},
75   // This is intended to be called from the browser binding to update
76   // the enabled and disabled commands.
77   enableDisableCommands(aAction, aEnabledCommands, aDisabledCommands) {
78     // Clear the list first
79     this._supportedCommands = {};
81     for (let command of aEnabledCommands) {
82       this._supportedCommands[command] = true;
83     }
85     for (let command of aDisabledCommands) {
86       this._supportedCommands[command] = false;
87     }
89     // Don't update anything if we're not the active element
90     if (this._browser != this._browser.ownerDocument.activeElement) {
91       return;
92     }
93     this._browser.ownerGlobal.updateCommands(aAction);
94   },