Simplify Popup.showContent API to use only two details arguments (#684)
This commit is contained in:
parent
3754c92041
commit
e493cbc998
@ -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(),
|
||||
{
|
||||
source: this._id,
|
||||
optionsContext,
|
||||
elementRect: textSource.getRect(),
|
||||
writingMode: textSource.getWritingMode()
|
||||
},
|
||||
{
|
||||
type,
|
||||
details,
|
||||
context
|
||||
details
|
||||
}
|
||||
);
|
||||
this._lastShowPromise.catch((error) => {
|
||||
if (yomichan.isExtensionUnloaded) { return; }
|
||||
|
@ -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}) {
|
||||
|
@ -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) {
|
||||
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);
|
||||
}
|
||||
elementRect = {x, y, width, height};
|
||||
return await this._invoke('showContent', {id: this._id, elementRect, writingMode, type, details, context});
|
||||
details.elementRect = {x, y, width, height};
|
||||
}
|
||||
return await this._invoke('showContent', {id: this._id, details, displayDetails});
|
||||
}
|
||||
|
||||
setCustomCss(css) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
if (typeof elementRect !== 'undefined' && typeof writingMode !== 'undefined') {
|
||||
await this._show(elementRect, writingMode);
|
||||
if (type === null) { return; }
|
||||
this._invokeApi('setContent', {type, details});
|
||||
}
|
||||
|
||||
if (displayDetails !== null) {
|
||||
this._invokeApi('setContent', {type: displayDetails.type, details: displayDetails.details});
|
||||
}
|
||||
}
|
||||
|
||||
setCustomCss(css) {
|
||||
|
Loading…
Reference in New Issue
Block a user