Commit dc71d70d authored by Jack Lynch's avatar Jack Lynch Committed by Commit Bot

DevTools: Improve event listener context menus

This CL adds context menu items to each listener to reveal its source
code, remove it, or toggle whether it is passive or blocking (when
applicable). This improves the accessibility of the event listeners view
in the Elements panel as well as the global listeners view in the
Sources panel, as previously the passive toggle and delete buttons were
available only on hover.

Previously reviewed at
https://chromium-review.googlesource.com/c/chromium/src/+/1665298, split
into this CL as it impacts multiple parts of the UI.

Screenshot: https://gyazo.com/dc1b54b5e0ae1f9b67f89b0400a168a8
Bug: 963183
Change-Id: I497e96ee3eb5d58358f904dd7e9ac92b15840baf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1716462
Commit-Queue: Jack Lynch <jalyn@microsoft.com>
Reviewed-by: default avatarLorne Mitchell <lomitch@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#704730}
parent bcaa3f35
...@@ -270,9 +270,6 @@ ...@@ -270,9 +270,6 @@
<message name="IDS_DEVTOOLS_f750c8807bc5f4a7bd259788114a4ebd" desc="Tooltip text that appears when hovering over the largeicon background color button in the Styles Sidebar Pane of the Elements panel"> <message name="IDS_DEVTOOLS_f750c8807bc5f4a7bd259788114a4ebd" desc="Tooltip text that appears when hovering over the largeicon background color button in the Styles Sidebar Pane of the Elements panel">
Add background-color Add background-color
</message> </message>
<message name="IDS_DEVTOOLS_f80bc338b6146b566004a046f8137c85" desc="Text in Event Listeners Widget of the Elements panel">
Passive
</message>
<message name="IDS_DEVTOOLS_f8d0f1896a9e4ad16d43caa28534df32" desc="Show all button text content in Styles Sidebar Pane of the Elements panel"> <message name="IDS_DEVTOOLS_f8d0f1896a9e4ad16d43caa28534df32" desc="Show all button text content in Styles Sidebar Pane of the Elements panel">
Show All Properties (<ph name="PROPERTIES_LENGTH___COUNT">$1s<ex>3</ex></ph> more) Show All Properties (<ph name="PROPERTIES_LENGTH___COUNT">$1s<ex>3</ex></ph> more)
</message> </message>
......
...@@ -303,7 +303,8 @@ EventListeners.ObjectEventListenerBar = class extends UI.TreeElement { ...@@ -303,7 +303,8 @@ EventListeners.ObjectEventListenerBar = class extends UI.TreeElement {
_setTitle(object, linkifier) { _setTitle(object, linkifier) {
const title = this.listItemElement.createChild('span', 'event-listener-details'); const title = this.listItemElement.createChild('span', 'event-listener-details');
const subtitle = this.listItemElement.createChild('span', 'event-listener-tree-subtitle'); const subtitle = this.listItemElement.createChild('span', 'event-listener-tree-subtitle');
subtitle.appendChild(linkifier.linkifyRawLocation(this._eventListener.location(), this._eventListener.sourceURL())); const linkElement = linkifier.linkifyRawLocation(this._eventListener.location(), this._eventListener.sourceURL());
subtitle.appendChild(linkElement);
this._valueTitle = this._valueTitle =
ObjectUI.ObjectPropertiesSection.createValueElement(object, false /* wasThrown */, false /* showPreview */); ObjectUI.ObjectPropertiesSection.createValueElement(object, false /* wasThrown */, false /* showPreview */);
...@@ -313,7 +314,10 @@ EventListeners.ObjectEventListenerBar = class extends UI.TreeElement { ...@@ -313,7 +314,10 @@ EventListeners.ObjectEventListenerBar = class extends UI.TreeElement {
const deleteButton = title.createChild('span', 'event-listener-button'); const deleteButton = title.createChild('span', 'event-listener-button');
deleteButton.textContent = Common.UIString('Remove'); deleteButton.textContent = Common.UIString('Remove');
deleteButton.title = Common.UIString('Delete event listener'); deleteButton.title = Common.UIString('Delete event listener');
deleteButton.addEventListener('click', removeListener.bind(this), false); deleteButton.addEventListener('click', event => {
this._removeListener();
event.consume();
}, false);
title.appendChild(deleteButton); title.appendChild(deleteButton);
} }
...@@ -321,28 +325,34 @@ EventListeners.ObjectEventListenerBar = class extends UI.TreeElement { ...@@ -321,28 +325,34 @@ EventListeners.ObjectEventListenerBar = class extends UI.TreeElement {
const passiveButton = title.createChild('span', 'event-listener-button'); const passiveButton = title.createChild('span', 'event-listener-button');
passiveButton.textContent = Common.UIString('Toggle Passive'); passiveButton.textContent = Common.UIString('Toggle Passive');
passiveButton.title = Common.UIString('Toggle whether event listener is passive or blocking'); passiveButton.title = Common.UIString('Toggle whether event listener is passive or blocking');
passiveButton.addEventListener('click', togglePassiveListener.bind(this), false); passiveButton.addEventListener('click', event => {
this._togglePassiveListener();
event.consume();
}, false);
title.appendChild(passiveButton); title.appendChild(passiveButton);
} }
/** this.listItemElement.addEventListener('contextmenu', event => {
* @param {!Event} event const menu = new UI.ContextMenu(event);
* @this {EventListeners.ObjectEventListenerBar} if (event.target !== linkElement) {
*/ menu.appendApplicableItems(linkElement);
function removeListener(event) { }
event.consume(); menu.defaultSection().appendItem(
this._removeListenerBar(); ls`Delete event listener`, this._removeListener.bind(this), !this._eventListener.canRemove());
this._eventListener.remove(); menu.defaultSection().appendCheckboxItem(
} ls`Passive`, this._togglePassiveListener.bind(this), this._eventListener.passive(),
!this._eventListener.canTogglePassive());
menu.show();
});
}
/** _removeListener() {
* @param {!Event} event this._removeListenerBar();
* @this {EventListeners.ObjectEventListenerBar} this._eventListener.remove();
*/ }
function togglePassiveListener(event) {
event.consume(); _togglePassiveListener() {
this._eventListener.togglePassive().then(this._changeCallback()); this._eventListener.togglePassive().then(this._changeCallback());
}
} }
_removeListenerBar() { _removeListenerBar() {
......
...@@ -616,6 +616,9 @@ ...@@ -616,6 +616,9 @@
<message name="IDS_DEVTOOLS_f53944c3a55bdb5ad65c6226e358a626" desc="Text to undock the DevTools"> <message name="IDS_DEVTOOLS_f53944c3a55bdb5ad65c6226e358a626" desc="Text to undock the DevTools">
Undock into separate window Undock into separate window
</message> </message>
<message name="IDS_DEVTOOLS_f80bc338b6146b566004a046f8137c85" desc="Text in Event Listeners Widget of the Elements panel">
Passive
</message>
<message name="IDS_DEVTOOLS_f907e651164789346ae0a1e257c462d8" desc="Label for a group of JavaScript files"> <message name="IDS_DEVTOOLS_f907e651164789346ae0a1e257c462d8" desc="Label for a group of JavaScript files">
Script Script
</message> </message>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment