aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js/popup-proxy-host.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/fg/js/popup-proxy-host.js')
-rw-r--r--ext/fg/js/popup-proxy-host.js67
1 files changed, 41 insertions, 26 deletions
diff --git a/ext/fg/js/popup-proxy-host.js b/ext/fg/js/popup-proxy-host.js
index e55801ff..793d3949 100644
--- a/ext/fg/js/popup-proxy-host.js
+++ b/ext/fg/js/popup-proxy-host.js
@@ -16,7 +16,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
-/*global apiFrameInformationGet, FrontendApiReceiver, Popup*/
+/* global
+ * FrontendApiReceiver
+ * Popup
+ * apiFrameInformationGet
+ */
class PopupProxyHost {
constructor() {
@@ -34,20 +38,20 @@ class PopupProxyHost {
if (typeof frameId !== 'number') { return; }
this._apiReceiver = new FrontendApiReceiver(`popup-proxy-host#${frameId}`, new Map([
- ['getOrCreatePopup', ({id, parentId}) => this._onApiGetOrCreatePopup(id, parentId)],
- ['setOptions', ({id, options}) => this._onApiSetOptions(id, options)],
- ['hide', ({id, changeFocus}) => this._onApiHide(id, changeFocus)],
- ['isVisible', ({id}) => this._onApiIsVisibleAsync(id)],
- ['setVisibleOverride', ({id, visible}) => this._onApiSetVisibleOverride(id, visible)],
- ['containsPoint', ({id, x, y}) => this._onApiContainsPoint(id, x, y)],
- ['showContent', ({id, elementRect, writingMode, type, details}) => this._onApiShowContent(id, elementRect, writingMode, type, details)],
- ['setCustomCss', ({id, css}) => this._onApiSetCustomCss(id, css)],
- ['clearAutoPlayTimer', ({id}) => this._onApiClearAutoPlayTimer(id)],
- ['setContentScale', ({id, scale}) => this._onApiSetContentScale(id, scale)]
+ ['getOrCreatePopup', this._onApiGetOrCreatePopup.bind(this)],
+ ['setOptions', this._onApiSetOptions.bind(this)],
+ ['hide', this._onApiHide.bind(this)],
+ ['isVisible', this._onApiIsVisibleAsync.bind(this)],
+ ['setVisibleOverride', this._onApiSetVisibleOverride.bind(this)],
+ ['containsPoint', this._onApiContainsPoint.bind(this)],
+ ['showContent', this._onApiShowContent.bind(this)],
+ ['setCustomCss', this._onApiSetCustomCss.bind(this)],
+ ['clearAutoPlayTimer', this._onApiClearAutoPlayTimer.bind(this)],
+ ['setContentScale', this._onApiSetContentScale.bind(this)]
]));
}
- getOrCreatePopup(id=null, parentId=null) {
+ getOrCreatePopup(id=null, parentId=null, depth=null) {
// Find by existing id
if (id !== null) {
const popup = this._popups.get(id);
@@ -76,7 +80,14 @@ class PopupProxyHost {
}
// Create new popup
- const depth = (parent !== null ? parent.depth + 1 : 0);
+ if (parent !== null) {
+ if (depth !== null) {
+ throw new Error('Depth cannot be set when parent exists');
+ }
+ depth = parent.depth + 1;
+ } else if (depth === null) {
+ depth = 0;
+ }
const popup = new Popup(id, depth, this._frameIdPromise);
if (parent !== null) {
popup.setParent(parent);
@@ -87,56 +98,57 @@ class PopupProxyHost {
// Message handlers
- async _onApiGetOrCreatePopup(id, parentId) {
+ async _onApiGetOrCreatePopup({id, parentId}) {
const popup = this.getOrCreatePopup(id, parentId);
return {
id: popup.id
};
}
- async _onApiSetOptions(id, options) {
+ async _onApiSetOptions({id, options}) {
const popup = this._getPopup(id);
return await popup.setOptions(options);
}
- async _onApiHide(id, changeFocus) {
+ async _onApiHide({id, changeFocus}) {
const popup = this._getPopup(id);
return popup.hide(changeFocus);
}
- async _onApiIsVisibleAsync(id) {
+ async _onApiIsVisibleAsync({id}) {
const popup = this._getPopup(id);
return await popup.isVisible();
}
- async _onApiSetVisibleOverride(id, visible) {
+ async _onApiSetVisibleOverride({id, visible}) {
const popup = this._getPopup(id);
return await popup.setVisibleOverride(visible);
}
- async _onApiContainsPoint(id, x, y) {
+ async _onApiContainsPoint({id, x, y}) {
const popup = this._getPopup(id);
+ [x, y] = PopupProxyHost._convertPopupPointToRootPagePoint(popup, x, y);
return await popup.containsPoint(x, y);
}
- async _onApiShowContent(id, elementRect, writingMode, type, details) {
+ async _onApiShowContent({id, elementRect, writingMode, type, details}) {
const popup = this._getPopup(id);
elementRect = PopupProxyHost._convertJsonRectToDOMRect(popup, elementRect);
if (!PopupProxyHost._popupCanShow(popup)) { return; }
return await popup.showContent(elementRect, writingMode, type, details);
}
- async _onApiSetCustomCss(id, css) {
+ async _onApiSetCustomCss({id, css}) {
const popup = this._getPopup(id);
return popup.setCustomCss(css);
}
- async _onApiClearAutoPlayTimer(id) {
+ async _onApiClearAutoPlayTimer({id}) {
const popup = this._getPopup(id);
return popup.clearAutoPlayTimer();
}
- async _onApiSetContentScale(id, scale) {
+ async _onApiSetContentScale({id, scale}) {
const popup = this._getPopup(id);
return popup.setContentScale(scale);
}
@@ -152,14 +164,17 @@ class PopupProxyHost {
}
static _convertJsonRectToDOMRect(popup, jsonRect) {
- let x = jsonRect.x;
- let y = jsonRect.y;
+ const [x, y] = PopupProxyHost._convertPopupPointToRootPagePoint(popup, jsonRect.x, jsonRect.y);
+ return new DOMRect(x, y, jsonRect.width, jsonRect.height);
+ }
+
+ static _convertPopupPointToRootPagePoint(popup, x, y) {
if (popup.parent !== null) {
const popupRect = popup.parent.getContainerRect();
x += popupRect.x;
y += popupRect.y;
}
- return new DOMRect(x, y, jsonRect.width, jsonRect.height);
+ return [x, y];
}
static _popupCanShow(popup) {