Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Unified Diff: third_party/WebKit/Source/devtools/front_end/console/ConsoleContextSelector.js

Issue 2911363002: DevTools: Split SoftDropdown out of ConsoleContextSelector (Closed)
Patch Set: fixes Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/devtools/front_end/console/ConsoleContextSelector.js
diff --git a/third_party/WebKit/Source/devtools/front_end/console/ConsoleContextSelector.js b/third_party/WebKit/Source/devtools/front_end/console/ConsoleContextSelector.js
index 77123fc0a947123606f56a1e5b9f20708cc582a1..00c3ce2b6d9ca2ad9df356f4edc2d91006d28d98 100644
--- a/third_party/WebKit/Source/devtools/front_end/console/ConsoleContextSelector.js
+++ b/third_party/WebKit/Source/devtools/front_end/console/ConsoleContextSelector.js
@@ -3,58 +3,21 @@
// found in the LICENSE file.
/**
* @implements {SDK.SDKModelObserver<!SDK.RuntimeModel>}
- * @implements {UI.ListDelegate<!SDK.ExecutionContext>}
+ * @implements {UI.SoftDropDown.Delegate<!SDK.ExecutionContext>}
*/
Console.ConsoleContextSelector = class {
constructor() {
- this._toolbarItem = new UI.ToolbarItem(createElementWithClass('button', 'console-context'));
- var shadowRoot =
- UI.createShadowRootWithCoreStyles(this._toolbarItem.element, 'console/consoleContextSelectorButton.css');
- this._titleElement = shadowRoot.createChild('span', 'title');
+ /** @type {!UI.ListModel<!SDK.ExecutionContext>} */
+ this._items = new UI.ListModel();
+ /** @type {!UI.SoftDropDown<!SDK.ExecutionContext>} */
+ this._dropDown = new UI.SoftDropDown(this._items, this);
+ this._dropDown.setRowHeight(36);
+ this._toolbarItem = new UI.ToolbarItem(this._dropDown.element);
/** @type {!Map<!SDK.ExecutionContext, !ProductRegistry.BadgePool>} */
this._badgePoolForExecutionContext = new Map();
this._toolbarItem.element.classList.add('toolbar-has-dropdown');
- this._toolbarItem.element.tabIndex = 0;
- this._glassPane = new UI.GlassPane();
- this._glassPane.setMarginBehavior(UI.GlassPane.MarginBehavior.NoMargin);
- this._glassPane.setAnchorBehavior(UI.GlassPane.AnchorBehavior.PreferBottom);
- this._glassPane.setOutsideClickCallback(this._hide.bind(this));
- this._glassPane.setPointerEventsBehavior(UI.GlassPane.PointerEventsBehavior.BlockedByGlassPane);
- /** @type {!UI.ListModel<!SDK.ExecutionContext>} */
- this._items = new UI.ListModel();
- /** @type {!UI.ListControl<!SDK.ExecutionContext>} */
- this._list = new UI.ListControl(this._items, this, UI.ListMode.EqualHeightItems);
- this._list.element.classList.add('context-list');
- this._rowHeight = 36;
- UI.createShadowRootWithCoreStyles(this._glassPane.contentElement, 'console/consoleContextSelector.css')
- .appendChild(this._list.element);
-
- this._listWasShowing200msAgo = false;
- this._toolbarItem.element.addEventListener('mousedown', event => {
- if (this._listWasShowing200msAgo)
- this._hide(event);
- else
- this._show(event);
- }, false);
- this._toolbarItem.element.addEventListener('keydown', this._onKeyDown.bind(this), false);
- this._toolbarItem.element.addEventListener('focusout', this._hide.bind(this), false);
- this._list.element.addEventListener('mousedown', event => {
- event.consume(true);
- }, false);
- this._list.element.addEventListener('mouseup', event => {
- if (event.target === this._list.element)
- return;
-
- if (!this._listWasShowing200msAgo)
- return;
- this._updateSelectedContext();
- this._hide(event);
- }, false);
-
- var dropdownArrowIcon = UI.Icon.create('smallicon-triangle-down');
- shadowRoot.appendChild(dropdownArrowIcon);
SDK.targetManager.addModelListener(
SDK.RuntimeModel, SDK.RuntimeModel.Events.ExecutionContextCreated, this._onExecutionContextCreated, this);
@@ -80,144 +43,31 @@ Console.ConsoleContextSelector = class {
}
/**
- * @param {!Event} event
- */
- _show(event) {
- if (this._glassPane.isShowing())
- return;
- this._glassPane.setContentAnchorBox(this._toolbarItem.element.boxInWindow());
- this._glassPane.show(/** @type {!Document} **/ (this._toolbarItem.element.ownerDocument));
- this._updateGlasspaneSize();
- var selectedContext = UI.context.flavor(SDK.ExecutionContext);
- if (selectedContext) {
- this._list.selectItem(selectedContext);
- this._list.scrollItemIntoView(selectedContext, true);
- }
- this._toolbarItem.element.focus();
- event.consume(true);
- setTimeout(() => this._listWasShowing200msAgo = true, 200);
- }
-
- _updateGlasspaneSize() {
- var maxHeight = this._rowHeight * (Math.min(this._items.length, 9));
- this._glassPane.setMaxContentSize(new UI.Size(315, maxHeight));
- this._list.viewportResized();
- }
-
- /**
- * @param {!Event} event
+ * @override
+ * @param {?SDK.ExecutionContext} from
+ * @param {?SDK.ExecutionContext} to
+ * @param {?Element} fromElement
+ * @param {?Element} toElement
*/
- _hide(event) {
- setTimeout(() => this._listWasShowing200msAgo = false, 200);
- this._glassPane.hide();
+ highlightedItemChanged(from, to, fromElement, toElement) {
SDK.OverlayModel.hideDOMNodeHighlight();
- event.consume(true);
- }
-
- /**
- * @param {!Event} event
- */
- _onKeyDown(event) {
- var handled = false;
- switch (event.key) {
- case 'ArrowUp':
- handled = this._list.selectPreviousItem(false, false);
- break;
- case 'ArrowDown':
- handled = this._list.selectNextItem(false, false);
- break;
- case 'ArrowRight':
- var currentExecutionContext = this._list.selectedItem();
- if (!currentExecutionContext)
- break;
- var nextExecutionContext = this._items.at(this._list.selectedIndex() + 1);
- if (nextExecutionContext && this._depthFor(currentExecutionContext) < this._depthFor(nextExecutionContext))
- handled = this._list.selectNextItem(false, false);
- break;
- case 'ArrowLeft':
- var currentExecutionContext = this._list.selectedItem();
- if (!currentExecutionContext)
- break;
- var depth = this._depthFor(currentExecutionContext);
- for (var i = this._list.selectedIndex() - 1; i >= 0; i--) {
- if (this._depthFor(this._items.at(i)) < depth) {
- handled = true;
- this._list.selectItem(this._items.at(i), false);
- break;
- }
- }
- break;
- case 'PageUp':
- handled = this._list.selectItemPreviousPage(false);
- break;
- case 'PageDown':
- handled = this._list.selectItemNextPage(false);
- break;
- case 'Home':
- for (var i = 0; i < this._items.length; i++) {
- if (this.isItemSelectable(this._items.at(i))) {
- this._list.selectItem(this._items.at(i));
- handled = true;
- break;
- }
- }
- break;
- case 'End':
- for (var i = this._items.length - 1; i >= 0; i--) {
- if (this.isItemSelectable(this._items.at(i))) {
- this._list.selectItem(this._items.at(i));
- handled = true;
- break;
- }
- }
- break;
- case 'Escape':
- this._hide(event);
- break;
- case 'Tab':
- if (!this._glassPane.isShowing())
- break;
- this._updateSelectedContext();
- this._hide(event);
- break;
- case 'Enter':
- if (!this._glassPane.isShowing()) {
- this._show(event);
- break;
- }
- this._updateSelectedContext();
- this._hide(event);
- break;
- case ' ':
- this._show(event);
- break;
- default:
- if (event.key.length === 1) {
- var selectedIndex = this._list.selectedIndex();
- var letter = event.key.toUpperCase();
- for (var i = 0; i < this._items.length; i++) {
- var context = this._items.at((selectedIndex + i + 1) % this._items.length);
- if (this._titleFor(context).toUpperCase().startsWith(letter)) {
- this._list.selectItem(context);
- break;
- }
- }
- handled = true;
- }
- break;
- }
-
- if (handled) {
- event.consume(true);
- this._updateSelectedContext();
+ if (to && to.frameId) {
+ var overlayModel = to.target().model(SDK.OverlayModel);
+ if (overlayModel)
+ overlayModel.highlightFrame(to.frameId);
}
+ if (fromElement)
+ fromElement.classList.remove('highlighted');
+ if (toElement)
+ toElement.classList.add('highlighted');
}
/**
+ * @override
* @param {!SDK.ExecutionContext} executionContext
* @return {string}
*/
- _titleFor(executionContext) {
+ titleFor(executionContext) {
var target = executionContext.target();
var label = executionContext.label() ? target.decorateLabel(executionContext.label()) : '';
if (executionContext.frameId) {
@@ -302,7 +152,7 @@ Console.ConsoleContextSelector = class {
this._items.insertWithComparator(executionContext, executionContext.runtimeModel.executionContextComparator());
if (executionContext === UI.context.flavor(SDK.ExecutionContext))
- this._updateSelectionTitle();
+ this._dropDown.selectItem(executionContext);
}
/**
@@ -311,8 +161,6 @@ Console.ConsoleContextSelector = class {
_onExecutionContextCreated(event) {
var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data);
this._executionContextCreated(executionContext);
- this._updateSelectionTitle();
- this._updateGlasspaneSize();
}
/**
@@ -324,7 +172,6 @@ Console.ConsoleContextSelector = class {
return;
this._executionContextDestroyed(executionContext);
this._executionContextCreated(executionContext);
- this._updateSelectionTitle();
}
/**
@@ -336,7 +183,6 @@ Console.ConsoleContextSelector = class {
return;
this._disposeExecutionContextBadge(executionContext);
this._items.remove(index);
- this._updateGlasspaneSize();
}
/**
@@ -345,7 +191,6 @@ Console.ConsoleContextSelector = class {
_onExecutionContextDestroyed(event) {
var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data);
this._executionContextDestroyed(executionContext);
- this._updateSelectionTitle();
}
/**
@@ -353,20 +198,7 @@ Console.ConsoleContextSelector = class {
*/
_executionContextChangedExternally(event) {
var executionContext = /** @type {?SDK.ExecutionContext} */ (event.data);
- if (!executionContext || this._items.indexOf(executionContext) === -1)
- return;
- this._list.selectItem(executionContext);
- this._updateSelectedContext();
- }
-
- _updateSelectionTitle() {
- var executionContext = UI.context.flavor(SDK.ExecutionContext);
- if (executionContext)
- this._titleElement.textContent = this._titleFor(executionContext);
- else
- this._titleElement.textContent = '';
- this._toolbarItem.element.classList.toggle(
- 'warning', !this._isTopContext(executionContext) && this._hasTopContext());
+ this._dropDown.selectItem(executionContext);
}
/**
@@ -415,23 +247,18 @@ Console.ConsoleContextSelector = class {
* @return {!Element}
*/
createElementForItem(item) {
- var element = createElementWithClass('div', 'context');
- element.style.paddingLeft = (8 + this._depthFor(item) * 15) + 'px';
- // var titleArea = element.createChild('div', 'title-area');
- var title = element.createChild('div', 'title');
- title.createTextChild(this._titleFor(item).trimEnd(100));
- var subTitle = element.createChild('div', 'subtitle');
+ var element = createElementWithClass('div');
+ var shadowRoot = UI.createShadowRootWithCoreStyles(element, 'console/consoleContextSelector.css');
+ var title = shadowRoot.createChild('div', 'title');
+ title.createTextChild(this.titleFor(item).trimEnd(100));
+ var subTitle = shadowRoot.createChild('div', 'subtitle');
var badgeElement = this._badgeFor(item);
if (badgeElement) {
badgeElement.classList.add('badge');
subTitle.appendChild(badgeElement);
}
subTitle.createTextChild(this._subtitleFor(item));
- element.addEventListener('mousemove', e => {
- if ((e.movementX || e.movementY) && this.isItemSelectable(item))
- this._list.selectItem(item, false, /* Don't scroll */ true);
- });
- element.classList.toggle('disabled', !this.isItemSelectable(item));
+ element.style.paddingLeft = (8 + this._depthFor(item) * 15) + 'px';
return element;
}
@@ -462,15 +289,6 @@ Console.ConsoleContextSelector = class {
return '';
}
- /**
- * @override
- * @param {!SDK.ExecutionContext} item
- * @return {number}
- */
- heightForItem(item) {
- return this._rowHeight;
- }
-
/**
* @override
* @param {!SDK.ExecutionContext} item
@@ -484,28 +302,11 @@ Console.ConsoleContextSelector = class {
/**
* @override
- * @param {?SDK.ExecutionContext} from
- * @param {?SDK.ExecutionContext} to
- * @param {?Element} fromElement
- * @param {?Element} toElement
+ * @param {?SDK.ExecutionContext} item
*/
- selectedItemChanged(from, to, fromElement, toElement) {
- if (fromElement)
- fromElement.classList.remove('selected');
- if (toElement)
- toElement.classList.add('selected');
- SDK.OverlayModel.hideDOMNodeHighlight();
- if (to && to.frameId) {
- var resourceTreeModel = to.target().model(SDK.ResourceTreeModel);
- if (resourceTreeModel)
- resourceTreeModel.domModel().overlayModel().highlightFrame(to.frameId);
- }
- }
-
- _updateSelectedContext() {
- var context = this._list.selectedItem();
- UI.context.setFlavor(SDK.ExecutionContext, context);
- this._updateSelectionTitle();
+ itemSelected(item) {
+ this._toolbarItem.element.classList.toggle('warning', !this._isTopContext(item) && this._hasTopContext());
+ UI.context.setFlavor(SDK.ExecutionContext, item);
}
_callFrameSelectedInUI() {
@@ -523,7 +324,7 @@ Console.ConsoleContextSelector = class {
for (var executionContext of this._items) {
if (executionContext.debuggerModel === debuggerModel) {
this._disposeExecutionContextBadge(executionContext);
- this._list.refreshItem(executionContext);
+ this._dropDown.refreshItem(executionContext);
}
}
}
@@ -532,11 +333,14 @@ Console.ConsoleContextSelector = class {
* @param {!Common.Event} event
*/
_frameNavigated(event) {
- var frameId = event.data.id;
- for (var executionContext of this._items) {
- if (frameId === executionContext.frameId) {
+ var frame = /** @type {!SDK.ResourceTreeFrame} */ (event.data);
+ var runtimeModel = frame.resourceTreeModel().target().model(SDK.RuntimeModel);
+ if (!runtimeModel)
+ return;
+ for (var executionContext of runtimeModel.executionContexts()) {
+ if (frame.id === executionContext.frameId) {
this._disposeExecutionContextBadge(executionContext);
- this._list.refreshItem(executionContext);
+ this._dropDown.refreshItem(executionContext);
}
}
}

Powered by Google App Engine
This is Rietveld 408576698