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 13 matching lines...) Expand all Loading... | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * @constructor | 32 * @constructor |
| 33 * @extends {WebInspector.VBox} | 33 * @extends {WebInspector.VBox} |
| 34 * @param {string} prefix | |
| 34 */ | 35 */ |
| 35 WebInspector.TimelineOverviewPane = function() | 36 WebInspector.TimelineOverviewPane = function(prefix) |
| 36 { | 37 { |
| 37 WebInspector.VBox.call(this); | 38 WebInspector.VBox.call(this); |
| 38 this.element.id = "timeline-overview-pane"; | 39 this.element.id = prefix + "-overview-pane"; |
| 39 | 40 |
| 40 this._overviewCalculator = new WebInspector.TimelineOverviewCalculator(); | 41 this._overviewCalculator = new WebInspector.TimelineOverviewCalculator(); |
| 41 this._overviewCalculator._setWindow(0, 1000); | 42 this._overviewGrid = new WebInspector.OverviewGrid(prefix); |
| 42 | |
| 43 this._overviewGrid = new WebInspector.OverviewGrid("timeline"); | |
| 44 this.element.appendChild(this._overviewGrid.element); | 43 this.element.appendChild(this._overviewGrid.element); |
| 45 | 44 |
| 46 this._overviewGrid.setResizeEnabled(false); | 45 this._overviewGrid.setResizeEnabled(false); |
| 47 this._overviewGrid.addEventListener(WebInspector.OverviewGrid.Events.WindowC hanged, this._onWindowChanged, this); | 46 this._overviewGrid.addEventListener(WebInspector.OverviewGrid.Events.WindowC hanged, this._onWindowChanged, this); |
| 48 this._overviewGrid.addEventListener(WebInspector.OverviewGrid.Events.Click, this._onClick, this); | 47 this._overviewGrid.addEventListener(WebInspector.OverviewGrid.Events.Click, this._onClick, this); |
| 49 this._overviewControls = []; | 48 this._overviewControls = []; |
| 50 this._markers = new Map(); | 49 this._markers = new Map(); |
| 51 } | 50 } |
| 52 | 51 |
| 53 WebInspector.TimelineOverviewPane.Events = { | 52 WebInspector.TimelineOverviewPane.Events = { |
| 54 WindowChanged: "WindowChanged", | 53 WindowChanged: Symbol("WindowChanged") |
|
yurys
2015/06/11 15:33:36
If you allow to use Symbols for event names, you s
alph
2015/06/11 16:35:00
Acknowledged.
| |
| 55 SelectionChanged: "SelectionChanged" | |
| 56 }; | 54 }; |
| 57 | 55 |
| 58 WebInspector.TimelineOverviewPane.prototype = { | 56 WebInspector.TimelineOverviewPane.prototype = { |
| 59 /** | 57 /** |
| 60 * @override | 58 * @override |
| 61 */ | 59 */ |
| 62 wasShown: function() | 60 wasShown: function() |
| 63 { | 61 { |
| 64 this.update(); | 62 this.update(); |
| 65 }, | 63 }, |
| 66 | 64 |
| 67 /** | 65 /** |
| 68 * @override | 66 * @override |
| 69 */ | 67 */ |
| 70 onResize: function() | 68 onResize: function() |
| 71 { | 69 { |
| 72 this.update(); | 70 this.update(); |
| 73 }, | 71 }, |
| 74 | 72 |
| 75 /** | 73 /** |
| 76 * @param {!Array.<!WebInspector.TimelineOverview>} overviewControls | 74 * @param {!Array.<!WebInspector.TimelineOverview>} overviewControls |
| 77 */ | 75 */ |
| 78 setOverviewControls: function(overviewControls) | 76 setOverviewControls: function(overviewControls) |
| 79 { | 77 { |
| 80 for (var i = 0; i < this._overviewControls.length; ++i) | 78 for (var i = 0; i < this._overviewControls.length; ++i) |
| 81 this._overviewControls[i].dispose(); | 79 this._overviewControls[i].dispose(); |
| 82 | 80 |
| 83 for (var i = 0; i < overviewControls.length; ++i) { | 81 for (var i = 0; i < overviewControls.length; ++i) { |
| 82 overviewControls[i].setCalculator(this._overviewCalculator); | |
| 84 overviewControls[i].show(this._overviewGrid.element); | 83 overviewControls[i].show(this._overviewGrid.element); |
| 85 if (this._currentSelection) | |
| 86 overviewControls[i].select(this._currentSelection); | |
| 87 } | 84 } |
| 88 this._overviewControls = overviewControls; | 85 this._overviewControls = overviewControls; |
| 89 this.update(); | 86 this.update(); |
| 90 }, | 87 }, |
| 91 | 88 |
| 92 /** | 89 /** |
| 93 * @param {number} minimumBoundary | 90 * @param {number} minimumBoundary |
| 94 * @param {number} maximumBoundary | 91 * @param {number} maximumBoundary |
| 95 */ | 92 */ |
| 96 setBounds: function(minimumBoundary, maximumBoundary) | 93 setBounds: function(minimumBoundary, maximumBoundary) |
| 97 { | 94 { |
| 98 this._overviewCalculator._setWindow(minimumBoundary, maximumBoundary); | 95 this._overviewCalculator.setBounds(minimumBoundary, maximumBoundary); |
| 99 this._overviewGrid.setResizeEnabled(true); | 96 this._overviewGrid.setResizeEnabled(true); |
| 100 }, | 97 }, |
| 101 | 98 |
| 102 update: function() | 99 update: function() |
| 103 { | 100 { |
| 104 if (!this.isShowing()) | 101 if (!this.isShowing()) |
| 105 return; | 102 return; |
| 106 this._overviewCalculator._setDisplayWindow(0, this._overviewGrid.clientW idth()); | 103 this._overviewCalculator.setDisplayWindow(this._overviewGrid.clientWidth ()); |
| 107 for (var i = 0; i < this._overviewControls.length; ++i) | 104 for (var i = 0; i < this._overviewControls.length; ++i) |
| 108 this._overviewControls[i].update(); | 105 this._overviewControls[i].update(); |
| 109 this._overviewGrid.updateDividers(this._overviewCalculator); | 106 this._overviewGrid.updateDividers(this._overviewCalculator); |
| 110 this._updateMarkers(); | 107 this._updateMarkers(); |
| 111 this._updateWindow(); | 108 this._updateWindow(); |
| 112 }, | 109 }, |
| 113 | 110 |
| 114 /** | 111 /** |
| 115 * @param {?WebInspector.TimelineSelection} selection | |
| 116 */ | |
| 117 select: function(selection) | |
| 118 { | |
| 119 this._currentSelection = selection; | |
| 120 for (var overviewControl of this._overviewControls) | |
| 121 overviewControl.select(selection); | |
| 122 }, | |
| 123 | |
| 124 /** | |
| 125 * @param {!Map<number, !Element>} markers | 112 * @param {!Map<number, !Element>} markers |
| 126 */ | 113 */ |
| 127 setMarkers: function(markers) | 114 setMarkers: function(markers) |
| 128 { | 115 { |
| 129 this._markers = markers; | 116 this._markers = markers; |
| 130 this._updateMarkers(); | 117 this._updateMarkers(); |
| 131 }, | 118 }, |
| 132 | 119 |
| 133 _updateMarkers: function() | 120 _updateMarkers: function() |
| 134 { | 121 { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 157 this._overviewControls[i].reset(); | 144 this._overviewControls[i].reset(); |
| 158 this.update(); | 145 this.update(); |
| 159 }, | 146 }, |
| 160 | 147 |
| 161 /** | 148 /** |
| 162 * @param {!WebInspector.Event} event | 149 * @param {!WebInspector.Event} event |
| 163 */ | 150 */ |
| 164 _onClick: function(event) | 151 _onClick: function(event) |
| 165 { | 152 { |
| 166 var domEvent = /** @type {!Event} */ (event.data); | 153 var domEvent = /** @type {!Event} */ (event.data); |
| 167 var selection; | |
| 168 for (var overviewControl of this._overviewControls) { | 154 for (var overviewControl of this._overviewControls) { |
| 169 selection = overviewControl.selectionFromEvent(domEvent); | 155 if (overviewControl.onClick(domEvent)) { |
| 170 if (selection) | 156 event.preventDefault(); |
| 171 break; | 157 return; |
| 158 } | |
| 172 } | 159 } |
| 173 if (typeof selection !== "object") | |
| 174 return; | |
| 175 event.preventDefault(); | |
| 176 this.dispatchEventToListeners(WebInspector.TimelineOverviewPane.Events.S electionChanged, selection); | |
| 177 }, | 160 }, |
| 178 | 161 |
| 179 /** | 162 /** |
| 180 * @param {!WebInspector.Event} event | 163 * @param {!WebInspector.Event} event |
| 181 */ | 164 */ |
| 182 _onWindowChanged: function(event) | 165 _onWindowChanged: function(event) |
| 183 { | 166 { |
| 184 if (this._muteOnWindowChanged) | 167 if (this._muteOnWindowChanged) |
| 185 return; | 168 return; |
| 186 // Always use first control as a time converter. | 169 // Always use first control as a time converter. |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 | 201 |
| 219 __proto__: WebInspector.VBox.prototype | 202 __proto__: WebInspector.VBox.prototype |
| 220 } | 203 } |
| 221 | 204 |
| 222 /** | 205 /** |
| 223 * @constructor | 206 * @constructor |
| 224 * @implements {WebInspector.TimelineGrid.Calculator} | 207 * @implements {WebInspector.TimelineGrid.Calculator} |
| 225 */ | 208 */ |
| 226 WebInspector.TimelineOverviewCalculator = function() | 209 WebInspector.TimelineOverviewCalculator = function() |
| 227 { | 210 { |
| 211 this.reset(); | |
| 228 } | 212 } |
| 229 | 213 |
| 230 WebInspector.TimelineOverviewCalculator.prototype = { | 214 WebInspector.TimelineOverviewCalculator.prototype = { |
| 231 /** | 215 /** |
| 232 * @override | 216 * @override |
| 233 * @return {number} | 217 * @return {number} |
| 234 */ | 218 */ |
| 235 paddingLeft: function() | 219 paddingLeft: function() |
| 236 { | 220 { |
| 237 return this._paddingLeft; | 221 return this._paddingLeft; |
| 238 }, | 222 }, |
| 239 | 223 |
| 240 /** | 224 /** |
| 241 * @override | 225 * @override |
| 242 * @param {number} time | 226 * @param {number} time |
| 243 * @return {number} | 227 * @return {number} |
| 244 */ | 228 */ |
| 245 computePosition: function(time) | 229 computePosition: function(time) |
| 246 { | 230 { |
| 247 return (time - this._minimumBoundary) / this.boundarySpan() * this._work ingArea + this._paddingLeft; | 231 return (time - this._minimumBoundary) / this.boundarySpan() * this._work ingArea + this._paddingLeft; |
| 248 }, | 232 }, |
| 249 | 233 |
| 250 /** | 234 /** |
| 251 * @param {number=} minimumRecordTime | 235 * @param {number} minimumBoundary |
| 252 * @param {number=} maximumRecordTime | 236 * @param {number} maximumBoundary |
| 253 */ | 237 */ |
| 254 _setWindow: function(minimumRecordTime, maximumRecordTime) | 238 setBounds: function(minimumBoundary, maximumBoundary) |
| 255 { | 239 { |
| 256 this._minimumBoundary = minimumRecordTime; | 240 this._minimumBoundary = minimumBoundary; |
| 257 this._maximumBoundary = maximumRecordTime; | 241 this._maximumBoundary = maximumBoundary; |
| 258 }, | 242 }, |
| 259 | 243 |
| 260 /** | 244 /** |
| 261 * @param {number} paddingLeft | |
| 262 * @param {number} clientWidth | 245 * @param {number} clientWidth |
| 246 * @param {number=} paddingLeft | |
| 263 */ | 247 */ |
| 264 _setDisplayWindow: function(paddingLeft, clientWidth) | 248 setDisplayWindow: function(clientWidth, paddingLeft) |
| 265 { | 249 { |
| 266 this._workingArea = clientWidth - paddingLeft; | 250 this._paddingLeft = paddingLeft || 0; |
| 267 this._paddingLeft = paddingLeft; | 251 this._workingArea = clientWidth - this._paddingLeft; |
| 268 }, | 252 }, |
| 269 | 253 |
| 270 reset: function() | 254 reset: function() |
| 271 { | 255 { |
| 272 this._setWindow(0, 1000); | 256 this.setBounds(0, 1000); |
| 273 }, | 257 }, |
| 274 | 258 |
| 275 /** | 259 /** |
| 276 * @override | 260 * @override |
| 277 * @param {number} value | 261 * @param {number} value |
| 278 * @param {number=} precision | 262 * @param {number=} precision |
| 279 * @return {string} | 263 * @return {string} |
| 280 */ | 264 */ |
| 281 formatTime: function(value, precision) | 265 formatTime: function(value, precision) |
| 282 { | 266 { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 */ | 300 */ |
| 317 boundarySpan: function() | 301 boundarySpan: function() |
| 318 { | 302 { |
| 319 return this._maximumBoundary - this._minimumBoundary; | 303 return this._maximumBoundary - this._minimumBoundary; |
| 320 } | 304 } |
| 321 } | 305 } |
| 322 | 306 |
| 323 /** | 307 /** |
| 324 * @interface | 308 * @interface |
| 325 */ | 309 */ |
| 326 WebInspector.TimelineOverview = function(model) | 310 WebInspector.TimelineOverview = function() |
| 327 { | 311 { |
| 328 } | 312 } |
| 329 | 313 |
| 330 WebInspector.TimelineOverview.prototype = { | 314 WebInspector.TimelineOverview.prototype = { |
| 331 /** | 315 /** |
| 332 * @param {?Element} parentElement | 316 * @param {?Element} parentElement |
| 333 * @param {!Element=} insertBefore | 317 * @param {!Element=} insertBefore |
| 334 */ | 318 */ |
| 335 show: function(parentElement, insertBefore) { }, | 319 show: function(parentElement, insertBefore) { }, |
| 336 | 320 |
| 337 update: function() { }, | 321 update: function() { }, |
| 338 | 322 |
| 339 dispose: function() { }, | 323 dispose: function() { }, |
| 340 | 324 |
| 341 reset: function() { }, | 325 reset: function() { }, |
| 342 | 326 |
| 343 /** | 327 /** |
| 344 * @param {!WebInspector.TimelineSelection} selection | 328 * @param {!Event} event |
| 329 * @return {boolean} | |
| 345 */ | 330 */ |
| 346 select: function(selection) { }, | 331 onClick: function(event) { }, |
| 347 | |
| 348 /** | |
| 349 * @param {!Event} event | |
| 350 * @return {?WebInspector.TimelineSelection|undefined} | |
| 351 */ | |
| 352 selectionFromEvent: function(event) { }, | |
| 353 | 332 |
| 354 /** | 333 /** |
| 355 * @param {number} windowLeft | 334 * @param {number} windowLeft |
| 356 * @param {number} windowRight | 335 * @param {number} windowRight |
| 357 * @return {!{startTime: number, endTime: number}} | 336 * @return {!{startTime: number, endTime: number}} |
| 358 */ | 337 */ |
| 359 windowTimes: function(windowLeft, windowRight) { }, | 338 windowTimes: function(windowLeft, windowRight) { }, |
| 360 | 339 |
| 361 /** | 340 /** |
| 362 * @param {number} startTime | 341 * @param {number} startTime |
| 363 * @param {number} endTime | 342 * @param {number} endTime |
| 364 * @return {!{left: number, right: number}} | 343 * @return {!{left: number, right: number}} |
| 365 */ | 344 */ |
| 366 windowBoundaries: function(startTime, endTime) { }, | 345 windowBoundaries: function(startTime, endTime) { }, |
| 367 | 346 |
| 368 timelineStarted: function() { }, | 347 timelineStarted: function() { }, |
| 369 | 348 |
| 370 timelineStopped: function() { }, | 349 timelineStopped: function() { }, |
| 371 } | 350 } |
| 372 | 351 |
| 373 /** | 352 /** |
| 374 * @constructor | 353 * @constructor |
| 375 * @extends {WebInspector.VBox} | 354 * @extends {WebInspector.VBox} |
| 376 * @implements {WebInspector.TimelineOverview} | 355 * @implements {WebInspector.TimelineOverview} |
| 377 * @param {!WebInspector.TimelineModel} model | |
| 378 */ | 356 */ |
| 379 WebInspector.TimelineOverviewBase = function(model) | 357 WebInspector.TimelineOverviewBase = function() |
| 380 { | 358 { |
| 381 WebInspector.VBox.call(this); | 359 WebInspector.VBox.call(this); |
| 382 | 360 /** @type {?WebInspector.TimelineOverviewCalculator} */ |
| 383 this._model = model; | 361 this._calculator = null; |
| 384 this._canvas = this.element.createChild("canvas", "fill"); | 362 this._canvas = this.element.createChild("canvas", "fill"); |
| 385 this._context = this._canvas.getContext("2d"); | 363 this._context = this._canvas.getContext("2d"); |
| 386 } | 364 } |
| 387 | 365 |
| 388 WebInspector.TimelineOverviewBase.prototype = { | 366 WebInspector.TimelineOverviewBase.prototype = { |
| 389 /** | 367 /** |
| 390 * @override | 368 * @override |
| 391 */ | 369 */ |
| 392 update: function() | 370 update: function() |
| 393 { | 371 { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 417 }, | 395 }, |
| 418 | 396 |
| 419 /** | 397 /** |
| 420 * @override | 398 * @override |
| 421 */ | 399 */ |
| 422 timelineStopped: function() | 400 timelineStopped: function() |
| 423 { | 401 { |
| 424 }, | 402 }, |
| 425 | 403 |
| 426 /** | 404 /** |
| 405 * @param {!WebInspector.TimelineOverviewCalculator} calculator | |
| 406 */ | |
| 407 setCalculator: function(calculator) | |
| 408 { | |
| 409 this._calculator = calculator; | |
| 410 }, | |
| 411 | |
| 412 /** | |
| 427 * @override | 413 * @override |
| 428 * @param {!WebInspector.TimelineSelection} selection | 414 * @param {!Event} event |
| 415 * @return {boolean} | |
| 429 */ | 416 */ |
| 430 select: function(selection) { }, | 417 onClick: function(event) |
| 431 | |
| 432 /** | |
| 433 * @override | |
| 434 * @param {!Event} event | |
| 435 * @return {?WebInspector.TimelineSelection|undefined} | |
| 436 */ | |
| 437 selectionFromEvent: function(event) | |
| 438 { | 418 { |
| 439 return undefined; | 419 return false; |
| 440 }, | 420 }, |
| 441 | 421 |
| 442 /** | 422 /** |
| 443 * @override | 423 * @override |
| 444 * @param {number} windowLeft | 424 * @param {number} windowLeft |
| 445 * @param {number} windowRight | 425 * @param {number} windowRight |
| 446 * @return {!{startTime: number, endTime: number}} | 426 * @return {!{startTime: number, endTime: number}} |
| 447 */ | 427 */ |
| 448 windowTimes: function(windowLeft, windowRight) | 428 windowTimes: function(windowLeft, windowRight) |
| 449 { | 429 { |
| 450 var absoluteMin = this._model.minimumRecordTime(); | 430 var absoluteMin = this._calculator.minimumBoundary(); |
|
yurys
2015/06/11 15:33:36
Do we need this code in base?
alph
2015/06/11 16:35:00
I'd like to have a default implementation in base.
| |
| 451 var timeSpan = this._model.maximumRecordTime() - absoluteMin; | 431 var timeSpan = this._calculator.maximumBoundary() - absoluteMin; |
| 452 return { | 432 return { |
| 453 startTime: absoluteMin + timeSpan * windowLeft, | 433 startTime: absoluteMin + timeSpan * windowLeft, |
| 454 endTime: absoluteMin + timeSpan * windowRight | 434 endTime: absoluteMin + timeSpan * windowRight |
| 455 }; | 435 }; |
| 456 }, | 436 }, |
| 457 | 437 |
| 458 /** | 438 /** |
| 459 * @override | 439 * @override |
| 460 * @param {number} startTime | 440 * @param {number} startTime |
| 461 * @param {number} endTime | 441 * @param {number} endTime |
| 462 * @return {!{left: number, right: number}} | 442 * @return {!{left: number, right: number}} |
| 463 */ | 443 */ |
| 464 windowBoundaries: function(startTime, endTime) | 444 windowBoundaries: function(startTime, endTime) |
| 465 { | 445 { |
| 466 var absoluteMin = this._model.minimumRecordTime(); | 446 var absoluteMin = this._calculator.minimumBoundary(); |
| 467 var timeSpan = this._model.maximumRecordTime() - absoluteMin; | 447 var timeSpan = this._calculator.maximumBoundary() - absoluteMin; |
| 468 var haveRecords = absoluteMin > 0; | 448 var haveRecords = absoluteMin > 0; |
| 469 return { | 449 return { |
| 470 left: haveRecords && startTime ? Math.min((startTime - absoluteMin) / timeSpan, 1) : 0, | 450 left: haveRecords && startTime ? Math.min((startTime - absoluteMin) / timeSpan, 1) : 0, |
| 471 right: haveRecords && endTime < Infinity ? (endTime - absoluteMin) / timeSpan : 1 | 451 right: haveRecords && endTime < Infinity ? (endTime - absoluteMin) / timeSpan : 1 |
| 472 }; | 452 }; |
| 473 }, | 453 }, |
| 474 | 454 |
| 475 resetCanvas: function() | 455 resetCanvas: function() |
| 476 { | 456 { |
| 477 this._canvas.width = this.element.clientWidth * window.devicePixelRatio; | 457 this._canvas.width = this.element.clientWidth * window.devicePixelRatio; |
| 478 this._canvas.height = this.element.clientHeight * window.devicePixelRati o; | 458 this._canvas.height = this.element.clientHeight * window.devicePixelRati o; |
| 479 }, | 459 }, |
| 480 | 460 |
| 481 __proto__: WebInspector.VBox.prototype | 461 __proto__: WebInspector.VBox.prototype |
| 482 } | 462 } |
| OLD | NEW |