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();
if (valid) {
const {definitions} = await apiTermsFind(query, this.optionsContext);
this.termsShow(definitions, this.options);
this.termsShow(definitions, {
focus: false,
sentence: null,
url: window.location.href
});
} else {
this.container.textContent = '';
}

View File

@ -143,8 +143,8 @@ DisplayFloat.onKeyDownHandlers = {
};
DisplayFloat.messageHandlers = {
termsShow: (self, {definitions, options, context}) => self.termsShow(definitions, options, context),
kanjiShow: (self, {definitions, options, context}) => self.kanjiShow(definitions, options, context),
termsShow: (self, {definitions, context}) => self.termsShow(definitions, context),
kanjiShow: (self, {definitions, context}) => self.kanjiShow(definitions, context),
clearAutoPlayTimer: (self) => self.clearAutoPlayTimer(),
orphaned: (self) => self.onOrphaned(),
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') {
this.popup.showOrphaned(
textSource.getRect(),
textSource.getWritingMode(),
this.options
textSource.getWritingMode()
);
}
} else {
@ -374,7 +373,6 @@ class Frontend {
textSource.getRect(),
textSource.getWritingMode(),
definitions,
this.options,
{sentence, url, focus}
);
@ -405,7 +403,6 @@ class Frontend {
textSource.getRect(),
textSource.getWritingMode(),
definitions,
this.options,
{sentence, url, focus}
);

View File

@ -39,12 +39,12 @@ class PopupProxyHost {
this.apiReceiver = new FrontendApiReceiver(`popup-proxy-host#${frameId}`, {
createNestedPopup: ({parentId}) => this.createNestedPopup(parentId),
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),
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),
termsShow: ({id, elementRect, writingMode, definitions, context}) => this.termsShow(id, elementRect, writingMode, definitions, context),
kanjiShow: ({id, elementRect, writingMode, definitions, context}) => this.kanjiShow(id, elementRect, writingMode, definitions, context),
clearAutoPlayTimer: ({id}) => this.clearAutoPlayTimer(id)
});
}
@ -91,10 +91,10 @@ class PopupProxyHost {
return await popup.setOptions(options);
}
async showOrphaned(id, elementRect, options) {
async showOrphaned(id, elementRect) {
const popup = this.getPopup(id);
elementRect = this.jsonRectToDOMRect(popup, elementRect);
return await popup.showOrphaned(elementRect, options);
return await popup.showOrphaned(elementRect);
}
async hide(id, changeFocus) {
@ -112,18 +112,18 @@ class PopupProxyHost {
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);
elementRect = this.jsonRectToDOMRect(popup, elementRect);
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);
elementRect = this.jsonRectToDOMRect(popup, elementRect);
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) {

View File

@ -51,10 +51,10 @@ class PopupProxy {
return await this.invokeHostApi('setOptions', {id, options});
}
async showOrphaned(elementRect, options) {
async showOrphaned(elementRect) {
const id = await this.getPopupId();
elementRect = PopupProxy.DOMRectToJson(elementRect);
return await this.invokeHostApi('showOrphaned', {id, elementRect, options});
return await this.invokeHostApi('showOrphaned', {id, elementRect});
}
async hide(changeFocus) {
@ -76,16 +76,16 @@ class PopupProxy {
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();
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();
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() {

View File

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

View File

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