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 28 matching lines...) Expand all Loading... | |
| 39 */ | 39 */ |
| 40 applySuggestion(suggestion, isIntermediateSuggestion) {}, | 40 applySuggestion(suggestion, isIntermediateSuggestion) {}, |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * acceptSuggestion will be always called after call to applySuggestion with i sIntermediateSuggestion being equal to false. | 43 * acceptSuggestion will be always called after call to applySuggestion with i sIntermediateSuggestion being equal to false. |
| 44 */ | 44 */ |
| 45 acceptSuggestion() {}, | 45 acceptSuggestion() {}, |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 /** | 48 /** |
| 49 * @implements {UI.ViewportControl.Provider} | |
| 50 * @unrestricted | 49 * @unrestricted |
| 51 */ | 50 */ |
| 52 UI.SuggestBox = class { | 51 UI.SuggestBox = class { |
| 53 /** | 52 /** |
| 54 * @param {!UI.SuggestBoxDelegate} suggestBoxDelegate | 53 * @param {!UI.SuggestBoxDelegate} suggestBoxDelegate |
| 55 * @param {number=} maxItemsHeight | 54 * @param {number=} maxItemsHeight |
| 56 * @param {boolean=} captureEnter | 55 * @param {boolean=} captureEnter |
| 57 */ | 56 */ |
| 58 constructor(suggestBoxDelegate, maxItemsHeight, captureEnter) { | 57 constructor(suggestBoxDelegate, maxItemsHeight, captureEnter) { |
| 59 this._suggestBoxDelegate = suggestBoxDelegate; | 58 this._suggestBoxDelegate = suggestBoxDelegate; |
| 60 this._length = 0; | |
| 61 this._selectedIndex = -1; | 59 this._selectedIndex = -1; |
| 62 this._selectedElement = null; | 60 this._selectedElement = null; |
| 63 this._maxItemsHeight = maxItemsHeight; | 61 this._maxItemsHeight = maxItemsHeight; |
| 64 this._maybeHideBound = this._maybeHide.bind(this); | 62 this._maybeHideBound = this._maybeHide.bind(this); |
| 65 this._container = createElementWithClass('div', 'suggest-box-container'); | 63 this._container = createElementWithClass('div', 'suggest-box-container'); |
| 66 this._viewport = new UI.ViewportControl(this); | 64 this._viewport = new UI.SimpleViewport(this._createItemElement.bind(this)); |
| 67 this._element = this._viewport.element; | 65 this._element = this._viewport.element; |
| 68 this._element.classList.add('suggest-box'); | 66 this._element.classList.add('suggest-box'); |
| 69 this._container.appendChild(this._element); | 67 this._container.appendChild(this._element); |
| 70 this._element.addEventListener('mousedown', this._onBoxMouseDown.bind(this), true); | 68 this._element.addEventListener('mousedown', this._onBoxMouseDown.bind(this), true); |
| 71 this._detailsPopup = this._container.createChild('div', 'suggest-box details -popup monospace'); | 69 this._detailsPopup = this._container.createChild('div', 'suggest-box details -popup monospace'); |
| 72 this._detailsPopup.classList.add('hidden'); | 70 this._detailsPopup.classList.add('hidden'); |
| 73 this._asyncDetailsCallback = null; | 71 this._asyncDetailsCallback = null; |
| 74 /** @type {!Map<number, !Promise<{detail: string, description: string}>>} */ | 72 /** @type {!Map<number, !Promise<{detail: string, description: string}>>} */ |
| 75 this._asyncDetailsPromises = new Map(); | 73 this._asyncDetailsPromises = new Map(); |
| 76 this._userInteracted = false; | 74 this._userInteracted = false; |
| 77 this._captureEnter = captureEnter; | 75 this._captureEnter = captureEnter; |
| 78 /** @type {!Array<!Element>} */ | |
| 79 this._elementList = []; | |
| 80 this._rowHeight = 17; | |
| 81 this._viewportWidth = '100vw'; | 76 this._viewportWidth = '100vw'; |
| 82 this._hasVerticalScroll = false; | 77 this._hasVerticalScroll = false; |
| 83 this._userEnteredText = ''; | 78 this._userEnteredText = ''; |
| 84 /** @type {!UI.SuggestBox.Suggestions} */ | 79 /** @type {!UI.SuggestBox.Suggestions} */ |
| 85 this._items = []; | 80 this._items = []; |
| 86 } | 81 } |
| 87 | 82 |
| 88 /** | 83 /** |
| 89 * @return {boolean} | 84 * @return {boolean} |
| 90 */ | 85 */ |
| 91 visible() { | 86 visible() { |
| 92 return !!this._container.parentElement; | 87 return !!this._container.parentElement; |
| 93 } | 88 } |
| 94 | 89 |
| 95 /** | 90 /** |
| 96 * @param {!AnchorBox} anchorBox | 91 * @param {!AnchorBox} anchorBox |
| 97 */ | 92 */ |
| 98 setPosition(anchorBox) { | 93 setPosition(anchorBox) { |
| 99 this._updateBoxPosition(anchorBox); | 94 this._updateBoxPosition(anchorBox); |
| 100 } | 95 } |
| 101 | 96 |
| 102 /** | 97 /** |
| 103 * @param {!AnchorBox} anchorBox | 98 * @param {!AnchorBox} anchorBox |
| 104 */ | 99 */ |
| 105 _updateBoxPosition(anchorBox) { | 100 _updateBoxPosition(anchorBox) { |
| 106 console.assert(this._overlay); | 101 console.assert(this._overlay); |
| 107 if (this._lastAnchorBox && this._lastAnchorBox.equals(anchorBox) && this._la stItemCount === this.itemCount()) | 102 if (this._lastAnchorBox && this._lastAnchorBox.equals(anchorBox) && this._la stItemCount === this._items.length) |
| 108 return; | 103 return; |
| 109 this._lastItemCount = this.itemCount(); | 104 this._lastItemCount = this._items.length; |
| 110 this._lastAnchorBox = anchorBox; | 105 this._lastAnchorBox = anchorBox; |
| 111 | 106 |
| 112 // Position relative to main DevTools element. | 107 // Position relative to main DevTools element. |
| 113 var container = UI.Dialog.modalHostView().element; | 108 var container = UI.Dialog.modalHostView().element; |
| 114 anchorBox = anchorBox.relativeToElement(container); | 109 anchorBox = anchorBox.relativeToElement(container); |
| 115 var totalHeight = container.offsetHeight; | 110 var totalHeight = container.offsetHeight; |
| 116 var aboveHeight = anchorBox.y; | 111 var aboveHeight = anchorBox.y; |
| 117 var underHeight = totalHeight - anchorBox.y - anchorBox.height; | 112 var underHeight = totalHeight - anchorBox.y - anchorBox.height; |
| 118 | 113 |
| 119 this._overlay.setLeftOffset(anchorBox.x); | 114 this._overlay.setLeftOffset(anchorBox.x); |
| 120 | 115 |
| 121 var under = underHeight >= aboveHeight; | 116 var under = underHeight >= aboveHeight; |
| 122 if (under) | 117 if (under) |
| 123 this._overlay.setVerticalOffset(anchorBox.y + anchorBox.height, true); | 118 this._overlay.setVerticalOffset(anchorBox.y + anchorBox.height, true); |
| 124 else | 119 else |
| 125 this._overlay.setVerticalOffset(totalHeight - anchorBox.y, false); | 120 this._overlay.setVerticalOffset(totalHeight - anchorBox.y, false); |
| 126 | 121 |
| 127 var spacer = 6; | 122 var spacer = 6; |
| 123 var rowHeight = this._viewport.elementHeight(); | |
| 128 var maxHeight = Math.min( | 124 var maxHeight = Math.min( |
| 129 Math.max(underHeight, aboveHeight) - spacer, | 125 Math.max(underHeight, aboveHeight) - spacer, |
| 130 this._maxItemsHeight ? this._maxItemsHeight * this._rowHeight : Infinity ); | 126 this._maxItemsHeight ? this._maxItemsHeight * rowHeight : Infinity); |
| 131 var height = this._rowHeight * this._items.length; | 127 var height = rowHeight * this._items.length; |
| 132 this._hasVerticalScroll = height > maxHeight; | 128 this._hasVerticalScroll = height > maxHeight; |
| 133 this._element.style.height = Math.min(maxHeight, height) + 'px'; | 129 this._element.style.height = Math.min(maxHeight, height) + 'px'; |
| 134 } | 130 } |
| 135 | 131 |
| 136 _updateWidth() { | 132 _updateWidth() { |
| 137 if (this._hasVerticalScroll) { | 133 if (this._hasVerticalScroll) { |
| 138 this._element.style.width = '100vw'; | 134 this._element.style.width = '100vw'; |
| 139 return; | 135 return; |
| 140 } | 136 } |
| 141 // If there are no scrollbars, set the width to the width of the largest row . | 137 // If there are no scrollbars, set the width to the width of the largest row . |
| 142 var maxIndex = 0; | 138 var maxIndex = 0; |
| 143 for (var i = 0; i < this._items.length; i++) { | 139 for (var i = 0; i < this._items.length; i++) { |
| 144 if (this._items[i].title.length > this._items[maxIndex].title.length) | 140 if (this._items[i].title.length > this._items[maxIndex].title.length) |
| 145 maxIndex = i; | 141 maxIndex = i; |
| 146 } | 142 } |
| 147 var element = /** @type {!Element} */ (this.itemElement(maxIndex)); | 143 var element = /** @type {!Element} */ (this._viewport.elementAtIndex(maxInde x)); |
| 148 this._element.style.width = UI.measurePreferredSize(element, this._element). width + 'px'; | 144 this._element.style.width = UI.measurePreferredSize(element, this._element). width + 'px'; |
| 149 } | 145 } |
| 150 | 146 |
| 151 /** | 147 /** |
| 152 * @param {!Event} event | 148 * @param {!Event} event |
| 153 */ | 149 */ |
| 154 _onBoxMouseDown(event) { | 150 _onBoxMouseDown(event) { |
| 155 if (this._hideTimeoutId) { | 151 if (this._hideTimeoutId) { |
| 156 window.clearTimeout(this._hideTimeoutId); | 152 window.clearTimeout(this._hideTimeoutId); |
| 157 delete this._hideTimeoutId; | 153 delete this._hideTimeoutId; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 168 * // FIXME: make SuggestBox work for multiple documents. | 164 * // FIXME: make SuggestBox work for multiple documents. |
| 169 * @suppressGlobalPropertiesCheck | 165 * @suppressGlobalPropertiesCheck |
| 170 */ | 166 */ |
| 171 _show() { | 167 _show() { |
| 172 if (this.visible()) | 168 if (this.visible()) |
| 173 return; | 169 return; |
| 174 this._bodyElement = document.body; | 170 this._bodyElement = document.body; |
| 175 this._bodyElement.addEventListener('mousedown', this._maybeHideBound, true); | 171 this._bodyElement.addEventListener('mousedown', this._maybeHideBound, true); |
| 176 this._overlay = new UI.SuggestBox.Overlay(); | 172 this._overlay = new UI.SuggestBox.Overlay(); |
| 177 this._overlay.setContentElement(this._container); | 173 this._overlay.setContentElement(this._container); |
| 178 var measuringElement = this._createItemElement('1', '12'); | |
| 179 this._viewport.element.appendChild(measuringElement); | |
| 180 this._rowHeight = measuringElement.getBoundingClientRect().height; | |
| 181 measuringElement.remove(); | |
| 182 } | 174 } |
| 183 | 175 |
| 184 hide() { | 176 hide() { |
| 185 if (!this.visible()) | 177 if (!this.visible()) |
| 186 return; | 178 return; |
| 187 | 179 |
| 188 this._userInteracted = false; | 180 this._userInteracted = false; |
| 189 this._bodyElement.removeEventListener('mousedown', this._maybeHideBound, tru e); | 181 this._bodyElement.removeEventListener('mousedown', this._maybeHideBound, tru e); |
| 190 delete this._bodyElement; | 182 delete this._bodyElement; |
| 191 this._container.remove(); | 183 this._container.remove(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 | 226 |
| 235 return true; | 227 return true; |
| 236 } | 228 } |
| 237 | 229 |
| 238 /** | 230 /** |
| 239 * @param {number} shift | 231 * @param {number} shift |
| 240 * @param {boolean=} isCircular | 232 * @param {boolean=} isCircular |
| 241 * @return {boolean} is changed | 233 * @return {boolean} is changed |
| 242 */ | 234 */ |
| 243 _selectClosest(shift, isCircular) { | 235 _selectClosest(shift, isCircular) { |
| 244 if (!this._length) | 236 if (!this._items.length) |
| 245 return false; | 237 return false; |
| 246 | 238 |
| 247 this._userInteracted = true; | 239 this._userInteracted = true; |
| 248 | 240 |
| 249 if (this._selectedIndex === -1 && shift < 0) | 241 if (this._selectedIndex === -1 && shift < 0) |
| 250 shift += 1; | 242 shift += 1; |
| 251 | 243 |
| 252 var index = this._selectedIndex + shift; | 244 var index = this._selectedIndex + shift; |
| 253 | 245 |
| 254 if (isCircular) | 246 if (isCircular) |
| 255 index = (this._length + index) % this._length; | 247 index = (this._items.length + index) % this._items.length; |
| 256 else | 248 else |
| 257 index = Number.constrain(index, 0, this._length - 1); | 249 index = Number.constrain(index, 0, this._items.length - 1); |
| 258 | 250 |
| 259 this._selectItem(index); | 251 this._selectItem(index); |
| 260 return true; | 252 return true; |
| 261 } | 253 } |
| 262 | 254 |
| 263 /** | 255 /** |
| 264 * @param {!Event} event | 256 * @param {!Event} event |
| 265 */ | 257 */ |
| 266 _onItemMouseDown(event) { | 258 _onItemMouseDown(event) { |
| 267 this._selectedElement = event.currentTarget; | 259 this._selectedElement = event.currentTarget; |
| 268 this.acceptSuggestion(); | 260 this.acceptSuggestion(); |
| 269 event.consume(true); | 261 event.consume(true); |
| 270 } | 262 } |
| 271 | 263 |
| 272 /** | 264 /** |
| 273 * @param {string} query | 265 * @param {number} itemIndex |
| 274 * @param {string} title | |
| 275 * @param {string=} subtitle | |
| 276 * @param {string=} iconType | |
| 277 * @param {boolean=} isSecondary | |
| 278 * @return {!Element} | 266 * @return {!Element} |
| 279 */ | 267 */ |
| 280 _createItemElement(query, title, subtitle, iconType, isSecondary) { | 268 _createItemElement(itemIndex) { |
| 269 var query = this._userEnteredText; | |
| 270 var title = this._items[itemIndex].title; | |
| 271 var subtitle = this._items[itemIndex].subtitle; | |
| 272 var iconType = this._items[itemIndex].iconType; | |
| 273 var isSecondary = this._items[itemIndex].isSecondary; | |
| 281 var element = createElementWithClass('div', 'suggest-box-content-item source -code'); | 274 var element = createElementWithClass('div', 'suggest-box-content-item source -code'); |
| 282 if (iconType) { | 275 if (iconType) { |
| 283 var icon = UI.Icon.create(iconType, 'suggestion-icon'); | 276 var icon = UI.Icon.create(iconType, 'suggestion-icon'); |
| 284 element.appendChild(icon); | 277 element.appendChild(icon); |
| 285 } | 278 } |
| 286 if (isSecondary) | 279 if (isSecondary) |
| 287 element.classList.add('secondary'); | 280 element.classList.add('secondary'); |
| 288 element.tabIndex = -1; | 281 element.tabIndex = -1; |
| 289 var displayText = title.trimEnd(50 + query.length); | 282 var displayText = title.trimEnd(50 + query.length); |
| 290 | 283 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 304 element.addEventListener('mousedown', this._onItemMouseDown.bind(this), fals e); | 297 element.addEventListener('mousedown', this._onItemMouseDown.bind(this), fals e); |
| 305 return element; | 298 return element; |
| 306 } | 299 } |
| 307 | 300 |
| 308 /** | 301 /** |
| 309 * @param {!UI.SuggestBox.Suggestions} items | 302 * @param {!UI.SuggestBox.Suggestions} items |
| 310 * @param {string} userEnteredText | 303 * @param {string} userEnteredText |
| 311 * @param {function(number): !Promise<{detail:string, description:string}>=} a syncDetails | 304 * @param {function(number): !Promise<{detail:string, description:string}>=} a syncDetails |
| 312 */ | 305 */ |
| 313 _updateItems(items, userEnteredText, asyncDetails) { | 306 _updateItems(items, userEnteredText, asyncDetails) { |
| 314 this._length = items.length; | |
| 315 this._asyncDetailsPromises.clear(); | 307 this._asyncDetailsPromises.clear(); |
| 316 this._asyncDetailsCallback = asyncDetails; | 308 this._asyncDetailsCallback = asyncDetails; |
| 317 this._elementList = []; | |
| 318 delete this._selectedElement; | 309 delete this._selectedElement; |
| 319 | |
| 320 this._userEnteredText = userEnteredText; | 310 this._userEnteredText = userEnteredText; |
| 321 this._items = items; | 311 this._items = items; |
| 322 } | 312 } |
| 323 | 313 |
| 324 /** | 314 /** |
| 325 * @param {number} index | 315 * @param {number} index |
| 326 * @return {!Promise<?{detail: string, description: string}>} | 316 * @return {!Promise<?{detail: string, description: string}>} |
| 327 */ | 317 */ |
| 328 _asyncDetails(index) { | 318 _asyncDetails(index) { |
| 329 if (!this._asyncDetailsCallback) | 319 if (!this._asyncDetailsCallback) |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 351 _selectItem(index) { | 341 _selectItem(index) { |
| 352 if (this._selectedElement) { | 342 if (this._selectedElement) { |
| 353 this._selectedElement.classList.remove('selected'); | 343 this._selectedElement.classList.remove('selected'); |
| 354 this._selectedElement.classList.remove('force-white-icons'); | 344 this._selectedElement.classList.remove('force-white-icons'); |
| 355 } | 345 } |
| 356 | 346 |
| 357 this._selectedIndex = index; | 347 this._selectedIndex = index; |
| 358 if (index < 0) | 348 if (index < 0) |
| 359 return; | 349 return; |
| 360 | 350 |
| 361 this._selectedElement = this.itemElement(index); | 351 this._selectedElement = this._viewport.elementAtIndex(index); |
| 362 this._selectedElement.classList.add('selected'); | 352 this._selectedElement.classList.add('selected'); |
| 363 this._selectedElement.classList.add('force-white-icons'); | 353 this._selectedElement.classList.add('force-white-icons'); |
| 364 this._detailsPopup.classList.add('hidden'); | 354 this._detailsPopup.classList.add('hidden'); |
| 365 var elem = this._selectedElement; | 355 var elem = this._selectedElement; |
| 366 this._asyncDetails(index).then(showDetails.bind(this), function() {}); | 356 this._asyncDetails(index).then(showDetails.bind(this), function() {}); |
| 367 | 357 |
| 368 this._viewport.scrollItemIntoView(index); | 358 this._viewport.scrollItemIntoView(index); |
| 369 this._applySuggestion(true); | 359 this._applySuggestion(true); |
| 370 | 360 |
| 371 /** | 361 /** |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 391 if (completions.length > 1) | 381 if (completions.length > 1) |
| 392 return true; | 382 return true; |
| 393 | 383 |
| 394 if (!completions[0].title.startsWith(userEnteredText)) | 384 if (!completions[0].title.startsWith(userEnteredText)) |
| 395 return true; | 385 return true; |
| 396 | 386 |
| 397 // Do not show a single suggestion if it is the same as user-entered query, even if allowed to show single-item suggest boxes. | 387 // Do not show a single suggestion if it is the same as user-entered query, even if allowed to show single-item suggest boxes. |
| 398 return canShowForSingleItem && completions[0].title !== userEnteredText; | 388 return canShowForSingleItem && completions[0].title !== userEnteredText; |
| 399 } | 389 } |
| 400 | 390 |
| 401 _ensureRowCountPerViewport() { | |
| 402 if (this._rowCountPerViewport) | |
| 403 return; | |
| 404 if (!this._items.length) | |
| 405 return; | |
| 406 | |
| 407 this._rowCountPerViewport = Math.floor(this._element.getBoundingClientRect() .height / this._rowHeight); | |
| 408 } | |
| 409 | |
| 410 /** | 391 /** |
| 411 * @param {!AnchorBox} anchorBox | 392 * @param {!AnchorBox} anchorBox |
| 412 * @param {!UI.SuggestBox.Suggestions} completions | 393 * @param {!UI.SuggestBox.Suggestions} completions |
| 413 * @param {boolean} selectHighestPriority | 394 * @param {boolean} selectHighestPriority |
| 414 * @param {boolean} canShowForSingleItem | 395 * @param {boolean} canShowForSingleItem |
| 415 * @param {string} userEnteredText | 396 * @param {string} userEnteredText |
| 416 * @param {function(number): !Promise<{detail:string, description:string}>=} a syncDetails | 397 * @param {function(number): !Promise<{detail:string, description:string}>=} a syncDetails |
| 417 */ | 398 */ |
| 418 updateSuggestions( | 399 updateSuggestions( |
| 419 anchorBox, | 400 anchorBox, |
| 420 completions, | 401 completions, |
| 421 selectHighestPriority, | 402 selectHighestPriority, |
| 422 canShowForSingleItem, | 403 canShowForSingleItem, |
| 423 userEnteredText, | 404 userEnteredText, |
| 424 asyncDetails) { | 405 asyncDetails) { |
| 425 delete this._onlyCompletion; | 406 delete this._onlyCompletion; |
| 426 if (this._canShowBox(completions, canShowForSingleItem, userEnteredText)) { | 407 if (this._canShowBox(completions, canShowForSingleItem, userEnteredText)) { |
| 427 this._updateItems(completions, userEnteredText, asyncDetails); | 408 this._updateItems(completions, userEnteredText, asyncDetails); |
| 409 this._viewport.resetElementHeight(); | |
| 428 this._show(); | 410 this._show(); |
| 429 this._updateBoxPosition(anchorBox); | 411 this._updateBoxPosition(anchorBox); |
| 412 this._viewport.refresh(this._items.length); | |
| 430 this._updateWidth(); | 413 this._updateWidth(); |
| 431 this._viewport.refresh(); | |
| 432 var highestPriorityItem = -1; | 414 var highestPriorityItem = -1; |
| 433 if (selectHighestPriority) { | 415 if (selectHighestPriority) { |
| 434 var highestPriority = -Infinity; | 416 var highestPriority = -Infinity; |
| 435 for (var i = 0; i < completions.length; i++) { | 417 for (var i = 0; i < completions.length; i++) { |
| 436 var priority = completions[i].priority || 0; | 418 var priority = completions[i].priority || 0; |
| 437 if (highestPriority < priority) { | 419 if (highestPriority < priority) { |
| 438 highestPriority = priority; | 420 highestPriority = priority; |
| 439 highestPriorityItem = i; | 421 highestPriorityItem = i; |
| 440 } | 422 } |
| 441 } | 423 } |
| 442 } | 424 } |
| 443 this._selectItem(highestPriorityItem); | 425 this._selectItem(highestPriorityItem); |
| 444 delete this._rowCountPerViewport; | |
| 445 } else { | 426 } else { |
| 446 if (completions.length === 1) { | 427 if (completions.length === 1) { |
| 447 this._onlyCompletion = completions[0].title; | 428 this._onlyCompletion = completions[0].title; |
| 448 this._applySuggestion(true); | 429 this._applySuggestion(true); |
| 449 } | 430 } |
| 450 this.hide(); | 431 this.hide(); |
| 451 } | 432 } |
| 452 } | 433 } |
| 453 | 434 |
| 454 /** | 435 /** |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 482 * @return {boolean} | 463 * @return {boolean} |
| 483 */ | 464 */ |
| 484 downKeyPressed() { | 465 downKeyPressed() { |
| 485 return this._selectClosest(1, true); | 466 return this._selectClosest(1, true); |
| 486 } | 467 } |
| 487 | 468 |
| 488 /** | 469 /** |
| 489 * @return {boolean} | 470 * @return {boolean} |
| 490 */ | 471 */ |
| 491 pageUpKeyPressed() { | 472 pageUpKeyPressed() { |
| 492 this._ensureRowCountPerViewport(); | 473 return this._selectClosest(-this._viewport.elementsPerViewport(), false); |
|
pfeldman
2016/12/20 02:00:18
Since scrollbar belongs to viewport, this should a
| |
| 493 return this._selectClosest(-this._rowCountPerViewport, false); | |
| 494 } | 474 } |
| 495 | 475 |
| 496 /** | 476 /** |
| 497 * @return {boolean} | 477 * @return {boolean} |
| 498 */ | 478 */ |
| 499 pageDownKeyPressed() { | 479 pageDownKeyPressed() { |
| 500 this._ensureRowCountPerViewport(); | 480 return this._selectClosest(this._viewport.elementsPerViewport(), false); |
| 501 return this._selectClosest(this._rowCountPerViewport, false); | |
| 502 } | 481 } |
| 503 | 482 |
| 504 /** | 483 /** |
| 505 * @return {boolean} | 484 * @return {boolean} |
| 506 */ | 485 */ |
| 507 enterKeyPressed() { | 486 enterKeyPressed() { |
| 508 if (!this._userInteracted && this._captureEnter) | 487 if (!this._userInteracted && this._captureEnter) |
| 509 return false; | 488 return false; |
| 510 | 489 |
| 511 var hasSelectedItem = !!this._selectedElement || this._onlyCompletion; | 490 var hasSelectedItem = !!this._selectedElement || this._onlyCompletion; |
| 512 this.acceptSuggestion(); | 491 this.acceptSuggestion(); |
| 513 | 492 |
| 514 // Report the event as non-handled if there is no selected item, | 493 // Report the event as non-handled if there is no selected item, |
| 515 // to commit the input or handle it otherwise. | 494 // to commit the input or handle it otherwise. |
| 516 return hasSelectedItem; | 495 return hasSelectedItem; |
| 517 } | 496 } |
| 518 | |
| 519 /** | |
| 520 * @override | |
| 521 * @param {number} index | |
| 522 * @return {number} | |
| 523 */ | |
| 524 fastItemHeight(index) { | |
| 525 return this._rowHeight; | |
| 526 } | |
| 527 | |
| 528 /** | |
| 529 * @override | |
| 530 * @return {number} | |
| 531 */ | |
| 532 itemCount() { | |
| 533 return this._items.length; | |
| 534 } | |
| 535 | |
| 536 /** | |
| 537 * @override | |
| 538 * @param {number} index | |
| 539 * @return {?Element} | |
| 540 */ | |
| 541 itemElement(index) { | |
| 542 if (!this._elementList[index]) { | |
| 543 this._elementList[index] = this._createItemElement( | |
| 544 this._userEnteredText, this._items[index].title, this._items[index].su btitle, this._items[index].iconType, | |
| 545 this._items[index].isSecondary); | |
| 546 } | |
| 547 return this._elementList[index]; | |
| 548 } | |
| 549 }; | 497 }; |
| 550 | 498 |
| 551 /** | 499 /** |
| 552 * @typedef {!Array.<{title: string, subtitle: (string|undefined), iconType: (st ring|undefined), priority: (number|undefined), isSecondary: (boolean|undefined)} >} | 500 * @typedef {!Array.<{title: string, subtitle: (string|undefined), iconType: (st ring|undefined), priority: (number|undefined), isSecondary: (boolean|undefined)} >} |
| 553 */ | 501 */ |
| 554 UI.SuggestBox.Suggestions; | 502 UI.SuggestBox.Suggestions; |
| 555 | 503 |
| 556 /** | 504 /** |
| 557 * @unrestricted | 505 * @unrestricted |
| 558 */ | 506 */ |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 609 this.element.style.left = containerBox.x + 'px'; | 557 this.element.style.left = containerBox.x + 'px'; |
| 610 this.element.style.top = containerBox.y + 'px'; | 558 this.element.style.top = containerBox.y + 'px'; |
| 611 this.element.style.height = containerBox.height + 'px'; | 559 this.element.style.height = containerBox.height + 'px'; |
| 612 this.element.style.width = containerBox.width + 'px'; | 560 this.element.style.width = containerBox.width + 'px'; |
| 613 } | 561 } |
| 614 | 562 |
| 615 dispose() { | 563 dispose() { |
| 616 this.element.remove(); | 564 this.element.remove(); |
| 617 } | 565 } |
| 618 }; | 566 }; |
| OLD | NEW |