1 // Copyright (c) 2010 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 /** 6 * The DetailsView handles the tabbed view that displays either the "log" or 7 * "timeline" view. This class keeps track of what the current view is, and 8 * invalidates the specific view each time the selected data has changed. 9 * 10 * @constructor 11 */ 12 function DetailsView(tabHandlesContainerId, 13 logTabId, 14 timelineTabId, 15 logBoxId, 16 timelineBoxId) { 17 TabSwitcherView.call(this, tabHandlesContainerId); 18 19 this.logView_ = new DetailsLogView(logBoxId); 20 this.timelineView_ = new DetailsTimelineView(timelineBoxId); 21 22 this.addTab(logTabId, this.logView_, true); 23 this.addTab(timelineTabId, this.timelineView_, true); 24 25 // Default to the log view. 26 this.switchToTab(logTabId, null); 27 }; 28 29 inherits(DetailsView, TabSwitcherView); 30 31 // The delay between updates to repaint. 32 DetailsView.REPAINT_TIMEOUT_MS = 50; 33 34 /** 35 * Updates the data this view is using. 36 */ 37 DetailsView.prototype.setData = function(currentData) { 38 // Make a copy of the array (in case the caller mutates it), and sort it 39 // by the source ID. 40 var sortedCurrentData = DetailsView.createSortedCopy_(currentData); 41 42 for (var i = 0; i < this.tabs_.length; ++i) 43 this.tabs_[i].contentView.setData(sortedCurrentData); 44 }; 45 46 DetailsView.createSortedCopy_ = function(origArray) { 47 var sortedArray = origArray.slice(0); 48 sortedArray.sort(function(a, b) { 49 return a.getSourceId() - b.getSourceId(); 50 }); 51 return sortedArray; 52 }; 53 54 //----------------------------------------------------------------------------- 55 56 /** 57 * Base class for the Log view and Timeline view. 58 * 59 * @constructor 60 */ 61 function DetailsSubView(boxId) { 62 DivView.call(this, boxId); 63 this.sourceEntries_ = []; 64 } 65 66 inherits(DetailsSubView, DivView); 67 68 DetailsSubView.prototype.setData = function(sourceEntries) { 69 this.sourceEntries_ = sourceEntries; 70 71 // Repaint the view. 72 if (this.isVisible() && !this.outstandingRepaint_) { 73 this.outstandingRepaint_ = true; 74 window.setTimeout(this.repaint.bind(this), 75 DetailsView.REPAINT_TIMEOUT_MS); 76 } 77 }; 78 79 DetailsSubView.prototype.repaint = function() { 80 this.outstandingRepaint_ = false; 81 this.getNode().innerHTML = ''; 82 }; 83 84 DetailsSubView.prototype.show = function(isVisible) { 85 DetailsSubView.superClass_.show.call(this, isVisible); 86 if (isVisible) { 87 this.repaint(); 88 } else { 89 this.getNode().innerHTML = ''; 90 } 91 }; 92 93 //----------------------------------------------------------------------------- 94 95 96 /** 97 * Subview that is displayed in the log tab. 98 * @constructor 99 */ 100 function DetailsLogView(boxId) { 101 DetailsSubView.call(this, boxId); 102 } 103 104 inherits(DetailsLogView, DetailsSubView); 105 106 DetailsLogView.prototype.repaint = function() { 107 DetailsLogView.superClass_.repaint.call(this); 108 PaintLogView(this.sourceEntries_, this.getNode()); 109 }; 110 111 //----------------------------------------------------------------------------- 112 113 /** 114 * Subview that is displayed in the timeline tab. 115 * @constructor 116 */ 117 function DetailsTimelineView(boxId) { 118 DetailsSubView.call(this, boxId); 119 } 120 121 inherits(DetailsTimelineView, DetailsSubView); 122 123 DetailsTimelineView.prototype.repaint = function() { 124 DetailsTimelineView.superClass_.repaint.call(this); 125 PaintTimelineView(this.sourceEntries_, this.getNode()); 126 }; 127