From 76aa30cebad504c3d6811029384713044d4d0428 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Wed, 11 Sep 2019 21:29:08 -0400 Subject: Add writingMode to PopupProxy* termsShow and kanjiShow --- ext/fg/js/popup-proxy-host.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'ext/fg/js/popup-proxy-host.js') diff --git a/ext/fg/js/popup-proxy-host.js b/ext/fg/js/popup-proxy-host.js index fa61aeb4..041900ed 100644 --- a/ext/fg/js/popup-proxy-host.js +++ b/ext/fg/js/popup-proxy-host.js @@ -43,8 +43,8 @@ class PopupProxyHost { hide: ({id}) => this.hide(id), setVisible: ({id, visible}) => this.setVisible(id, visible), containsPoint: ({id, point}) => this.containsPoint(id, point), - termsShow: ({id, elementRect, definitions, options, context}) => this.termsShow(id, elementRect, definitions, options, context), - kanjiShow: ({id, elementRect, definitions, options, context}) => this.kanjiShow(id, elementRect, definitions, options, context), + 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), clearAutoPlayTimer: ({id}) => this.clearAutoPlayTimer(id) }); } @@ -113,16 +113,16 @@ class PopupProxyHost { return await popup.containsPoint(point); } - async termsShow(id, elementRect, definitions, options, context) { + async termsShow(id, elementRect, writingMode, definitions, options, context) { const popup = this.getPopup(id); elementRect = this.jsonRectToDOMRect(popup, elementRect); - return await popup.termsShow(elementRect, definitions, options, context); + return await popup.termsShow(elementRect, writingMode, definitions, options, context); } - async kanjiShow(id, elementRect, definitions, options, context) { + async kanjiShow(id, elementRect, writingMode, definitions, options, context) { const popup = this.getPopup(id); elementRect = this.jsonRectToDOMRect(popup, elementRect); - return await popup.kanjiShow(elementRect, definitions, options, context); + return await popup.kanjiShow(elementRect, writingMode, definitions, options, context); } async clearAutoPlayTimer(id) { -- cgit v1.2.3 From bab6a13bfbc00728ed41411d83aef9f1071786ff Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Wed, 11 Sep 2019 21:32:27 -0400 Subject: Fix nested popups being shown if parent is hidden --- ext/fg/js/popup-proxy-host.js | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'ext/fg/js/popup-proxy-host.js') diff --git a/ext/fg/js/popup-proxy-host.js b/ext/fg/js/popup-proxy-host.js index 041900ed..1f14a06f 100644 --- a/ext/fg/js/popup-proxy-host.js +++ b/ext/fg/js/popup-proxy-host.js @@ -116,12 +116,14 @@ class PopupProxyHost { async termsShow(id, elementRect, writingMode, definitions, options, context) { const popup = this.getPopup(id); elementRect = this.jsonRectToDOMRect(popup, elementRect); + if (!PopupProxyHost.popupCanShow(popup)) { return false; } return await popup.termsShow(elementRect, writingMode, definitions, options, context); } async kanjiShow(id, elementRect, writingMode, definitions, options, context) { const popup = this.getPopup(id); elementRect = this.jsonRectToDOMRect(popup, elementRect); + if (!PopupProxyHost.popupCanShow(popup)) { return false; } return await popup.kanjiShow(elementRect, writingMode, definitions, options, context); } @@ -129,6 +131,10 @@ class PopupProxyHost { const popup = this.getPopup(id); return popup.clearAutoPlayTimer(); } + + static popupCanShow(popup) { + return popup.parent === null || popup.parent.isVisible(); + } } PopupProxyHost.instance = PopupProxyHost.create(); -- cgit v1.2.3 From 6d3037f3d6548b742fa73aec7504c4384f327674 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 14 Sep 2019 14:27:25 -0400 Subject: Remove destructuring from searchAt, containsPoint, docRangeFromPoint --- ext/fg/js/document.js | 2 +- ext/fg/js/frontend.js | 10 +++++----- 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 | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) (limited to 'ext/fg/js/popup-proxy-host.js') diff --git a/ext/fg/js/document.js b/ext/fg/js/document.js index 60b1b9bd..f2459197 100644 --- a/ext/fg/js/document.js +++ b/ext/fg/js/document.js @@ -89,7 +89,7 @@ function docImposterCreate(element, isTextarea) { return [imposter, container]; } -function docRangeFromPoint({x, y}, options) { +function docRangeFromPoint(x, y, options) { const elements = document.elementsFromPoint(x, y); let imposter = null; let imposterContainer = null; diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js index 9341e492..a6919b37 100644 --- a/ext/fg/js/frontend.js +++ b/ext/fg/js/frontend.js @@ -104,7 +104,7 @@ class Frontend { const search = async () => { try { - await this.searchAt({x: e.clientX, y: e.clientY}, 'mouse'); + await this.searchAt(e.clientX, e.clientY, 'mouse'); } catch (e) { this.onError(e); } @@ -280,12 +280,12 @@ class Frontend { } } - async searchAt(point, type) { - if (this.pendingLookup || await this.popup.containsPoint(point)) { + async searchAt(x, y, type) { + if (this.pendingLookup || await this.popup.containsPoint(x, y)) { return; } - const textSource = docRangeFromPoint(point, this.options); + const textSource = docRangeFromPoint(x, y, this.options); let hideResults = textSource === null; let searched = false; let success = false; @@ -470,7 +470,7 @@ class Frontend { const search = async () => { try { - await this.searchAt({x, y}, type); + await this.searchAt(x, y, type); } catch (e) { this.onError(e); } diff --git a/ext/fg/js/popup-proxy-host.js b/ext/fg/js/popup-proxy-host.js index 041900ed..47f49b8d 100644 --- a/ext/fg/js/popup-proxy-host.js +++ b/ext/fg/js/popup-proxy-host.js @@ -42,7 +42,7 @@ class PopupProxyHost { showOrphaned: ({id, elementRect, options}) => this.show(id, elementRect, options), hide: ({id}) => this.hide(id), setVisible: ({id, visible}) => this.setVisible(id, visible), - containsPoint: ({id, point}) => this.containsPoint(id, point), + 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), clearAutoPlayTimer: ({id}) => this.clearAutoPlayTimer(id) @@ -108,9 +108,9 @@ class PopupProxyHost { return popup.setVisible(visible); } - async containsPoint(id, point) { + async containsPoint(id, x, y) { const popup = this.getPopup(id); - return await popup.containsPoint(point); + return await popup.containsPoint(x, y); } async termsShow(id, elementRect, writingMode, definitions, options, context) { diff --git a/ext/fg/js/popup-proxy.js b/ext/fg/js/popup-proxy.js index c3a7bff0..f04e24e0 100644 --- a/ext/fg/js/popup-proxy.js +++ b/ext/fg/js/popup-proxy.js @@ -69,11 +69,11 @@ class PopupProxy { return await this.invokeHostApi('setVisible', {id, visible}); } - async containsPoint(point) { + async containsPoint(x, y) { if (this.id === null) { return false; } - return await this.invokeHostApi('containsPoint', {id: this.id, point}); + return await this.invokeHostApi('containsPoint', {id: this.id, x, y}); } async termsShow(elementRect, writingMode, definitions, options, context) { diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index 1b15977b..1d6fa5b3 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -251,7 +251,7 @@ class Popup { } } - async containsPoint({x, y}) { + async containsPoint(x, y) { for (let popup = this; popup !== null && popup.isVisible(); popup = popup.child) { const rect = popup.container.getBoundingClientRect(); if (x >= rect.left && y >= rect.top && x < rect.right && y < rect.bottom) { diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index eca67b5e..ca1738a6 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -81,7 +81,7 @@ class Display { const {docRangeFromPoint, docSentenceExtract} = this.dependencies; const clickedElement = $(e.target); - const textSource = docRangeFromPoint({x: e.clientX, y: e.clientY}, this.options); + const textSource = docRangeFromPoint(e.clientX, e.clientY, this.options); if (textSource === null) { return false; } -- cgit v1.2.3