head.js (2339B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 /* eslint no-unused-vars: [2, {"vars": "local"}] */ 4 5 "use strict"; 6 7 // Import the inspector's head.js first (which itself imports shared-head.js). 8 Services.scriptloader.loadSubScript( 9 "chrome://mochitests/content/browser/devtools/client/inspector/test/head.js", 10 this 11 ); 12 13 const asyncStorage = require("resource://devtools/shared/async-storage.js"); 14 15 registerCleanupFunction(async function () { 16 await asyncStorage.removeItem("gridInspectorHostColors"); 17 }); 18 19 /** 20 * Simulate a mouseover event on a grid cell currently rendered in the grid 21 * inspector. 22 * 23 * @param {Document} doc 24 * The owner document for the grid inspector. 25 * @param {number} gridCellIndex 26 * The index (0-based) of the grid cell that should be hovered. 27 */ 28 function synthesizeMouseOverOnGridCell(doc, gridCellIndex = 0) { 29 // Make sure to retrieve the current live grid item before attempting to 30 // interact with it using mouse APIs. 31 const gridCell = doc.querySelectorAll("#grid-cell-group rect")[gridCellIndex]; 32 33 EventUtils.synthesizeMouseAtCenter( 34 gridCell, 35 { type: "mouseover" }, 36 doc.defaultView 37 ); 38 } 39 40 /** 41 * Returns the number of visible grid highlighters 42 * 43 * @param {object} options 44 * @param {boolean} options.isParent: Pass false/true if only the parent/child grid highlighter 45 * should be counted. 46 * @returns {number} 47 */ 48 function getNumberOfVisibleGridHighlighters({ isParent } = {}) { 49 return SpecialPowers.spawn( 50 gBrowser.selectedBrowser, 51 [isParent], 52 _isParent => { 53 const roots = content.document.getConnectedShadowRoots(); 54 return roots.filter(root => { 55 // We want to check that the highlighter canvas is actually visible 56 const gridHighlighterEl = root.querySelector( 57 `#css-grid-root:has(canvas:not([hidden]))` 58 ); 59 60 if (!gridHighlighterEl) { 61 return false; 62 } 63 64 if (typeof _isParent === "boolean") { 65 return ( 66 gridHighlighterEl.getAttribute("data-is-parent-grid") === 67 _isParent.toString() 68 ); 69 } 70 71 // If isParent wasn't passed, we return all grid highlighters, parent and child. 72 return true; 73 }).length; 74 } 75 ); 76 }