Update how popup visibility works

This commit is contained in:
toasted-nutbread 2019-10-05 21:57:13 -04:00
parent 2255fadf52
commit cd6d4e7ee1
2 changed files with 27 additions and 28 deletions

View File

@ -34,6 +34,9 @@ class Popup {
this.container.style.height = '0px'; this.container.style.height = '0px';
this.injectPromise = null; this.injectPromise = null;
this.isInjected = false; this.isInjected = false;
this.visible = false;
this.visibleOverride = null;
this.updateVisibility();
} }
inject(options) { inject(options) {
@ -105,9 +108,11 @@ class Popup {
container.style.top = `${y}px`; container.style.top = `${y}px`;
container.style.width = `${width}px`; container.style.width = `${width}px`;
container.style.height = `${height}px`; container.style.height = `${height}px`;
container.style.visibility = 'visible';
this.hideChildren(true); this.setVisible(true);
if (this.child !== null) {
this.child.hide(true);
}
} }
static getPositionForHorizontalText(elementRect, width, height, maxWidth, maxHeight, optionsGeneral) { static getPositionForHorizontalText(elementRect, width, height, maxWidth, maxHeight, optionsGeneral) {
@ -209,41 +214,35 @@ class Popup {
} }
hide(changeFocus) { hide(changeFocus) {
if (this.isContainerHidden()) { if (!this.isVisible()) {
changeFocus = false; return;
}
this.setVisible(false);
if (this.child !== null) {
this.child.hide(false);
} }
this.hideChildren(changeFocus);
this.hideContainer();
if (changeFocus) { if (changeFocus) {
this.focusParent(); this.focusParent();
} }
} }
hideChildren(changeFocus) {
// Recursively hides all children.
if (this.child !== null && !this.child.isContainerHidden()) {
this.child.hide(changeFocus);
}
}
hideContainer() {
this.container.style.visibility = 'hidden';
}
isContainerHidden() {
return (this.container.style.visibility === 'hidden');
}
isVisible() { isVisible() {
return this.isInjected && this.container.style.visibility !== 'hidden'; return this.isInjected && (this.visibleOverride !== null ? this.visibleOverride : this.visible);
}
setVisible(visible) {
this.visible = visible;
this.updateVisibility();
} }
setVisibleOverride(visible) { setVisibleOverride(visible) {
if (visible) { this.visibleOverride = visible;
this.container.style.setProperty('display', ''); this.updateVisibility();
} else { }
this.container.style.setProperty('display', 'none', 'important');
} updateVisibility() {
this.container.style.setProperty('visibility', this.isVisible() ? 'visible' : 'hidden', 'important');
} }
focusParent() { focusParent() {

View File

@ -454,7 +454,7 @@ class Display {
return {dataUrl, format}; return {dataUrl, format};
} finally { } finally {
await this.setPopupVisibleOverride(true); await this.setPopupVisibleOverride(null);
} }
} }