mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:47:45 +00:00
LibWeb+LibWebView+WebContent: Add an Inspector IPC to open context menus
The Inspector will have context menu support to manipulate the DOM, e.g. adding or removing nodes/attributes. This context menu will require some detailed knowledge about what element in the Inspector has been clicked. To support this, we intercept the `contextmenu` event and collect the required information to be sent to the Inspector client over IPC.
This commit is contained in:
parent
2d69a009fb
commit
2633ea8c79
13 changed files with 89 additions and 1 deletions
|
@ -5,6 +5,7 @@ let selectedBottomTab = null;
|
|||
let selectedBottomTabButton = null;
|
||||
|
||||
let selectedDOMNode = null;
|
||||
let pendingEditDOMNode = null;
|
||||
|
||||
let consoleGroupStack = [];
|
||||
let consoleGroupNextID = 0;
|
||||
|
@ -233,6 +234,34 @@ const editDOMNode = domNode => {
|
|||
});
|
||||
};
|
||||
|
||||
const requestContextMenu = (clientX, clientY, domNode) => {
|
||||
pendingEditDOMNode = null;
|
||||
|
||||
if (typeof domNode.dataset.nodeType === "undefined") {
|
||||
if (domNode.parentNode !== null) {
|
||||
domNode = domNode.parentNode;
|
||||
}
|
||||
}
|
||||
|
||||
const domNodeID = domNode.closest(".hoverable")?.dataset.id;
|
||||
const type = domNode.dataset.nodeType;
|
||||
|
||||
if (typeof domNodeID === "undefined" || typeof type === "undefined") {
|
||||
return;
|
||||
}
|
||||
|
||||
let tagOrAttributeName = null;
|
||||
pendingEditDOMNode = domNode;
|
||||
|
||||
if (type === "tag") {
|
||||
tagOrAttributeName = domNode.innerText;
|
||||
} else if (type === "attribute") {
|
||||
tagOrAttributeName = domNode.dataset.attributeName;
|
||||
}
|
||||
|
||||
inspector.requestDOMTreeContextMenu(domNodeID, clientX, clientY, type, tagOrAttributeName);
|
||||
};
|
||||
|
||||
const executeConsoleScript = consoleInput => {
|
||||
const script = consoleInput.value;
|
||||
|
||||
|
@ -371,5 +400,10 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||
}
|
||||
});
|
||||
|
||||
document.addEventListener("contextmenu", event => {
|
||||
requestContextMenu(event.clientX, event.clientY, event.target);
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
inspector.inspectorLoaded();
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue