1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// TODO(viona): Write a README document/instructions.
/** This view displays the event waterfall. */
var WaterfallView = (function() {
'use strict';
// We inherit from DivView.
var superClass = DivView;
/**
* @constructor
*/
function WaterfallView() {
assertFirstConstructorCall(WaterfallView);
// Call superclass's constructor.
superClass.call(this, WaterfallView.MAIN_BOX_ID);
SourceTracker.getInstance().addSourceEntryObserver(this);
// For adjusting the range of view.
$(WaterfallView.SCALE_ID).addEventListener(
'click', this.setStartEndTimes_.bind(this), true);
$(WaterfallView.MAIN_BOX_ID).addEventListener(
'mousewheel', this.scrollToZoom_.bind(this), true);
$(WaterfallView.MAIN_BOX_ID).addEventListener(
'scroll', this.scrollInfoTable_.bind(this), true);
this.initializeSourceList_();
window.onload = this.scrollInfoTable_();
}
WaterfallView.TAB_ID = 'tab-handle-waterfall';
WaterfallView.TAB_NAME = 'Waterfall';
WaterfallView.TAB_HASH = '#waterfall';
// IDs for special HTML elements in events_waterfall_view.html.
WaterfallView.MAIN_BOX_ID = 'waterfall-view-tab-content';
WaterfallView.BAR_TABLE_ID = 'waterfall-view-time-bar-table';
WaterfallView.BAR_TBODY_ID = 'waterfall-view-time-bar-tbody';
WaterfallView.SCALE_ID = 'waterfall-view-adjust-to-window';
WaterfallView.TIME_SCALE_HEADER_ID = 'waterfall-view-time-scale-labels';
WaterfallView.TIME_RANGE_ID = 'waterfall-view-time-range-submit';
WaterfallView.START_TIME_ID = 'waterfall-view-start-input';
WaterfallView.END_TIME_ID = 'waterfall-view-end-input';
WaterfallView.INFO_TABLE_ID = 'waterfall-view-information-table';
WaterfallView.INFO_TBODY_ID = 'waterfall-view-information-tbody';
WaterfallView.CONTROLS_ID = 'waterfall-view-controls';
WaterfallView.ID_HEADER_ID = 'waterfall-view-id-header';
WaterfallView.URL_HEADER_ID = 'waterfall-view-url-header';
// The number of units mouse wheel deltas increase for each tick of the
// wheel.
var MOUSE_WHEEL_UNITS_PER_CLICK = 120;
// Amount we zoom for one vertical tick of the mouse wheel, as a ratio.
var MOUSE_WHEEL_ZOOM_RATE = 1.25;
// Amount we scroll for one horizontal tick of the mouse wheel, in pixels.
var MOUSE_WHEEL_SCROLL_RATE = MOUSE_WHEEL_UNITS_PER_CLICK;
cr.addSingletonGetter(WaterfallView);
WaterfallView.prototype = {
// Inherit the superclass's methods.
__proto__: superClass.prototype,
/**
* Creates new WaterfallRows for URL Requests when the sourceEntries are
* updated if they do not already exist.
* Updates pre-existing WaterfallRows that correspond to updated sources.
*/
onSourceEntriesUpdated: function(sourceEntries) {
if (this.startTime_ == null && sourceEntries.length > 0) {
var logEntries = sourceEntries[0].getLogEntries();
this.startTime_ = timeutil.convertTimeTicksToTime(logEntries[0].time);
// Initial scale factor.
this.scaleFactor_ = 0.1;
}
for (var i = 0; i < sourceEntries.length; ++i) {
var sourceEntry = sourceEntries[i];
var id = sourceEntry.getSourceId();
if (sourceEntry.getSourceType() == EventSourceType.URL_REQUEST) {
var row = this.sourceIdToRowMap_[id];
if (!row) {
var newRow = new WaterfallRow(this, sourceEntry);
this.sourceIdToRowMap_[id] = newRow;
} else {
row.onSourceUpdated();
}
}
}
this.scrollInfoTable_();
this.positionBarTable_();
this.updateTimeScale_(this.scaleFactor_);
},
onAllSourceEntriesDeleted: function() {
this.initializeSourceList_();
},
onLoadLogFinish: function(data) {
return true;
},
getScaleFactor: function() {
return this.scaleFactor_;
},
getStartTime: function() {
return this.startTime_;
},
setGeometry: function(left, top, width, height) {
superClass.prototype.setGeometry.call(this, left, top, width, height);
this.scrollInfoTable_();
},
show: function(isVisible) {
superClass.prototype.show.call(this, isVisible);
if (isVisible) {
this.scrollInfoTable_();
}
},
/**
* Initializes the list of source entries. If source entries are already
* being displayed, removes them all in the process.
*/
initializeSourceList_: function() {
this.sourceIdToRowMap_ = {};
$(WaterfallView.BAR_TBODY_ID).innerHTML = '';
$(WaterfallView.INFO_TBODY_ID).innerHTML = '';
this.startTime_ = null;
this.scaleFactor_ = null;
},
/**
* Changes scroll position of the window such that horizontally, everything
* within the specified range fits into the user's viewport.
*/
adjustToWindow_: function(windowStart, windowEnd) {
var waterfallLeft = $(WaterfallView.INFO_TABLE_ID).offsetWidth +
$(WaterfallView.INFO_TABLE_ID).offsetLeft +
$(WaterfallView.ID_HEADER_ID).offsetWidth;
var maxWidth = $(WaterfallView.MAIN_BOX_ID).offsetWidth - waterfallLeft;
var totalDuration = 0;
if (windowEnd != -1) {
totalDuration = windowEnd - windowStart;
} else {
for (var id in this.sourceIdToRowMap_) {
var row = this.sourceIdToRowMap_[id];
var rowDuration = row.getEndTime() - this.startTime_;
if (totalDuration < rowDuration && !row.hide) {
totalDuration = rowDuration;
}
}
}
if (totalDuration <= 0) {
return;
}
this.scaleAll_(maxWidth / totalDuration);
$(WaterfallView.MAIN_BOX_ID).scrollLeft =
windowStart * this.scaleFactor_;
},
/** Updates the time tick indicators. */
updateTimeScale_: function(scaleFactor) {
var timePerTick = 1;
var minTickDistance = 20;
$(WaterfallView.TIME_SCALE_HEADER_ID).innerHTML = '';
// Holder provides environment to prevent wrapping.
var timeTickRow = addNode($(WaterfallView.TIME_SCALE_HEADER_ID), 'div');
timeTickRow.classList.add('waterfall-view-time-scale-row');
var availableWidth = $(WaterfallView.BAR_TBODY_ID).clientWidth;
var tickDistance = scaleFactor * timePerTick;
while (tickDistance < minTickDistance) {
timePerTick = timePerTick * 10;
tickDistance = scaleFactor * timePerTick;
}
var tickCount = availableWidth / tickDistance;
for (var i = 0; i < tickCount; ++i) {
var timeCell = addNode(timeTickRow, 'div');
setNodeWidth(timeCell, tickDistance);
timeCell.classList.add('waterfall-view-time-scale');
timeCell.title = i * timePerTick + ' to ' +
(i + 1) * timePerTick + ' ms';
// Red marker for every 5th bar.
if (i % 5 == 0) {
timeCell.classList.add('waterfall-view-time-scale-special');
}
}
},
/**
* Scales all existing rows by scaleFactor.
*/
scaleAll_: function(scaleFactor) {
this.scaleFactor_ = scaleFactor;
for (var id in this.sourceIdToRowMap_) {
var row = this.sourceIdToRowMap_[id];
row.updateRow();
}
this.updateTimeScale_(scaleFactor);
},
scrollToZoom_: function(event) {
// To use scrolling to control zoom, hold down the alt key and scroll.
if ('wheelDelta' in event && event.altKey) {
event.preventDefault();
var zoomFactor = Math.pow(MOUSE_WHEEL_ZOOM_RATE,
event.wheelDeltaY / MOUSE_WHEEL_UNITS_PER_CLICK);
var waterfallLeft = $(WaterfallView.ID_HEADER_ID).offsetWidth +
$(WaterfallView.URL_HEADER_ID).offsetWidth;
var oldCursorPosition = event.pageX +
$(WaterfallView.MAIN_BOX_ID).scrollLeft;
var oldCursorPositionInTable = oldCursorPosition - waterfallLeft;
this.scaleAll_(this.scaleFactor_ * zoomFactor);
// Shifts the view when scrolling. newScroll could be less than 0 or
// more than the maximum scroll position, but both cases are handled
// by the inbuilt scrollLeft implementation.
var newScroll =
oldCursorPositionInTable * zoomFactor - event.pageX + waterfallLeft;
$(WaterfallView.MAIN_BOX_ID).scrollLeft = newScroll;
}
},
/**
* Positions the bar table such that it is in line with the right edge of
* the info table.
*/
positionBarTable_: function() {
var offsetLeft = $(WaterfallView.INFO_TABLE_ID).offsetWidth +
$(WaterfallView.INFO_TABLE_ID).offsetLeft;
$(WaterfallView.BAR_TABLE_ID).style.left = offsetLeft + 'px';
},
/**
* Moves the info table when the page is scrolled vertically, ensuring that
* the correct information is displayed on the page, and that no elements
* are blocked unnecessarily.
*/
scrollInfoTable_: function(event) {
$(WaterfallView.INFO_TABLE_ID).style.top =
$(WaterfallView.MAIN_BOX_ID).offsetTop +
$(WaterfallView.BAR_TABLE_ID).offsetTop -
$(WaterfallView.MAIN_BOX_ID).scrollTop + 'px';
if ($(WaterfallView.INFO_TABLE_ID).offsetHeight >
$(WaterfallView.MAIN_BOX_ID).clientHeight) {
var scroll = $(WaterfallView.MAIN_BOX_ID).scrollTop;
var bottomClip =
$(WaterfallView.MAIN_BOX_ID).clientHeight -
$(WaterfallView.BAR_TABLE_ID).offsetTop +
$(WaterfallView.MAIN_BOX_ID).scrollTop;
// Clips the information table such that it does not cover the scroll
// bars or the controls bar.
$(WaterfallView.INFO_TABLE_ID).style.clip = 'rect(' + scroll +
'px auto ' + bottomClip + 'px auto)';
}
},
/** Parses user input, then calls adjustToWindow to shift that into view. */
setStartEndTimes_: function() {
var windowStart = parseInt($(WaterfallView.START_TIME_ID).value);
var windowEnd = parseInt($(WaterfallView.END_TIME_ID).value);
if ($(WaterfallView.END_TIME_ID).value == '') {
windowEnd = -1;
}
if ($(WaterfallView.START_TIME_ID).value == '') {
windowStart = 0;
}
this.adjustToWindow_(windowStart, windowEnd);
},
};
return WaterfallView;
})();
|