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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/components_lazy/CoverageProfile.js

Issue 2472213005: DevTools: introduce "Track CSS Usage" experiment (Closed)
Patch Set: Unused CSS highlight in sources panel Created 4 years, 1 month 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
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 WebInspector.CoverageProfile = class {
6 constructor() {
7 this._updateTimer = null;
8 this.reset();
9 }
10
11 /**
12 * @return {!WebInspector.CoverageProfile}
13 */
14 static instance() {
15 if (!WebInspector.CoverageProfile._instance)
16 WebInspector.CoverageProfile._instance = new WebInspector.CoverageProfile( );
17
18 return WebInspector.CoverageProfile._instance;
19 }
20
21 /**
22 * @param {string} url
23 * @param {!WebInspector.TextRange} range
24 */
25 appendUnusedRule(url, range) {
26 if (!url)
27 return;
28
29 var fileInfo = this._coverageForURL.get(url);
lushnikov 2016/11/09 01:55:22 fileInfo is a poor name as well
30 if (!fileInfo) {
31 fileInfo = new Set();
32 this._coverageForURL.set(url, fileInfo);
33 }
34 fileInfo.add(range);
35
36 this._scheduleUpdate();
37 }
38
39 reset() {
40 /** @type {!Map<string, !Set<!WebInspector.TextRange>>} */
lushnikov 2016/11/09 01:55:22 use Multimap
41 this._coverageForURL = new Map();
42 this._scheduleUpdate();
43 }
44
45 _scheduleUpdate() {
46 if (this._updateTimer)
47 return;
48
49 this._updateTimer = setTimeout(() => {
50 this._updateTimer = null;
51 this._doUpdate();
52 }, 0);
lushnikov 2016/11/09 01:55:22 let's have non-zero timeout, e.g. 100
53 }
54
55 _doUpdate() {
56 for (var url of this._coverageForURL.keysArray()) {
lushnikov 2016/11/09 01:55:22 this appproach not gonna work in case of reset() m
57 var uiSourceCode = WebInspector.workspace.uiSourceCodeForURL(url);
58 if (uiSourceCode)
59 uiSourceCode.removeAllLineDecorations(WebInspector.CoverageProfile.LineD ecorator.type);
60 }
61
62 for (var fileInfo of this._coverageForURL) {
lushnikov 2016/11/09 01:55:22 let's iterate over keys here to avoid typecasts
63 var url = /** @type {string} */ (fileInfo[0]);
64 var uiSourceCode = WebInspector.workspace.uiSourceCodeForURL(url);
65 if (!uiSourceCode)
66 continue;
67
68 for (var range of fileInfo[1]) {
69 for (var line = range.startLine; line <= range.endLine; ++line) {
lushnikov 2016/11/09 01:55:22 multimple style issues here: 1. extra spaces befor
70 uiSourceCode.addLineDecoration(line, WebInspector.CoverageProfile.Li neDecorator.type, range.startColumn);
71 }
72 }
73 }
74 }
75 };
76
77 /**
78 * @implements {WebInspector.UISourceCodeFrame.LineDecorator}
79 */
80 WebInspector.CoverageProfile.LineDecorator = class {
81 /**
82 * @override
83 * @param {!WebInspector.UISourceCode} uiSourceCode
84 * @param {!WebInspector.CodeMirrorTextEditor} textEditor
85 */
86 decorate(uiSourceCode, textEditor) {
87 var gutterType = 'CodeMirror-gutter-coverage';
88
89 var decorations = uiSourceCode.lineDecorations(WebInspector.CoverageProfile. LineDecorator.type);
90 textEditor.uninstallGutter(gutterType);
91 if (!decorations)
92 return;
93
94 textEditor.installGutter(gutterType, false);
95
96 for (var decoration of decorations.values()) {
97 var element = createElementWithClass('div', 'text-editor-line-marker-cover age');
98 textEditor.setGutterDecoration(decoration.line(), gutterType, element);
99 }
100 }
101 };
102
103 WebInspector.CoverageProfile.LineDecorator.type = 'coverage';
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/BUILD.gn ('k') | third_party/WebKit/Source/devtools/front_end/components_lazy/module.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698