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

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

Issue 2534383002: DevTools: [SuggestBox] migrate suggestbox icons onto UI.Icon (Closed)
Patch Set: address comments + better centering Created 4 years 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 unified diff | Download patch
OLDNEW
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 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
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} text
274 * @param {string=} className 274 * @param {string=} iconType
275 * @param {boolean=} isSecondary
275 * @return {!Element} 276 * @return {!Element}
276 */ 277 */
277 _createItemElement(query, text, className) { 278 _createItemElement(query, text, iconType, isSecondary) {
278 var element = createElementWithClass('div', 'suggest-box-content-item source -code ' + (className || '')); 279 var element = createElementWithClass('div', 'suggest-box-content-item source -code');
280 if (iconType) {
281 var icon = UI.Icon.create(iconType, 'suggestion-icon');
282 element.appendChild(icon);
283 }
284 if (isSecondary)
285 element.classList.add('secondary');
279 element.tabIndex = -1; 286 element.tabIndex = -1;
280 var displayText = text.trimEnd(50 + query.length); 287 var displayText = text.trimEnd(50 + query.length);
281 var index = displayText.toLowerCase().indexOf(query.toLowerCase()); 288 var index = displayText.toLowerCase().indexOf(query.toLowerCase());
282 if (index > 0) 289 if (index > 0)
283 element.createChild('span').textContent = displayText.substring(0, index); 290 element.createChild('span').textContent = displayText.substring(0, index);
284 if (index > -1) 291 if (index > -1)
285 element.createChild('span', 'query').textContent = displayText.substring(i ndex, index + query.length); 292 element.createChild('span', 'query').textContent = displayText.substring(i ndex, index + query.length);
286 element.createChild('span').textContent = displayText.substring(index > -1 ? index + query.length : 0); 293 element.createChild('span').textContent = displayText.substring(index > -1 ? index + query.length : 0);
287 element.__fullValue = text; 294 element.__fullValue = text;
288 element.createChild('span', 'spacer'); 295 element.createChild('span', 'spacer');
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 return; 334 return;
328 this._detailsPopup.createChild('section', 'detail').createTextChild(details. detail); 335 this._detailsPopup.createChild('section', 'detail').createTextChild(details. detail);
329 this._detailsPopup.createChild('section', 'description').createTextChild(det ails.description); 336 this._detailsPopup.createChild('section', 'description').createTextChild(det ails.description);
330 this._detailsPopup.classList.remove('hidden'); 337 this._detailsPopup.classList.remove('hidden');
331 } 338 }
332 339
333 /** 340 /**
334 * @param {number} index 341 * @param {number} index
335 */ 342 */
336 _selectItem(index) { 343 _selectItem(index) {
337 if (this._selectedElement) 344 if (this._selectedElement) {
338 this._selectedElement.classList.remove('selected'); 345 this._selectedElement.classList.remove('selected');
346 this._selectedElement.classList.remove('force-white-icons');
347 }
339 348
340 this._selectedIndex = index; 349 this._selectedIndex = index;
341 if (index < 0) 350 if (index < 0)
342 return; 351 return;
343 352
344 this._selectedElement = this.itemElement(index); 353 this._selectedElement = this.itemElement(index);
345 this._selectedElement.classList.add('selected'); 354 this._selectedElement.classList.add('selected');
355 this._selectedElement.classList.add('force-white-icons');
346 this._detailsPopup.classList.add('hidden'); 356 this._detailsPopup.classList.add('hidden');
347 var elem = this._selectedElement; 357 var elem = this._selectedElement;
348 this._asyncDetails(index).then(showDetails.bind(this), function() {}); 358 this._asyncDetails(index).then(showDetails.bind(this), function() {});
349 359
350 this._viewport.scrollItemIntoView(index); 360 this._viewport.scrollItemIntoView(index);
351 this._applySuggestion(true); 361 this._applySuggestion(true);
352 362
353 /** 363 /**
354 * @param {?{detail: string, description: string}} details 364 * @param {?{detail: string, description: string}} details
355 * @this {UI.SuggestBox} 365 * @this {UI.SuggestBox}
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 return this._items.length; 525 return this._items.length;
516 } 526 }
517 527
518 /** 528 /**
519 * @override 529 * @override
520 * @param {number} index 530 * @param {number} index
521 * @return {?Element} 531 * @return {?Element}
522 */ 532 */
523 itemElement(index) { 533 itemElement(index) {
524 if (!this._elementList[index]) { 534 if (!this._elementList[index]) {
525 this._elementList[index] = 535 this._elementList[index] = this._createItemElement(
526 this._createItemElement(this._userEnteredText, this._items[index].titl e, this._items[index].className); 536 this._userEnteredText, this._items[index].title, this._items[index].ic onType, this._items[index].isSecondary);
527 } 537 }
528 return this._elementList[index]; 538 return this._elementList[index];
529 } 539 }
530 }; 540 };
531 541
532 /** 542 /**
533 * @typedef {!Array.<{title: string, className: (string|undefined), priority: (n umber|undefined)}>} 543 * @typedef {!Array.<{title: string, iconType: (string|undefined), priority: (nu mber|undefined), isSecondary: (boolean|undefined)}>}
534 */ 544 */
535 UI.SuggestBox.Suggestions; 545 UI.SuggestBox.Suggestions;
536 546
537 /** 547 /**
538 * @unrestricted 548 * @unrestricted
539 */ 549 */
540 UI.SuggestBox.Overlay = class { 550 UI.SuggestBox.Overlay = class {
541 /** 551 /**
542 * // FIXME: make SuggestBox work for multiple documents. 552 * // FIXME: make SuggestBox work for multiple documents.
543 * @suppressGlobalPropertiesCheck 553 * @suppressGlobalPropertiesCheck
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 this.element.style.left = containerBox.x + 'px'; 600 this.element.style.left = containerBox.x + 'px';
591 this.element.style.top = containerBox.y + 'px'; 601 this.element.style.top = containerBox.y + 'px';
592 this.element.style.height = containerBox.height + 'px'; 602 this.element.style.height = containerBox.height + 'px';
593 this.element.style.width = containerBox.width + 'px'; 603 this.element.style.width = containerBox.width + 'px';
594 } 604 }
595 605
596 dispose() { 606 dispose() {
597 this.element.remove(); 607 this.element.remove();
598 } 608 }
599 }; 609 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698