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

Unified Diff: third_party/WebKit/Source/devtools/front_end/ui/SuggestBox.js

Issue 2609363002: [DevTools] Tweak ListControl API. (Closed)
Patch Set: Created 3 years, 12 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/ui/SuggestBox.js
diff --git a/third_party/WebKit/Source/devtools/front_end/ui/SuggestBox.js b/third_party/WebKit/Source/devtools/front_end/ui/SuggestBox.js
index ee250df8b0e4faeb94720ac5bec2f6d2f193eb44..8586d1d110f676be1da43371c58453f3b5bd331a 100644
--- a/third_party/WebKit/Source/devtools/front_end/ui/SuggestBox.js
+++ b/third_party/WebKit/Source/devtools/front_end/ui/SuggestBox.js
@@ -62,7 +62,7 @@ UI.SuggestBox = class {
this._container = createElementWithClass('div', 'suggest-box-container');
this._rowHeight = 17;
/** @type {!UI.ListControl<!UI.SuggestBox.Suggestion>} */
- this._list = new UI.ListControl(this, UI.ListMode.ViewportFixedItems);
+ this._list = new UI.ListControl(this, UI.ListMode.SameHeightItems);
this._element = this._list.element;
this._element.classList.add('suggest-box');
this._container.appendChild(this._element);
@@ -259,7 +259,6 @@ UI.SuggestBox = class {
var subtitleElement = element.createChild('span', 'suggestion-subtitle');
subtitleElement.textContent = item.subtitle.trimEnd(15);
}
- element.addEventListener('mousedown', this._onItemMouseDown.bind(this), false);
return element;
}
@@ -304,14 +303,16 @@ UI.SuggestBox = class {
}
/**
+ * @override
+ * @param {!UI.SuggestBox.Suggestion} item
+ * @param {!Element} element
* @param {!Event} event
*/
- _onItemMouseDown(event) {
- if (!this._list.onClick(event))
- return;
+ itemElementClicked(item, element, event) {
+ this._list.selectItem(item);
this._userInteracted = true;
- this.acceptSuggestion();
event.consume(true);
+ this.acceptSuggestion();
}
/**
@@ -385,21 +386,21 @@ UI.SuggestBox = class {
this._show();
this._updateBoxPosition(anchorBox, completions.length);
this._updateWidth(completions);
- this._list.fixedHeightChanged();
+ this._list.invalidateSameHeight();
this._list.replaceAllItems(completions);
- var highestPriorityItem = -1;
if (selectHighestPriority) {
- var highestPriority = -Infinity;
+ var highestPriorityItem = completions[0];
+ var highestPriority = completions[0].priority || 0;
for (var i = 0; i < completions.length; i++) {
var priority = completions[i].priority || 0;
if (highestPriority < priority) {
highestPriority = priority;
- highestPriorityItem = i;
+ highestPriorityItem = completions[i];
}
}
+ this._list.selectItem(highestPriorityItem, true);
}
- this._list.selectItemAtIndex(highestPriorityItem, true);
} else {
if (completions.length === 1) {
this._onlyCompletion = completions[0].title;
@@ -414,12 +415,29 @@ UI.SuggestBox = class {
* @return {boolean}
*/
keyPressed(event) {
- if (this._list.onKeyDown(event)) {
+ var selected = false;
+ switch (event.key) {
+ case 'Enter':
+ return this.enterKeyPressed();
+ case 'ArrowUp':
+ selected = this._list.selectPreviousItem(true, false);
+ break;
+ case 'ArrowDown':
+ selected = this._list.selectNextItem(true, false);
+ break;
+ case 'PageUp':
+ selected = this._list.selectItemPreviousPage(false);
+ break;
+ case 'PageDown':
+ selected = this._list.selectItemNextPage(false);
+ break;
+ default:
+ return false;
+ }
+ if (selected) {
this._userInteracted = true;
return true;
}
- if (event.key === 'Enter')
- return this.enterKeyPressed();
return false;
}

Powered by Google App Engine
This is Rietveld 408576698