Add disableEventListener() and enableEventListener() to EventListenerService.cpp
Categories
(DevTools :: Inspector, enhancement, P3)
Tracking
(firefox46 affected)
Tracking | Status | |
---|---|---|
firefox46 | --- | affected |
People
(Reporter: miker, Unassigned)
References
(Blocks 1 open bug)
Details
Attachments
(1 file)
205.45 KB,
image/png
|
Details |
It would be awesome if developer tools had a way to toggle events on and off and adding these two methods would make this possible.
Comment 1•8 years ago
|
||
It is not clear to me what this is about. Is this about disabling some event listener temporarily or disabling handling certain event type temporarily or what?
Comment 2•8 years ago
|
||
Also, whatever this is about, would this be global or just some particular event target?
Reporter | ||
Comment 3•8 years ago
|
||
See the attached image to get some idea of the UX: In the Inspector we show each node and if there are any events attached to that node we show a small button labelled "ev". Clicking on "ev" shows a popup containing an accordian style list of events attached to that node. The pause button opens that event's handler in the debugger. We would like to add a button to the popup to toggle the specific event disabled / enabled. I should have been clearer about the API: disableEventListener(node, "click", onButtonClicked, true); enableEventListener(node, "click", onButtonClicked, true); When the event is disabled it should still be obtainable using getListenerInfoFor() etc. but it should not be triggered. We considered just removing the event and adding it again but that would result in events being triggered out of sequence.
Comment 4•8 years ago
|
||
(In reply to Michael Ratcliffe [:miker] [:mratcliffe] from comment #3) > In the Inspector we show each node and if there are any events attached to > that node we show a small button labelled "ev". "events attached" == "event listeners added", right? > We would like to add a button to the popup to toggle the specific event > disabled / enabled. So "event disabled" means the event shouldn't fire at all? But I think you're talking about event listeners being disabled. > I should have been clearer about the API: > disableEventListener(node, "click", onButtonClicked, true); > enableEventListener(node, "click", onButtonClicked, true); ok, so some particular event listener for some event target could be disabled. > We considered just removing the event and adding it again but that would > result in events being triggered out of sequence. Right. So, EventListenerManager::Listener struct could have a bool flag to tell whether it is enabled or disabled and EventListenerManager::Listener::IsListening would just check that and if disabled, return false.
Reporter | ||
Comment 5•5 years ago
|
||
We could use the Debugger API to set a hidden (to the user) breakpoint on the first bytecode of the listener, and when the breakpoint hits force an early return rather than executing the body.
This would not require any additional platform work and builds on the debugging primitives we already use.
@jlast Is this something that would be simple to implement? The UI is simple but I am not sure how large a patch this would be on the debugger side.
Comment 6•5 years ago
|
||
I think that would be possible. I think Logan's new event system might be a better fit as we can subscribe to specific events i.e. "click" and not just byte offsets. This way we can pause when there is a click event that calls the listener we care about.
Comment 7•5 years ago
•
|
||
The downside of the breakpoint approach is that a function can be an event handler on multiple nodes, like
function doThing() {
}
node.addEventListener("click", doThing);
otherNode.addEventListener("click", doThing);
and I wouldn't want disabling the node
event listener to necessarily also cancel the listener for otherNode
. You presumably want to cancel a given triplet of (Node, EventType, Function) and maybe even taking the event-listener options into account? (passive, capture, etc)
The new logic in https://bugzilla.mozilla.org/show_bug.cgi?id=1529345 should work great for this. It notifies you just before and just after Gecko calls an event handler, and it gives you the Event
object, so you can check the event's currentTarget
and type, and if it is a partial match for the triplet, you can set an onEnterFrame
handler to run code when the listener runs. Then on enter, you could look to see what function you entered, and if it is the one you want to cancel, stop execution of the function immediately.
Updated•3 years ago
|
Updated•2 years ago
|
Description
•