aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js/popup-factory.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-08-15 17:27:03 -0400
committerGitHub <noreply@github.com>2020-08-15 17:27:03 -0400
commitd5865db457ef6f96aa32662a8219fdf73478ae20 (patch)
tree8144a77e4172a32d74fec60f13817fc251b461f2 /ext/fg/js/popup-factory.js
parenta9b16bd9379a881bb7b875a1e56bffbd78440a6a (diff)
Popup API refactor (#732)
* Simplify how parent/child are set * Remove unused public frameId property * Change use of getFrame * Simplify parent access * Use property for the container * Remove isProxy * Public function API parity * Public property API parity
Diffstat (limited to 'ext/fg/js/popup-factory.js')
-rw-r--r--ext/fg/js/popup-factory.js52
1 files changed, 38 insertions, 14 deletions
diff --git a/ext/fg/js/popup-factory.js b/ext/fg/js/popup-factory.js
index 1dc7d61e..7d6f9846 100644
--- a/ext/fg/js/popup-factory.js
+++ b/ext/fg/js/popup-factory.js
@@ -30,16 +30,19 @@ class PopupFactory {
prepare() {
api.crossFrame.registerHandlers([
- ['getOrCreatePopup', {async: false, handler: this._onApiGetOrCreatePopup.bind(this)}],
- ['setOptionsContext', {async: true, handler: this._onApiSetOptionsContext.bind(this)}],
- ['hide', {async: false, handler: this._onApiHide.bind(this)}],
- ['isVisible', {async: true, handler: this._onApiIsVisibleAsync.bind(this)}],
- ['setVisibleOverride', {async: true, handler: this._onApiSetVisibleOverride.bind(this)}],
- ['containsPoint', {async: true, handler: this._onApiContainsPoint.bind(this)}],
- ['showContent', {async: true, handler: this._onApiShowContent.bind(this)}],
- ['setCustomCss', {async: false, handler: this._onApiSetCustomCss.bind(this)}],
- ['clearAutoPlayTimer', {async: false, handler: this._onApiClearAutoPlayTimer.bind(this)}],
- ['setContentScale', {async: false, handler: this._onApiSetContentScale.bind(this)}]
+ ['getOrCreatePopup', {async: false, handler: this._onApiGetOrCreatePopup.bind(this)}],
+ ['setOptionsContext', {async: true, handler: this._onApiSetOptionsContext.bind(this)}],
+ ['hide', {async: false, handler: this._onApiHide.bind(this)}],
+ ['isVisible', {async: true, handler: this._onApiIsVisibleAsync.bind(this)}],
+ ['setVisibleOverride', {async: true, handler: this._onApiSetVisibleOverride.bind(this)}],
+ ['containsPoint', {async: true, handler: this._onApiContainsPoint.bind(this)}],
+ ['showContent', {async: true, handler: this._onApiShowContent.bind(this)}],
+ ['setCustomCss', {async: false, handler: this._onApiSetCustomCss.bind(this)}],
+ ['clearAutoPlayTimer', {async: false, handler: this._onApiClearAutoPlayTimer.bind(this)}],
+ ['setContentScale', {async: false, handler: this._onApiSetContentScale.bind(this)}],
+ ['updateTheme', {async: false, handler: this._onApiUpdateTheme.bind(this)}],
+ ['setCustomOuterCss', {async: false, handler: this._onApiSetCustomOuterCss.bind(this)}],
+ ['setChildrenSupported', {async: false, handler: this._onApiSetChildrenSupported.bind(this)}]
]);
}
@@ -82,7 +85,11 @@ class PopupFactory {
}
const popup = new Popup(id, depth, this._frameId, ownerFrameId);
if (parent !== null) {
- popup.setParent(parent);
+ if (parent.child !== null) {
+ throw new Error('Parent popup already has a child');
+ }
+ popup.parent = parent;
+ parent.child = popup;
}
this._popups.set(id, popup);
popup.prepare();
@@ -151,6 +158,21 @@ class PopupFactory {
return popup.setContentScale(scale);
}
+ _onApiUpdateTheme({id}) {
+ const popup = this._getPopup(id);
+ return popup.updateTheme();
+ }
+
+ _onApiSetCustomOuterCss({id, css, useWebExtensionApi}) {
+ const popup = this._getPopup(id);
+ return popup.setCustomOuterCss(css, useWebExtensionApi);
+ }
+
+ _onApiSetChildrenSupported({id, value}) {
+ const popup = this._getPopup(id);
+ return popup.setChildrenSupported(value);
+ }
+
// Private functions
_getPopup(id) {
@@ -167,8 +189,9 @@ class PopupFactory {
}
_convertPopupPointToRootPagePoint(popup, x, y) {
- if (popup.parent !== null) {
- const popupRect = popup.parent.getFrameRect();
+ const parent = popup.parent;
+ if (parent !== null) {
+ const popupRect = parent.getFrameRect();
x += popupRect.x;
y += popupRect.y;
}
@@ -176,6 +199,7 @@ class PopupFactory {
}
_popupCanShow(popup) {
- return popup.parent === null || popup.parent.isVisibleSync();
+ const parent = popup.parent;
+ return parent === null || parent.isVisibleSync();
}
}