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

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

Issue 2587293002: DevTools: teach TabbedPane.setTabIcon to accept UI.Icon instances (Closed)
Patch Set: formatting Created 3 years, 12 months 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) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 lastOpenedTabIds(tabsCount) { 342 lastOpenedTabIds(tabsCount) {
343 function tabToTabId(tab) { 343 function tabToTabId(tab) {
344 return tab.id; 344 return tab.id;
345 } 345 }
346 346
347 return this._tabsHistory.slice(0, tabsCount).map(tabToTabId); 347 return this._tabsHistory.slice(0, tabsCount).map(tabToTabId);
348 } 348 }
349 349
350 /** 350 /**
351 * @param {string} id 351 * @param {string} id
352 * @param {string} iconType 352 * @param {?UI.Icon} icon
353 * @param {string=} iconTooltip
354 */ 353 */
355 setTabIcon(id, iconType, iconTooltip) { 354 setTabIcon(id, icon) {
356 var tab = this._tabsById.get(id); 355 var tab = this._tabsById.get(id);
357 if (tab._setIconType(iconType, iconTooltip)) 356 tab._setIcon(icon);
358 this._updateTabElements(); 357 this._updateTabElements();
359 } 358 }
360 359
361 /** 360 /**
362 * @param {string} id 361 * @param {string} id
363 * @param {boolean} enabled 362 * @param {boolean} enabled
364 */ 363 */
365 setTabEnabled(id, enabled) { 364 setTabEnabled(id, enabled) {
366 var tab = this._tabsById.get(id); 365 var tab = this._tabsById.get(id);
367 tab.tabElement.classList.toggle('disabled', !enabled); 366 tab.tabElement.classList.toggle('disabled', !enabled);
368 } 367 }
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 * @param {string=} tooltip 854 * @param {string=} tooltip
856 */ 855 */
857 constructor(tabbedPane, id, title, closeable, view, tooltip) { 856 constructor(tabbedPane, id, title, closeable, view, tooltip) {
858 this._closeable = closeable; 857 this._closeable = closeable;
859 this._tabbedPane = tabbedPane; 858 this._tabbedPane = tabbedPane;
860 this._id = id; 859 this._id = id;
861 this._title = title; 860 this._title = title;
862 this._tooltip = tooltip; 861 this._tooltip = tooltip;
863 this._view = view; 862 this._view = view;
864 this._shown = false; 863 this._shown = false;
865 /** @type {number} */ this._measuredWidth; 864 /** @type {number} */
866 /** @type {!Element|undefined} */ this._tabElement; 865 this._measuredWidth;
866 /** @type {!Element|undefined} */
867 this._tabElement;
868 /** @type {?Element} */
869 this._iconContainer = null;
867 } 870 }
868 871
869 /** 872 /**
870 * @return {string} 873 * @return {string}
871 */ 874 */
872 get id() { 875 get id() {
873 return this._id; 876 return this._id;
874 } 877 }
875 878
876 /** 879 /**
(...skipping 16 matching lines...) Expand all
893 } 896 }
894 897
895 /** 898 /**
896 * @return {boolean} 899 * @return {boolean}
897 */ 900 */
898 isCloseable() { 901 isCloseable() {
899 return this._closeable; 902 return this._closeable;
900 } 903 }
901 904
902 /** 905 /**
903 * @param {string} iconType 906 * @param {?UI.Icon} icon
904 * @param {string=} iconTooltip
905 * @return {boolean}
906 */ 907 */
907 _setIconType(iconType, iconTooltip) { 908 _setIcon(icon) {
908 if (iconType === this._iconType && iconTooltip === this._iconTooltip) 909 this._icon = icon;
909 return false;
910 this._iconType = iconType;
911 this._iconTooltip = iconTooltip;
912 if (this._tabElement) 910 if (this._tabElement)
913 this._createIconElement(this._tabElement, this._titleElement); 911 this._createIconElement(this._tabElement, this._titleElement, false);
914 delete this._measuredWidth; 912 delete this._measuredWidth;
915 return true;
916 } 913 }
917 914
918 /** 915 /**
919 * @param {string} className 916 * @param {string} className
920 * @param {boolean=} force 917 * @param {boolean=} force
921 * @return {boolean} 918 * @return {boolean}
922 */ 919 */
923 _toggleClass(className, force) { 920 _toggleClass(className, force) {
924 var element = this.tabElement; 921 var element = this.tabElement;
925 var hasClass = element.classList.contains(className); 922 var hasClass = element.classList.contains(className);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
988 /** 985 /**
989 * @param {!UI.TabbedPaneTabDelegate} delegate 986 * @param {!UI.TabbedPaneTabDelegate} delegate
990 */ 987 */
991 setDelegate(delegate) { 988 setDelegate(delegate) {
992 this._delegate = delegate; 989 this._delegate = delegate;
993 } 990 }
994 991
995 /** 992 /**
996 * @param {!Element} tabElement 993 * @param {!Element} tabElement
997 * @param {!Element} titleElement 994 * @param {!Element} titleElement
995 * @param {boolean} measuring
998 */ 996 */
999 _createIconElement(tabElement, titleElement) { 997 _createIconElement(tabElement, titleElement, measuring) {
1000 if (tabElement.__iconElement) 998 if (tabElement.__iconElement) {
1001 tabElement.__iconElement.remove(); 999 tabElement.__iconElement.remove();
1002 if (!this._iconType) 1000 tabElement.__iconElement = null;
1001 }
1002 if (!this._icon)
1003 return; 1003 return;
1004 1004
1005 var iconElement = createElementWithClass('label', 'tabbed-pane-header-tab-ic on', 'dt-icon-label'); 1005 var iconContainer = createElementWithClass('span', 'tabbed-pane-header-tab-i con');
1006 iconElement.type = this._iconType; 1006 var iconNode = measuring ? this._icon.cloneNode(true) : this._icon;
1007 if (this._iconTooltip) 1007 iconContainer.appendChild(iconNode);
1008 iconElement.title = this._iconTooltip; 1008 tabElement.insertBefore(iconContainer, titleElement);
1009 tabElement.insertBefore(iconElement, titleElement); 1009 tabElement.__iconElement = iconContainer;
1010 tabElement.__iconElement = iconElement;
1011 } 1010 }
1012 1011
1013 /** 1012 /**
1014 * @param {boolean} measuring 1013 * @param {boolean} measuring
1015 * @return {!Element} 1014 * @return {!Element}
1016 */ 1015 */
1017 _createTabElement(measuring) { 1016 _createTabElement(measuring) {
1018 var tabElement = createElementWithClass('div', 'tabbed-pane-header-tab'); 1017 var tabElement = createElementWithClass('div', 'tabbed-pane-header-tab');
1019 tabElement.id = 'tab-' + this._id; 1018 tabElement.id = 'tab-' + this._id;
1020 tabElement.tabIndex = -1; 1019 tabElement.tabIndex = -1;
1021 tabElement.setAttribute('role', 'tab'); 1020 tabElement.setAttribute('role', 'tab');
1022 tabElement.setAttribute('aria-selected', 'false'); 1021 tabElement.setAttribute('aria-selected', 'false');
1023 tabElement.selectTabForTest = this._tabbedPane.selectTab.bind(this._tabbedPa ne, this.id, true); 1022 tabElement.selectTabForTest = this._tabbedPane.selectTab.bind(this._tabbedPa ne, this.id, true);
1024 1023
1025 var titleElement = tabElement.createChild('span', 'tabbed-pane-header-tab-ti tle'); 1024 var titleElement = tabElement.createChild('span', 'tabbed-pane-header-tab-ti tle');
1026 titleElement.textContent = this.title; 1025 titleElement.textContent = this.title;
1027 titleElement.title = this.tooltip || ''; 1026 titleElement.title = this.tooltip || '';
1028 this._createIconElement(tabElement, titleElement); 1027 this._createIconElement(tabElement, titleElement, measuring);
1029 if (!measuring) 1028 if (!measuring)
1030 this._titleElement = titleElement; 1029 this._titleElement = titleElement;
1031 1030
1032 if (this._closeable) 1031 if (this._closeable)
1033 tabElement.createChild('div', 'tabbed-pane-close-button', 'dt-close-button ').gray = true; 1032 tabElement.createChild('div', 'tabbed-pane-close-button', 'dt-close-button ').gray = true;
1034 1033
1035 if (measuring) { 1034 if (measuring) {
1036 tabElement.classList.add('measuring'); 1035 tabElement.classList.add('measuring');
1037 } else { 1036 } else {
1038 tabElement.addEventListener('click', this._tabClicked.bind(this), false); 1037 tabElement.addEventListener('click', this._tabClicked.bind(this), false);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1211 * @param {!Array.<string>} ids 1210 * @param {!Array.<string>} ids
1212 */ 1211 */
1213 closeTabs(tabbedPane, ids) {}, 1212 closeTabs(tabbedPane, ids) {},
1214 1213
1215 /** 1214 /**
1216 * @param {string} tabId 1215 * @param {string} tabId
1217 * @param {!UI.ContextMenu} contextMenu 1216 * @param {!UI.ContextMenu} contextMenu
1218 */ 1217 */
1219 onContextMenu(tabId, contextMenu) {} 1218 onContextMenu(tabId, contextMenu) {}
1220 }; 1219 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698