OLD | NEW |
1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 Coverage.CoverageListView = class extends UI.VBox { | 5 Coverage.CoverageListView = class extends UI.VBox { |
6 constructor() { | 6 /** |
| 7 * @param {function(!Coverage.URLCoverageInfo):boolean} filterCallback |
| 8 */ |
| 9 constructor(filterCallback) { |
7 super(true); | 10 super(true); |
8 /** @type {!Map<!Coverage.URLCoverageInfo, !Coverage.CoverageListView.GridNo
de>} */ | 11 /** @type {!Map<!Coverage.URLCoverageInfo, !Coverage.CoverageListView.GridNo
de>} */ |
9 this._nodeForCoverageInfo = new Map(); | 12 this._nodeForCoverageInfo = new Map(); |
| 13 this._filterCallback = filterCallback; |
10 /** @type {?RegExp} */ | 14 /** @type {?RegExp} */ |
11 this._filterRegExp = null; | 15 this._highlightRegExp = null; |
12 this.registerRequiredCSS('coverage/coverageListView.css'); | 16 this.registerRequiredCSS('coverage/coverageListView.css'); |
13 var columns = [ | 17 var columns = [ |
14 {id: 'url', title: Common.UIString('URL'), width: '300px', fixedWidth: fal
se, sortable: true}, | 18 {id: 'url', title: Common.UIString('URL'), width: '250px', fixedWidth: fal
se, sortable: true}, |
15 {id: 'type', title: Common.UIString('Type'), width: '45px', fixedWidth: tr
ue, sortable: true}, { | 19 {id: 'type', title: Common.UIString('Type'), width: '45px', fixedWidth: tr
ue, sortable: true}, { |
16 id: 'size', | 20 id: 'size', |
17 title: Common.UIString('Total Bytes'), | 21 title: Common.UIString('Total Bytes'), |
18 width: '60px', | 22 width: '60px', |
19 fixedWidth: true, | 23 fixedWidth: true, |
20 sortable: true, | 24 sortable: true, |
21 align: DataGrid.DataGrid.Align.Right | 25 align: DataGrid.DataGrid.Align.Right |
22 }, | 26 }, |
23 { | 27 { |
24 id: 'unusedSize', | 28 id: 'unusedSize', |
25 title: Common.UIString('Unused Bytes'), | 29 title: Common.UIString('Unused Bytes'), |
26 width: '60px', | 30 width: '100px', |
27 fixedWidth: true, | 31 fixedWidth: true, |
28 sortable: true, | 32 sortable: true, |
29 align: DataGrid.DataGrid.Align.Right, | 33 align: DataGrid.DataGrid.Align.Right, |
30 sort: DataGrid.DataGrid.Order.Descending | 34 sort: DataGrid.DataGrid.Order.Descending |
31 }, | 35 }, |
32 {id: 'bars', title: '', width: '500px', fixedWidth: false, sortable: true} | 36 {id: 'bars', title: '', width: '250px', fixedWidth: false, sortable: true} |
33 ]; | 37 ]; |
34 this._dataGrid = new DataGrid.SortableDataGrid(columns); | 38 this._dataGrid = new DataGrid.SortableDataGrid(columns); |
35 this._dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last); | 39 this._dataGrid.setResizeMethod(DataGrid.DataGrid.ResizeMethod.Last); |
36 this._dataGrid.element.classList.add('flex-auto'); | 40 this._dataGrid.element.classList.add('flex-auto'); |
37 this._dataGrid.element.addEventListener('keydown', this._onKeyDown.bind(this
), false); | 41 this._dataGrid.element.addEventListener('keydown', this._onKeyDown.bind(this
), false); |
38 this._dataGrid.addEventListener(DataGrid.DataGrid.Events.OpenedNode, this._o
nOpenedNode, this); | 42 this._dataGrid.addEventListener(DataGrid.DataGrid.Events.OpenedNode, this._o
nOpenedNode, this); |
39 this._dataGrid.addEventListener(DataGrid.DataGrid.Events.SortingChanged, thi
s._sortingChanged, this); | 43 this._dataGrid.addEventListener(DataGrid.DataGrid.Events.SortingChanged, thi
s._sortingChanged, this); |
40 | 44 |
41 var dataGridWidget = this._dataGrid.asWidget(); | 45 var dataGridWidget = this._dataGrid.asWidget(); |
42 dataGridWidget.show(this.contentElement); | 46 dataGridWidget.show(this.contentElement); |
43 } | 47 } |
44 | 48 |
45 /** | 49 /** |
46 * @param {!Array<!Coverage.URLCoverageInfo>} coverageInfo | 50 * @param {!Array<!Coverage.URLCoverageInfo>} coverageInfo |
47 */ | 51 */ |
48 update(coverageInfo) { | 52 update(coverageInfo) { |
49 var hadUpdates = false; | 53 var hadUpdates = false; |
50 var maxSize = coverageInfo.reduce((acc, entry) => Math.max(acc, entry.size()
), 0); | 54 var maxSize = coverageInfo.reduce((acc, entry) => Math.max(acc, entry.size()
), 0); |
51 var rootNode = this._dataGrid.rootNode(); | 55 var rootNode = this._dataGrid.rootNode(); |
52 for (var entry of coverageInfo) { | 56 for (var entry of coverageInfo) { |
53 var node = this._nodeForCoverageInfo.get(entry); | 57 var node = this._nodeForCoverageInfo.get(entry); |
54 if (node) { | 58 if (node) { |
55 if (this._isVisible(node)) | 59 if (this._filterCallback(node._coverageInfo)) |
56 hadUpdates = node._refreshIfNeeded(maxSize) || hadUpdates; | 60 hadUpdates = node._refreshIfNeeded(maxSize) || hadUpdates; |
57 continue; | 61 continue; |
58 } | 62 } |
59 node = new Coverage.CoverageListView.GridNode(entry, maxSize); | 63 node = new Coverage.CoverageListView.GridNode(entry, maxSize); |
60 this._nodeForCoverageInfo.set(entry, node); | 64 this._nodeForCoverageInfo.set(entry, node); |
61 if (this._isVisible(node)) { | 65 if (this._filterCallback(node._coverageInfo)) { |
62 rootNode.appendChild(node); | 66 rootNode.appendChild(node); |
63 hadUpdates = true; | 67 hadUpdates = true; |
64 } | 68 } |
65 } | 69 } |
66 if (hadUpdates) | 70 if (hadUpdates) |
67 this._sortingChanged(); | 71 this._sortingChanged(); |
68 } | 72 } |
69 | 73 |
70 reset() { | 74 reset() { |
71 this._nodeForCoverageInfo.clear(); | 75 this._nodeForCoverageInfo.clear(); |
72 this._dataGrid.rootNode().removeChildren(); | 76 this._dataGrid.rootNode().removeChildren(); |
73 } | 77 } |
74 | 78 |
75 /** | 79 /** |
76 * @param {?RegExp} regExp | 80 * @param {?RegExp} highlightRegExp |
77 */ | 81 */ |
78 setFilter(regExp) { | 82 updateFilterAndHighlight(highlightRegExp) { |
79 this._filterRegExp = regExp; | 83 this._highlightRegExp = highlightRegExp; |
80 var hadTreeUpdates = false; | 84 var hadTreeUpdates = false; |
81 for (var node of this._nodeForCoverageInfo.values()) { | 85 for (var node of this._nodeForCoverageInfo.values()) { |
82 var shouldBeVisible = this._isVisible(node); | 86 var shouldBeVisible = this._filterCallback(node._coverageInfo); |
83 var isVisible = !!node.parent; | 87 var isVisible = !!node.parent; |
84 if (shouldBeVisible) | 88 if (shouldBeVisible) |
85 node._setHighlight(regExp); | 89 node._setHighlight(this._highlightRegExp); |
86 if (shouldBeVisible === isVisible) | 90 if (shouldBeVisible === isVisible) |
87 continue; | 91 continue; |
88 hadTreeUpdates = true; | 92 hadTreeUpdates = true; |
89 if (!shouldBeVisible) | 93 if (!shouldBeVisible) |
90 node.remove(); | 94 node.remove(); |
91 else | 95 else |
92 this._dataGrid.rootNode().appendChild(node); | 96 this._dataGrid.rootNode().appendChild(node); |
93 } | 97 } |
94 if (hadTreeUpdates) | 98 if (hadTreeUpdates) |
95 this._sortingChanged(); | 99 this._sortingChanged(); |
96 } | 100 } |
97 | 101 |
98 /** | 102 /** |
99 * @param {!Common.Event} event | 103 * @param {!Common.Event} event |
100 */ | 104 */ |
101 _onOpenedNode(event) { | 105 _onOpenedNode(event) { |
102 var node = /** @type Coverage.CoverageListView.GridNode */ (event.data); | 106 var node = /** @type Coverage.CoverageListView.GridNode */ (event.data); |
103 this._revealSourceForNode(node); | 107 this._revealSourceForNode(node); |
104 } | 108 } |
105 | 109 |
106 /** | 110 /** |
107 * @param {!Coverage.CoverageListView.GridNode} node | |
108 * @return {boolean} | |
109 */ | |
110 _isVisible(node) { | |
111 return !this._filterRegExp || this._filterRegExp.test(node._url); | |
112 } | |
113 | |
114 /** | |
115 * @param {!Event} event | 111 * @param {!Event} event |
116 */ | 112 */ |
117 _onKeyDown(event) { | 113 _onKeyDown(event) { |
118 if (!isEnterKey(event)) | 114 if (!isEnterKey(event)) |
119 return; | 115 return; |
120 event.consume(true); | 116 event.consume(true); |
121 this._revealSourceForNode(this._dataGrid.selectedNode); | 117 this._revealSourceForNode(this._dataGrid.selectedNode); |
122 } | 118 } |
123 | 119 |
124 /** | 120 /** |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 * @param {string} textContent | 301 * @param {string} textContent |
306 */ | 302 */ |
307 _highlight(element, textContent) { | 303 _highlight(element, textContent) { |
308 var matches = this._highlightRegExp.exec(textContent); | 304 var matches = this._highlightRegExp.exec(textContent); |
309 if (!matches || !matches.length) | 305 if (!matches || !matches.length) |
310 return; | 306 return; |
311 var range = new TextUtils.SourceRange(matches.index, matches[0].length); | 307 var range = new TextUtils.SourceRange(matches.index, matches[0].length); |
312 UI.highlightRangesWithStyleClass(element, [range], 'filter-highlight'); | 308 UI.highlightRangesWithStyleClass(element, [range], 'filter-highlight'); |
313 } | 309 } |
314 }; | 310 }; |
OLD | NEW |