Don't pass options around for calls to termsShow, kanjiShow, etc.

This commit is contained in:
toasted-nutbread 2019-10-12 14:55:18 -04:00
parent a5b208fb89
commit 6da7683552
7 changed files with 48 additions and 45 deletions

View File

@ -103,7 +103,11 @@ class DisplaySearch extends Display {
this.updateSearchButton(); this.updateSearchButton();
if (valid) { if (valid) {
const {definitions} = await apiTermsFind(query, this.optionsContext); const {definitions} = await apiTermsFind(query, this.optionsContext);
this.termsShow(definitions, this.options); this.termsShow(definitions, {
focus: false,
sentence: null,
url: window.location.href
});
} else { } else {
this.container.textContent = ''; this.container.textContent = '';
} }

View File

@ -143,8 +143,8 @@ DisplayFloat.onKeyDownHandlers = {
}; };
DisplayFloat.messageHandlers = { DisplayFloat.messageHandlers = {
termsShow: (self, {definitions, options, context}) => self.termsShow(definitions, options, context), termsShow: (self, {definitions, context}) => self.termsShow(definitions, context),
kanjiShow: (self, {definitions, options, context}) => self.kanjiShow(definitions, options, context), kanjiShow: (self, {definitions, context}) => self.kanjiShow(definitions, context),
clearAutoPlayTimer: (self) => self.clearAutoPlayTimer(), clearAutoPlayTimer: (self) => self.clearAutoPlayTimer(),
orphaned: (self) => self.onOrphaned(), orphaned: (self) => self.onOrphaned(),
initialize: (self, {options, popupInfo, url, childrenSupported}) => self.initialize(options, popupInfo, url, childrenSupported) initialize: (self, {options, popupInfo, url, childrenSupported}) => self.initialize(options, popupInfo, url, childrenSupported)

View File

@ -333,8 +333,7 @@ class Frontend {
if (textSource && this.options.scanning.modifier !== 'none') { if (textSource && this.options.scanning.modifier !== 'none') {
this.popup.showOrphaned( this.popup.showOrphaned(
textSource.getRect(), textSource.getRect(),
textSource.getWritingMode(), textSource.getWritingMode()
this.options
); );
} }
} else { } else {
@ -374,7 +373,6 @@ class Frontend {
textSource.getRect(), textSource.getRect(),
textSource.getWritingMode(), textSource.getWritingMode(),
definitions, definitions,
this.options,
{sentence, url, focus} {sentence, url, focus}
); );
@ -405,7 +403,6 @@ class Frontend {
textSource.getRect(), textSource.getRect(),
textSource.getWritingMode(), textSource.getWritingMode(),
definitions, definitions,
this.options,
{sentence, url, focus} {sentence, url, focus}
); );

View File

@ -39,12 +39,12 @@ class PopupProxyHost {
this.apiReceiver = new FrontendApiReceiver(`popup-proxy-host#${frameId}`, { this.apiReceiver = new FrontendApiReceiver(`popup-proxy-host#${frameId}`, {
createNestedPopup: ({parentId}) => this.createNestedPopup(parentId), createNestedPopup: ({parentId}) => this.createNestedPopup(parentId),
setOptions: ({id, options}) => this.setOptions(id, options), setOptions: ({id, options}) => this.setOptions(id, options),
showOrphaned: ({id, elementRect, options}) => this.showOrphaned(id, elementRect, options), showOrphaned: ({id, elementRect}) => this.showOrphaned(id, elementRect),
hide: ({id, changeFocus}) => this.hide(id, changeFocus), hide: ({id, changeFocus}) => this.hide(id, changeFocus),
setVisibleOverride: ({id, visible}) => this.setVisibleOverride(id, visible), setVisibleOverride: ({id, visible}) => this.setVisibleOverride(id, visible),
containsPoint: ({id, x, y}) => this.containsPoint(id, x, y), containsPoint: ({id, x, y}) => this.containsPoint(id, x, y),
termsShow: ({id, elementRect, writingMode, definitions, options, context}) => this.termsShow(id, elementRect, writingMode, definitions, options, context), termsShow: ({id, elementRect, writingMode, definitions, context}) => this.termsShow(id, elementRect, writingMode, definitions, context),
kanjiShow: ({id, elementRect, writingMode, definitions, options, context}) => this.kanjiShow(id, elementRect, writingMode, definitions, options, context), kanjiShow: ({id, elementRect, writingMode, definitions, context}) => this.kanjiShow(id, elementRect, writingMode, definitions, context),
clearAutoPlayTimer: ({id}) => this.clearAutoPlayTimer(id) clearAutoPlayTimer: ({id}) => this.clearAutoPlayTimer(id)
}); });
} }
@ -91,10 +91,10 @@ class PopupProxyHost {
return await popup.setOptions(options); return await popup.setOptions(options);
} }
async showOrphaned(id, elementRect, options) { async showOrphaned(id, elementRect) {
const popup = this.getPopup(id); const popup = this.getPopup(id);
elementRect = this.jsonRectToDOMRect(popup, elementRect); elementRect = this.jsonRectToDOMRect(popup, elementRect);
return await popup.showOrphaned(elementRect, options); return await popup.showOrphaned(elementRect);
} }
async hide(id, changeFocus) { async hide(id, changeFocus) {
@ -112,18 +112,18 @@ class PopupProxyHost {
return await popup.containsPoint(x, y); return await popup.containsPoint(x, y);
} }
async termsShow(id, elementRect, writingMode, definitions, options, context) { async termsShow(id, elementRect, writingMode, definitions, context) {
const popup = this.getPopup(id); const popup = this.getPopup(id);
elementRect = this.jsonRectToDOMRect(popup, elementRect); elementRect = this.jsonRectToDOMRect(popup, elementRect);
if (!PopupProxyHost.popupCanShow(popup)) { return false; } if (!PopupProxyHost.popupCanShow(popup)) { return false; }
return await popup.termsShow(elementRect, writingMode, definitions, options, context); return await popup.termsShow(elementRect, writingMode, definitions, context);
} }
async kanjiShow(id, elementRect, writingMode, definitions, options, context) { async kanjiShow(id, elementRect, writingMode, definitions, context) {
const popup = this.getPopup(id); const popup = this.getPopup(id);
elementRect = this.jsonRectToDOMRect(popup, elementRect); elementRect = this.jsonRectToDOMRect(popup, elementRect);
if (!PopupProxyHost.popupCanShow(popup)) { return false; } if (!PopupProxyHost.popupCanShow(popup)) { return false; }
return await popup.kanjiShow(elementRect, writingMode, definitions, options, context); return await popup.kanjiShow(elementRect, writingMode, definitions, context);
} }
async clearAutoPlayTimer(id) { async clearAutoPlayTimer(id) {

View File

@ -51,10 +51,10 @@ class PopupProxy {
return await this.invokeHostApi('setOptions', {id, options}); return await this.invokeHostApi('setOptions', {id, options});
} }
async showOrphaned(elementRect, options) { async showOrphaned(elementRect) {
const id = await this.getPopupId(); const id = await this.getPopupId();
elementRect = PopupProxy.DOMRectToJson(elementRect); elementRect = PopupProxy.DOMRectToJson(elementRect);
return await this.invokeHostApi('showOrphaned', {id, elementRect, options}); return await this.invokeHostApi('showOrphaned', {id, elementRect});
} }
async hide(changeFocus) { async hide(changeFocus) {
@ -76,16 +76,16 @@ class PopupProxy {
return await this.invokeHostApi('containsPoint', {id: this.id, x, y}); return await this.invokeHostApi('containsPoint', {id: this.id, x, y});
} }
async termsShow(elementRect, writingMode, definitions, options, context) { async termsShow(elementRect, writingMode, definitions, context) {
const id = await this.getPopupId(); const id = await this.getPopupId();
elementRect = PopupProxy.DOMRectToJson(elementRect); elementRect = PopupProxy.DOMRectToJson(elementRect);
return await this.invokeHostApi('termsShow', {id, elementRect, writingMode, definitions, options, context}); return await this.invokeHostApi('termsShow', {id, elementRect, writingMode, definitions, context});
} }
async kanjiShow(elementRect, writingMode, definitions, options, context) { async kanjiShow(elementRect, writingMode, definitions, context) {
const id = await this.getPopupId(); const id = await this.getPopupId();
elementRect = PopupProxy.DOMRectToJson(elementRect); elementRect = PopupProxy.DOMRectToJson(elementRect);
return await this.invokeHostApi('kanjiShow', {id, elementRect, writingMode, definitions, options, context}); return await this.invokeHostApi('kanjiShow', {id, elementRect, writingMode, definitions, context});
} }
async clearAutoPlayTimer() { async clearAutoPlayTimer() {

View File

@ -41,14 +41,14 @@ class Popup {
this.updateVisibility(); this.updateVisibility();
} }
inject(options) { inject() {
if (this.injectPromise === null) { if (this.injectPromise === null) {
this.injectPromise = this.createInjectPromise(options); this.injectPromise = this.createInjectPromise();
} }
return this.injectPromise; return this.injectPromise;
} }
async createInjectPromise(options) { async createInjectPromise() {
try { try {
const {frameId} = await this.frameIdPromise; const {frameId} = await this.frameIdPromise;
if (typeof frameId === 'number') { if (typeof frameId === 'number') {
@ -62,7 +62,7 @@ class Popup {
const parentFrameId = (typeof this.frameId === 'number' ? this.frameId : null); const parentFrameId = (typeof this.frameId === 'number' ? this.frameId : null);
this.container.addEventListener('load', () => { this.container.addEventListener('load', () => {
this.invokeApi('initialize', { this.invokeApi('initialize', {
options: options, options: this.options,
popupInfo: { popupInfo: {
id: this.id, id: this.id,
depth: this.depth, depth: this.depth,
@ -87,10 +87,10 @@ class Popup {
this.options = options; this.options = options;
} }
async show(elementRect, writingMode, options) { async show(elementRect, writingMode) {
await this.inject(options); await this.inject();
const optionsGeneral = options.general; const optionsGeneral = this.options.general;
const container = this.container; const container = this.container;
const containerRect = container.getBoundingClientRect(); const containerRect = container.getBoundingClientRect();
const getPosition = ( const getPosition = (
@ -215,9 +215,9 @@ class Popup {
return [position, size, after]; return [position, size, after];
} }
async showOrphaned(elementRect, writingMode, options) { async showOrphaned(elementRect, writingMode) {
if (!this.isInitialized()) { return; } if (!this.isInitialized()) { return; }
await this.show(elementRect, writingMode, options); await this.show(elementRect, writingMode);
this.invokeApi('orphaned'); this.invokeApi('orphaned');
} }
@ -279,16 +279,16 @@ class Popup {
return false; return false;
} }
async termsShow(elementRect, writingMode, definitions, options, context) { async termsShow(elementRect, writingMode, definitions, context) {
if (!this.isInitialized()) { return; } if (!this.isInitialized()) { return; }
await this.show(elementRect, writingMode, options); await this.show(elementRect, writingMode);
this.invokeApi('termsShow', {definitions, options, context}); this.invokeApi('termsShow', {definitions, context});
} }
async kanjiShow(elementRect, writingMode, definitions, options, context) { async kanjiShow(elementRect, writingMode, definitions, context) {
if (!this.isInitialized()) { return; } if (!this.isInitialized()) { return; }
await this.show(elementRect, writingMode, options); await this.show(elementRect, writingMode);
this.invokeApi('kanjiShow', {definitions, options, context}); this.invokeApi('kanjiShow', {definitions, context});
} }
clearAutoPlayTimer() { clearAutoPlayTimer() {

View File

@ -76,7 +76,7 @@ class Display {
} }
const kanjiDefs = await apiKanjiFind(link.textContent, this.getOptionsContext()); const kanjiDefs = await apiKanjiFind(link.textContent, this.getOptionsContext());
this.kanjiShow(kanjiDefs, this.options, context); this.kanjiShow(kanjiDefs, context);
} catch (e) { } catch (e) {
this.onError(e); this.onError(e);
} }
@ -125,7 +125,7 @@ class Display {
context.source.source = this.context.source; context.source.source = this.context.source;
} }
this.termsShow(definitions, this.options, context); this.termsShow(definitions, context);
} catch (e) { } catch (e) {
this.onError(e); this.onError(e);
} }
@ -239,10 +239,12 @@ class Display {
}); });
} }
async termsShow(definitions, options, context) { async termsShow(definitions, context) {
if (!this.isInitialized()) { return; } if (!this.isInitialized()) { return; }
try { try {
const options = this.options;
this.setEventListenersActive(false); this.setEventListenersActive(false);
if (!context || context.focus !== false) { if (!context || context.focus !== false) {
@ -250,7 +252,6 @@ class Display {
} }
this.definitions = definitions; this.definitions = definitions;
this.options = options;
this.context = context; this.context = context;
const sequence = ++this.sequence; const sequence = ++this.sequence;
@ -280,7 +281,7 @@ class Display {
const {index, scroll} = context || {}; const {index, scroll} = context || {};
this.entryScrollIntoView(index || 0, scroll); this.entryScrollIntoView(index || 0, scroll);
if (this.options.audio.enabled && this.options.audio.autoPlay) { if (options.audio.enabled && options.audio.autoPlay) {
this.autoPlayAudio(); this.autoPlayAudio();
} }
@ -292,10 +293,12 @@ class Display {
} }
} }
async kanjiShow(definitions, options, context) { async kanjiShow(definitions, context) {
if (!this.isInitialized()) { return; } if (!this.isInitialized()) { return; }
try { try {
const options = this.options;
this.setEventListenersActive(false); this.setEventListenersActive(false);
if (!context || context.focus !== false) { if (!context || context.focus !== false) {
@ -303,7 +306,6 @@ class Display {
} }
this.definitions = definitions; this.definitions = definitions;
this.options = options;
this.context = context; this.context = context;
const sequence = ++this.sequence; const sequence = ++this.sequence;
@ -415,7 +417,7 @@ class Display {
source: this.context.source.source source: this.context.source.source
}; };
this.termsShow(this.context.source.definitions, this.options, context); this.termsShow(this.context.source.definitions, context);
} }
} }