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

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._locationPool = new WebInspector.LiveLocationPool();
9 this.reset();
10 }
11
12 /**
13 * @return {!WebInspector.CoverageProfile}
14 */
15 static instance() {
16 if (!WebInspector.CoverageProfile._instance)
17 WebInspector.CoverageProfile._instance = new WebInspector.CoverageProfile( );
18
19 return WebInspector.CoverageProfile._instance;
20 }
21
22 /**
23 * @param {string} url
24 * @param {!WebInspector.TextRange} range
25 */
26 appendUnusedRule(url, range) {
27 if (!url)
28 return;
29
30 var fileInfo = this._files.get(url);
31 if (!fileInfo) {
32 fileInfo = new Set();
33 this._files.set(url, fileInfo);
34 }
35 fileInfo.add(range);
36 this._scheduleUpdate();
37 }
38
39 reset() {
40 /** @type {!Map<string, !Set<!WebInspector.TextRange>>} */
41 this._files = new Map();
lushnikov 2016/11/09 00:45:30 this is not a collection of "files". Let's come up
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);
53 }
54
55 /**
56 * @param {!WebInspector.Event} event
57 */
58 _uiSourceCodeChanged(event) {
59 WebInspector.workspace.uiSourceCodes().forEach(
60 uiSourceCode => uiSourceCode.removeAllLineDecorations(WebInspector.Cover ageProfile.LineDecorator.type));
61 }
62
63 _doUpdate() {
64 this._locationPool.disposeAll();
65 WebInspector.workspace.uiSourceCodes().forEach(
66 uiSourceCode => uiSourceCode.removeAllLineDecorations(WebInspector.Cover ageProfile.LineDecorator.type));
lushnikov 2016/11/09 00:45:30 can we be smarter and avoid traversing the whole w
67
68 WebInspector.workspace.uiSourceCodes().forEach(
69 uiSourceCode => uiSourceCode.addEventListener(
70 WebInspector.UISourceCode.Events.WorkingCopyChanged, this._uiSourceCodeChanged, this));
lushnikov 2016/11/09 00:45:30 The workignCopyChanged happens for every keypress
71
72 for (var fileInfo of this._files) {
lushnikov 2016/11/09 00:45:30 let's iterate keys here - this way you'll avoid un
73 var url = /** @type {string} */ (fileInfo[0]);
74 var uiSourceCode = WebInspector.workspace.uiSourceCodeForURL(url);
75 if (!uiSourceCode)
76 continue;
77
78 var target =
79 WebInspector.NetworkProject.targetForUISourceCode(uiSourceCode) || Web Inspector.targetManager.mainTarget();
lushnikov 2016/11/09 00:45:30 why do you need mainTarget?
80 var debuggerModel = target ? WebInspector.DebuggerModel.fromTarget(target) : null;
lushnikov 2016/11/09 00:45:30 since you're dealing with CSS, you should not talk
81 if (!debuggerModel)
82 continue;
83
84 for (var range of fileInfo[1]) {
85 for (var line = range.startLine; line <= range.endLine; ++line) {
86
87 var rawLocation = debuggerModel.createRawLocationByURL(url, line, 0);
lushnikov 2016/11/09 00:45:31 this whole code will not work; let's add a test wh
88 if (rawLocation)
89 new WebInspector.CoverageProfile.Presentation(rawLocation, this._loc ationPool);
90 else if (uiSourceCode)
91 uiSourceCode.addLineDecoration(line, WebInspector.CoverageProfile.Li neDecorator.type, 0);
92 }
93 }
94 }
95 }
96 };
97
98 WebInspector.CoverageProfile.Presentation = class {
lushnikov 2016/11/09 00:45:30 probably you don't need this - unless it comes han
99 /**
100 * @param {!WebInspector.DebuggerModel.Location} rawLocation
101 * @param {!WebInspector.LiveLocationPool} locationPool
102 */
103 constructor(rawLocation, locationPool) {
104 WebInspector.debuggerWorkspaceBinding.createLiveLocation(rawLocation, this.u pdateLocation.bind(this), locationPool);
lushnikov 2016/11/09 00:45:30 Debugger has nothing to do with styles; use cssWor
105 this._uiLocation = null;
106 }
107
108 /**
109 * @param {!WebInspector.LiveLocation} liveLocation
110 */
111 updateLocation(liveLocation) {
112 if (this._uiLocation)
113 this._uiLocation.uiSourceCode.removeLineDecoration(
114 this._uiLocation.lineNumber, WebInspector.CoverageProfile.LineDecorato r.type);
115
116 this._uiLocation = liveLocation.uiLocation();
117 if (this._uiLocation)
118 this._uiLocation.uiSourceCode.addLineDecoration(
119 this._uiLocation.lineNumber, WebInspector.CoverageProfile.LineDecorato r.type, 0);
120 }
121 };
122
123 /**
124 * @implements {WebInspector.UISourceCodeFrame.LineDecorator}
125 */
126 WebInspector.CoverageProfile.LineDecorator = class {
127 /**
128 * @override
129 * @param {!WebInspector.UISourceCode} uiSourceCode
130 * @param {!WebInspector.CodeMirrorTextEditor} textEditor
131 */
132 decorate(uiSourceCode, textEditor) {
133 var gutterType = 'CodeMirror-gutter-coverage';
134
135 var decorations = uiSourceCode.lineDecorations(WebInspector.CoverageProfile. LineDecorator.type);
136 textEditor.uninstallGutter(gutterType);
137 if (!decorations)
138 return;
139
140 textEditor.installGutter(gutterType, false);
141
142 for (var decoration of decorations.values()) {
143 var element = createElementWithClass('div', 'text-editor-line-marker-cover age');
144 textEditor.setGutterDecoration(decoration.line(), gutterType, element);
145 }
146 }
147 };
148
149 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