1 // Copyright (c) 2012 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.
5 var DetailsView
= (function() {
8 // We inherit from DivView.
9 var superClass
= DivView
;
12 * The DetailsView displays the "log" view. This class keeps track of the
13 * selected SourceEntries, and repaints when they change.
17 function DetailsView(boxId
) {
18 superClass
.call(this, boxId
);
19 this.sourceEntries_
= [];
20 // Map of source IDs to their corresponding DIVs.
21 this.sourceIdToDivMap_
= {};
22 // True when there's an asychronous repaint outstanding.
23 this.outstandingRepaint_
= false;
24 // ID of source entry we should jump to after the oustanding repaint.
25 // 0 if none, or there's no such repaint.
26 this.outstandingScrollToId_
= 0;
29 // The delay between updates to repaint.
30 var REPAINT_TIMEOUT_MS
= 50;
32 DetailsView
.prototype = {
33 // Inherit the superclass's methods.
34 __proto__
: superClass
.prototype,
36 setData: function(sourceEntries
) {
37 // Make a copy of the array (in case the caller mutates it), and sort it
39 this.sourceEntries_
= createSortedCopy_(sourceEntries
);
42 if (this.isVisible() && !this.outstandingRepaint_
) {
43 this.outstandingRepaint_
= true;
44 window
.setTimeout(this.repaint
.bind(this),
50 this.outstandingRepaint_
= false;
51 this.sourceIdToDivMap_
= {};
52 this.getNode().innerHTML
= '';
54 var node
= this.getNode();
56 for (var i
= 0; i
< this.sourceEntries_
.length
; ++i
) {
60 var sourceEntry
= this.sourceEntries_
[i
];
61 var div
= addNode(node
, 'div');
62 div
.className
= 'log-source-entry';
64 var p
= addNode(div
, 'p');
65 addNodeWithText(p
, 'h4',
66 sourceEntry
.getSourceId() + ': ' +
67 sourceEntry
.getSourceTypeString());
69 if (sourceEntry
.getDescription())
70 addNodeWithText(p
, 'h4', sourceEntry
.getDescription());
72 var logEntries
= sourceEntry
.getLogEntries();
73 var startDate
= timeutil
.convertTimeTicksToDate(logEntries
[0].time
);
74 var startTimeDiv
= addNodeWithText(p
, 'div', 'Start Time: ');
75 timeutil
.addNodeWithDate(startTimeDiv
, startDate
);
77 sourceEntry
.printAsText(div
);
79 this.sourceIdToDivMap_
[sourceEntry
.getSourceId()] = div
;
82 if (this.outstandingScrollToId_
) {
83 this.scrollToSourceId(this.outstandingScrollToId_
);
84 this.outstandingScrollToId_
= 0;
88 show: function(isVisible
) {
89 superClass
.prototype.show
.call(this, isVisible
);
93 this.getNode().innerHTML
= '';
98 * Scrolls to the source indicated by |sourceId|, if displayed. If a
99 * repaint is outstanding, waits for it to complete before scrolling.
101 scrollToSourceId: function(sourceId
) {
102 if (this.outstandingRepaint_
) {
103 this.outstandingScrollToId_
= sourceId
;
106 var div
= this.sourceIdToDivMap_
[sourceId
];
108 div
.scrollIntoView();
112 function createSortedCopy_(origArray
) {
113 var sortedArray
= origArray
.slice(0);
114 sortedArray
.sort(function(a
, b
) {
115 return a
.getSourceId() - b
.getSourceId();