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

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

Issue 2911363002: DevTools: Split SoftDropdown out of ConsoleContextSelector (Closed)
Patch Set: Created 3 years, 7 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 673b08a7b302e43971f4235f7bf3319cb263f22c..0cd06799fa9b9f7f099804934edb01552c3dc0ae 100644
--- a/third_party/WebKit/Source/devtools/front_end/console/ConsoleContextSelector.js
+++ b/third_party/WebKit/Source/devtools/front_end/console/ConsoleContextSelector.js
@@ -3,56 +3,18 @@
// 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.SoftDropDown<!SDK.ExecutionContext>} */
+ this._dropDown = new UI.SoftDropDown(this);
+ 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);
- this._list = new UI.ListControl(this, UI.ListMode.EqualHeightItems);
- this._list.element.classList.add('context-list');
- this._list.element.tabIndex = -1;
- 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);
@@ -78,144 +40,24 @@ 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._list.length(), 9));
- this._glassPane.setMaxContentSize(new UI.Size(315, maxHeight));
- this._list.viewportResized();
- }
-
- /**
- * @param {!Event} event
+ * @override
+ * @param {?SDK.ExecutionContext} item
*/
- _hide(event) {
- setTimeout(() => this._listWasShowing200msAgo = false, 200);
- this._glassPane.hide();
+ itemHighlighted(item) {
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._list.itemAtIndex(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._list.itemAtIndex(i)) < depth) {
- handled = true;
- this._list.selectItem(this._list.itemAtIndex(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._list.length(); i++) {
- if (this.isItemSelectable(this._list.itemAtIndex(i))) {
- this._list.selectItem(this._list.itemAtIndex(i));
- handled = true;
- break;
- }
- }
- break;
- case 'End':
- for (var i = this._list.length() - 1; i >= 0; i--) {
- if (this.isItemSelectable(this._list.itemAtIndex(i))) {
- this._list.selectItem(this._list.itemAtIndex(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._list.length(); i++) {
- var context = this._list.itemAtIndex((selectedIndex + i + 1) % this._list.length());
- if (this._titleFor(context).toUpperCase().startsWith(letter)) {
- this._list.selectItem(context);
- break;
- }
- }
- handled = true;
- }
- break;
- }
-
- if (handled) {
- event.consume(true);
- this._updateSelectedContext();
+ if (item && item.frameId) {
+ var resourceTreeModel = item.target().model(SDK.ResourceTreeModel);
+ if (resourceTreeModel)
+ resourceTreeModel.domModel().overlayModel().highlightFrame(item.frameId);
caseq 2017/05/30 23:40:07 why not directly get OverlayModel for target?
einbinder 2017/05/31 21:14:26 I didn't realize you could just do that.
}
}
/**
+ * @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) {
@@ -230,10 +72,11 @@ Console.ConsoleContextSelector = class {
}
/**
+ * @override
* @param {!SDK.ExecutionContext} executionContext
* @return {number}
*/
- _depthFor(executionContext) {
+ depthFor(executionContext) {
var target = executionContext.target();
var depth = 0;
if (!executionContext.isDefault)
@@ -297,10 +140,11 @@ Console.ConsoleContextSelector = class {
if (!executionContext.target().hasJSCapability())
return;
- this._list.insertItemWithComparator(executionContext, executionContext.runtimeModel.executionContextComparator());
+ this._dropDown.insertItemWithComparator(
+ executionContext, executionContext.runtimeModel.executionContextComparator());
if (executionContext === UI.context.flavor(SDK.ExecutionContext))
- this._updateSelectionTitle();
+ this._dropDown.selectItem(executionContext);
}
/**
@@ -309,8 +153,6 @@ Console.ConsoleContextSelector = class {
_onExecutionContextCreated(event) {
var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data);
this._executionContextCreated(executionContext);
- this._updateSelectionTitle();
- this._updateGlasspaneSize();
}
/**
@@ -318,22 +160,16 @@ Console.ConsoleContextSelector = class {
*/
_onExecutionContextChanged(event) {
var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data);
- if (this._list.indexOfItem(executionContext) === -1)
- return;
this._executionContextDestroyed(executionContext);
this._executionContextCreated(executionContext);
- this._updateSelectionTitle();
}
/**
* @param {!SDK.ExecutionContext} executionContext
*/
_executionContextDestroyed(executionContext) {
- if (this._list.indexOfItem(executionContext) === -1)
- return;
this._disposeExecutionContextBadge(executionContext);
- this._list.removeItem(executionContext);
- this._updateGlasspaneSize();
+ this._dropDown.removeItem(executionContext);
}
/**
@@ -342,7 +178,6 @@ Console.ConsoleContextSelector = class {
_onExecutionContextDestroyed(event) {
var executionContext = /** @type {!SDK.ExecutionContext} */ (event.data);
this._executionContextDestroyed(executionContext);
- this._updateSelectionTitle();
}
/**
@@ -350,20 +185,7 @@ Console.ConsoleContextSelector = class {
*/
_executionContextChangedExternally(event) {
var executionContext = /** @type {?SDK.ExecutionContext} */ (event.data);
- if (!executionContext || this._list.indexOfItem(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);
}
/**
@@ -384,11 +206,13 @@ Console.ConsoleContextSelector = class {
* @return {boolean}
*/
_hasTopContext() {
- for (var i = 0; i < this._list.length(); i++) {
- if (this._isTopContext(this._list.itemAtIndex(i)))
- return true;
- }
- return false;
+ var mainTarget = SDK.targetManager.mainTarget();
+ if (!mainTarget)
+ return false;
+ var resourceTreeModel = mainTarget.model(SDK.ResourceTreeModel);
+ if (!resourceTreeModel)
+ return false;
+ return !!resourceTreeModel.mainFrame;
}
/**
@@ -404,10 +228,8 @@ Console.ConsoleContextSelector = class {
* @param {!SDK.RuntimeModel} runtimeModel
*/
modelRemoved(runtimeModel) {
- for (var i = 0; i < this._list.length(); i++) {
- if (this._list.itemAtIndex(i).runtimeModel === runtimeModel)
- this._executionContextDestroyed(this._list.itemAtIndex(i));
- }
+ for (var executionContext of runtimeModel.executionContexts())
+ this._executionContextDestroyed(executionContext);
}
/**
@@ -415,12 +237,10 @@ Console.ConsoleContextSelector = class {
* @param {!SDK.ExecutionContext} item
* @return {!Element}
*/
- createElementForItem(item) {
+ elementForItem(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));
+ title.createTextChild(this.titleFor(item).trimEnd(100));
var subTitle = element.createChild('div', 'subtitle');
var badgeElement = this._badgeFor(item);
if (badgeElement) {
@@ -428,11 +248,6 @@ Console.ConsoleContextSelector = class {
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));
return element;
}
@@ -466,15 +281,6 @@ Console.ConsoleContextSelector = class {
/**
* @override
* @param {!SDK.ExecutionContext} item
- * @return {number}
- */
- heightForItem(item) {
- return this._rowHeight;
- }
-
- /**
- * @override
- * @param {!SDK.ExecutionContext} item
* @return {boolean}
*/
isItemSelectable(item) {
@@ -485,28 +291,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() {
@@ -521,10 +310,10 @@ Console.ConsoleContextSelector = class {
*/
_callFrameSelectedInModel(event) {
var debuggerModel = /** @type {!SDK.DebuggerModel} */ (event.data);
- for (var i = 0; i < this._list.length(); i++) {
- if (this._list.itemAtIndex(i).debuggerModel === debuggerModel) {
- this._disposeExecutionContextBadge(this._list.itemAtIndex(i));
- this._list.refreshItemsInRange(i, i + 1);
+ for (var executionContext of debuggerModel.runtimeModel().executionContexts()) {
+ if (executionContext.debuggerModel === debuggerModel) {
+ this._disposeExecutionContextBadge(executionContext);
+ this._dropDown.refreshItem(executionContext);
}
}
}
@@ -533,11 +322,14 @@ Console.ConsoleContextSelector = class {
* @param {!Common.Event} event
*/
_frameNavigated(event) {
- var frameId = event.data.id;
- for (var i = 0; i < this._list.length(); i++) {
- if (frameId === this._list.itemAtIndex(i).frameId) {
- this._disposeExecutionContextBadge(this._list.itemAtIndex(i));
- this._list.refreshItemsInRange(i, i + 1);
+ 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._dropDown.refreshItem(executionContext);
}
}
}

Powered by Google App Engine
This is Rietveld 408576698