Commit 6fb7ab1a authored by Will Chen's avatar Will Chen Committed by Commit Bot

DevTools: extract console_counters module

Follow-up from https://codereview.chromium.org/2975523002/

Bug: 667560
Change-Id: Ic562500db2fc352f7938306ba3408e18e57a55dc
Reviewed-on: https://chromium-review.googlesource.com/575444
Commit-Queue: Will Chen <chenwilliam@chromium.org>
Reviewed-by: default avatarAndrey Kosyakov <caseq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488825}
parent 9f2dfb6d
...@@ -235,7 +235,7 @@ InspectorTest.dumpConsoleClassesBrief = function() ...@@ -235,7 +235,7 @@ InspectorTest.dumpConsoleClassesBrief = function()
InspectorTest.dumpConsoleCounters = function() InspectorTest.dumpConsoleCounters = function()
{ {
var counter = Main.Main.WarningErrorCounter._instanceForTest; var counter = ConsoleCounters.WarningErrorCounter._instanceForTest;
for (var index = 0; index < counter._titles.length; ++index) for (var index = 0; index < counter._titles.length; ++index)
InspectorTest.addResult(counter._titles[index]); InspectorTest.addResult(counter._titles[index]);
InspectorTest.dumpConsoleClassesBrief(); InspectorTest.dumpConsoleClassesBrief();
......
...@@ -4,6 +4,7 @@ Loaded modules: ...@@ -4,6 +4,7 @@ Loaded modules:
bindings bindings
common common
components components
console_counters
console_model console_model
dom_extension dom_extension
emulation emulation
......
...@@ -144,6 +144,9 @@ all_devtools_files = [ ...@@ -144,6 +144,9 @@ all_devtools_files = [
"front_end/console/ConsoleViewMessage.js", "front_end/console/ConsoleViewMessage.js",
"front_end/console/ConsoleViewport.js", "front_end/console/ConsoleViewport.js",
"front_end/console/module.json", "front_end/console/module.json",
"front_end/console_counters/errorWarningCounter.css",
"front_end/console_counters/module.json",
"front_end/console_counters/WarningErrorCounter.js",
"front_end/console_model/ConsoleModel.js", "front_end/console_model/ConsoleModel.js",
"front_end/console_model/module.json", "front_end/console_model/module.json",
"front_end/console_test_runner/ConsoleTestRunner.js", "front_end/console_test_runner/ConsoleTestRunner.js",
...@@ -309,7 +312,6 @@ all_devtools_files = [ ...@@ -309,7 +312,6 @@ all_devtools_files = [
"front_end/layers/LayersPanel.js", "front_end/layers/LayersPanel.js",
"front_end/layers/LayerTreeModel.js", "front_end/layers/LayerTreeModel.js",
"front_end/layers/module.json", "front_end/layers/module.json",
"front_end/main/errorWarningCounter.css",
"front_end/main/ExecutionContextSelector.js", "front_end/main/ExecutionContextSelector.js",
"front_end/main/GCActionDelegate.js", "front_end/main/GCActionDelegate.js",
"front_end/main/Main.js", "front_end/main/Main.js",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
* @implements {UI.ToolbarItem.Provider}
* @unrestricted
*/
ConsoleCounters.WarningErrorCounter = class {
constructor() {
ConsoleCounters.WarningErrorCounter._instanceForTest = this;
this._counter = createElement('div');
this._counter.addEventListener('click', Common.console.show.bind(Common.console), false);
this._toolbarItem = new UI.ToolbarItem(this._counter);
var shadowRoot = UI.createShadowRootWithCoreStyles(this._counter, 'console_counters/errorWarningCounter.css');
this._errors = this._createItem(shadowRoot, 'smallicon-error');
this._warnings = this._createItem(shadowRoot, 'smallicon-warning');
this._titles = [];
ConsoleModel.consoleModel.addEventListener(ConsoleModel.ConsoleModel.Events.ConsoleCleared, this._update, this);
ConsoleModel.consoleModel.addEventListener(ConsoleModel.ConsoleModel.Events.MessageAdded, this._update, this);
ConsoleModel.consoleModel.addEventListener(ConsoleModel.ConsoleModel.Events.MessageUpdated, this._update, this);
this._update();
}
/**
* @param {!Node} shadowRoot
* @param {string} iconType
* @return {!{item: !Element, text: !Element}}
*/
_createItem(shadowRoot, iconType) {
var item = createElementWithClass('span', 'counter-item');
var icon = item.createChild('label', '', 'dt-icon-label');
icon.type = iconType;
var text = icon.createChild('span');
shadowRoot.appendChild(item);
return {item: item, text: text};
}
/**
* @param {!{item: !Element, text: !Element}} item
* @param {number} count
* @param {boolean} first
* @param {string} title
*/
_updateItem(item, count, first, title) {
item.item.classList.toggle('hidden', !count);
item.item.classList.toggle('counter-item-first', first);
item.text.textContent = count;
if (count)
this._titles.push(title);
}
_update() {
var errors = ConsoleModel.consoleModel.errors();
var warnings = ConsoleModel.consoleModel.warnings();
this._titles = [];
this._toolbarItem.setVisible(!!(errors || warnings));
this._updateItem(this._errors, errors, false, Common.UIString(errors === 1 ? '%d error' : '%d errors', errors));
this._updateItem(
this._warnings, warnings, !errors, Common.UIString(warnings === 1 ? '%d warning' : '%d warnings', warnings));
this._counter.title = this._titles.join(', ');
UI.inspectorView.toolbarItemResized();
}
/**
* @override
* @return {?UI.ToolbarItem}
*/
item() {
return this._toolbarItem;
}
};
\ No newline at end of file
{
"extensions": [
{
"type": "@UI.ToolbarItem.Provider",
"className": "ConsoleCounters.WarningErrorCounter",
"order": 1,
"location": "main-toolbar-right"
}
],
"dependencies": [
"common",
"ui",
"console_model"
],
"scripts": [
"WarningErrorCounter.js"
],
"resources": [
"errorWarningCounter.css"
]
}
\ No newline at end of file
...@@ -291,7 +291,7 @@ ConsoleTestRunner.dumpConsoleClassesBrief = function() { ...@@ -291,7 +291,7 @@ ConsoleTestRunner.dumpConsoleClassesBrief = function() {
}; };
ConsoleTestRunner.dumpConsoleCounters = function() { ConsoleTestRunner.dumpConsoleCounters = function() {
var counter = Main.Main.WarningErrorCounter._instanceForTest; var counter = ConsoleCounters.WarningErrorCounter._instanceForTest;
for (var index = 0; index < counter._titles.length; ++index) for (var index = 0; index < counter._titles.length; ++index)
TestRunner.addResult(counter._titles[index]); TestRunner.addResult(counter._titles[index]);
ConsoleTestRunner.dumpConsoleClassesBrief(); ConsoleTestRunner.dumpConsoleClassesBrief();
......
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
"integration_test_runner", "integration_test_runner",
"console", "console",
"console_model", "console_model",
"main" "console_counters"
], ],
"scripts": [ "scripts": [
"ConsoleTestRunner.js" "ConsoleTestRunner.js"
] ]
} }
\ No newline at end of file
...@@ -63,7 +63,8 @@ ...@@ -63,7 +63,8 @@
{ "name": "changes"}, { "name": "changes"},
{ "name": "mobile_throttling", "type": "autostart"}, { "name": "mobile_throttling", "type": "autostart"},
{ "name": "network_priorities"}, { "name": "network_priorities"},
{ "name": "formatter" } { "name": "formatter" },
{ "name": "console_counters", "type": "autostart" }
], ],
"has_html": true "has_html": true
......
...@@ -69,7 +69,8 @@ ...@@ -69,7 +69,8 @@
{ "name": "changes"}, { "name": "changes"},
{ "name": "mobile_throttling", "type": "autostart"}, { "name": "mobile_throttling", "type": "autostart"},
{ "name": "network_priorities"}, { "name": "network_priorities"},
{ "name": "formatter" } { "name": "formatter" },
{ "name": "console_counters", "type": "autostart" }
], ],
"has_html": true "has_html": true
......
...@@ -588,80 +588,6 @@ Main.Main.SearchActionDelegate = class { ...@@ -588,80 +588,6 @@ Main.Main.SearchActionDelegate = class {
} }
}; };
/**
* @implements {UI.ToolbarItem.Provider}
* @unrestricted
*/
Main.Main.WarningErrorCounter = class {
constructor() {
Main.Main.WarningErrorCounter._instanceForTest = this;
this._counter = createElement('div');
this._counter.addEventListener('click', Common.console.show.bind(Common.console), false);
this._toolbarItem = new UI.ToolbarItem(this._counter);
var shadowRoot = UI.createShadowRootWithCoreStyles(this._counter, 'main/errorWarningCounter.css');
this._errors = this._createItem(shadowRoot, 'smallicon-error');
this._warnings = this._createItem(shadowRoot, 'smallicon-warning');
this._titles = [];
ConsoleModel.consoleModel.addEventListener(ConsoleModel.ConsoleModel.Events.ConsoleCleared, this._update, this);
ConsoleModel.consoleModel.addEventListener(ConsoleModel.ConsoleModel.Events.MessageAdded, this._update, this);
ConsoleModel.consoleModel.addEventListener(ConsoleModel.ConsoleModel.Events.MessageUpdated, this._update, this);
this._update();
}
/**
* @param {!Node} shadowRoot
* @param {string} iconType
* @return {!{item: !Element, text: !Element}}
*/
_createItem(shadowRoot, iconType) {
var item = createElementWithClass('span', 'counter-item');
var icon = item.createChild('label', '', 'dt-icon-label');
icon.type = iconType;
var text = icon.createChild('span');
shadowRoot.appendChild(item);
return {item: item, text: text};
}
/**
* @param {!{item: !Element, text: !Element}} item
* @param {number} count
* @param {boolean} first
* @param {string} title
*/
_updateItem(item, count, first, title) {
item.item.classList.toggle('hidden', !count);
item.item.classList.toggle('counter-item-first', first);
item.text.textContent = count;
if (count)
this._titles.push(title);
}
_update() {
var errors = ConsoleModel.consoleModel.errors();
var warnings = ConsoleModel.consoleModel.warnings();
this._titles = [];
this._toolbarItem.setVisible(!!(errors || warnings));
this._updateItem(this._errors, errors, false, Common.UIString(errors === 1 ? '%d error' : '%d errors', errors));
this._updateItem(
this._warnings, warnings, !errors, Common.UIString(warnings === 1 ? '%d warning' : '%d warnings', warnings));
this._counter.title = this._titles.join(', ');
UI.inspectorView.toolbarItemResized();
}
/**
* @override
* @return {?UI.ToolbarItem}
*/
item() {
return this._toolbarItem;
}
};
/** /**
* @implements {UI.ToolbarItem.Provider} * @implements {UI.ToolbarItem.Provider}
*/ */
......
...@@ -209,12 +209,6 @@ ...@@ -209,12 +209,6 @@
"location": "main-toolbar-left", "location": "main-toolbar-left",
"condition": "!nodeFrontend" "condition": "!nodeFrontend"
}, },
{
"type": "@UI.ToolbarItem.Provider",
"className": "Main.Main.WarningErrorCounter",
"order": 1,
"location": "main-toolbar-right"
},
{ {
"type": "@UI.ToolbarItem.Provider", "type": "@UI.ToolbarItem.Provider",
"separator": true, "separator": true,
...@@ -436,7 +430,8 @@ ...@@ -436,7 +430,8 @@
"persistence", "persistence",
"help", "help",
"console_model", "console_model",
"network_log" "network_log",
"console_counters"
], ],
"scripts": [ "scripts": [
"RenderingOptions.js", "RenderingOptions.js",
...@@ -447,7 +442,6 @@ ...@@ -447,7 +442,6 @@
"Main.js" "Main.js"
], ],
"resources": [ "resources": [
"errorWarningCounter.css",
"nodeIcon.css", "nodeIcon.css",
"remoteDebuggingTerminatedScreen.css", "remoteDebuggingTerminatedScreen.css",
"renderingOptions.css", "renderingOptions.css",
......
...@@ -39,8 +39,9 @@ const MODULES_TO_REMOVE = []; ...@@ -39,8 +39,9 @@ const MODULES_TO_REMOVE = [];
* If moving to an existing module: * If moving to an existing module:
* {file: 'ui/SomeFile.js', existing: 'common'} * {file: 'ui/SomeFile.js', existing: 'common'}
*/ */
const JS_FILES_MAPPING = const JS_FILES_MAPPING = [
[{file: 'common/FormatterWorkerPool.js', new: 'formatter'}, {file: 'sources/ScriptFormatter.js', new: 'formatter'}]; {file: 'main/WarningErrorCounter.js', new: 'console_counters'},
];
/** /**
* List all new modules here: * List all new modules here:
...@@ -52,11 +53,11 @@ const JS_FILES_MAPPING = ...@@ -52,11 +53,11 @@ const JS_FILES_MAPPING =
* } * }
*/ */
const MODULE_MAPPING = { const MODULE_MAPPING = {
formatter: { console_counters: {
dependencies: ['common'], dependencies: ['common', 'ui', 'console_model'],
dependents: ['sources', 'audits', 'network', 'sass'], dependents: ['main', 'console_test_runner'],
applications: ['inspector.json'], applications: ['inspector.json', 'integration_test_runner.json'],
autostart: false, autostart: true,
}, },
}; };
...@@ -72,7 +73,9 @@ const NEW_DEPENDENCIES_BY_EXISTING_MODULES = { ...@@ -72,7 +73,9 @@ const NEW_DEPENDENCIES_BY_EXISTING_MODULES = {
* If an existing module will no longer have a dependency on a module: * If an existing module will no longer have a dependency on a module:
* console: ['former_dependency'] * console: ['former_dependency']
*/ */
const REMOVE_DEPENDENCIES_BY_EXISTING_MODULES = {}; const REMOVE_DEPENDENCIES_BY_EXISTING_MODULES = {
console_test_runner: ['main']
};
/* /*
* ========================================== * ==========================================
......
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