Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: Source/devtools/front_end/ui_lazy/TimelineOverviewPane.js

Issue 1183483011: DevTools: Support popover on timeline overview. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Addressing comments. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 20 matching lines...) Expand all
31 /** 31 /**
32 * @constructor 32 * @constructor
33 * @extends {WebInspector.VBox} 33 * @extends {WebInspector.VBox}
34 * @param {string} prefix 34 * @param {string} prefix
35 */ 35 */
36 WebInspector.TimelineOverviewPane = function(prefix) 36 WebInspector.TimelineOverviewPane = function(prefix)
37 { 37 {
38 WebInspector.VBox.call(this); 38 WebInspector.VBox.call(this);
39 this.element.id = prefix + "-overview-pane"; 39 this.element.id = prefix + "-overview-pane";
40 40
41 this._currentPositionElement = this.element.createChild("div", "overview-gri d-current-position");
41 this._overviewCalculator = new WebInspector.TimelineOverviewCalculator(); 42 this._overviewCalculator = new WebInspector.TimelineOverviewCalculator();
42 this._overviewGrid = new WebInspector.OverviewGrid(prefix); 43 this._overviewGrid = new WebInspector.OverviewGrid(prefix);
43 this.element.appendChild(this._overviewGrid.element); 44 this.element.appendChild(this._overviewGrid.element);
45 this.element.addEventListener("mousemove", this._onMouseMove.bind(this), tru e);
46 this.element.addEventListener("mouseout", this._hideCurrentPosition.bind(thi s), true);
44 47
45 this._overviewGrid.setResizeEnabled(false); 48 this._overviewGrid.setResizeEnabled(false);
46 this._overviewGrid.addEventListener(WebInspector.OverviewGrid.Events.WindowC hanged, this._onWindowChanged, this); 49 this._overviewGrid.addEventListener(WebInspector.OverviewGrid.Events.WindowC hanged, this._onWindowChanged, this);
47 this._overviewGrid.addEventListener(WebInspector.OverviewGrid.Events.Click, this._onClick, this); 50 this._overviewGrid.addEventListener(WebInspector.OverviewGrid.Events.Click, this._onClick, this);
48 this._overviewControls = []; 51 this._overviewControls = [];
49 this._markers = new Map(); 52 this._markers = new Map();
53
54 this._popoverHelper = new WebInspector.PopoverHelper(this.contentElement, th is._getPopoverAnchor.bind(this), this._showPopover.bind(this), this._onHidePopov er.bind(this));
55 this._popoverHelper.setTimeout(0);
56
57 this._cursorEnabled = false;
50 } 58 }
51 59
52 WebInspector.TimelineOverviewPane.Events = { 60 WebInspector.TimelineOverviewPane.Events = {
53 WindowChanged: "WindowChanged" 61 WindowChanged: "WindowChanged"
54 }; 62 };
55 63
56 WebInspector.TimelineOverviewPane.prototype = { 64 WebInspector.TimelineOverviewPane.prototype = {
57 /** 65 /**
66 * @param {!Element} element
67 * @param {!Event} event
68 * @return {!Element|!AnchorBox|undefined}
69 */
70 _getPopoverAnchor: function(element, event)
71 {
72 return this.element;
73 },
74
75 /**
76 * @param {!Element} anchor
77 * @param {!WebInspector.Popover} popover
78 */
79 _showPopover: function(anchor, popover)
80 {
81 this._popover = popover;
82 this._popoverContents = createElement("div");
83 if (!this._populatePopoverContents())
84 return;
85 var content = new WebInspector.TimelineOverviewPane.PopoverContents();
86 content.contentElement.appendChild(this._popoverContents);
87 popover.showView(content, this._currentPositionElement);
88 },
89
90 _onHidePopover: function()
91 {
92 this._popover = null;
93 this._popoverContents = null;
94 },
95
96 /**
97 * @param {!Event} event
98 */
99 _onMouseMove: function(event)
100 {
101 if (!this._cursorEnabled)
102 return;
103 var x = event.offsetX + event.target.offsetLeft;
104 this._currentPositionElement.style.left = x + "px";
105 this._currentPositionElement.style.visibility = "visible";
106 if (!this._popover)
107 return;
108 this._populatePopoverContents();
109 this._popover.positionElement(this._currentPositionElement);
110 },
111
112 _populatePopoverContents: function()
113 {
114 var cursor = this._currentPositionElement;
115 var x = cursor.offsetLeft;
caseq 2015/06/17 17:19:03 Can we instead do pass this from outside, so we do
116 var elements = [];
117 for (var control of this._overviewControls) {
118 var element = control.popoverElement(x);
119 if (element)
120 elements.push(element);
121 }
122 this._popoverContents.removeChildren();
123 if (!elements.length)
124 return false;
125 elements.forEach(this._popoverContents.appendChild.bind(this._popoverCon tents));
126 return true;
127 },
128
129 _hideCurrentPosition: function()
130 {
131 this._currentPositionElement.style.visibility = "hidden";
132 },
133
134 /**
58 * @override 135 * @override
59 */ 136 */
60 wasShown: function() 137 wasShown: function()
61 { 138 {
62 this.update(); 139 this.update();
63 }, 140 },
64 141
65 /** 142 /**
66 * @override 143 * @override
67 */ 144 */
(...skipping 19 matching lines...) Expand all
87 }, 164 },
88 165
89 /** 166 /**
90 * @param {number} minimumBoundary 167 * @param {number} minimumBoundary
91 * @param {number} maximumBoundary 168 * @param {number} maximumBoundary
92 */ 169 */
93 setBounds: function(minimumBoundary, maximumBoundary) 170 setBounds: function(minimumBoundary, maximumBoundary)
94 { 171 {
95 this._overviewCalculator.setBounds(minimumBoundary, maximumBoundary); 172 this._overviewCalculator.setBounds(minimumBoundary, maximumBoundary);
96 this._overviewGrid.setResizeEnabled(true); 173 this._overviewGrid.setResizeEnabled(true);
174 this._cursorEnabled = true;
97 }, 175 },
98 176
99 update: function() 177 update: function()
100 { 178 {
101 if (!this.isShowing()) 179 if (!this.isShowing())
102 return; 180 return;
103 this._overviewCalculator.setDisplayWindow(this._overviewGrid.clientWidth ()); 181 this._overviewCalculator.setDisplayWindow(this._overviewGrid.clientWidth ());
104 for (var i = 0; i < this._overviewControls.length; ++i) 182 for (var i = 0; i < this._overviewControls.length; ++i)
105 this._overviewControls[i].update(); 183 this._overviewControls[i].update();
106 this._overviewGrid.updateDividers(this._overviewCalculator); 184 this._overviewGrid.updateDividers(this._overviewCalculator);
(...skipping 25 matching lines...) Expand all
132 this._overviewGrid.removeEventDividers(); 210 this._overviewGrid.removeEventDividers();
133 this._overviewGrid.addEventDividers(filteredMarkers.valuesArray()); 211 this._overviewGrid.addEventDividers(filteredMarkers.valuesArray());
134 }, 212 },
135 213
136 reset: function() 214 reset: function()
137 { 215 {
138 this._overviewCalculator.reset(); 216 this._overviewCalculator.reset();
139 this._overviewGrid.reset(); 217 this._overviewGrid.reset();
140 this._overviewGrid.setResizeEnabled(false); 218 this._overviewGrid.setResizeEnabled(false);
141 this._overviewGrid.updateDividers(this._overviewCalculator); 219 this._overviewGrid.updateDividers(this._overviewCalculator);
220 this._cursorEnabled = false;
221 this._hideCurrentPosition();
142 this._markers = new Map(); 222 this._markers = new Map();
143 for (var i = 0; i < this._overviewControls.length; ++i) 223 for (var i = 0; i < this._overviewControls.length; ++i)
144 this._overviewControls[i].reset(); 224 this._overviewControls[i].reset();
225 this._popoverHelper.hidePopover();
145 this.update(); 226 this.update();
146 }, 227 },
147 228
148 /** 229 /**
149 * @param {!WebInspector.Event} event 230 * @param {!WebInspector.Event} event
150 */ 231 */
151 _onClick: function(event) 232 _onClick: function(event)
152 { 233 {
153 var domEvent = /** @type {!Event} */ (event.data); 234 var domEvent = /** @type {!Event} */ (event.data);
154 for (var overviewControl of this._overviewControls) { 235 for (var overviewControl of this._overviewControls) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 this._muteOnWindowChanged = true; 278 this._muteOnWindowChanged = true;
198 this._overviewGrid.setWindow(windowBoundaries.left, windowBoundaries.rig ht); 279 this._overviewGrid.setWindow(windowBoundaries.left, windowBoundaries.rig ht);
199 this._muteOnWindowChanged = false; 280 this._muteOnWindowChanged = false;
200 }, 281 },
201 282
202 __proto__: WebInspector.VBox.prototype 283 __proto__: WebInspector.VBox.prototype
203 } 284 }
204 285
205 /** 286 /**
206 * @constructor 287 * @constructor
288 * @extends {WebInspector.VBox}
289 */
290 WebInspector.TimelineOverviewPane.PopoverContents = function()
291 {
292 WebInspector.VBox.call(this, true);
293 this.contentElement.classList.add("timeline-overview-popover");
294 }
295
296 WebInspector.TimelineOverviewPane.PopoverContents.prototype = {
297 __proto__: WebInspector.VBox.prototype
298 }
299
300 /**
301 * @constructor
207 * @implements {WebInspector.TimelineGrid.Calculator} 302 * @implements {WebInspector.TimelineGrid.Calculator}
208 */ 303 */
209 WebInspector.TimelineOverviewCalculator = function() 304 WebInspector.TimelineOverviewCalculator = function()
210 { 305 {
211 this.reset(); 306 this.reset();
212 } 307 }
213 308
214 WebInspector.TimelineOverviewCalculator.prototype = { 309 WebInspector.TimelineOverviewCalculator.prototype = {
215 /** 310 /**
216 * @override 311 * @override
217 * @return {number} 312 * @return {number}
218 */ 313 */
219 paddingLeft: function() 314 paddingLeft: function()
220 { 315 {
221 return this._paddingLeft; 316 return this._paddingLeft;
222 }, 317 },
223 318
224 /** 319 /**
225 * @override 320 * @override
226 * @param {number} time 321 * @param {number} time
227 * @return {number} 322 * @return {number}
228 */ 323 */
229 computePosition: function(time) 324 computePosition: function(time)
230 { 325 {
231 return (time - this._minimumBoundary) / this.boundarySpan() * this._work ingArea + this._paddingLeft; 326 return (time - this._minimumBoundary) / this.boundarySpan() * this._work ingArea + this._paddingLeft;
232 }, 327 },
233 328
234 /** 329 /**
330 * @param {number} position
331 * @return {number}
332 */
333 positionToTime: function(position)
caseq 2015/06/17 17:19:03 unused?
334 {
335 return (position - this._paddingLeft) / this._workingArea * this.boundar ySpan() + this._minimumBoundary;
336 },
337
338 /**
235 * @param {number} minimumBoundary 339 * @param {number} minimumBoundary
236 * @param {number} maximumBoundary 340 * @param {number} maximumBoundary
237 */ 341 */
238 setBounds: function(minimumBoundary, maximumBoundary) 342 setBounds: function(minimumBoundary, maximumBoundary)
239 { 343 {
240 this._minimumBoundary = minimumBoundary; 344 this._minimumBoundary = minimumBoundary;
241 this._maximumBoundary = maximumBoundary; 345 this._maximumBoundary = maximumBoundary;
242 }, 346 },
243 347
244 /** 348 /**
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 */ 422 */
319 show: function(parentElement, insertBefore) { }, 423 show: function(parentElement, insertBefore) { },
320 424
321 update: function() { }, 425 update: function() { },
322 426
323 dispose: function() { }, 427 dispose: function() { },
324 428
325 reset: function() { }, 429 reset: function() { },
326 430
327 /** 431 /**
432 * @param {number} x
433 * @return {?Element}
434 */
435 popoverElement: function(x) { },
436
437 /**
328 * @param {!Event} event 438 * @param {!Event} event
329 * @return {boolean} 439 * @return {boolean}
330 */ 440 */
331 onClick: function(event) { }, 441 onClick: function(event) { },
332 442
333 /** 443 /**
334 * @param {number} windowLeft 444 * @param {number} windowLeft
335 * @param {number} windowRight 445 * @param {number} windowRight
336 * @return {!{startTime: number, endTime: number}} 446 * @return {!{startTime: number, endTime: number}}
337 */ 447 */
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 492
383 /** 493 /**
384 * @override 494 * @override
385 */ 495 */
386 reset: function() 496 reset: function()
387 { 497 {
388 }, 498 },
389 499
390 /** 500 /**
391 * @override 501 * @override
502 * @param {number} x
503 * @return {?Element}
504 */
505 popoverElement: function(x)
506 {
507 return null;
508 },
509
510 /**
511 * @override
392 */ 512 */
393 timelineStarted: function() 513 timelineStarted: function()
394 { 514 {
395 }, 515 },
396 516
397 /** 517 /**
398 * @override 518 * @override
399 */ 519 */
400 timelineStopped: function() 520 timelineStopped: function()
401 { 521 {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 }, 573 },
454 574
455 resetCanvas: function() 575 resetCanvas: function()
456 { 576 {
457 this._canvas.width = this.element.clientWidth * window.devicePixelRatio; 577 this._canvas.width = this.element.clientWidth * window.devicePixelRatio;
458 this._canvas.height = this.element.clientHeight * window.devicePixelRati o; 578 this._canvas.height = this.element.clientHeight * window.devicePixelRati o;
459 }, 579 },
460 580
461 __proto__: WebInspector.VBox.prototype 581 __proto__: WebInspector.VBox.prototype
462 } 582 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698