Bug 1748431 - [devtools] Remove unnecessary setEventTooltip function. r=ochameau.

The function was only creating an EventTooltip instance, so we can directly modify
the only call site to do the same thing.

Since the EventTooltip isn't responsible for showing the tooltip itself, and given
that the consumer code already does some work when the tooltip gets hidden, we
let the consumer call EventTooltip#destroy instead of having the EventTooltip
register the event listener on the tooltip.

Differential Revision: https://phabricator.services.mozilla.com/D135127
This commit is contained in:
Nicolas Chevobbe 2022-01-07 07:50:02 +00:00
Родитель a98fcc09e6
Коммит face640fe2
2 изменённых файлов: 19 добавлений и 23 удалений

Просмотреть файл

@ -12,7 +12,7 @@ const { extend } = require("devtools/shared/extend");
loader.lazyRequireGetter(
this,
"setEventTooltip",
"EventTooltip",
"devtools/client/shared/widgets/tooltip/EventTooltipHelper",
true
);
@ -74,10 +74,14 @@ MarkupElementContainer.prototype = extend(MarkupContainer.prototype, {
const toolbox = this.markup.toolbox;
setEventTooltip(tooltip, listenerInfo, toolbox);
// Create the EventTooltip which will populate the tooltip content.
const eventTooltip = new EventTooltip(tooltip, listenerInfo, toolbox);
// Disable the image preview tooltip while we display the event details
this.markup._disableImagePreviewTooltip();
tooltip.once("hidden", () => {
eventTooltip.destroy();
// Enable the image preview tooltip after closing the event details
this.markup._enableImagePreviewTooltip();

Просмотреть файл

@ -15,23 +15,19 @@ const beautify = require("devtools/shared/jsbeautify/beautify");
const XHTML_NS = "http://www.w3.org/1999/xhtml";
const CONTAINER_WIDTH = 500;
/**
* Set the content of a provided HTMLTooltip instance to display a list of event
* listeners, with their event type, capturing argument and a link to the code
* of the event handler.
*
* @param {HTMLTooltip} tooltip
* The tooltip instance on which the event details content should be set
* @param {Array} eventListenerInfos
* A list of event listeners
* @param {Toolbox} toolbox
* Toolbox used to select debugger panel
*/
function setEventTooltip(tooltip, eventListenerInfos, toolbox) {
return new EventTooltip(tooltip, eventListenerInfos, toolbox);
}
class EventTooltip {
/**
* Set the content of a provided HTMLTooltip instance to display a list of event
* listeners, with their event type, capturing argument and a link to the code
* of the event handler.
*
* @param {HTMLTooltip} tooltip
* The tooltip instance on which the event details content should be set
* @param {Array} eventListenerInfos
* A list of event listeners
* @param {Toolbox} toolbox
* Toolbox used to select debugger panel
*/
constructor(tooltip, eventListenerInfos, toolbox) {
this._tooltip = tooltip;
this._toolbox = toolbox;
@ -42,7 +38,6 @@ class EventTooltip {
this._headerClicked = this._headerClicked.bind(this);
this._debugClicked = this._debugClicked.bind(this);
this.destroy = this.destroy.bind(this);
this._subscriptions = [];
const config = {
@ -197,7 +192,6 @@ class EventTooltip {
this._tooltip.panel.innerHTML = "";
this._tooltip.panel.appendChild(this.container);
this._tooltip.setContentSize({ width: CONTAINER_WIDTH, height: Infinity });
this._tooltip.on("hidden", this.destroy);
}
_addContentListeners(header) {
@ -314,8 +308,6 @@ class EventTooltip {
destroy() {
if (this._tooltip) {
this._tooltip.off("hidden", this.destroy);
const boxes = this.container.querySelectorAll(
".event-tooltip-content-box"
);
@ -350,4 +342,4 @@ class EventTooltip {
}
}
module.exports.setEventTooltip = setEventTooltip;
module.exports.EventTooltip = EventTooltip;