| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 applySuggestion: function(suggestion, isIntermediateSuggestion) { }, | 43 applySuggestion: function(suggestion, isIntermediateSuggestion) { }, |
| 44 | 44 |
| 45 /** | 45 /** |
| 46 * acceptSuggestion will be always called after call to applySuggestion with
isIntermediateSuggestion being equal to false. | 46 * acceptSuggestion will be always called after call to applySuggestion with
isIntermediateSuggestion being equal to false. |
| 47 */ | 47 */ |
| 48 acceptSuggestion: function() { }, | 48 acceptSuggestion: function() { }, |
| 49 } | 49 } |
| 50 | 50 |
| 51 /** | 51 /** |
| 52 * @constructor | 52 * @constructor |
| 53 * @implements {WebInspector.StaticViewportControl.Provider} |
| 53 * @param {!WebInspector.SuggestBoxDelegate} suggestBoxDelegate | 54 * @param {!WebInspector.SuggestBoxDelegate} suggestBoxDelegate |
| 54 * @param {number=} maxItemsHeight | 55 * @param {number=} maxItemsHeight |
| 55 * @param {boolean=} captureEnter | 56 * @param {boolean=} captureEnter |
| 56 */ | 57 */ |
| 57 WebInspector.SuggestBox = function(suggestBoxDelegate, maxItemsHeight, captureEn
ter) | 58 WebInspector.SuggestBox = function(suggestBoxDelegate, maxItemsHeight, captureEn
ter) |
| 58 { | 59 { |
| 59 this._suggestBoxDelegate = suggestBoxDelegate; | 60 this._suggestBoxDelegate = suggestBoxDelegate; |
| 60 this._length = 0; | 61 this._length = 0; |
| 61 this._selectedIndex = -1; | 62 this._selectedIndex = -1; |
| 62 this._selectedElement = null; | 63 this._selectedElement = null; |
| 63 this._maxItemsHeight = maxItemsHeight; | 64 this._maxItemsHeight = maxItemsHeight; |
| 64 this._maybeHideBound = this._maybeHide.bind(this); | 65 this._maybeHideBound = this._maybeHide.bind(this); |
| 65 this._container = createElementWithClass("div", "suggest-box-container"); | 66 this._container = createElementWithClass("div", "suggest-box-container"); |
| 66 this._element = this._container.createChild("div", "suggest-box"); | 67 this._viewport = new WebInspector.StaticViewportControl(this); |
| 68 this._element = this._viewport.element; |
| 69 this._element.classList.add("suggest-box"); |
| 70 this._container.appendChild(this._element); |
| 67 this._element.addEventListener("mousedown", this._onBoxMouseDown.bind(this),
true); | 71 this._element.addEventListener("mousedown", this._onBoxMouseDown.bind(this),
true); |
| 68 this._detailsPopup = this._container.createChild("div", "suggest-box details
-popup monospace"); | 72 this._detailsPopup = this._container.createChild("div", "suggest-box details
-popup monospace"); |
| 69 this._detailsPopup.classList.add("hidden"); | 73 this._detailsPopup.classList.add("hidden"); |
| 70 this._asyncDetailsCallback = null; | 74 this._asyncDetailsCallback = null; |
| 71 /** @type {!Map<number, !Promise<{detail: string, description: string}>>} */ | 75 /** @type {!Map<number, !Promise<{detail: string, description: string}>>} */ |
| 72 this._asyncDetailsPromises = new Map(); | 76 this._asyncDetailsPromises = new Map(); |
| 73 this._userInteracted = false; | 77 this._userInteracted = false; |
| 74 this._captureEnter = captureEnter; | 78 this._captureEnter = captureEnter; |
| 79 /** @type {!Array<!Element>} */ |
| 80 this._elementList = []; |
| 81 this._rowHeight = 17; |
| 82 this._viewportWidth = "100vw"; |
| 83 this._hasVerticalScroll = false; |
| 84 this._userEnteredText = ""; |
| 85 /** @type {!WebInspector.SuggestBox.Suggestions} */ |
| 86 this._items = []; |
| 75 } | 87 } |
| 76 | 88 |
| 77 /** | 89 /** |
| 78 * @typedef {!Array.<{title: string, className: (string|undefined)}>} | 90 * @typedef {!Array.<{title: string, className: (string|undefined)}>} |
| 79 */ | 91 */ |
| 80 WebInspector.SuggestBox.Suggestions; | 92 WebInspector.SuggestBox.Suggestions; |
| 81 | 93 |
| 82 WebInspector.SuggestBox.prototype = { | 94 WebInspector.SuggestBox.prototype = { |
| 83 /** | 95 /** |
| 84 * @return {boolean} | 96 * @return {boolean} |
| (...skipping 10 matching lines...) Expand all Loading... |
| 95 { | 107 { |
| 96 this._updateBoxPosition(anchorBox); | 108 this._updateBoxPosition(anchorBox); |
| 97 }, | 109 }, |
| 98 | 110 |
| 99 /** | 111 /** |
| 100 * @param {!AnchorBox} anchorBox | 112 * @param {!AnchorBox} anchorBox |
| 101 */ | 113 */ |
| 102 _updateBoxPosition: function(anchorBox) | 114 _updateBoxPosition: function(anchorBox) |
| 103 { | 115 { |
| 104 console.assert(this._overlay); | 116 console.assert(this._overlay); |
| 105 if (this._lastAnchorBox && this._lastAnchorBox.equals(anchorBox)) | 117 if (this._lastAnchorBox && this._lastAnchorBox.equals(anchorBox) && this
._lastItemCount === this.itemCount()) |
| 106 return; | 118 return; |
| 119 this._lastItemCount = this.itemCount(); |
| 107 this._lastAnchorBox = anchorBox; | 120 this._lastAnchorBox = anchorBox; |
| 108 | 121 |
| 109 // Position relative to main DevTools element. | 122 // Position relative to main DevTools element. |
| 110 var container = WebInspector.Dialog.modalHostView().element; | 123 var container = WebInspector.Dialog.modalHostView().element; |
| 111 anchorBox = anchorBox.relativeToElement(container); | 124 anchorBox = anchorBox.relativeToElement(container); |
| 112 var totalHeight = container.offsetHeight; | 125 var totalHeight = container.offsetHeight; |
| 113 var aboveHeight = anchorBox.y; | 126 var aboveHeight = anchorBox.y; |
| 114 var underHeight = totalHeight - anchorBox.y - anchorBox.height; | 127 var underHeight = totalHeight - anchorBox.y - anchorBox.height; |
| 115 | 128 |
| 116 this._overlay.setLeftOffset(anchorBox.x); | 129 this._overlay.setLeftOffset(anchorBox.x); |
| 117 | 130 |
| 118 var under = underHeight >= aboveHeight; | 131 var under = underHeight >= aboveHeight; |
| 119 if (under) | 132 if (under) |
| 120 this._overlay.setVerticalOffset(anchorBox.y + anchorBox.height, true
); | 133 this._overlay.setVerticalOffset(anchorBox.y + anchorBox.height, true
); |
| 121 else | 134 else |
| 122 this._overlay.setVerticalOffset(totalHeight - anchorBox.y, false); | 135 this._overlay.setVerticalOffset(totalHeight - anchorBox.y, false); |
| 123 | 136 |
| 124 /** const */ var rowHeight = 17; | 137 var spacer = 6; |
| 125 /** const */ var spacer = 6; | 138 var maxHeight = this._maxItemsHeight ? this._maxItemsHeight * this._rowH
eight : Math.max(underHeight, aboveHeight) - spacer; |
| 126 var maxHeight = this._maxItemsHeight ? this._maxItemsHeight * rowHeight
: Math.max(underHeight, aboveHeight) - spacer; | 139 var height = this._rowHeight * this._items.length; |
| 127 this._element.style.maxHeight = maxHeight + "px"; | 140 this._hasVerticalScroll = height > maxHeight; |
| 141 this._element.style.height = Math.min(maxHeight, height) + "px"; |
| 142 }, |
| 143 |
| 144 _updateWidth: function() |
| 145 { |
| 146 if (this._hasVerticalScroll) { |
| 147 this._element.style.width = "100vw"; |
| 148 return; |
| 149 } |
| 150 // If there are no scrollbars, set the width to the width of the largest
row. |
| 151 var maxIndex = 0; |
| 152 for (var i = 0; i < this._items.length; i++) { |
| 153 if (this._items[i].title.length > this._items[maxIndex].title.length
) |
| 154 maxIndex = i; |
| 155 } |
| 156 var element = /** @type {!Element} */ (this.itemElement(maxIndex)); |
| 157 this._element.style.width = WebInspector.measurePreferredSize(element, t
his._element).width + "px"; |
| 128 }, | 158 }, |
| 129 | 159 |
| 130 /** | 160 /** |
| 131 * @param {!Event} event | 161 * @param {!Event} event |
| 132 */ | 162 */ |
| 133 _onBoxMouseDown: function(event) | 163 _onBoxMouseDown: function(event) |
| 134 { | 164 { |
| 135 if (this._hideTimeoutId) { | 165 if (this._hideTimeoutId) { |
| 136 window.clearTimeout(this._hideTimeoutId); | 166 window.clearTimeout(this._hideTimeoutId); |
| 137 delete this._hideTimeoutId; | 167 delete this._hideTimeoutId; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 150 * @suppressGlobalPropertiesCheck | 180 * @suppressGlobalPropertiesCheck |
| 151 */ | 181 */ |
| 152 _show: function() | 182 _show: function() |
| 153 { | 183 { |
| 154 if (this.visible()) | 184 if (this.visible()) |
| 155 return; | 185 return; |
| 156 this._bodyElement = document.body; | 186 this._bodyElement = document.body; |
| 157 this._bodyElement.addEventListener("mousedown", this._maybeHideBound, tr
ue); | 187 this._bodyElement.addEventListener("mousedown", this._maybeHideBound, tr
ue); |
| 158 this._overlay = new WebInspector.SuggestBox.Overlay(); | 188 this._overlay = new WebInspector.SuggestBox.Overlay(); |
| 159 this._overlay.setContentElement(this._container); | 189 this._overlay.setContentElement(this._container); |
| 190 var measuringElement = this._createItemElement("1", "12"); |
| 191 this._viewport.element.appendChild(measuringElement); |
| 192 this._rowHeight = measuringElement.getBoundingClientRect().height; |
| 193 measuringElement.remove(); |
| 160 }, | 194 }, |
| 161 | 195 |
| 162 hide: function() | 196 hide: function() |
| 163 { | 197 { |
| 164 if (!this.visible()) | 198 if (!this.visible()) |
| 165 return; | 199 return; |
| 166 | 200 |
| 167 this._userInteracted = false; | 201 this._userInteracted = false; |
| 168 this._bodyElement.removeEventListener("mousedown", this._maybeHideBound,
true); | 202 this._bodyElement.removeEventListener("mousedown", this._maybeHideBound,
true); |
| 169 delete this._bodyElement; | 203 delete this._bodyElement; |
| 170 this._container.remove(); | 204 this._container.remove(); |
| 171 this._overlay.dispose(); | 205 this._overlay.dispose(); |
| 172 delete this._overlay; | 206 delete this._overlay; |
| 173 delete this._selectedElement; | 207 delete this._selectedElement; |
| 174 this._selectedIndex = -1; | 208 this._selectedIndex = -1; |
| 175 delete this._lastAnchorBox; | 209 delete this._lastAnchorBox; |
| 176 }, | 210 }, |
| 177 | 211 |
| 178 removeFromElement: function() | 212 removeFromElement: function() |
| 179 { | 213 { |
| 180 this.hide(); | 214 this.hide(); |
| 181 }, | 215 }, |
| 182 | 216 |
| 183 /** | 217 /** |
| 184 * @param {boolean=} isIntermediateSuggestion | 218 * @param {boolean=} isIntermediateSuggestion |
| 219 * @return {boolean} |
| 185 */ | 220 */ |
| 186 _applySuggestion: function(isIntermediateSuggestion) | 221 _applySuggestion: function(isIntermediateSuggestion) |
| 187 { | 222 { |
| 188 if (this._onlyCompletion) { | 223 if (this._onlyCompletion) { |
| 189 this._suggestBoxDelegate.applySuggestion(this._onlyCompletion, isInt
ermediateSuggestion); | 224 this._suggestBoxDelegate.applySuggestion(this._onlyCompletion, isInt
ermediateSuggestion); |
| 190 return true; | 225 return true; |
| 191 } | 226 } |
| 192 | 227 |
| 193 if (!this.visible() || !this._selectedElement) | 228 if (!this.visible() || !this._selectedElement) |
| 194 return false; | 229 return false; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 _onItemMouseDown: function(event) | 284 _onItemMouseDown: function(event) |
| 250 { | 285 { |
| 251 this._selectedElement = event.currentTarget; | 286 this._selectedElement = event.currentTarget; |
| 252 this.acceptSuggestion(); | 287 this.acceptSuggestion(); |
| 253 event.consume(true); | 288 event.consume(true); |
| 254 }, | 289 }, |
| 255 | 290 |
| 256 /** | 291 /** |
| 257 * @param {string} prefix | 292 * @param {string} prefix |
| 258 * @param {string} text | 293 * @param {string} text |
| 259 * @param {string|undefined} className | 294 * @param {string=} className |
| 260 * @param {number} index | 295 * @return {!Element} |
| 261 */ | 296 */ |
| 262 _createItemElement: function(prefix, text, className, index) | 297 _createItemElement: function(prefix, text, className) |
| 263 { | 298 { |
| 264 var element = createElementWithClass("div", "suggest-box-content-item so
urce-code " + (className || "")); | 299 var element = createElementWithClass("div", "suggest-box-content-item so
urce-code " + (className || "")); |
| 265 element.tabIndex = -1; | 300 element.tabIndex = -1; |
| 266 if (prefix && prefix.length && !text.indexOf(prefix)) { | 301 if (prefix && prefix.length && !text.indexOf(prefix)) { |
| 267 element.createChild("span", "prefix").textContent = prefix; | 302 element.createChild("span", "prefix").textContent = prefix; |
| 268 element.createChild("span", "suffix").textContent = text.substring(p
refix.length).trimEnd(50); | 303 element.createChild("span", "suffix").textContent = text.substring(p
refix.length).trimEnd(50); |
| 269 } else { | 304 } else { |
| 270 element.createChild("span", "suffix").textContent = text.trimEnd(50)
; | 305 element.createChild("span", "suffix").textContent = text.trimEnd(50)
; |
| 271 } | 306 } |
| 272 element.__fullValue = text; | 307 element.__fullValue = text; |
| 273 element.createChild("span", "spacer"); | 308 element.createChild("span", "spacer"); |
| 274 element.addEventListener("mousedown", this._onItemMouseDown.bind(this),
false); | 309 element.addEventListener("mousedown", this._onItemMouseDown.bind(this),
false); |
| 275 return element; | 310 return element; |
| 276 }, | 311 }, |
| 277 | 312 |
| 278 /** | 313 /** |
| 279 * @param {!WebInspector.SuggestBox.Suggestions} items | 314 * @param {!WebInspector.SuggestBox.Suggestions} items |
| 280 * @param {string} userEnteredText | 315 * @param {string} userEnteredText |
| 281 * @param {function(number): !Promise<{detail:string, description:string}>=}
asyncDetails | 316 * @param {function(number): !Promise<{detail:string, description:string}>=}
asyncDetails |
| 282 */ | 317 */ |
| 283 _updateItems: function(items, userEnteredText, asyncDetails) | 318 _updateItems: function(items, userEnteredText, asyncDetails) |
| 284 { | 319 { |
| 285 this._length = items.length; | 320 this._length = items.length; |
| 286 this._asyncDetailsPromises.clear(); | 321 this._asyncDetailsPromises.clear(); |
| 287 this._asyncDetailsCallback = asyncDetails; | 322 this._asyncDetailsCallback = asyncDetails; |
| 288 this._element.removeChildren(); | 323 this._elementList = []; |
| 289 delete this._selectedElement; | 324 delete this._selectedElement; |
| 290 | 325 |
| 291 for (var i = 0; i < items.length; ++i) { | 326 this._userEnteredText = userEnteredText; |
| 292 var item = items[i]; | 327 this._items = items; |
| 293 var currentItemElement = this._createItemElement(userEnteredText, it
em.title, item.className, i); | |
| 294 this._element.appendChild(currentItemElement); | |
| 295 } | |
| 296 }, | 328 }, |
| 297 | 329 |
| 298 /** | 330 /** |
| 299 * @param {number} index | 331 * @param {number} index |
| 300 * @return {!Promise<?{detail: string, description: string}>} | 332 * @return {!Promise<?{detail: string, description: string}>} |
| 301 */ | 333 */ |
| 302 _asyncDetails: function(index) | 334 _asyncDetails: function(index) |
| 303 { | 335 { |
| 304 if (!this._asyncDetailsCallback) | 336 if (!this._asyncDetailsCallback) |
| 305 return Promise.resolve(/** @type {?{description: string, detail: str
ing}} */(null)); | 337 return Promise.resolve(/** @type {?{description: string, detail: str
ing}} */(null)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 327 */ | 359 */ |
| 328 _selectItem: function(index, scrollIntoView) | 360 _selectItem: function(index, scrollIntoView) |
| 329 { | 361 { |
| 330 if (this._selectedElement) | 362 if (this._selectedElement) |
| 331 this._selectedElement.classList.remove("selected"); | 363 this._selectedElement.classList.remove("selected"); |
| 332 | 364 |
| 333 this._selectedIndex = index; | 365 this._selectedIndex = index; |
| 334 if (index < 0) | 366 if (index < 0) |
| 335 return; | 367 return; |
| 336 | 368 |
| 337 this._selectedElement = this._element.children[index]; | 369 this._selectedElement = this.itemElement(index); |
| 338 this._selectedElement.classList.add("selected"); | 370 this._selectedElement.classList.add("selected"); |
| 339 this._detailsPopup.classList.add("hidden"); | 371 this._detailsPopup.classList.add("hidden"); |
| 340 var elem = this._selectedElement; | 372 var elem = this._selectedElement; |
| 341 this._asyncDetails(index).then(showDetails.bind(this), function(){}); | 373 this._asyncDetails(index).then(showDetails.bind(this), function(){}); |
| 342 | 374 |
| 343 if (scrollIntoView) | 375 if (scrollIntoView) |
| 344 this._selectedElement.scrollIntoViewIfNeeded(false); | 376 this._viewport.scrollItemIntoView(index); |
| 345 | 377 |
| 346 /** | 378 /** |
| 347 * @param {?{detail: string, description: string}} details | 379 * @param {?{detail: string, description: string}} details |
| 348 * @this {WebInspector.SuggestBox} | 380 * @this {WebInspector.SuggestBox} |
| 349 */ | 381 */ |
| 350 function showDetails(details) | 382 function showDetails(details) |
| 351 { | 383 { |
| 352 if (elem === this._selectedElement) | 384 if (elem === this._selectedElement) |
| 353 this._showDetailsPopup(details); | 385 this._showDetailsPopup(details); |
| 354 } | 386 } |
| 355 }, | 387 }, |
| 356 | 388 |
| 357 /** | 389 /** |
| 358 * @param {!WebInspector.SuggestBox.Suggestions} completions | 390 * @param {!WebInspector.SuggestBox.Suggestions} completions |
| 359 * @param {boolean} canShowForSingleItem | 391 * @param {boolean} canShowForSingleItem |
| 360 * @param {string} userEnteredText | 392 * @param {string} userEnteredText |
| 393 * @return {boolean} |
| 361 */ | 394 */ |
| 362 _canShowBox: function(completions, canShowForSingleItem, userEnteredText) | 395 _canShowBox: function(completions, canShowForSingleItem, userEnteredText) |
| 363 { | 396 { |
| 364 if (!completions || !completions.length) | 397 if (!completions || !completions.length) |
| 365 return false; | 398 return false; |
| 366 | 399 |
| 367 if (completions.length > 1) | 400 if (completions.length > 1) |
| 368 return true; | 401 return true; |
| 369 | 402 |
| 370 // Do not show a single suggestion if it is the same as user-entered pre
fix, even if allowed to show single-item suggest boxes. | 403 // Do not show a single suggestion if it is the same as user-entered pre
fix, even if allowed to show single-item suggest boxes. |
| 371 return canShowForSingleItem && completions[0].title !== userEnteredText; | 404 return canShowForSingleItem && completions[0].title !== userEnteredText; |
| 372 }, | 405 }, |
| 373 | 406 |
| 374 _ensureRowCountPerViewport: function() | 407 _ensureRowCountPerViewport: function() |
| 375 { | 408 { |
| 376 if (this._rowCountPerViewport) | 409 if (this._rowCountPerViewport) |
| 377 return; | 410 return; |
| 378 if (!this._element.firstChild) | 411 if (!this._items.length) |
| 379 return; | 412 return; |
| 380 | 413 |
| 381 this._rowCountPerViewport = Math.floor(this._element.offsetHeight / this
._element.firstChild.offsetHeight); | 414 this._rowCountPerViewport = Math.floor(this._element.getBoundingClientRe
ct().height / this._rowHeight); |
| 382 }, | 415 }, |
| 383 | 416 |
| 384 /** | 417 /** |
| 385 * @param {!AnchorBox} anchorBox | 418 * @param {!AnchorBox} anchorBox |
| 386 * @param {!WebInspector.SuggestBox.Suggestions} completions | 419 * @param {!WebInspector.SuggestBox.Suggestions} completions |
| 387 * @param {number} selectedIndex | 420 * @param {number} selectedIndex |
| 388 * @param {boolean} canShowForSingleItem | 421 * @param {boolean} canShowForSingleItem |
| 389 * @param {string} userEnteredText | 422 * @param {string} userEnteredText |
| 390 * @param {function(number): !Promise<{detail:string, description:string}>=}
asyncDetails | 423 * @param {function(number): !Promise<{detail:string, description:string}>=}
asyncDetails |
| 391 */ | 424 */ |
| 392 updateSuggestions: function(anchorBox, completions, selectedIndex, canShowFo
rSingleItem, userEnteredText, asyncDetails) | 425 updateSuggestions: function(anchorBox, completions, selectedIndex, canShowFo
rSingleItem, userEnteredText, asyncDetails) |
| 393 { | 426 { |
| 394 delete this._onlyCompletion; | 427 delete this._onlyCompletion; |
| 395 if (this._canShowBox(completions, canShowForSingleItem, userEnteredText)
) { | 428 if (this._canShowBox(completions, canShowForSingleItem, userEnteredText)
) { |
| 396 this._updateItems(completions, userEnteredText, asyncDetails); | 429 this._updateItems(completions, userEnteredText, asyncDetails); |
| 397 this._show(); | 430 this._show(); |
| 398 this._updateBoxPosition(anchorBox); | 431 this._updateBoxPosition(anchorBox); |
| 432 this._updateWidth(); |
| 433 this._viewport.refresh(); |
| 399 this._selectItem(selectedIndex, selectedIndex > 0); | 434 this._selectItem(selectedIndex, selectedIndex > 0); |
| 400 delete this._rowCountPerViewport; | 435 delete this._rowCountPerViewport; |
| 401 } else { | 436 } else { |
| 402 if (completions.length === 1) | 437 if (completions.length === 1) |
| 403 this._onlyCompletion = completions[0].title; | 438 this._onlyCompletion = completions[0].title; |
| 404 this.hide(); | 439 this.hide(); |
| 405 } | 440 } |
| 406 }, | 441 }, |
| 407 | 442 |
| 408 /** | 443 /** |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 { | 502 { |
| 468 if (!this._userInteracted && this._captureEnter) | 503 if (!this._userInteracted && this._captureEnter) |
| 469 return false; | 504 return false; |
| 470 | 505 |
| 471 var hasSelectedItem = !!this._selectedElement || this._onlyCompletion; | 506 var hasSelectedItem = !!this._selectedElement || this._onlyCompletion; |
| 472 this.acceptSuggestion(); | 507 this.acceptSuggestion(); |
| 473 | 508 |
| 474 // Report the event as non-handled if there is no selected item, | 509 // Report the event as non-handled if there is no selected item, |
| 475 // to commit the input or handle it otherwise. | 510 // to commit the input or handle it otherwise. |
| 476 return hasSelectedItem; | 511 return hasSelectedItem; |
| 512 }, |
| 513 |
| 514 /** |
| 515 * @override |
| 516 * @param {number} index |
| 517 * @return {number} |
| 518 */ |
| 519 fastItemHeight: function(index) |
| 520 { |
| 521 return this._rowHeight; |
| 522 }, |
| 523 |
| 524 /** |
| 525 * @override |
| 526 * @return {number} |
| 527 */ |
| 528 itemCount: function() |
| 529 { |
| 530 return this._items.length; |
| 531 }, |
| 532 |
| 533 /** |
| 534 * @override |
| 535 * @param {number} index |
| 536 * @return {?Element} |
| 537 */ |
| 538 itemElement: function(index) |
| 539 { |
| 540 if (!this._elementList[index]) |
| 541 this._elementList[index] = this._createItemElement(this._userEntered
Text, this._items[index].title, this._items[index].className); |
| 542 return this._elementList[index]; |
| 477 } | 543 } |
| 478 } | 544 } |
| 479 | 545 |
| 480 /** | 546 /** |
| 481 * @constructor | 547 * @constructor |
| 482 * // FIXME: make SuggestBox work for multiple documents. | 548 * // FIXME: make SuggestBox work for multiple documents. |
| 483 * @suppressGlobalPropertiesCheck | 549 * @suppressGlobalPropertiesCheck |
| 484 */ | 550 */ |
| 485 WebInspector.SuggestBox.Overlay = function() | 551 WebInspector.SuggestBox.Overlay = function() |
| 486 { | 552 { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 this.element.style.top = containerBox.y + "px"; | 603 this.element.style.top = containerBox.y + "px"; |
| 538 this.element.style.height = containerBox.height + "px"; | 604 this.element.style.height = containerBox.height + "px"; |
| 539 this.element.style.width = containerBox.width + "px"; | 605 this.element.style.width = containerBox.width + "px"; |
| 540 }, | 606 }, |
| 541 | 607 |
| 542 dispose: function() | 608 dispose: function() |
| 543 { | 609 { |
| 544 this.element.remove(); | 610 this.element.remove(); |
| 545 } | 611 } |
| 546 } | 612 } |
| OLD | NEW |