ScreenshotsHelperChild.sys.mjs (1509B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 import { 6 getBestRectForElement, 7 getElementFromPoint, 8 } from "chrome://browser/content/screenshots/overlayHelpers.mjs"; 9 10 /** 11 * This class is used to get the dimensions of hovered elements within iframes. 12 * The main content process cannot get the dimensions of elements within 13 * iframes so a message will be send to this actor to get the dimensions of the 14 * element for a given point inside the iframe. 15 */ 16 export class ScreenshotsHelperChild extends JSWindowActorChild { 17 receiveMessage(message) { 18 if (message.name === "ScreenshotsHelper:GetElementRectFromPoint") { 19 return this.getBestElementRectFromPoint(message.data); 20 } 21 return null; 22 } 23 24 async getBestElementRectFromPoint(data) { 25 let { x, y } = data; 26 27 x -= this.contentWindow.mozInnerScreenX; 28 y -= this.contentWindow.mozInnerScreenY; 29 30 let { ele, rect } = await getElementFromPoint(x, y, this.document); 31 32 if (!rect) { 33 rect = getBestRectForElement(ele, this.document); 34 } 35 36 if (rect) { 37 rect = { 38 left: rect.left + this.contentWindow.mozInnerScreenX, 39 right: rect.right + this.contentWindow.mozInnerScreenX, 40 top: rect.top + this.contentWindow.mozInnerScreenY, 41 bottom: rect.bottom + this.contentWindow.mozInnerScreenY, 42 }; 43 } 44 45 return rect; 46 } 47 }