aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js/frontend.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2019-12-23 17:12:09 -0500
committertoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-01-22 20:38:21 -0500
commite740965d4f39a34eecf8a211f22eddf56d185fed (patch)
treebe3f02ded6213fb1abc5d4cdc646eeaa5a991892 /ext/fg/js/frontend.js
parent22afab2f47bcc1e5e9ac0db35d2f1b168becf76e (diff)
Scale popup based on current page zoom factor
Diffstat (limited to 'ext/fg/js/frontend.js')
-rw-r--r--ext/fg/js/frontend.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/ext/fg/js/frontend.js b/ext/fg/js/frontend.js
index 85f1f373..52e3a5bc 100644
--- a/ext/fg/js/frontend.js
+++ b/ext/fg/js/frontend.js
@@ -34,6 +34,8 @@ class Frontend extends TextScanner {
url: popup.url
};
+ this._pageZoomFactor = 1.0;
+ this._contentScale = 1.0;
this._orphaned = true;
this._lastShowPromise = Promise.resolve();
}
@@ -41,11 +43,14 @@ class Frontend extends TextScanner {
async prepare() {
try {
await this.updateOptions();
+ const {zoomFactor} = await apiGetZoom();
+ this.onZoomChanged({newZoomFactor: zoomFactor});
window.addEventListener('resize', this.onResize.bind(this), false);
yomichan.on('orphaned', () => this.onOrphaned());
yomichan.on('optionsUpdate', () => this.updateOptions());
+ yomichan.on('zoomChanged', (e) => this.onZoomChanged(e));
chrome.runtime.onMessage.addListener(this.onRuntimeMessage.bind(this));
} catch (e) {
this.onError(e);
@@ -80,6 +85,11 @@ class Frontend extends TextScanner {
this._orphaned = true;
}
+ onZoomChanged({newZoomFactor}) {
+ this._pageZoomFactor = newZoomFactor;
+ this._updateContentScale();
+ }
+
getMouseEventListeners() {
return [
...super.getMouseEventListeners(),
@@ -90,6 +100,7 @@ class Frontend extends TextScanner {
async updateOptions() {
this.setOptions(await apiOptionsGet(this.getOptionsContext()));
await this.popup.setOptions(this.options);
+ this._updateContentScale();
}
async onSearchSource(textSource, cause) {
@@ -183,6 +194,15 @@ class Frontend extends TextScanner {
);
return this._lastShowPromise;
}
+
+ _updateContentScale() {
+ const contentScale = 1.0 / this._pageZoomFactor; // TODO : Use options
+ if (contentScale === this._contentScale) { return; }
+
+ this._contentScale = contentScale;
+ this.popup.setContentScale(this._contentScale);
+ this.onResize();
+ }
}
Frontend._windowMessageHandlers = new Map([