Commit 911cf4b7 authored by lushnikov's avatar lushnikov Committed by Commit bot

DevTools: teach TabbedPane.setTabIcon to accept UI.Icon instances

This patch is a preparation for a "badged icons" instead of green
checkmarks in the "persistence2" experiment.

Currently, TabbedPane.setTabIcon method accepts icon type and icon
titles. This works fine, but we'd like to pass in a more complex
objects - badged icons.

For this to work, the TabbedPane.setTabIcon has to accept general
instances of UI.Icon class.

BUG=675856
R=dgozman

Review-Url: https://codereview.chromium.org/2587293002
Cr-Commit-Position: refs/heads/master@{#439828}
parent 3f6873e9
...@@ -768,12 +768,15 @@ Main.NetworkPanelIndicator = class { ...@@ -768,12 +768,15 @@ Main.NetworkPanelIndicator = class {
updateVisibility(); updateVisibility();
function updateVisibility() { function updateVisibility() {
if (manager.isThrottling()) var icon = null;
UI.inspectorView.setPanelIcon('network', 'smallicon-warning', Common.UIString('Network throttling is enabled')); if (manager.isThrottling()) {
else if (blockedURLsSetting.get().length) icon = UI.Icon.create('smallicon-warning');
UI.inspectorView.setPanelIcon('network', 'smallicon-warning', Common.UIString('Requests may be blocked')); icon.title = Common.UIString('Network throttling is enabled');
else } else if (blockedURLsSetting.get().length) {
UI.inspectorView.setPanelIcon('network', '', ''); icon = UI.Icon.create('smallicon-warning');
icon.title = Common.UIString('Requests may be blocked');
}
UI.inspectorView.setPanelIcon('network', icon);
} }
} }
}; };
...@@ -787,11 +790,13 @@ Main.SourcesPanelIndicator = class { ...@@ -787,11 +790,13 @@ Main.SourcesPanelIndicator = class {
javaScriptDisabledChanged(); javaScriptDisabledChanged();
function javaScriptDisabledChanged() { function javaScriptDisabledChanged() {
var icon = null;
var javaScriptDisabled = Common.moduleSetting('javaScriptDisabled').get(); var javaScriptDisabled = Common.moduleSetting('javaScriptDisabled').get();
if (javaScriptDisabled) if (javaScriptDisabled) {
UI.inspectorView.setPanelIcon('sources', 'smallicon-warning', Common.UIString('JavaScript is disabled')); icon = UI.Icon.create('smallicon-warning');
else icon.title = Common.UIString('JavaScript is disabled');
UI.inspectorView.setPanelIcon('sources', '', ''); }
UI.inspectorView.setPanelIcon('sources', icon);
} }
} }
}; };
......
...@@ -533,17 +533,16 @@ Sources.TabbedEditorContainer = class extends Common.Object { ...@@ -533,17 +533,16 @@ Sources.TabbedEditorContainer = class extends Common.Object {
if (tabId) { if (tabId) {
var title = this._titleForFile(uiSourceCode); var title = this._titleForFile(uiSourceCode);
this._tabbedPane.changeTabTitle(tabId, title); this._tabbedPane.changeTabTitle(tabId, title);
var icon = null;
if (Persistence.persistence.hasUnsavedCommittedChanges(uiSourceCode)) { if (Persistence.persistence.hasUnsavedCommittedChanges(uiSourceCode)) {
this._tabbedPane.setTabIcon( icon = UI.Icon.create('smallicon-warning');
tabId, 'smallicon-warning', Common.UIString('Changes to this file were not saved to file system.')); icon.title = Common.UIString('Changes to this file were not saved to file system.');
} else if (Runtime.experiments.isEnabled('persistence2') && Persistence.persistence.binding(uiSourceCode)) { } else if (Runtime.experiments.isEnabled('persistence2') && Persistence.persistence.binding(uiSourceCode)) {
var binding = Persistence.persistence.binding(uiSourceCode); var binding = Persistence.persistence.binding(uiSourceCode);
this._tabbedPane.setTabIcon( icon = UI.Icon.create('smallicon-green-checkmark');
tabId, 'smallicon-green-checkmark', icon.title = Persistence.PersistenceUtils.tooltipForUISourceCode(binding.fileSystem);
Persistence.PersistenceUtils.tooltipForUISourceCode(binding.fileSystem));
} else {
this._tabbedPane.setTabIcon(tabId, '');
} }
this._tabbedPane.setTabIcon(tabId, icon);
} }
} }
......
...@@ -291,13 +291,13 @@ Timeline.TimelinePanel = class extends UI.Panel { ...@@ -291,13 +291,13 @@ Timeline.TimelinePanel = class extends UI.Panel {
// Record // Record
if (Runtime.experiments.isEnabled('timelineLandingPage')) { if (Runtime.experiments.isEnabled('timelineLandingPage')) {
const newButton = new UI.ToolbarButton( const newButton = new UI.ToolbarButton(Common.UIString('New recording'), 'largeicon-add', Common.UIString('New'));
Common.UIString('New recording'), 'largeicon-add', Common.UIString('New'));
newButton.addEventListener(UI.ToolbarButton.Events.Click, this._clear, this); newButton.addEventListener(UI.ToolbarButton.Events.Click, this._clear, this);
this._panelToolbar.appendToolbarItem(newButton); this._panelToolbar.appendToolbarItem(newButton);
this._panelToolbar.appendToolbarItem(UI.Toolbar.createActionButtonForId('main.reload')); this._panelToolbar.appendToolbarItem(UI.Toolbar.createActionButtonForId('main.reload'));
this._panelToolbar.appendToolbarItem(UI.Toolbar.createActionButton(this._toggleRecordAction)); this._panelToolbar.appendToolbarItem(UI.Toolbar.createActionButton(this._toggleRecordAction));
} else if (Runtime.experiments.isEnabled('timelineRecordingPerspectives') && } else if (
Runtime.experiments.isEnabled('timelineRecordingPerspectives') &&
perspectiveSetting.get() === Timeline.TimelinePanel.Perspectives.Load) { perspectiveSetting.get() === Timeline.TimelinePanel.Perspectives.Load) {
const reloadButton = new UI.ToolbarButton(Common.UIString('Record & Reload'), 'largeicon-refresh'); const reloadButton = new UI.ToolbarButton(Common.UIString('Record & Reload'), 'largeicon-refresh');
reloadButton.addEventListener(UI.ToolbarButton.Events.Click, () => SDK.targetManager.reloadPage()); reloadButton.addEventListener(UI.ToolbarButton.Events.Click, () => SDK.targetManager.reloadPage());
...@@ -378,12 +378,13 @@ Timeline.TimelinePanel = class extends UI.Panel { ...@@ -378,12 +378,13 @@ Timeline.TimelinePanel = class extends UI.Panel {
// Checkboxes // Checkboxes
if (Runtime.experiments.isEnabled('timelineLandingPage')) { if (Runtime.experiments.isEnabled('timelineLandingPage')) {
if (!this._model.isEmpty()) { if (!this._model.isEmpty()) {
this._panelToolbar.appendToolbarItem(this._createSettingCheckbox(Common.UIString('Memory'), this._panelToolbar.appendToolbarItem(this._createSettingCheckbox(
this._showMemorySetting, Common.UIString('Show memory timeline.'))); Common.UIString('Memory'), this._showMemorySetting, Common.UIString('Show memory timeline.')));
if (this._filmStripModel.frames().length) { if (this._filmStripModel.frames().length) {
this._showScreenshotsSetting.set(true); this._showScreenshotsSetting.set(true);
this._panelToolbar.appendToolbarItem(this._createSettingCheckbox(Common.UIString('Screenshots'), this._panelToolbar.appendToolbarItem(this._createSettingCheckbox(
this._showScreenshotsSetting, Common.UIString('Show captured screenshots.'))); Common.UIString('Screenshots'), this._showScreenshotsSetting,
Common.UIString('Show captured screenshots.')));
} }
} }
} else { } else {
...@@ -565,11 +566,11 @@ Timeline.TimelinePanel = class extends UI.Panel { ...@@ -565,11 +566,11 @@ Timeline.TimelinePanel = class extends UI.Panel {
_onModeChanged() { _onModeChanged() {
if (this._bulkUpdate) if (this._bulkUpdate)
return; return;
const showMemory = Runtime.experiments.isEnabled('timelineLandingPage') const showMemory = Runtime.experiments.isEnabled('timelineLandingPage') ? this._showMemorySetting.get() :
? this._showMemorySetting.get() : this._captureMemorySetting.get(); this._captureMemorySetting.get();
const showScreenshots = Runtime.experiments.isEnabled('timelineLandingPage') const showScreenshots = Runtime.experiments.isEnabled('timelineLandingPage') ?
? this._showScreenshotsSetting.get() && this._filmStripModel.frames().length this._showScreenshotsSetting.get() && this._filmStripModel.frames().length :
: this._captureFilmStripSetting.get(); this._captureFilmStripSetting.get();
// Set up overview controls. // Set up overview controls.
this._overviewControls = []; this._overviewControls = [];
this._overviewControls.push(new Timeline.TimelineEventOverviewResponsiveness(this._model, this._frameModel)); this._overviewControls.push(new Timeline.TimelineEventOverviewResponsiveness(this._model, this._frameModel));
...@@ -592,8 +593,8 @@ Timeline.TimelinePanel = class extends UI.Panel { ...@@ -592,8 +593,8 @@ Timeline.TimelinePanel = class extends UI.Panel {
this._addModeView(this._flameChart); this._addModeView(this._flameChart);
if (showMemory) { if (showMemory) {
this._addModeView(new Timeline.MemoryCountersGraph( this._addModeView(
this, this._model, [Timeline.TimelineUIUtils.visibleEventsFilter()])); new Timeline.MemoryCountersGraph(this, this._model, [Timeline.TimelineUIUtils.visibleEventsFilter()]));
} }
if (Runtime.experiments.isEnabled('timelineLandingPage')) if (Runtime.experiments.isEnabled('timelineLandingPage'))
this._flameChart.enableNetworkPane(true); this._flameChart.enableNetworkPane(true);
...@@ -2059,10 +2060,12 @@ Timeline.CPUThrottlingManager = class extends Common.Object { ...@@ -2059,10 +2060,12 @@ Timeline.CPUThrottlingManager = class extends Common.Object {
setRate(value) { setRate(value) {
this._throttlingRate = value; this._throttlingRate = value;
this._targets.forEach(target => target.emulationAgent().setCPUThrottlingRate(value)); this._targets.forEach(target => target.emulationAgent().setCPUThrottlingRate(value));
if (value !== 1) var icon = null;
UI.inspectorView.setPanelIcon('timeline', 'smallicon-warning', Common.UIString('CPU throttling is enabled')); if (value !== 1) {
else icon = UI.Icon.create('smallicon-warning');
UI.inspectorView.setPanelIcon('timeline', '', ''); icon.title = Common.UIString('CPU throttling is enabled');
}
UI.inspectorView.setPanelIcon('timeline', icon);
} }
/** /**
......
...@@ -169,11 +169,10 @@ UI.InspectorView = class extends UI.VBox { ...@@ -169,11 +169,10 @@ UI.InspectorView = class extends UI.VBox {
/** /**
* @param {string} panelName * @param {string} panelName
* @param {string} iconType * @param {?UI.Icon} icon
* @param {string=} iconTooltip
*/ */
setPanelIcon(panelName, iconType, iconTooltip) { setPanelIcon(panelName, icon) {
this._tabbedPane.setTabIcon(panelName, iconType, iconTooltip); this._tabbedPane.setTabIcon(panelName, icon);
} }
/** /**
......
...@@ -349,12 +349,11 @@ UI.TabbedPane = class extends UI.VBox { ...@@ -349,12 +349,11 @@ UI.TabbedPane = class extends UI.VBox {
/** /**
* @param {string} id * @param {string} id
* @param {string} iconType * @param {?UI.Icon} icon
* @param {string=} iconTooltip
*/ */
setTabIcon(id, iconType, iconTooltip) { setTabIcon(id, icon) {
var tab = this._tabsById.get(id); var tab = this._tabsById.get(id);
if (tab._setIconType(iconType, iconTooltip)) tab._setIcon(icon);
this._updateTabElements(); this._updateTabElements();
} }
...@@ -862,8 +861,12 @@ UI.TabbedPaneTab = class { ...@@ -862,8 +861,12 @@ UI.TabbedPaneTab = class {
this._tooltip = tooltip; this._tooltip = tooltip;
this._view = view; this._view = view;
this._shown = false; this._shown = false;
/** @type {number} */ this._measuredWidth; /** @type {number} */
/** @type {!Element|undefined} */ this._tabElement; this._measuredWidth;
/** @type {!Element|undefined} */
this._tabElement;
/** @type {?Element} */
this._iconContainer = null;
} }
/** /**
...@@ -900,19 +903,13 @@ UI.TabbedPaneTab = class { ...@@ -900,19 +903,13 @@ UI.TabbedPaneTab = class {
} }
/** /**
* @param {string} iconType * @param {?UI.Icon} icon
* @param {string=} iconTooltip
* @return {boolean}
*/ */
_setIconType(iconType, iconTooltip) { _setIcon(icon) {
if (iconType === this._iconType && iconTooltip === this._iconTooltip) this._icon = icon;
return false;
this._iconType = iconType;
this._iconTooltip = iconTooltip;
if (this._tabElement) if (this._tabElement)
this._createIconElement(this._tabElement, this._titleElement); this._createIconElement(this._tabElement, this._titleElement, false);
delete this._measuredWidth; delete this._measuredWidth;
return true;
} }
/** /**
...@@ -995,19 +992,21 @@ UI.TabbedPaneTab = class { ...@@ -995,19 +992,21 @@ UI.TabbedPaneTab = class {
/** /**
* @param {!Element} tabElement * @param {!Element} tabElement
* @param {!Element} titleElement * @param {!Element} titleElement
* @param {boolean} measuring
*/ */
_createIconElement(tabElement, titleElement) { _createIconElement(tabElement, titleElement, measuring) {
if (tabElement.__iconElement) if (tabElement.__iconElement) {
tabElement.__iconElement.remove(); tabElement.__iconElement.remove();
if (!this._iconType) tabElement.__iconElement = null;
}
if (!this._icon)
return; return;
var iconElement = createElementWithClass('label', 'tabbed-pane-header-tab-icon', 'dt-icon-label'); var iconContainer = createElementWithClass('span', 'tabbed-pane-header-tab-icon');
iconElement.type = this._iconType; var iconNode = measuring ? this._icon.cloneNode(true) : this._icon;
if (this._iconTooltip) iconContainer.appendChild(iconNode);
iconElement.title = this._iconTooltip; tabElement.insertBefore(iconContainer, titleElement);
tabElement.insertBefore(iconElement, titleElement); tabElement.__iconElement = iconContainer;
tabElement.__iconElement = iconElement;
} }
/** /**
...@@ -1025,7 +1024,7 @@ UI.TabbedPaneTab = class { ...@@ -1025,7 +1024,7 @@ UI.TabbedPaneTab = class {
var titleElement = tabElement.createChild('span', 'tabbed-pane-header-tab-title'); var titleElement = tabElement.createChild('span', 'tabbed-pane-header-tab-title');
titleElement.textContent = this.title; titleElement.textContent = this.title;
titleElement.title = this.tooltip || ''; titleElement.title = this.tooltip || '';
this._createIconElement(tabElement, titleElement); this._createIconElement(tabElement, titleElement, measuring);
if (!measuring) if (!measuring)
this._titleElement = titleElement; this._titleElement = titleElement;
......
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
} }
.tabbed-pane-header-tab-icon { .tabbed-pane-header-tab-icon {
margin-right: 2px; margin-right: 6px;
} }
.tabbed-pane-header-tab { .tabbed-pane-header-tab {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment