From 2255fadf52bff17d183f48e0bc72a078568481f2 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 5 Oct 2019 21:38:13 -0400 Subject: [PATCH 1/3] Rename Popup.setVisible to setVisibleOverride --- ext/fg/js/frontend.js | 4 ++-- ext/fg/js/popup-proxy-host.js | 6 +++--- ext/fg/js/popup-proxy.js | 4 ++-- ext/fg/js/popup.js | 2 +- ext/mixed/js/display.js | 8 ++++---- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 58dc0e4a..3fa70357 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -527,8 +527,8 @@ Frontend.runtimeMessageHandlers = { self.updateOptions(); }, - popupSetVisible: (self, {visible}) => { - self.popup.setVisible(visible); + popupSetVisibleOverride: (self, {visible}) => { + self.popup.setVisibleOverride(visible); } }; diff --git a/ext/fg/js/popup-proxy-host.js b/ext/fg/js/popup-proxy-host.js index cb9741be..7fad71c1 100644 --- a/ext/fg/js/popup-proxy-host.js +++ b/ext/fg/js/popup-proxy-host.js @@ -41,7 +41,7 @@ class PopupProxyHost { show: ({id, elementRect, options}) => this.show(id, elementRect, options), showOrphaned: ({id, elementRect, options}) => this.show(id, elementRect, options), hide: ({id, changeFocus}) => this.hide(id, changeFocus), - setVisible: ({id, visible}) => this.setVisible(id, visible), + setVisibleOverride: ({id, visible}) => this.setVisibleOverride(id, visible), containsPoint: ({id, x, y}) => this.containsPoint(id, x, y), termsShow: ({id, elementRect, writingMode, definitions, options, context}) => this.termsShow(id, elementRect, writingMode, definitions, options, context), kanjiShow: ({id, elementRect, writingMode, definitions, options, context}) => this.kanjiShow(id, elementRect, writingMode, definitions, options, context), @@ -103,9 +103,9 @@ class PopupProxyHost { return popup.hide(changeFocus); } - async setVisible(id, visible) { + async setVisibleOverride(id, visible) { const popup = this.getPopup(id); - return popup.setVisible(visible); + return popup.setVisibleOverride(visible); } async containsPoint(id, x, y) { diff --git a/ext/fg/js/popup-proxy.js b/ext/fg/js/popup-proxy.js index 072cebc9..99b28549 100644 --- a/ext/fg/js/popup-proxy.js +++ b/ext/fg/js/popup-proxy.js @@ -65,9 +65,9 @@ class PopupProxy { return await this.invokeHostApi('hide', {id: this.id, changeFocus}); } - async setVisible(visible) { + async setVisibleOverride(visible) { const id = await this.getPopupId(); - return await this.invokeHostApi('setVisible', {id, visible}); + return await this.invokeHostApi('setVisibleOverride', {id, visible}); } async containsPoint(x, y) { diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index 9dff6f28..5509c98c 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -238,7 +238,7 @@ class Popup { return this.isInjected && this.container.style.visibility !== 'hidden'; } - setVisible(visible) { + setVisibleOverride(visible) { if (visible) { this.container.style.setProperty('display', ''); } else { diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index dc64dbea..b70fa4b8 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -445,7 +445,7 @@ class Display { async getScreenshot() { try { - await this.setPopupVisible(false); + await this.setPopupVisibleOverride(false); await Display.delay(1); // Wait for popup to be hidden. const {format, quality} = this.options.anki.screenshot; @@ -454,7 +454,7 @@ class Display { return {dataUrl, format}; } finally { - await this.setPopupVisible(true); + await this.setPopupVisibleOverride(true); } } @@ -462,8 +462,8 @@ class Display { return this.options.general.resultOutputMode === 'merge' ? 0 : -1; } - setPopupVisible(visible) { - return apiForward('popupSetVisible', {visible}); + setPopupVisibleOverride(visible) { + return apiForward('popupSetVisibleOverride', {visible}); } setSpinnerVisible(visible) { From cd6d4e7ee14b3bfde9efb76eb65d7ee91c740c77 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 5 Oct 2019 21:57:13 -0400 Subject: [PATCH 2/3] Update how popup visibility works --- ext/fg/js/popup.js | 53 ++++++++++++++++++++--------------------- ext/mixed/js/display.js | 2 +- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index 5509c98c..9ca91afa 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -34,6 +34,9 @@ class Popup { this.container.style.height = '0px'; this.injectPromise = null; this.isInjected = false; + this.visible = false; + this.visibleOverride = null; + this.updateVisibility(); } inject(options) { @@ -105,9 +108,11 @@ class Popup { container.style.top = `${y}px`; container.style.width = `${width}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) { @@ -209,41 +214,35 @@ class Popup { } hide(changeFocus) { - if (this.isContainerHidden()) { - changeFocus = false; + if (!this.isVisible()) { + return; + } + + this.setVisible(false); + if (this.child !== null) { + this.child.hide(false); } - this.hideChildren(changeFocus); - this.hideContainer(); if (changeFocus) { 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() { - 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) { - if (visible) { - this.container.style.setProperty('display', ''); - } else { - this.container.style.setProperty('display', 'none', 'important'); - } + this.visibleOverride = visible; + this.updateVisibility(); + } + + updateVisibility() { + this.container.style.setProperty('visibility', this.isVisible() ? 'visible' : 'hidden', 'important'); } focusParent() { diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index b70fa4b8..575011fd 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -454,7 +454,7 @@ class Display { return {dataUrl, format}; } finally { - await this.setPopupVisibleOverride(true); + await this.setPopupVisibleOverride(null); } } From 113cc725c1764e5eb814a22ace23a7e7150d016f Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 5 Oct 2019 22:11:05 -0400 Subject: [PATCH 3/3] Make the window.onresize handler not change focus --- ext/fg/js/frontend.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 3fa70357..4ad78aa7 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -145,7 +145,7 @@ class Frontend { } onResize() { - this.searchClear(true); + this.searchClear(false); } onClick(e) {