| OLD | NEW |
| (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 {!Protocol.CSS.SourceRange} range |
| 24 */ |
| 25 appendUnusedRule(url, range) { |
| 26 if (!url) |
| 27 return; |
| 28 |
| 29 this._coverageForURL.set(url, range); |
| 30 this._scheduleUpdate(); |
| 31 } |
| 32 |
| 33 reset() { |
| 34 /** @type {!Multimap<string, !Protocol.CSS.SourceRange>} */ |
| 35 this._coverageForURL = new Multimap(); |
| 36 WebInspector.workspace.uiSourceCodes().forEach( |
| 37 uiSourceCode => uiSourceCode.removeAllLineDecorations(WebInspector.LineL
evelProfile.LineDecorator.type)); |
| 38 } |
| 39 |
| 40 _scheduleUpdate() { |
| 41 if (this._updateTimer) |
| 42 return; |
| 43 |
| 44 this._updateTimer = setTimeout(() => { |
| 45 this._updateTimer = null; |
| 46 this._doUpdate(); |
| 47 }, 100); |
| 48 } |
| 49 |
| 50 _doUpdate() { |
| 51 for (var url of this._coverageForURL.keysArray()) { |
| 52 |
| 53 var uiSourceCode = WebInspector.workspace.uiSourceCodeForURL(url); |
| 54 if (uiSourceCode) |
| 55 uiSourceCode.removeAllLineDecorations(WebInspector.CoverageProfile.LineD
ecorator.type); |
| 56 } |
| 57 |
| 58 for (var url of this._coverageForURL.keysArray()) { |
| 59 |
| 60 var uiSourceCode = WebInspector.workspace.uiSourceCodeForURL(url); |
| 61 if (!uiSourceCode) |
| 62 continue; |
| 63 |
| 64 for (var range of this._coverageForURL.get(url)) { |
| 65 for (var line = range.startLine; line <= range.endLine; ++line) |
| 66 uiSourceCode.addLineDecoration(line, WebInspector.CoverageProfile.Line
Decorator.type, range.startColumn); |
| 67 } |
| 68 } |
| 69 } |
| 70 }; |
| 71 |
| 72 /** |
| 73 * @implements {WebInspector.UISourceCodeFrame.LineDecorator} |
| 74 */ |
| 75 WebInspector.CoverageProfile.LineDecorator = class { |
| 76 /** |
| 77 * @override |
| 78 * @param {!WebInspector.UISourceCode} uiSourceCode |
| 79 * @param {!WebInspector.CodeMirrorTextEditor} textEditor |
| 80 */ |
| 81 decorate(uiSourceCode, textEditor) { |
| 82 var gutterType = 'CodeMirror-gutter-coverage'; |
| 83 |
| 84 var decorations = uiSourceCode.lineDecorations(WebInspector.CoverageProfile.
LineDecorator.type); |
| 85 textEditor.uninstallGutter(gutterType); |
| 86 if (!decorations) |
| 87 return; |
| 88 |
| 89 textEditor.installGutter(gutterType, false); |
| 90 |
| 91 for (var decoration of decorations.values()) { |
| 92 var element = createElementWithClass('div', 'text-editor-line-marker-cover
age'); |
| 93 textEditor.setGutterDecoration(decoration.line(), gutterType, element); |
| 94 } |
| 95 } |
| 96 }; |
| 97 |
| 98 WebInspector.CoverageProfile.LineDecorator.type = 'coverage'; |
| OLD | NEW |