aboutsummaryrefslogtreecommitdiff
path: root/ext/js/app/popup.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/app/popup.js')
-rw-r--r--ext/js/app/popup.js127
1 files changed, 127 insertions, 0 deletions
diff --git a/ext/js/app/popup.js b/ext/js/app/popup.js
index 3a29563d..7581c8d7 100644
--- a/ext/js/app/popup.js
+++ b/ext/js/app/popup.js
@@ -21,7 +21,18 @@
* dynamicLoader
*/
+/**
+ * This class is the container which hosts the display of search results.
+ */
class Popup extends EventDispatcher {
+ /**
+ * Creates a new instance.
+ * @param {object} details
+ * @param {string} details.id The ID of the popup.
+ * @param {number} details.depth The depth of the popup.
+ * @param {number} details.frameId The ID of the host frame.
+ * @param {boolean} details.childrenSupported Whether or not the popup is able to show child popups.
+ */
constructor({
id,
depth,
@@ -59,44 +70,84 @@ class Popup extends EventDispatcher {
// Public properties
+ /**
+ * The ID of the popup.
+ * @type {string}
+ */
get id() {
return this._id;
}
+ /**
+ * The parent of the popup.
+ * @type {Popup}
+ */
get parent() {
return this._parent;
}
+ /**
+ * Sets the parent popup.
+ * @param {Popup} value The parent popup to assign.
+ */
set parent(value) {
this._parent = value;
}
+ /**
+ * The child of the popup.
+ * @type {Popup}
+ */
get child() {
return this._child;
}
+ /**
+ * Sets the child popup.
+ * @param {Popup} value The child popup to assign.
+ */
set child(value) {
this._child = value;
}
+ /**
+ * The depth of the popup.
+ * @type {numer}
+ */
get depth() {
return this._depth;
}
+ /**
+ * Gets the content window of the frame, which can be `null`
+ * depending on the current state of the frame.
+ * @type {?Window}
+ */
get frameContentWindow() {
return this._frame.contentWindow;
}
+ /**
+ * Gets the DOM node that contains the frame.
+ * @type {Element}
+ */
get container() {
return this._container;
}
+ /**
+ * Gets the ID of the frame.
+ * @type {number}
+ */
get frameId() {
return this._frameId;
}
// Public functions
+ /**
+ * Prepares the popup for use.
+ */
prepare() {
this._frame.addEventListener('mouseover', this._onFrameMouseOver.bind(this));
this._frame.addEventListener('mouseout', this._onFrameMouseOut.bind(this));
@@ -108,11 +159,19 @@ class Popup extends EventDispatcher {
this._onVisibleChange({value: this.isVisibleSync()});
}
+ /**
+ * Sets the options context for the popup.
+ * @param {object} optionsContext The options context object.
+ */
async setOptionsContext(optionsContext) {
await this._setOptionsContext(optionsContext);
await this._invokeSafe('setOptionsContext', {optionsContext});
}
+ /**
+ * Hides the popup.
+ * @param {boolean} changeFocus Whether or not the parent popup or host frame should be focused.
+ */
hide(changeFocus) {
if (!this.isVisibleSync()) {
return;
@@ -127,18 +186,40 @@ class Popup extends EventDispatcher {
}
}
+ /**
+ * Returns whether or not the popup is currently visible.
+ * @returns {Promise<boolean>} `true` if the popup is visible, `false` otherwise.
+ */
async isVisible() {
return this.isVisibleSync();
}
+ /**
+ * Force assigns the visibility of the popup.
+ * @param {boolean} value Whether or not the popup should be visible.
+ * @param {number} priority The priority of the override.
+ * @returns {Promise<string?>} A token used which can be passed to `clearVisibleOverride`,
+ * or null if the override wasn't assigned.
+ */
async setVisibleOverride(value, priority) {
return this._visible.setOverride(value, priority);
}
+ /**
+ * Clears a visibility override that was generated by `setVisibleOverride`.
+ * @param {string} token The token returned from `setVisibleOverride`.
+ * @returns {Promise<boolean>} `true` if the override existed and was removed, `false` otherwise.
+ */
async clearVisibleOverride(token) {
return this._visible.clearOverride(token);
}
+ /**
+ * Checks whether a point is contained within the popup's rect.
+ * @param {number} x The x coordinate.
+ * @param {number} y The y coordinate.
+ * @returns {Promise<boolean>} `true` if the point is contained within the popup's rect, `false` otherwise.
+ */
async containsPoint(x, y) {
for (let popup = this; popup !== null && popup.isVisibleSync(); popup = popup.child) {
const rect = popup.getFrameRect();
@@ -149,6 +230,12 @@ class Popup extends EventDispatcher {
return false;
}
+ /**
+ * Shows and updates the positioning and content of the popup.
+ * @param {{optionsContext: object, elementRect: {x: number, y: number, width: number, height: number}, writingMode: string}} details Settings for the outer popup.
+ * @param {object} displayDetails The details parameter passed to `Display.setContent`; see that function for details.
+ * @returns {Promise<void>}
+ */
async showContent(details, displayDetails) {
if (this._options === null) { throw new Error('Options not assigned'); }
@@ -166,24 +253,43 @@ class Popup extends EventDispatcher {
}
}
+ /**
+ * Sets the custom styles for the popup content.
+ * @param {string} css The CSS rules.
+ */
setCustomCss(css) {
this._invokeSafe('setCustomCss', {css});
}
+ /**
+ * Stops the audio auto-play timer, if one has started.
+ */
clearAutoPlayTimer() {
this._invokeSafe('clearAutoPlayTimer');
}
+ /**
+ * Sets the scaling factor of the popup content.
+ * @param {number} scale The scaling factor.
+ */
setContentScale(scale) {
this._contentScale = scale;
this._frame.style.fontSize = `${scale}px`;
this._invokeSafe('setContentScale', {scale});
}
+ /**
+ * Returns whether or not the popup is currently visible, synchronously.
+ * @returns {boolean} `true` if the popup is visible, `false` otherwise.
+ */
isVisibleSync() {
return this._visible.value;
}
+ /**
+ * Updates the outer theme of the popup.
+ * @returns {Promise<void>}
+ */
updateTheme() {
const {popupTheme, popupOuterTheme} = this._options.general;
this._frame.dataset.theme = popupTheme;
@@ -191,6 +297,12 @@ class Popup extends EventDispatcher {
this._frame.dataset.siteColor = this._getSiteColor();
}
+ /**
+ * Sets the custom styles for the outer popup container.
+ * @param {string} css The CSS rules.
+ * @param {boolean} useWebExtensionApi Whether or not web extension APIs should be used to inject the rules.
+ * When web extension APIs are used, a DOM node is not generated, making it harder to detect the changes.
+ */
async setCustomOuterCss(css, useWebExtensionApi) {
let parentNode = null;
const inShadow = (this._shadow !== null);
@@ -202,16 +314,31 @@ class Popup extends EventDispatcher {
this.trigger('customOuterCssChanged', {node, useWebExtensionApi, inShadow});
}
+ /**
+ * Gets the rectangle of the DOM frame, synchronously.
+ * @returns {{x: number, y: number, width: number, height: number, valid: boolean}} The rect.
+ * `valid` is `false` for `PopupProxy`, since the DOM node is hosted in a different frame.
+ */
getFrameRect() {
const {left, top, width, height} = this._frame.getBoundingClientRect();
return {x: left, y: top, width, height, valid: true};
}
+ /**
+ * Gets the size of the DOM frame.
+ * @returns {Promise<{width: number, height: number, valid: boolean}>} The size and whether or not it is valid.
+ */
async getFrameSize() {
const {width, height} = this._frame.getBoundingClientRect();
return {width, height, valid: true};
}
+ /**
+ * Sets the size of the DOM frame.
+ * @param {number} width The desired width of the popup.
+ * @param {number} height The desired height of the popup.
+ * @returns {Promise<boolean>} `true` if the size assignment was successful, `false` otherwise.
+ */
async setFrameSize(width, height) {
this._setFrameSize(width, height);
return true;