| 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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 * @param {!Event} event | 263 * @param {!Event} event |
| 264 */ | 264 */ |
| 265 _onItemMouseDown(event) { | 265 _onItemMouseDown(event) { |
| 266 this._selectedElement = event.currentTarget; | 266 this._selectedElement = event.currentTarget; |
| 267 this.acceptSuggestion(); | 267 this.acceptSuggestion(); |
| 268 event.consume(true); | 268 event.consume(true); |
| 269 } | 269 } |
| 270 | 270 |
| 271 /** | 271 /** |
| 272 * @param {string} query | 272 * @param {string} query |
| 273 * @param {string} text | 273 * @param {string} title |
| 274 * @param {string=} subtitle |
| 274 * @param {string=} iconType | 275 * @param {string=} iconType |
| 275 * @param {boolean=} isSecondary | 276 * @param {boolean=} isSecondary |
| 276 * @return {!Element} | 277 * @return {!Element} |
| 277 */ | 278 */ |
| 278 _createItemElement(query, text, iconType, isSecondary) { | 279 _createItemElement(query, title, subtitle, iconType, isSecondary) { |
| 279 var element = createElementWithClass('div', 'suggest-box-content-item source
-code'); | 280 var element = createElementWithClass('div', 'suggest-box-content-item source
-code'); |
| 280 if (iconType) { | 281 if (iconType) { |
| 281 var icon = UI.Icon.create(iconType, 'suggestion-icon'); | 282 var icon = UI.Icon.create(iconType, 'suggestion-icon'); |
| 282 element.appendChild(icon); | 283 element.appendChild(icon); |
| 283 } | 284 } |
| 284 if (isSecondary) | 285 if (isSecondary) |
| 285 element.classList.add('secondary'); | 286 element.classList.add('secondary'); |
| 286 element.tabIndex = -1; | 287 element.tabIndex = -1; |
| 287 var displayText = text.trimEnd(50 + query.length); | 288 var displayText = title.trimEnd(50 + query.length); |
| 288 | 289 |
| 289 var suggestionText = element.createChild('span', 'suggestion-text'); | 290 var titleElement = element.createChild('span', 'suggestion-title'); |
| 290 var index = displayText.toLowerCase().indexOf(query.toLowerCase()); | 291 var index = displayText.toLowerCase().indexOf(query.toLowerCase()); |
| 291 if (index > 0) | 292 if (index > 0) |
| 292 suggestionText.createChild('span').textContent = displayText.substring(0,
index); | 293 titleElement.createChild('span').textContent = displayText.substring(0, in
dex); |
| 293 if (index > -1) | 294 if (index > -1) |
| 294 suggestionText.createChild('span', 'query').textContent = displayText.subs
tring(index, index + query.length); | 295 titleElement.createChild('span', 'query').textContent = displayText.substr
ing(index, index + query.length); |
| 295 suggestionText.createChild('span').textContent = displayText.substring(index
> -1 ? index + query.length : 0); | 296 titleElement.createChild('span').textContent = displayText.substring(index >
-1 ? index + query.length : 0); |
| 296 suggestionText.createChild('span', 'spacer'); | 297 titleElement.createChild('span', 'spacer'); |
| 297 element.__fullValue = text; | 298 if (subtitle) { |
| 299 var subtitleElement = element.createChild('span', 'suggestion-subtitle'); |
| 300 subtitleElement.textContent = subtitle.trimEnd(15); |
| 301 } |
| 302 element.__fullValue = title; |
| 298 element.addEventListener('mousedown', this._onItemMouseDown.bind(this), fals
e); | 303 element.addEventListener('mousedown', this._onItemMouseDown.bind(this), fals
e); |
| 299 return element; | 304 return element; |
| 300 } | 305 } |
| 301 | 306 |
| 302 /** | 307 /** |
| 303 * @param {!UI.SuggestBox.Suggestions} items | 308 * @param {!UI.SuggestBox.Suggestions} items |
| 304 * @param {string} userEnteredText | 309 * @param {string} userEnteredText |
| 305 * @param {function(number): !Promise<{detail:string, description:string}>=} a
syncDetails | 310 * @param {function(number): !Promise<{detail:string, description:string}>=} a
syncDetails |
| 306 */ | 311 */ |
| 307 _updateItems(items, userEnteredText, asyncDetails) { | 312 _updateItems(items, userEnteredText, asyncDetails) { |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 528 } | 533 } |
| 529 | 534 |
| 530 /** | 535 /** |
| 531 * @override | 536 * @override |
| 532 * @param {number} index | 537 * @param {number} index |
| 533 * @return {?Element} | 538 * @return {?Element} |
| 534 */ | 539 */ |
| 535 itemElement(index) { | 540 itemElement(index) { |
| 536 if (!this._elementList[index]) { | 541 if (!this._elementList[index]) { |
| 537 this._elementList[index] = this._createItemElement( | 542 this._elementList[index] = this._createItemElement( |
| 538 this._userEnteredText, this._items[index].title, this._items[index].ic
onType, this._items[index].isSecondary); | 543 this._userEnteredText, this._items[index].title, this._items[index].su
btitle, this._items[index].iconType, |
| 544 this._items[index].isSecondary); |
| 539 } | 545 } |
| 540 return this._elementList[index]; | 546 return this._elementList[index]; |
| 541 } | 547 } |
| 542 }; | 548 }; |
| 543 | 549 |
| 544 /** | 550 /** |
| 545 * @typedef {!Array.<{title: string, iconType: (string|undefined), priority: (nu
mber|undefined), isSecondary: (boolean|undefined)}>} | 551 * @typedef {!Array.<{title: string, subtitle: (string|undefined), iconType: (st
ring|undefined), priority: (number|undefined), isSecondary: (boolean|undefined)}
>} |
| 546 */ | 552 */ |
| 547 UI.SuggestBox.Suggestions; | 553 UI.SuggestBox.Suggestions; |
| 548 | 554 |
| 549 /** | 555 /** |
| 550 * @unrestricted | 556 * @unrestricted |
| 551 */ | 557 */ |
| 552 UI.SuggestBox.Overlay = class { | 558 UI.SuggestBox.Overlay = class { |
| 553 /** | 559 /** |
| 554 * // FIXME: make SuggestBox work for multiple documents. | 560 * // FIXME: make SuggestBox work for multiple documents. |
| 555 * @suppressGlobalPropertiesCheck | 561 * @suppressGlobalPropertiesCheck |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 this.element.style.left = containerBox.x + 'px'; | 608 this.element.style.left = containerBox.x + 'px'; |
| 603 this.element.style.top = containerBox.y + 'px'; | 609 this.element.style.top = containerBox.y + 'px'; |
| 604 this.element.style.height = containerBox.height + 'px'; | 610 this.element.style.height = containerBox.height + 'px'; |
| 605 this.element.style.width = containerBox.width + 'px'; | 611 this.element.style.width = containerBox.width + 'px'; |
| 606 } | 612 } |
| 607 | 613 |
| 608 dispose() { | 614 dispose() { |
| 609 this.element.remove(); | 615 this.element.remove(); |
| 610 } | 616 } |
| 611 }; | 617 }; |
| OLD | NEW |