diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
commit | 8dd16259287f58f9273002717ec4d27e97127719 (patch) | |
tree | 3863e62a53829a84037444beab3abd4ed9dfc7d0 /devtools/server/actors/inspector/node-picker.js | |
parent | Releasing progress-linux version 126.0.1-1~progress7.99u1. (diff) | |
download | firefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz firefox-8dd16259287f58f9273002717ec4d27e97127719.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/server/actors/inspector/node-picker.js')
-rw-r--r-- | devtools/server/actors/inspector/node-picker.js | 74 |
1 files changed, 42 insertions, 32 deletions
diff --git a/devtools/server/actors/inspector/node-picker.js b/devtools/server/actors/inspector/node-picker.js index 4e090959c9..21777ced80 100644 --- a/devtools/server/actors/inspector/node-picker.js +++ b/devtools/server/actors/inspector/node-picker.js @@ -79,42 +79,52 @@ class NodePicker { * @returns HTMLElement */ _findNodeAtMouseEventPosition(event) { - const winUtils = this._targetActor.window.windowUtils; + const win = this._targetActor.window; + const winUtils = win.windowUtils; const rectSize = 1; - const elements = winUtils.nodesFromRect( - // aX - event.clientX, - // aY - event.clientY, - // aTopSize - rectSize, - // aRightSize - rectSize, - // aBottomSize - rectSize, - // aLeftSize - rectSize, - // aIgnoreRootScrollFrame - true, - // aFlushLayout - false, - // aOnlyVisible - true, - // aTransparencyThreshold - 1 - ); + const elements = Array.from( + winUtils.nodesFromRect( + // aX + event.clientX, + // aY + event.clientY, + // aTopSize + rectSize, + // aRightSize + rectSize, + // aBottomSize + rectSize, + // aLeftSize + rectSize, + // aIgnoreRootScrollFrame + true, + // aFlushLayout + false, + // aOnlyVisible + true, + // aTransparencyThreshold + 1 + ) + ).filter(element => { + // Strip out text nodes, we want to highlight Elements only + return !win.Text.isInstance(element); + }); - // ⚠️ When a highlighter was added to the page (which is the case at this point), - // the first element is the html node, and might be the last one as well (See Bug 1744941). - // Until we figure this out, let's pick the second returned item when hit this. - if ( - elements.length > 1 && - ChromeUtils.getClassName(elements[0]) == "HTMLHtmlElement" - ) { - return elements[1]; + if (!elements.length) { + return null; } - return elements[0]; + if (elements.length === 1) { + return elements[0]; + } + + // Let's return the first element that we find that is not a parent of another matching + // element, so we get the "deepest" element possible. + // At this points, we have at least 2 elements and are guaranteed to find an element + // which is not the parent of any other ones. + return elements.find( + element => !elements.some(e => element !== e && element.contains(e)) + ); } /** |