| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 /** | 5 /** |
| 6 * The DetailsView handles the tabbed view that displays either the "log" or | 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 | 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. | 8 * invalidates the specific view each time the selected data has changed. |
| 9 * | 9 * |
| 10 * @constructor | 10 * @constructor |
| 11 */ | 11 */ |
| 12 function DetailsView(logTabHandleId, | 12 function DetailsView(tabHandlesContainerId, |
| 13 timelineTabHandleId, | 13 logTabId, |
| 14 detailsTabContentId) { | 14 timelineTabId, |
| 15 // The DOM nodes that which contain the tab title. | 15 logBoxId, |
| 16 this.tabHandles_ = {}; | 16 timelineBoxId) { |
| 17 TabSwitcherView.call(this, new DivView(tabHandlesContainerId)); |
| 17 | 18 |
| 18 this.tabHandles_['timeline'] = document.getElementById(timelineTabHandleId); | 19 this.logView_ = new DetailsLogView(logBoxId); |
| 19 this.tabHandles_['log'] = document.getElementById(logTabHandleId); | 20 this.timelineView_ = new DetailsTimelineView(timelineBoxId); |
| 20 | 21 |
| 21 // The DOM node that contains the currently active tab sheet. | 22 this.addTab(logTabId, this.logView_); |
| 22 this.contentArea_ = document.getElementById(detailsTabContentId); | 23 this.addTab(timelineTabId, this.timelineView_); |
| 23 | |
| 24 // Attach listeners to the "tab handles" so when you click them, it switches | |
| 25 // active view. | |
| 26 | |
| 27 var self = this; | |
| 28 | |
| 29 this.tabHandles_['timeline'].onclick = function() { | |
| 30 self.switchToView_('timeline'); | |
| 31 }; | |
| 32 | |
| 33 this.tabHandles_['log'].onclick = function() { | |
| 34 self.switchToView_('log'); | |
| 35 }; | |
| 36 | |
| 37 this.currentData_ = []; | |
| 38 | 24 |
| 39 // Default to the log view. | 25 // Default to the log view. |
| 40 this.switchToView_('log'); | 26 this.switchToTab(logTabId); |
| 41 }; | 27 }; |
| 42 | 28 |
| 29 inherits(DetailsView, TabSwitcherView); |
| 30 |
| 43 // The delay between updates to repaint. | 31 // The delay between updates to repaint. |
| 44 DetailsView.REPAINT_TIMEOUT_MS = 50; | 32 DetailsView.REPAINT_TIMEOUT_MS = 50; |
| 45 | 33 |
| 46 /** | 34 /** |
| 47 * Switches to the tab with name |viewName|. (Either 'log' or 'timeline'. | |
| 48 */ | |
| 49 DetailsView.prototype.switchToView_ = function(viewName) { | |
| 50 if (this.currentView_) { | |
| 51 // Remove the selected styling on currently selected tab. | |
| 52 changeClassName(this.tabHandles_[this.currentView_], 'selected', false); | |
| 53 } | |
| 54 | |
| 55 this.currentView_ = viewName; | |
| 56 changeClassName(this.tabHandles_[this.currentView_], 'selected', true); | |
| 57 this.repaint_(); | |
| 58 }; | |
| 59 | |
| 60 /** | |
| 61 * Updates the data this view is using. | 35 * Updates the data this view is using. |
| 62 */ | 36 */ |
| 63 DetailsView.prototype.setData = function(currentData) { | 37 DetailsView.prototype.setData = function(currentData) { |
| 64 // Make a copy of the array (in case the caller mutates it), and sort it | 38 // Make a copy of the array (in case the caller mutates it), and sort it |
| 65 // by the source ID. | 39 // by the source ID. |
| 66 this.currentData_ = DetailsView.createSortedCopy_(currentData); | 40 var sortedCurrentData = DetailsView.createSortedCopy_(currentData); |
| 67 | 41 |
| 68 // Invalidate the view. | 42 for (var i = 0; i < this.tabs_.length; ++i) |
| 69 if (!this.outstandingRepaint_) { | 43 this.tabs_[i].contentView.setData(sortedCurrentData); |
| 70 this.outstandingRepaint_ = true; | |
| 71 window.setTimeout(this.repaint_.bind(this), | |
| 72 DetailsView.REPAINT_TIMEOUT_MS); | |
| 73 } | |
| 74 }; | |
| 75 | |
| 76 DetailsView.prototype.repaint_ = function() { | |
| 77 this.outstandingRepaint_ = false; | |
| 78 this.contentArea_.innerHTML = ''; | |
| 79 | |
| 80 if (this.currentView_ == 'log') { | |
| 81 PaintLogView(this.currentData_, this.contentArea_); | |
| 82 } else { | |
| 83 PaintTimelineView(this.currentData_, this.contentArea_); | |
| 84 } | |
| 85 }; | 44 }; |
| 86 | 45 |
| 87 DetailsView.createSortedCopy_ = function(origArray) { | 46 DetailsView.createSortedCopy_ = function(origArray) { |
| 88 var sortedArray = origArray.slice(0); | 47 var sortedArray = origArray.slice(0); |
| 89 sortedArray.sort(function(a, b) { | 48 sortedArray.sort(function(a, b) { |
| 90 return a.getSourceId() - b.getSourceId(); | 49 return a.getSourceId() - b.getSourceId(); |
| 91 }); | 50 }); |
| 92 return sortedArray; | 51 return sortedArray; |
| 93 }; | 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 }; |
| OLD | NEW |