fix popup containsPoint offset

This commit is contained in:
siikamiika 2020-03-07 03:52:36 +02:00
parent 421b60db0f
commit 86be737508

View File

@ -116,7 +116,8 @@ class PopupProxyHost {
async _onApiContainsPoint({id, x, y}) { async _onApiContainsPoint({id, x, y}) {
const popup = this._getPopup(id); const popup = this._getPopup(id);
return await popup.containsPoint(x, y); const rootPagePoint = PopupProxyHost._convertPopupPointToRootPagePoint(popup, x, y);
return await popup.containsPoint(...rootPagePoint);
} }
async _onApiShowContent({id, elementRect, writingMode, type, details}) { async _onApiShowContent({id, elementRect, writingMode, type, details}) {
@ -152,14 +153,17 @@ class PopupProxyHost {
} }
static _convertJsonRectToDOMRect(popup, jsonRect) { static _convertJsonRectToDOMRect(popup, jsonRect) {
let x = jsonRect.x; const [x, y] = PopupProxyHost._convertPopupPointToRootPagePoint(popup, jsonRect.x, jsonRect.y);
let y = jsonRect.y; return new DOMRect(x, y, jsonRect.width, jsonRect.height);
}
static _convertPopupPointToRootPagePoint(popup, x, y) {
if (popup.parent !== null) { if (popup.parent !== null) {
const popupRect = popup.parent.getContainerRect(); const popupRect = popup.parent.getContainerRect();
x += popupRect.x; x += popupRect.x;
y += popupRect.y; y += popupRect.y;
} }
return new DOMRect(x, y, jsonRect.width, jsonRect.height); return [x, y];
} }
static _popupCanShow(popup) { static _popupCanShow(popup) {