Simplify Popup.showContent API to use only two details arguments (#684)

This commit is contained in:
toasted-nutbread 2020-07-24 17:34:53 -04:00 committed by GitHub
parent 3754c92041
commit e493cbc998
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 22 deletions

View File

@ -432,13 +432,17 @@ class Frontend {
}
_showPopupContent(textSource, optionsContext, type=null, details=null) {
const context = {optionsContext, source: this._id};
this._lastShowPromise = this._popup.showContent(
textSource.getRect(),
textSource.getWritingMode(),
type,
details,
context
{
source: this._id,
optionsContext,
elementRect: textSource.getRect(),
writingMode: textSource.getWritingMode()
},
{
type,
details
}
);
this._lastShowPromise.catch((error) => {
if (yomichan.isExtensionUnloaded) { return; }

View File

@ -124,11 +124,16 @@ class PopupFactory {
return await popup.containsPoint(x, y);
}
async _onApiShowContent({id, elementRect, writingMode, type, details, context}) {
async _onApiShowContent({id, details, displayDetails}) {
const popup = this._getPopup(id);
elementRect = this._convertJsonRectToDOMRect(popup, elementRect);
if (!this._popupCanShow(popup)) { return; }
return await popup.showContent(elementRect, writingMode, type, details, context);
const {elementRect} = details;
if (typeof elementRect !== 'undefined') {
details.elementRect = this._convertJsonRectToDOMRect(popup, elementRect);
}
return await popup.showContent(details, displayDetails);
}
_onApiSetCustomCss({id, css}) {

View File

@ -88,14 +88,17 @@ class PopupProxy extends EventDispatcher {
return await this._invoke('containsPoint', {id: this._id, x, y});
}
async showContent(elementRect, writingMode, type, details, context) {
let {x, y, width, height} = elementRect;
if (this._frameOffsetForwarder !== null) {
await this._updateFrameOffset();
[x, y] = this._applyFrameOffset(x, y);
async showContent(details, displayDetails) {
const {elementRect} = details;
if (typeof elementRect !== 'undefined') {
let {x, y, width, height} = elementRect;
if (this._frameOffsetForwarder !== null) {
await this._updateFrameOffset();
[x, y] = this._applyFrameOffset(x, y);
}
details.elementRect = {x, y, width, height};
}
elementRect = {x, y, width, height};
return await this._invoke('showContent', {id: this._id, elementRect, writingMode, type, details, context});
return await this._invoke('showContent', {id: this._id, details, displayDetails});
}
setCustomCss(css) {

View File

@ -133,17 +133,21 @@ class Popup {
return false;
}
async showContent(elementRect, writingMode, type, details, context) {
async showContent(details, displayDetails) {
if (this._options === null) { throw new Error('Options not assigned'); }
const {optionsContext, source} = context;
if (source !== this._previousOptionsContextSource) {
const {source, optionsContext, elementRect, writingMode} = details;
if (typeof source !== 'undefined' && source !== this._previousOptionsContextSource) {
await this.setOptionsContext(optionsContext, source);
}
await this._show(elementRect, writingMode);
if (type === null) { return; }
this._invokeApi('setContent', {type, details});
if (typeof elementRect !== 'undefined' && typeof writingMode !== 'undefined') {
await this._show(elementRect, writingMode);
}
if (displayDetails !== null) {
this._invokeApi('setContent', {type: displayDetails.type, details: displayDetails.details});
}
}
setCustomCss(css) {