Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 this._selectedIndex = -1; | 60 this._selectedIndex = -1; |
| 61 this._selectedElement = null; | 61 this._selectedElement = null; |
| 62 this._maxItemsHeight = maxItemsHeight; | 62 this._maxItemsHeight = maxItemsHeight; |
| 63 this._maybeHideBound = this._maybeHide.bind(this); | 63 this._maybeHideBound = this._maybeHide.bind(this); |
| 64 this._container = createElementWithClass("div", "suggest-box-container"); | 64 this._container = createElementWithClass("div", "suggest-box-container"); |
| 65 this._element = this._container.createChild("div", "suggest-box"); | 65 this._element = this._container.createChild("div", "suggest-box"); |
| 66 this._element.addEventListener("mousedown", this._onBoxMouseDown.bind(this), true); | 66 this._element.addEventListener("mousedown", this._onBoxMouseDown.bind(this), true); |
| 67 this._detailsPopup = this._container.createChild("div", "suggest-box details -popup monospace"); | 67 this._detailsPopup = this._container.createChild("div", "suggest-box details -popup monospace"); |
| 68 this._detailsPopup.classList.add("hidden"); | 68 this._detailsPopup.classList.add("hidden"); |
| 69 this._asyncDetailsCallback = null; | 69 this._asyncDetailsCallback = null; |
| 70 this._asyncDetailsPromises = /** @type {!Map<number, !Promise>} */ ({}); | 70 /** @type {!Map<number, !Promise<{detail: string, description: string}>>} */ |
| 71 this._asyncDetailsPromises = new Map(); | |
| 71 } | 72 } |
| 72 | 73 |
| 73 WebInspector.SuggestBox.prototype = { | 74 WebInspector.SuggestBox.prototype = { |
| 74 /** | 75 /** |
| 75 * @return {boolean} | 76 * @return {boolean} |
| 76 */ | 77 */ |
| 77 visible: function() | 78 visible: function() |
| 78 { | 79 { |
| 79 return !!this._container.parentElement; | 80 return !!this._container.parentElement; |
| 80 }, | 81 }, |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 }, | 259 }, |
| 259 | 260 |
| 260 /** | 261 /** |
| 261 * @param {!Array.<string>} items | 262 * @param {!Array.<string>} items |
| 262 * @param {string} userEnteredText | 263 * @param {string} userEnteredText |
| 263 * @param {function(number): !Promise<{detail:string, description:string}>=} asyncDetails | 264 * @param {function(number): !Promise<{detail:string, description:string}>=} asyncDetails |
| 264 */ | 265 */ |
| 265 _updateItems: function(items, userEnteredText, asyncDetails) | 266 _updateItems: function(items, userEnteredText, asyncDetails) |
| 266 { | 267 { |
| 267 this._length = items.length; | 268 this._length = items.length; |
| 268 this._asyncDetailsPromises = {}; | 269 this._asyncDetailsPromises.clear(); |
| 269 this._asyncDetailsCallback = asyncDetails; | 270 this._asyncDetailsCallback = asyncDetails; |
| 270 this._element.removeChildren(); | 271 this._element.removeChildren(); |
| 271 delete this._selectedElement; | 272 delete this._selectedElement; |
| 272 | 273 |
| 273 for (var i = 0; i < items.length; ++i) { | 274 for (var i = 0; i < items.length; ++i) { |
| 274 var item = items[i]; | 275 var item = items[i]; |
| 275 var currentItemElement = this._createItemElement(userEnteredText, it em, i); | 276 var currentItemElement = this._createItemElement(userEnteredText, it em, i); |
| 276 this._element.appendChild(currentItemElement); | 277 this._element.appendChild(currentItemElement); |
| 277 } | 278 } |
| 278 }, | 279 }, |
| 279 | 280 |
| 280 /** | 281 /** |
| 281 * @param {number} index | 282 * @param {number} index |
| 282 * @return {!Promise<({detail: string, description: string}|undefined)>} | 283 * @return {!Promise<{detail: string, description: string}>|!Promise<undefin ed>} |
|
lushnikov
2016/03/04 00:42:44
use null instead
kozy
2016/03/04 00:50:11
Done.
| |
| 283 */ | 284 */ |
| 284 _asyncDetails: function(index) | 285 _asyncDetails: function(index) |
| 285 { | 286 { |
| 286 if (!this._asyncDetailsCallback) | 287 if (!this._asyncDetailsCallback) |
| 287 return Promise.resolve(); | 288 return Promise.resolve(); |
| 288 if (!this._asyncDetailsPromises[index]) | 289 if (!this._asyncDetailsPromises.has(index)) |
| 289 this._asyncDetailsPromises[index] = this._asyncDetailsCallback(index ); | 290 this._asyncDetailsPromises.set(index, this._asyncDetailsCallback(ind ex)); |
| 290 return this._asyncDetailsPromises[index]; | 291 return /** @type {!Promise<{detail: string, description: string}>} */(th is._asyncDetailsPromises.get(index)); |
| 291 }, | 292 }, |
| 292 | 293 |
| 293 /** | 294 /** |
| 294 * @param {{detail: string, description: string}=} details | 295 * @param {{detail: string, description: string}=} details |
| 295 */ | 296 */ |
| 296 _showDetailsPopup: function(details) | 297 _showDetailsPopup: function(details) |
| 297 { | 298 { |
| 298 this._detailsPopup.removeChildren(); | 299 this._detailsPopup.removeChildren(); |
| 299 if (!details) | 300 if (!details) |
| 300 return; | 301 return; |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 512 this.element.style.top = containerBox.y + "px"; | 513 this.element.style.top = containerBox.y + "px"; |
| 513 this.element.style.height = containerBox.height + "px"; | 514 this.element.style.height = containerBox.height + "px"; |
| 514 this.element.style.width = containerBox.width + "px"; | 515 this.element.style.width = containerBox.width + "px"; |
| 515 }, | 516 }, |
| 516 | 517 |
| 517 dispose: function() | 518 dispose: function() |
| 518 { | 519 { |
| 519 this.element.remove(); | 520 this.element.remove(); |
| 520 } | 521 } |
| 521 } | 522 } |
| OLD | NEW |