Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 23 matching lines...) Expand all Loading... | |
| 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._overviewCalculator = new WebInspector.TimelineOverviewCalculator(); | 41 this._overviewCalculator = new WebInspector.TimelineOverviewCalculator(); |
| 42 this._overviewGrid = new WebInspector.OverviewGrid(prefix); | 42 this._overviewGrid = new WebInspector.OverviewGrid(prefix); |
| 43 this.element.appendChild(this._overviewGrid.element); | 43 this.element.appendChild(this._overviewGrid.element); |
| 44 this.element.addEventListener("mousemove", this._onMouseMove.bind(this), tru e); | |
| 44 | 45 |
| 45 this._overviewGrid.setResizeEnabled(false); | 46 this._overviewGrid.setResizeEnabled(false); |
| 46 this._overviewGrid.addEventListener(WebInspector.OverviewGrid.Events.WindowC hanged, this._onWindowChanged, this); | 47 this._overviewGrid.addEventListener(WebInspector.OverviewGrid.Events.WindowC hanged, this._onWindowChanged, this); |
| 47 this._overviewGrid.addEventListener(WebInspector.OverviewGrid.Events.Click, this._onClick, this); | 48 this._overviewGrid.addEventListener(WebInspector.OverviewGrid.Events.Click, this._onClick, this); |
| 48 this._overviewControls = []; | 49 this._overviewControls = []; |
| 49 this._markers = new Map(); | 50 this._markers = new Map(); |
| 51 | |
| 52 this._popoverHelper = new WebInspector.PopoverHelper(this.contentElement, th is._getPopoverAnchor.bind(this), this._showPopover.bind(this), this._onHidePopov er.bind(this)); | |
| 53 this._popoverHelper.setTimeout(0); | |
| 50 } | 54 } |
| 51 | 55 |
| 52 WebInspector.TimelineOverviewPane.Events = { | 56 WebInspector.TimelineOverviewPane.Events = { |
| 53 WindowChanged: "WindowChanged" | 57 WindowChanged: "WindowChanged" |
| 54 }; | 58 }; |
| 55 | 59 |
| 56 WebInspector.TimelineOverviewPane.prototype = { | 60 WebInspector.TimelineOverviewPane.prototype = { |
| 57 /** | 61 /** |
| 62 * @param {!Element} element | |
| 63 * @param {!Event} event | |
| 64 * @return {!Element|!AnchorBox|undefined} | |
| 65 */ | |
| 66 _getPopoverAnchor: function(element, event) | |
| 67 { | |
| 68 return this.element; | |
| 69 }, | |
| 70 | |
| 71 /** | |
| 72 * @param {!Element} anchor | |
| 73 * @param {!WebInspector.Popover} popover | |
| 74 */ | |
| 75 _showPopover: function(anchor, popover) | |
| 76 { | |
| 77 this._popover = popover; | |
| 78 this._popoverContents = createElement("div"); | |
| 79 if (!this._populatePopoverContents()) | |
| 80 return; | |
| 81 var content = new WebInspector.TimelineOverviewPane.PopoverContents(); | |
| 82 content.contentElement.appendChild(this._popoverContents); | |
| 83 popover.showView(content, this._overviewGrid.cursorElement()); | |
| 84 }, | |
| 85 | |
| 86 _onHidePopover: function() | |
| 87 { | |
| 88 this._popover = null; | |
| 89 this._popoverContents = null; | |
| 90 }, | |
| 91 | |
| 92 /** | |
| 93 * @param {!Event} event | |
| 94 */ | |
| 95 _onMouseMove: function(event) | |
| 96 { | |
| 97 if (!this._popover) | |
| 98 return; | |
| 99 this._populatePopoverContents(); | |
| 100 this._popover.positionElement(this._overviewGrid.cursorElement()); | |
| 101 }, | |
| 102 | |
| 103 _populatePopoverContents: function() | |
| 104 { | |
| 105 var cursor = this._overviewGrid.cursorElement(); | |
| 106 var x = cursor.offsetLeft; | |
| 107 var time = this._overviewCalculator.positionToTime(x); | |
| 108 var elements = []; | |
| 109 for (var control of this._overviewControls) { | |
| 110 var element = control.popoverElement(time); | |
| 111 if (element) | |
| 112 elements.push(element); | |
| 113 } | |
| 114 this._popoverContents.removeChildren(); | |
| 115 if (!elements.length) | |
| 116 return false; | |
| 117 elements.forEach(this._popoverContents.appendChild.bind(this._popoverCon tents)); | |
| 118 return true; | |
| 119 }, | |
| 120 | |
| 121 /** | |
| 58 * @override | 122 * @override |
| 59 */ | 123 */ |
| 60 wasShown: function() | 124 wasShown: function() |
| 61 { | 125 { |
| 62 this.update(); | 126 this.update(); |
| 63 }, | 127 }, |
| 64 | 128 |
| 65 /** | 129 /** |
| 66 * @override | 130 * @override |
| 67 */ | 131 */ |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 | 199 |
| 136 reset: function() | 200 reset: function() |
| 137 { | 201 { |
| 138 this._overviewCalculator.reset(); | 202 this._overviewCalculator.reset(); |
| 139 this._overviewGrid.reset(); | 203 this._overviewGrid.reset(); |
| 140 this._overviewGrid.setResizeEnabled(false); | 204 this._overviewGrid.setResizeEnabled(false); |
| 141 this._overviewGrid.updateDividers(this._overviewCalculator); | 205 this._overviewGrid.updateDividers(this._overviewCalculator); |
| 142 this._markers = new Map(); | 206 this._markers = new Map(); |
| 143 for (var i = 0; i < this._overviewControls.length; ++i) | 207 for (var i = 0; i < this._overviewControls.length; ++i) |
| 144 this._overviewControls[i].reset(); | 208 this._overviewControls[i].reset(); |
| 209 this._popoverHelper.hidePopover(); | |
| 145 this.update(); | 210 this.update(); |
| 146 }, | 211 }, |
| 147 | 212 |
| 148 /** | 213 /** |
| 149 * @param {!WebInspector.Event} event | 214 * @param {!WebInspector.Event} event |
| 150 */ | 215 */ |
| 151 _onClick: function(event) | 216 _onClick: function(event) |
| 152 { | 217 { |
| 153 var domEvent = /** @type {!Event} */ (event.data); | 218 var domEvent = /** @type {!Event} */ (event.data); |
| 154 for (var overviewControl of this._overviewControls) { | 219 for (var overviewControl of this._overviewControls) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 this._muteOnWindowChanged = true; | 262 this._muteOnWindowChanged = true; |
| 198 this._overviewGrid.setWindow(windowBoundaries.left, windowBoundaries.rig ht); | 263 this._overviewGrid.setWindow(windowBoundaries.left, windowBoundaries.rig ht); |
| 199 this._muteOnWindowChanged = false; | 264 this._muteOnWindowChanged = false; |
| 200 }, | 265 }, |
| 201 | 266 |
| 202 __proto__: WebInspector.VBox.prototype | 267 __proto__: WebInspector.VBox.prototype |
| 203 } | 268 } |
| 204 | 269 |
| 205 /** | 270 /** |
| 206 * @constructor | 271 * @constructor |
| 272 * @extends {WebInspector.VBox} | |
| 273 */ | |
| 274 WebInspector.TimelineOverviewPane.PopoverContents = function() | |
|
caseq
2015/06/16 14:14:50
Do you really need a class for this?
alph
2015/06/17 09:17:09
I made it a component, so children can inject thei
| |
| 275 { | |
| 276 WebInspector.VBox.call(this, true); | |
| 277 this.contentElement.classList.add("timeline-overview-popover"); | |
| 278 } | |
| 279 | |
| 280 WebInspector.TimelineOverviewPane.PopoverContents.prototype = { | |
| 281 __proto__: WebInspector.VBox.prototype | |
| 282 } | |
| 283 | |
| 284 /** | |
| 285 * @constructor | |
| 207 * @implements {WebInspector.TimelineGrid.Calculator} | 286 * @implements {WebInspector.TimelineGrid.Calculator} |
| 208 */ | 287 */ |
| 209 WebInspector.TimelineOverviewCalculator = function() | 288 WebInspector.TimelineOverviewCalculator = function() |
| 210 { | 289 { |
| 211 this.reset(); | 290 this.reset(); |
| 212 } | 291 } |
| 213 | 292 |
| 214 WebInspector.TimelineOverviewCalculator.prototype = { | 293 WebInspector.TimelineOverviewCalculator.prototype = { |
| 215 /** | 294 /** |
| 216 * @override | 295 * @override |
| 217 * @return {number} | 296 * @return {number} |
| 218 */ | 297 */ |
| 219 paddingLeft: function() | 298 paddingLeft: function() |
| 220 { | 299 { |
| 221 return this._paddingLeft; | 300 return this._paddingLeft; |
| 222 }, | 301 }, |
| 223 | 302 |
| 224 /** | 303 /** |
| 225 * @override | 304 * @override |
| 226 * @param {number} time | 305 * @param {number} time |
| 227 * @return {number} | 306 * @return {number} |
| 228 */ | 307 */ |
| 229 computePosition: function(time) | 308 computePosition: function(time) |
| 230 { | 309 { |
| 231 return (time - this._minimumBoundary) / this.boundarySpan() * this._work ingArea + this._paddingLeft; | 310 return (time - this._minimumBoundary) / this.boundarySpan() * this._work ingArea + this._paddingLeft; |
| 232 }, | 311 }, |
| 233 | 312 |
| 234 /** | 313 /** |
| 314 * @param {number} position | |
| 315 * @return {number} | |
| 316 */ | |
| 317 positionToTime: function(position) | |
| 318 { | |
| 319 return (position - this._paddingLeft) / this._workingArea * this.boundar ySpan() + this._minimumBoundary; | |
| 320 }, | |
| 321 | |
| 322 /** | |
| 235 * @param {number} minimumBoundary | 323 * @param {number} minimumBoundary |
| 236 * @param {number} maximumBoundary | 324 * @param {number} maximumBoundary |
| 237 */ | 325 */ |
| 238 setBounds: function(minimumBoundary, maximumBoundary) | 326 setBounds: function(minimumBoundary, maximumBoundary) |
| 239 { | 327 { |
| 240 this._minimumBoundary = minimumBoundary; | 328 this._minimumBoundary = minimumBoundary; |
| 241 this._maximumBoundary = maximumBoundary; | 329 this._maximumBoundary = maximumBoundary; |
| 242 }, | 330 }, |
| 243 | 331 |
| 244 /** | 332 /** |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 */ | 406 */ |
| 319 show: function(parentElement, insertBefore) { }, | 407 show: function(parentElement, insertBefore) { }, |
| 320 | 408 |
| 321 update: function() { }, | 409 update: function() { }, |
| 322 | 410 |
| 323 dispose: function() { }, | 411 dispose: function() { }, |
| 324 | 412 |
| 325 reset: function() { }, | 413 reset: function() { }, |
| 326 | 414 |
| 327 /** | 415 /** |
| 416 * @param {number} time | |
| 417 * @return {?Element} | |
| 418 */ | |
| 419 popoverElement: function(time) { }, | |
|
caseq
2015/06/16 14:14:50
Why is this interface in terms of time, not window
alph
2015/06/17 09:17:09
Done.
| |
| 420 | |
| 421 /** | |
| 328 * @param {!Event} event | 422 * @param {!Event} event |
| 329 * @return {boolean} | 423 * @return {boolean} |
| 330 */ | 424 */ |
| 331 onClick: function(event) { }, | 425 onClick: function(event) { }, |
| 332 | 426 |
| 333 /** | 427 /** |
| 334 * @param {number} windowLeft | 428 * @param {number} windowLeft |
| 335 * @param {number} windowRight | 429 * @param {number} windowRight |
| 336 * @return {!{startTime: number, endTime: number}} | 430 * @return {!{startTime: number, endTime: number}} |
| 337 */ | 431 */ |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 382 | 476 |
| 383 /** | 477 /** |
| 384 * @override | 478 * @override |
| 385 */ | 479 */ |
| 386 reset: function() | 480 reset: function() |
| 387 { | 481 { |
| 388 }, | 482 }, |
| 389 | 483 |
| 390 /** | 484 /** |
| 391 * @override | 485 * @override |
| 486 * @param {number} time | |
| 487 * @return {?Element} | |
| 488 */ | |
| 489 popoverElement: function(time) | |
| 490 { | |
| 491 return null; | |
| 492 }, | |
| 493 | |
| 494 /** | |
| 495 * @override | |
| 392 */ | 496 */ |
| 393 timelineStarted: function() | 497 timelineStarted: function() |
| 394 { | 498 { |
| 395 }, | 499 }, |
| 396 | 500 |
| 397 /** | 501 /** |
| 398 * @override | 502 * @override |
| 399 */ | 503 */ |
| 400 timelineStopped: function() | 504 timelineStopped: function() |
| 401 { | 505 { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 453 }, | 557 }, |
| 454 | 558 |
| 455 resetCanvas: function() | 559 resetCanvas: function() |
| 456 { | 560 { |
| 457 this._canvas.width = this.element.clientWidth * window.devicePixelRatio; | 561 this._canvas.width = this.element.clientWidth * window.devicePixelRatio; |
| 458 this._canvas.height = this.element.clientHeight * window.devicePixelRati o; | 562 this._canvas.height = this.element.clientHeight * window.devicePixelRati o; |
| 459 }, | 563 }, |
| 460 | 564 |
| 461 __proto__: WebInspector.VBox.prototype | 565 __proto__: WebInspector.VBox.prototype |
| 462 } | 566 } |
| OLD | NEW |