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) { _showPopupContent(textSource, optionsContext, type=null, details=null) {
const context = {optionsContext, source: this._id};
this._lastShowPromise = this._popup.showContent( this._lastShowPromise = this._popup.showContent(
textSource.getRect(), {
textSource.getWritingMode(), source: this._id,
type, optionsContext,
details, elementRect: textSource.getRect(),
context writingMode: textSource.getWritingMode()
},
{
type,
details
}
); );
this._lastShowPromise.catch((error) => { this._lastShowPromise.catch((error) => {
if (yomichan.isExtensionUnloaded) { return; } if (yomichan.isExtensionUnloaded) { return; }

View File

@ -124,11 +124,16 @@ class PopupFactory {
return await popup.containsPoint(x, y); return await popup.containsPoint(x, y);
} }
async _onApiShowContent({id, elementRect, writingMode, type, details, context}) { async _onApiShowContent({id, details, displayDetails}) {
const popup = this._getPopup(id); const popup = this._getPopup(id);
elementRect = this._convertJsonRectToDOMRect(popup, elementRect);
if (!this._popupCanShow(popup)) { return; } 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}) { _onApiSetCustomCss({id, css}) {

View File

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

View File

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