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