Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Web Inspector: Elements Tab: create an Event badge for nodes that hav…
…e event listeners https://bugs.webkit.org/show_bug.cgi?id=244124 Reviewed by Patrick Angle. Only show "Event" badges for nodes that directly have event listeners (i.e. no ancestors). This will give developers a visual way of seeing where an event could be handled in a particular ancestor path as they'd be able to scan for "Event" badges to find every ancestor that has an event listener. Clicking the "Event" badge will show a popover containing details about the attached event listeners, such as capturing/bubbling, once, enabled/disabled, and breakpoint, all grouped by event type. * Source/JavaScriptCore/inspector/protocol/CSS.json: Add an `"event"` enum value to `CSS.LayoutFlag`. * Source/WebCore/inspector/InspectorInstrumentation.cpp: (WebCore::InspectorInstrumentation::didAddEventListenerImpl): (WebCore::InspectorInstrumentation::willRemoveEventListenerImpl): Also inform the `InspectorCSSAgent` that an event listener was added/removed. * Source/WebCore/inspector/agents/InspectorCSSAgent.h: * Source/WebCore/inspector/agents/InspectorCSSAgent.cpp: (WebCore::InspectorCSSAgent::reset): (WebCore::layoutFlagContextType): (WebCore::layoutFlagsContainLayoutContextType): Added. (WebCore::hasJSEventListener): (WebCore::InspectorCSSAgent::layoutFlagsForNode): (WebCore::toProtocol): Added. (WebCore::InspectorCSSAgent::protocolLayoutFlagsForNode): Added. (WebCore::pushChildrenNodesToFrontendIfLayoutFlagIsRelevant): (WebCore::InspectorCSSAgent::didChangeRendererForDOMNode): (WebCore::InspectorCSSAgent::didAddEventListener): Added. (WebCore::InspectorCSSAgent::willRemoveEventListener): Added. (WebCore::InspectorCSSAgent::nodeHasLayoutFlagsChange): Added. (WebCore::InspectorCSSAgent::nodesWithPendingLayoutFlagsChangeDispatchTimerFired): (WebCore::layoutFlagContextTypeForRenderer): Deleted. Keep track of the layout flags for each `Node` to avoid re-dispatching the same flags to the frontend. This is especially important for event listeners as they can be very noisy (211169@main). * Source/JavaScriptCore/inspector/protocol/DOM.json: * Source/WebCore/inspector/agents/InspectorDOMAgent.h: * Source/WebCore/inspector/agents/InspectorDOMAgent.cpp: (WebCore::InspectorDOMAgent::getEventListenersForNode): (WebCore::InspectorDOMAgent::buildObjectForNode): Allow `DOM.getEventListenersForNode` to control whether ancestor event listeners are included. * Source/WebInspectorUI/UserInterface/Models/DOMNode.js: (WI.DOMNode.prototype.set layoutFlags): (WI.DOMNode.prototype.getEventListeners): * Source/WebInspectorUI/UserInterface/Views/DOMTreeContentView.js: (WI.DOMTreeContentView.prototype._populateConfigureDOMTreeBadgesNavigationItemContextMenu): * Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.js: (WI.DOMTreeElement.prototype._createBadge): (WI.DOMTreeElement.prototype._createBadges): (WI.DOMTreeElement.prototype.async _handleEventBadgeClicked): Added. (WI.DOMTreeElement.prototype._handleBadgeDoubleClicked): Renamed from `_layoutBadgeDoubleClicked`. * Source/WebInspectorUI/UserInterface/Views/DOMTreeElement.css: (.event-badge-popover-content): Added. (.event-badge-popover-content > .details-section.event-listeners): Added. (.event-badge-popover-content > .details-section.event-listeners .details-section): Added. Add logic for creating an "Event" badge that shows the list of event listeners directly attached to that node (i.e. no ancestors). * Source/WebInspectorUI/UserInterface/Views/EventListenerSectionGroup.js: (WI.EventListenerSectionGroup.groupIntoSectionsByEvent): Added. (WI.EventListenerSectionGroup.groupIntoSectionsByTarget): Added. (WI.EventListenerSectionGroup._createEventListenerSection): Added. * Source/WebInspectorUI/UserInterface/Views/EventListenerSectionGroup.css: (.event-listener-section > .header > .event-listener-options): Added. (.event-listener-section:hover > .header > .event-listener-options): Added. * Source/WebInspectorUI/UserInterface/Views/DOMNodeDetailsSidebarPanel.js: (WI.DOMNodeDetailsSidebarPanel.prototype.async _refreshEventListeners): (WI.DOMNodeDetailsSidebarPanel.prototype._refreshEventListeners.createEventListenerSection): Deleted. (WI.DOMNodeDetailsSidebarPanel.prototype._refreshEventListeners.generateGroupsByEvent): Deleted. (WI.DOMNodeDetailsSidebarPanel.prototype._refreshEventListeners.generateGroupsByTarget): Deleted. (WI.DOMNodeDetailsSidebarPanel.prototype._refreshEventListeners.eventListenersCallback): Deleted. * Source/WebInspectorUI/UserInterface/Views/DOMNodeDetailsSidebarPanel.css: (.sidebar > .panel.dom-node-details .details-section.dom-node-event-listeners .details-section.event-listener-section > .header > .event-listener-options): Deleted. (.sidebar > .panel.dom-node-details .details-section.dom-node-event-listeners .details-section.event-listener-section:hover > .header > .event-listener-options): Deleted. Move the code that groups `WI.EventListenerSectionGroup` to be `static` methods on `WI.EventListenerSectionGroup` so that it can be reused in other places (e.g. inside the `WI.Popover` for the "Event" badge). * Source/WebInspectorUI/UserInterface/Views/Popover.js: (WI.Popover.prototype.present): Add an option to also update the sizing of the `WI.Popover` when re-presenting the same content. This is necessary because the `WI.Popover` for the "Event" badge is limited in height to the size of Web Inspector, so resizing Web Inspector should also resize the popover (not just reposition). * Source/WebInspectorUI/UserInterface/Views/DetailsSection.js: (WI.DetailsSection): * Source/WebInspectorUI/UserInterface/Views/DetailsSection.css: (.details-section .details-section > .header): (.details-section:has(> .header > .title:not(:empty)) .details-section > .header): Added. Don't lower the header of a subsection unless the parent section has a `title`. This is necessary because the `WI.Popover` for the "Event" badge has a top-level `WI.DetailsSection` with no `title` in order to get the same nested styling applied to the Event Listeners section in the Node panel of the details sidebar in the Elements Tab. * LayoutTests/inspector/css/nodeLayoutFlagsChanged-Event-attribute.html: Added. * LayoutTests/inspector/css/nodeLayoutFlagsChanged-Event-attribute-expected.txt: Added. * LayoutTests/inspector/css/nodeLayoutFlagsChanged-Event-script.html: Added. * LayoutTests/inspector/css/nodeLayoutFlagsChanged-Event-script-expected.txt: Added. * LayoutTests/inspector/dom/getEventListenersForNode.html: * LayoutTests/inspector/dom/getEventListenersForNode-expected.txt: Canonical link: https://commits.webkit.org/253727@main
- Loading branch information