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 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107
|
/*
* Copyright (C) 2013, 2015-2016 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
WI.TimelineOverview = class TimelineOverview extends WI.View
{
constructor(timelineRecording)
{
super();
console.assert(timelineRecording instanceof WI.TimelineRecording);
this._timelinesViewModeSettings = this._createViewModeSettings(WI.TimelineOverview.ViewMode.Timelines, WI.TimelineOverview.MinimumDurationPerPixel, WI.TimelineOverview.MaximumDurationPerPixel, 0.01, 0, 15);
this._instrumentTypes = WI.TimelineManager.availableTimelineTypes();
let minimumDurationPerPixel = 1 / WI.TimelineRecordFrame.MaximumWidthPixels;
let maximumDurationPerPixel = 1 / WI.TimelineRecordFrame.MinimumWidthPixels;
this._renderingFramesViewModeSettings = this._createViewModeSettings(WI.TimelineOverview.ViewMode.RenderingFrames, minimumDurationPerPixel, maximumDurationPerPixel, minimumDurationPerPixel, 0, 100);
this._recording = timelineRecording;
this._recording.addEventListener(WI.TimelineRecording.Event.InstrumentAdded, this._instrumentAdded, this);
this._recording.addEventListener(WI.TimelineRecording.Event.InstrumentRemoved, this._instrumentRemoved, this);
this._recording.addEventListener(WI.TimelineRecording.Event.MarkerAdded, this._markerAdded, this);
this._recording.addEventListener(WI.TimelineRecording.Event.Reset, this._recordingReset, this);
this.element.classList.add("timeline-overview");
this._updateWheelAndGestureHandlers();
this._graphsContainerView = new WI.View;
this._graphsContainerView.element.classList.add("graphs-container");
this._graphsContainerView.element.addEventListener("click", this._handleGraphsContainerClick.bind(this));
this.addSubview(this._graphsContainerView);
this._selectedTimelineRecord = null;
this._overviewGraphsByTypeMap = new Map;
this._editInstrumentsButton = new WI.ActivateButtonNavigationItem("toggle-edit-instruments", WI.UIString("Edit configuration"), WI.UIString("Save configuration"), "Images/Pencil.svg", 16, 16);
this._editInstrumentsButton.addEventListener(WI.ButtonNavigationItem.Event.Clicked, this._toggleEditingInstruments, this);
this._editingInstruments = false;
this._updateEditInstrumentsButton();
let instrumentsNavigationBar = new WI.NavigationBar;
instrumentsNavigationBar.element.classList.add("timelines");
instrumentsNavigationBar.addNavigationItem(new WI.TextNavigationItem("enabled-timelines", WI.UIString("Enabled Timelines", "Enabled Timelines @ Timelines Tab", "Label for column showing the list of enabled timelines.")));
instrumentsNavigationBar.addNavigationItem(new WI.FlexibleSpaceNavigationItem);
instrumentsNavigationBar.addNavigationItem(this._editInstrumentsButton);
this.addSubview(instrumentsNavigationBar);
this._timelinesTreeOutline = new WI.TreeOutline;
this._timelinesTreeOutline.element.classList.add("timelines");
this._timelinesTreeOutline.disclosureButtons = false;
this._timelinesTreeOutline.large = true;
this._timelinesTreeOutline.addEventListener(WI.TreeOutline.Event.SelectionDidChange, this._timelinesTreeSelectionDidChange, this);
this.element.appendChild(this._timelinesTreeOutline.element);
this._treeElementsByTypeMap = new Map;
this._timelineRuler = new WI.TimelineRuler;
this._timelineRuler.allowsClippedLabels = true;
this._timelineRuler.allowsTimeRangeSelection = true;
this._timelineRuler.element.addEventListener("mousedown", this._timelineRulerMouseDown.bind(this));
this._timelineRuler.element.addEventListener("click", this._timelineRulerMouseClicked.bind(this));
this._timelineRuler.addEventListener(WI.TimelineRuler.Event.TimeRangeSelectionChanged, this._timeRangeSelectionChanged, this);
this.addSubview(this._timelineRuler);
this._currentTimeMarker = new WI.TimelineMarker(0, WI.TimelineMarker.Type.CurrentTime);
this._timelineRuler.addMarker(this._currentTimeMarker);
this._scrollContainerElement = document.createElement("div");
this._scrollContainerElement.classList.add("scroll-container");
this._scrollContainerElement.addEventListener("scroll", this._handleScrollEvent.bind(this));
this.element.appendChild(this._scrollContainerElement);
this._scrollWidthSizer = document.createElement("div");
this._scrollWidthSizer.classList.add("scroll-width-sizer");
this._scrollContainerElement.appendChild(this._scrollWidthSizer);
this._startTime = 0;
this._currentTime = 0;
this._revealCurrentTime = false;
this._endTime = 0;
this._pixelAlignDuration = false;
this._mouseWheelDelta = 0;
this._cachedScrollContainerWidth = NaN;
this._timelineRulerSelectionChanged = false;
this._viewMode = WI.TimelineOverview.ViewMode.Timelines;
this._selectedTimeline = null;
for (let instrument of this._recording.instruments)
this._instrumentAdded(instrument);
if (!WI.timelineManager.isCapturingPageReload())
this._resetSelection();
this._viewModeDidChange();
WI.timelineManager.addEventListener(WI.TimelineManager.Event.CapturingStateChanged, this._handleTimelineCapturingStateChanged, this);
WI.timelineManager.addEventListener(WI.TimelineManager.Event.RecordingImported, this._recordingImported, this);
}
// Import / Export
exportData()
{
let json = {
secondsPerPixel: this.secondsPerPixel,
scrollStartTime: this.scrollStartTime,
selectionStartTime: this.selectionStartTime,
selectionDuration: this.selectionDuration,
};
if (this._selectedTimeline)
json.selectedTimelineType = this._selectedTimeline.type;
return json;
}
// Public
get selectedTimeline()
{
return this._selectedTimeline;
}
set selectedTimeline(x)
{
if (this._editingInstruments)
return;
if (this._selectedTimeline === x)
return;
this._selectedTimeline = x;
if (this._selectedTimeline) {
let treeElement = this._treeElementsByTypeMap.get(this._selectedTimeline.type);
console.assert(treeElement, "Missing tree element for timeline", this._selectedTimeline);
let omitFocus = true;
let wasSelectedByUser = false;
treeElement.select(omitFocus, wasSelectedByUser);
} else if (this._timelinesTreeOutline.selectedTreeElement)
this._timelinesTreeOutline.selectedTreeElement.deselect();
}
get editingInstruments()
{
return this._editingInstruments;
}
get viewMode()
{
return this._viewMode;
}
set viewMode(x)
{
if (this._viewMode === x)
return;
this._viewMode = x;
this._viewModeDidChange();
}
get startTime()
{
return this._startTime;
}
set startTime(x)
{
x = x || 0;
if (this._startTime === x)
return;
if (this._viewMode !== WI.TimelineOverview.ViewMode.RenderingFrames) {
let selectionOffset = this.selectionStartTime - this._startTime;
this.selectionStartTime = selectionOffset + x;
}
this._startTime = x;
this.needsLayout();
}
get currentTime()
{
return this._currentTime;
}
set currentTime(x)
{
x = x || 0;
if (this._currentTime === x)
return;
this._currentTime = x;
this._revealCurrentTime = true;
this.needsLayout();
}
get secondsPerPixel()
{
return this._currentSettings.durationPerPixelSetting.value;
}
set secondsPerPixel(x)
{
x = Math.min(this._currentSettings.maximumDurationPerPixel, Math.max(this._currentSettings.minimumDurationPerPixel, x));
if (this.secondsPerPixel === x)
return;
if (this._pixelAlignDuration) {
x = 1 / Math.round(1 / x);
if (this.secondsPerPixel === x)
return;
}
this._currentSettings.durationPerPixelSetting.value = x;
this.needsLayout();
}
get pixelAlignDuration()
{
return this._pixelAlignDuration;
}
set pixelAlignDuration(x)
{
if (this._pixelAlignDuration === x)
return;
this._mouseWheelDelta = 0;
this._pixelAlignDuration = x;
if (this._pixelAlignDuration)
this.secondsPerPixel = 1 / Math.round(1 / this.secondsPerPixel);
}
get endTime()
{
return this._endTime;
}
set endTime(x)
{
x = x || 0;
if (this._endTime === x)
return;
this._endTime = x;
this.needsLayout();
}
get scrollStartTime()
{
return this._currentSettings.scrollStartTime;
}
set scrollStartTime(x)
{
x = x || 0;
if (this.scrollStartTime === x)
return;
this._currentSettings.scrollStartTime = x;
this.needsLayout();
}
get scrollContainerWidth()
{
return this._cachedScrollContainerWidth;
}
get visibleDuration()
{
if (isNaN(this._cachedScrollContainerWidth)) {
this._cachedScrollContainerWidth = this._scrollContainerElement.offsetWidth;
if (!this._cachedScrollContainerWidth)
this._cachedScrollContainerWidth = NaN;
}
return this._cachedScrollContainerWidth * this.secondsPerPixel;
}
get selectionStartTime()
{
return this._timelineRuler.selectionStartTime;
}
set selectionStartTime(x)
{
x = x || 0;
if (this._timelineRuler.selectionStartTime === x)
return;
let selectionDuration = this.selectionDuration;
this._timelineRuler.selectionStartTime = x;
this._timelineRuler.selectionEndTime = x + selectionDuration;
}
get selectionDuration()
{
return this._timelineRuler.selectionEndTime - this._timelineRuler.selectionStartTime;
}
set selectionDuration(x)
{
x = Math.max(this._timelineRuler.minimumSelectionDuration, x);
this._timelineRuler.selectionEndTime = this._timelineRuler.selectionStartTime + x;
}
get height()
{
let height = 0;
for (let overviewGraph of this._overviewGraphsByTypeMap.values()) {
if (!overviewGraph.hidden)
height += overviewGraph.height;
}
return height;
}
attached()
{
super.attached();
for (let [type, overviewGraph] of this._overviewGraphsByTypeMap) {
if (this._canShowTimelineType(type))
overviewGraph.hidden = false;
}
this.needsLayout(WI.View.LayoutReason.Resize);
}
detached()
{
for (let overviewGraph of this._overviewGraphsByTypeMap.values())
overviewGraph.hidden = true;
this.hideScanner();
super.detached();
}
closed()
{
WI.timelineManager.removeEventListener(WI.TimelineManager.Event.CapturingStateChanged, this._handleTimelineCapturingStateChanged, this);
WI.timelineManager.removeEventListener(WI.TimelineManager.Event.RecordingImported, this._recordingImported, this);
super.closed();
}
reset()
{
this._selectedTimelineRecord = null;
for (let overviewGraph of this._overviewGraphsByTypeMap.values())
overviewGraph.reset();
this._mouseWheelDelta = 0;
this._resetSelection();
}
revealMarker(marker)
{
this.scrollStartTime = marker.time - (this.visibleDuration / 2);
}
recordWasFiltered(timeline, record, filtered)
{
let overviewGraph = this._overviewGraphsByTypeMap.get(timeline.type);
console.assert(overviewGraph, "Missing overview graph for timeline type " + timeline.type);
if (!overviewGraph)
return;
console.assert(!overviewGraph.hidden, "Record filtered in hidden overview graph", record);
overviewGraph.recordWasFiltered(record, filtered);
}
selectRecord(timeline, record)
{
let overviewGraph = this._overviewGraphsByTypeMap.get(timeline.type);
console.assert(overviewGraph, "Missing overview graph for timeline type " + timeline.type);
if (!overviewGraph)
return;
console.assert(!overviewGraph.hidden, "Record selected in hidden overview graph", record);
overviewGraph.selectedRecord = record;
}
showScanner(time)
{
this._timelineRuler.showScanner(time);
}
hideScanner()
{
this._timelineRuler.hideScanner();
}
updateLayoutIfNeeded(layoutReason)
{
if (this.layoutPending) {
super.updateLayoutIfNeeded(layoutReason);
return;
}
this._timelineRuler.updateLayoutIfNeeded(layoutReason);
for (let overviewGraph of this._overviewGraphsByTypeMap.values()) {
if (!overviewGraph.hidden)
overviewGraph.updateLayoutIfNeeded(layoutReason);
}
}
discontinuitiesInTimeRange(startTime, endTime)
{
return this._recording.discontinuitiesInTimeRange(startTime, endTime);
}
// Protected
get timelineRuler()
{
return this._timelineRuler;
}
layout()
{
let startTime = this._startTime;
let endTime = this._endTime;
let currentTime = this._currentTime;
if (this._viewMode === WI.TimelineOverview.ViewMode.RenderingFrames) {
let renderingFramesTimeline = this._recording.timelines.get(WI.TimelineRecord.Type.RenderingFrame);
console.assert(renderingFramesTimeline, "Recoring missing rendering frames timeline");
startTime = 0;
endTime = renderingFramesTimeline.records.length;
currentTime = endTime;
}
// Calculate the required width based on the duration and seconds per pixel.
let duration = endTime - startTime;
let newWidth = Math.ceil(duration / this.secondsPerPixel);
// Update all relevant elements to the new required width.
this._updateElementWidth(this._scrollWidthSizer, newWidth);
this._currentTimeMarker.time = currentTime;
if (this._revealCurrentTime) {
this.revealMarker(this._currentTimeMarker);
this._revealCurrentTime = false;
}
const visibleDuration = this.visibleDuration;
// Clamp the scroll start time to match what the scroll bar would allow.
let scrollStartTime = Math.min(this.scrollStartTime, endTime - visibleDuration);
scrollStartTime = Math.max(startTime, scrollStartTime);
this._timelineRuler.zeroTime = startTime;
this._timelineRuler.startTime = scrollStartTime;
this._timelineRuler.secondsPerPixel = this.secondsPerPixel;
if (!this._dontUpdateScrollLeft) {
this._ignoreNextScrollEvent = true;
let scrollLeft = Math.ceil((scrollStartTime - startTime) / this.secondsPerPixel);
if (scrollLeft)
this._scrollContainerElement.scrollLeft = scrollLeft;
}
for (let overviewGraph of this._overviewGraphsByTypeMap.values()) {
if (overviewGraph.hidden)
continue;
overviewGraph.zeroTime = startTime;
overviewGraph.startTime = scrollStartTime;
overviewGraph.currentTime = currentTime;
overviewGraph.endTime = scrollStartTime + visibleDuration;
}
}
sizeDidChange()
{
this._cachedScrollContainerWidth = NaN;
}
// Private
_updateElementWidth(element, newWidth)
{
var currentWidth = parseInt(element.style.width);
if (currentWidth !== newWidth)
element.style.width = newWidth + "px";
}
_handleScrollEvent(event)
{
if (this._ignoreNextScrollEvent) {
this._ignoreNextScrollEvent = false;
return;
}
this._dontUpdateScrollLeft = true;
let scrollOffset = this._scrollContainerElement.scrollLeft;
if (WI.resolvedLayoutDirection() === WI.LayoutDirection.RTL)
this.scrollStartTime = this._startTime - (scrollOffset * this.secondsPerPixel);
else
this.scrollStartTime = this._startTime + (scrollOffset * this.secondsPerPixel);
// Force layout so we can update with the scroll position synchronously.
this.updateLayoutIfNeeded();
this._dontUpdateScrollLeft = false;
this.element.classList.toggle("has-scrollbar", this._scrollContainerElement.clientHeight <= 1);
}
_handleWheelEvent(event)
{
// Ignore cloned events that come our way, we already handled the original.
if (event.__cloned)
return;
// Ignore wheel events while handing gestures.
if (this._handlingGesture)
return;
// Require twice the vertical delta to overcome horizontal scrolling. This prevents most
// cases of inadvertent zooming for slightly diagonal scrolls.
if (Math.abs(event.deltaX) >= Math.abs(event.deltaY) * 0.5) {
// Clone the event to dispatch it on the scroll container. Mark it as cloned so we don't get into a loop.
let newWheelEvent = new event.constructor(event.type, event);
newWheelEvent.__cloned = true;
this._scrollContainerElement.dispatchEvent(newWheelEvent);
return;
}
// Remember the mouse position in time.
let mouseOffset = event.pageX - this._graphsContainerView.element.totalOffsetLeft;
let mousePositionTime = this._currentSettings.scrollStartTime + (mouseOffset * this.secondsPerPixel);
let deviceDirection = event.webkitDirectionInvertedFromDevice ? 1 : -1;
let delta = event.deltaY * (this.secondsPerPixel / WI.TimelineOverview.ScrollDeltaDenominator) * deviceDirection;
// Reset accumulated wheel delta when direction changes.
if (this._pixelAlignDuration && (delta < 0 && this._mouseWheelDelta >= 0 || delta >= 0 && this._mouseWheelDelta < 0))
this._mouseWheelDelta = 0;
let previousDurationPerPixel = this.secondsPerPixel;
this._mouseWheelDelta += delta;
this.secondsPerPixel += this._mouseWheelDelta;
if (this.secondsPerPixel === this._currentSettings.minimumDurationPerPixel && delta < 0 || this.secondsPerPixel === this._currentSettings.maximumDurationPerPixel && delta >= 0)
this._mouseWheelDelta = 0;
else
this._mouseWheelDelta = previousDurationPerPixel + this._mouseWheelDelta - this.secondsPerPixel;
// Center the zoom around the mouse based on the remembered mouse position time.
this.scrollStartTime = mousePositionTime - (mouseOffset * this.secondsPerPixel);
this.element.classList.toggle("has-scrollbar", this._scrollContainerElement.clientHeight <= 1);
event.preventDefault();
event.stopPropagation();
}
_handleGestureStart(event)
{
if (this._handlingGesture) {
// FIXME: <https://webkit.org/b/151068> [Mac] Unexpected gesturestart events when already handling gesture
return;
}
let mouseOffset = event.pageX - this._graphsContainerView.element.totalOffsetLeft;
let mousePositionTime = this._currentSettings.scrollStartTime + (mouseOffset * this.secondsPerPixel);
this._handlingGesture = true;
this._gestureStartStartTime = mousePositionTime;
this._gestureStartDurationPerPixel = this.secondsPerPixel;
this.element.classList.toggle("has-scrollbar", this._scrollContainerElement.clientHeight <= 1);
event.preventDefault();
event.stopPropagation();
}
_handleGestureChange(event)
{
// Cap zooming out at 5x.
let scale = Math.max(1 / 5, event.scale);
let mouseOffset = event.pageX - this._graphsContainerView.element.totalOffsetLeft;
let newSecondsPerPixel = this._gestureStartDurationPerPixel / scale;
this.secondsPerPixel = newSecondsPerPixel;
this.scrollStartTime = this._gestureStartStartTime - (mouseOffset * this.secondsPerPixel);
event.preventDefault();
event.stopPropagation();
}
_handleGestureEnd(event)
{
this._handlingGesture = false;
this._gestureStartStartTime = NaN;
this._gestureStartDurationPerPixel = NaN;
}
_instrumentAdded(instrumentOrEvent)
{
let instrument = instrumentOrEvent instanceof WI.Instrument ? instrumentOrEvent : instrumentOrEvent.data.instrument;
console.assert(instrument instanceof WI.Instrument, instrument);
let timeline = this._recording.timelineForInstrument(instrument);
console.assert(!this._overviewGraphsByTypeMap.has(timeline.type), timeline);
console.assert(!this._treeElementsByTypeMap.has(timeline.type), timeline);
let treeElement = new WI.TimelineTreeElement(timeline);
let insertionIndex = insertionIndexForObjectInListSortedByFunction(treeElement, this._timelinesTreeOutline.children, this._compareTimelineTreeElements.bind(this));
this._timelinesTreeOutline.insertChild(treeElement, insertionIndex);
this._treeElementsByTypeMap.set(timeline.type, treeElement);
let overviewGraph = WI.TimelineOverviewGraph.createForTimeline(timeline, this);
overviewGraph.addEventListener(WI.TimelineOverviewGraph.Event.RecordSelected, this._handleOverviewGraphRecordSelected, this);
this._overviewGraphsByTypeMap.set(timeline.type, overviewGraph);
this._graphsContainerView.insertSubviewBefore(overviewGraph, this._graphsContainerView.subviews[insertionIndex]);
treeElement.element.style.height = overviewGraph.height + "px";
if (!this._canShowTimelineType(timeline.type)) {
overviewGraph.hidden = true;
treeElement.hidden = true;
}
this.needsLayout();
}
_instrumentRemoved(event)
{
let instrument = event.data.instrument;
console.assert(instrument instanceof WI.Instrument, instrument);
let timeline = this._recording.timelineForInstrument(instrument);
let overviewGraph = this._overviewGraphsByTypeMap.get(timeline.type);
console.assert(overviewGraph, "Missing overview graph for timeline type", timeline.type);
let treeElement = this._treeElementsByTypeMap.get(timeline.type);
let shouldSuppressOnDeselect = false;
let shouldSuppressSelectSibling = true;
this._timelinesTreeOutline.removeChild(treeElement, shouldSuppressOnDeselect, shouldSuppressSelectSibling);
overviewGraph.removeEventListener(WI.TimelineOverviewGraph.Event.RecordSelected, this._handleOverviewGraphRecordSelected, this);
this._graphsContainerView.removeSubview(overviewGraph);
this._overviewGraphsByTypeMap.delete(timeline.type);
this._treeElementsByTypeMap.delete(timeline.type);
}
_markerAdded(event)
{
this._timelineRuler.addMarker(event.data.marker);
}
_handleGraphsContainerClick(event)
{
// Set when a WI.TimelineRecordBar receives the "click" first and is about to be selected.
if (event.__timelineRecordClickEventHandled)
return;
this._recordSelected(null, null);
}
_timelineRulerMouseDown(event)
{
this._timelineRulerSelectionChanged = false;
}
_timelineRulerMouseClicked(event)
{
if (this._timelineRulerSelectionChanged)
return;
for (let overviewGraph of this._overviewGraphsByTypeMap.values()) {
if (overviewGraph.hidden)
continue;
let graphRect = overviewGraph.element.getBoundingClientRect();
if (!(event.pageX >= graphRect.left && event.pageX <= graphRect.right && event.pageY >= graphRect.top && event.pageY <= graphRect.bottom))
continue;
// Clone the event to dispatch it on the overview graph element.
let newClickEvent = new event.constructor(event.type, event);
overviewGraph.element.dispatchEvent(newClickEvent);
return;
}
}
_timeRangeSelectionChanged(event)
{
this._timelineRulerSelectionChanged = true;
let startTime = this._viewMode === WI.TimelineOverview.ViewMode.Timelines ? this._startTime : 0;
this._currentSettings.selectionStartValueSetting.value = this.selectionStartTime - startTime;
this._currentSettings.selectionDurationSetting.value = this.selectionDuration;
this.dispatchEventToListeners(WI.TimelineOverview.Event.TimeRangeSelectionChanged);
}
_handleOverviewGraphRecordSelected(event)
{
let {record, recordBar} = event.data;
// Ignore deselection events, as they are handled by the newly selected record's timeline.
if (!record)
return;
this._recordSelected(record, recordBar);
}
_recordSelected(record, recordBar)
{
if (record === this._selectedTimelineRecord)
return;
if (this._selectedTimelineRecord && (!record || this._selectedTimelineRecord.type !== record.type)) {
let timelineOverviewGraph = this._overviewGraphsByTypeMap.get(this._selectedTimelineRecord.type);
console.assert(timelineOverviewGraph);
if (timelineOverviewGraph)
timelineOverviewGraph.selectedRecord = null;
}
this._selectedTimelineRecord = record;
if (this._selectedTimelineRecord) {
let firstRecord = this._selectedTimelineRecord;
let lastRecord = this._selectedTimelineRecord;
if (recordBar) {
firstRecord = recordBar.records[0];
lastRecord = recordBar.records.lastValue;
}
let startTime = firstRecord instanceof WI.RenderingFrameTimelineRecord ? firstRecord.frameIndex : firstRecord.startTime;
let endTime = lastRecord instanceof WI.RenderingFrameTimelineRecord ? lastRecord.frameIndex : lastRecord.endTime;
if (startTime < this.selectionStartTime || (endTime > this.selectionStartTime + this.selectionDuration) || firstRecord instanceof WI.CPUTimelineRecord) {
let selectionPadding = this.secondsPerPixel * 10;
this.selectionStartTime = startTime - selectionPadding;
this.selectionDuration = endTime - startTime + (selectionPadding * 2);
}
}
this.dispatchEventToListeners(WI.TimelineOverview.Event.RecordSelected, {record: this._selectedTimelineRecord});
}
_resetSelection()
{
function reset(settings)
{
settings.durationPerPixelSetting.reset();
settings.selectionStartValueSetting.reset();
settings.selectionDurationSetting.reset();
}
reset(this._timelinesViewModeSettings);
if (this._renderingFramesViewModeSettings)
reset(this._renderingFramesViewModeSettings);
this.secondsPerPixel = this._currentSettings.durationPerPixelSetting.value;
this.selectionStartTime = this._currentSettings.selectionStartValueSetting.value;
this.selectionDuration = this._currentSettings.selectionDurationSetting.value;
}
_recordingReset(event)
{
this._timelineRuler.clearMarkers();
this._timelineRuler.addMarker(this._currentTimeMarker);
}
_canShowTimelineType(type)
{
let timelineViewMode = WI.TimelineOverview.ViewMode.Timelines;
if (type === WI.TimelineRecord.Type.RenderingFrame)
timelineViewMode = WI.TimelineOverview.ViewMode.RenderingFrames;
return timelineViewMode === this._viewMode;
}
_viewModeDidChange()
{
this._stopEditingInstruments();
let startTime = 0;
let isRenderingFramesMode = this._viewMode === WI.TimelineOverview.ViewMode.RenderingFrames;
if (isRenderingFramesMode) {
this._timelineRuler.minimumSelectionDuration = 1;
this._timelineRuler.snapInterval = 1;
this._timelineRuler.formatLabelCallback = (value) => value.maxDecimals(0).toLocaleString();
} else {
this._timelineRuler.minimumSelectionDuration = 0.01;
this._timelineRuler.snapInterval = NaN;
this._timelineRuler.formatLabelCallback = null;
startTime = this._startTime;
}
this.pixelAlignDuration = isRenderingFramesMode;
this.selectionStartTime = this._currentSettings.selectionStartValueSetting.value + startTime;
this.selectionDuration = this._currentSettings.selectionDurationSetting.value;
for (let [type, overviewGraph] of this._overviewGraphsByTypeMap) {
let treeElement = this._treeElementsByTypeMap.get(type);
console.assert(treeElement, "Missing tree element for timeline type", type);
let hidden = !this._canShowTimelineType(type);
treeElement.hidden = hidden;
overviewGraph.hidden = hidden;
}
this.element.classList.toggle("frames", isRenderingFramesMode);
if (this.didInitialLayout)
this.updateLayout(WI.View.LayoutReason.Resize);
}
_createViewModeSettings(viewMode, minimumDurationPerPixel, maximumDurationPerPixel, durationPerPixel, selectionStartValue, selectionDuration)
{
durationPerPixel = Math.min(maximumDurationPerPixel, Math.max(minimumDurationPerPixel, durationPerPixel));
let durationPerPixelSetting = new WI.Setting(viewMode + "-duration-per-pixel", durationPerPixel);
let selectionStartValueSetting = new WI.Setting(viewMode + "-selection-start-value", selectionStartValue);
let selectionDurationSetting = new WI.Setting(viewMode + "-selection-duration", selectionDuration);
return {
scrollStartTime: 0,
minimumDurationPerPixel,
maximumDurationPerPixel,
durationPerPixelSetting,
selectionStartValueSetting,
selectionDurationSetting
};
}
get _currentSettings()
{
return this._viewMode === WI.TimelineOverview.ViewMode.Timelines ? this._timelinesViewModeSettings : this._renderingFramesViewModeSettings;
}
_timelinesTreeSelectionDidChange(event)
{
let timeline = null;
let selectedTreeElement = this._timelinesTreeOutline.selectedTreeElement;
if (selectedTreeElement) {
timeline = selectedTreeElement.representedObject;
console.assert(timeline instanceof WI.Timeline, timeline);
console.assert(this._recording.timelines.get(timeline.type) === timeline, timeline);
for (let [type, overviewGraph] of this._overviewGraphsByTypeMap)
overviewGraph.selected = type === timeline.type;
}
this._selectedTimeline = timeline;
this.dispatchEventToListeners(WI.TimelineOverview.Event.TimelineSelected);
}
_toggleEditingInstruments(event)
{
if (this._editingInstruments)
this._stopEditingInstruments();
else
this._startEditingInstruments();
}
_editingInstrumentsDidChange()
{
this.element.classList.toggle(WI.TimelineOverview.EditInstrumentsStyleClassName, this._editingInstruments);
this._timelineRuler.enabled = !this._editingInstruments;
this._updateWheelAndGestureHandlers();
this._updateEditInstrumentsButton();
this.dispatchEventToListeners(WI.TimelineOverview.Event.EditingInstrumentsDidChange);
}
_updateEditInstrumentsButton()
{
let newLabel = this._editingInstruments ? WI.UIString("Done") : WI.UIString("Edit");
this._editInstrumentsButton.label = newLabel;
this._editInstrumentsButton.activated = this._editingInstruments;
this._editInstrumentsButton.enabled = !WI.timelineManager.isCapturing();
}
_updateWheelAndGestureHandlers()
{
if (this._editingInstruments) {
this.element.removeEventListener("wheel", this._handleWheelEventListener);
this.element.removeEventListener("gesturestart", this._handleGestureStartEventListener);
this.element.removeEventListener("gesturechange", this._handleGestureChangeEventListener);
this.element.removeEventListener("gestureend", this._handleGestureEndEventListener);
this._handleWheelEventListener = null;
this._handleGestureStartEventListener = null;
this._handleGestureChangeEventListener = null;
this._handleGestureEndEventListener = null;
} else {
this._handleWheelEventListener = this._handleWheelEvent.bind(this);
this._handleGestureStartEventListener = this._handleGestureStart.bind(this);
this._handleGestureChangeEventListener = this._handleGestureChange.bind(this);
this._handleGestureEndEventListener = this._handleGestureEnd.bind(this);
this.element.addEventListener("wheel", this._handleWheelEventListener);
this.element.addEventListener("gesturestart", this._handleGestureStartEventListener);
this.element.addEventListener("gesturechange", this._handleGestureChangeEventListener);
this.element.addEventListener("gestureend", this._handleGestureEndEventListener);
}
}
_startEditingInstruments()
{
console.assert(this._viewMode === WI.TimelineOverview.ViewMode.Timelines);
if (this._editingInstruments)
return;
this._editingInstruments = true;
for (let type of this._instrumentTypes) {
let treeElement = this._treeElementsByTypeMap.get(type);
if (!treeElement) {
let timeline = this._recording.timelines.get(type);
console.assert(timeline, "Missing timeline for type " + type);
const placeholder = true;
treeElement = new WI.TimelineTreeElement(timeline, placeholder);
let insertionIndex = insertionIndexForObjectInListSortedByFunction(treeElement, this._timelinesTreeOutline.children, this._compareTimelineTreeElements.bind(this));
this._timelinesTreeOutline.insertChild(treeElement, insertionIndex);
let placeholderGraph = new WI.View;
placeholderGraph.element.classList.add("timeline-overview-graph");
treeElement[WI.TimelineOverview.PlaceholderOverviewGraph] = placeholderGraph;
this._graphsContainerView.insertSubviewBefore(placeholderGraph, this._graphsContainerView.subviews[insertionIndex]);
}
treeElement.editing = true;
treeElement.addEventListener(WI.TimelineTreeElement.Event.EnabledDidChange, this._timelineTreeElementEnabledDidChange, this);
}
this._editingInstrumentsDidChange();
}
_stopEditingInstruments()
{
if (!this._editingInstruments)
return;
this._editingInstruments = false;
let instruments = this._recording.instruments;
for (let treeElement of this._treeElementsByTypeMap.values()) {
if (treeElement.status.checked) {
treeElement.editing = false;
treeElement.removeEventListener(WI.TimelineTreeElement.Event.EnabledDidChange, this._timelineTreeElementEnabledDidChange, this);
continue;
}
let timelineInstrument = instruments.find((instrument) => instrument.timelineRecordType === treeElement.representedObject.type);
this._recording.removeInstrument(timelineInstrument);
}
let placeholderTreeElements = this._timelinesTreeOutline.children.filter((treeElement) => treeElement.placeholder);
for (let treeElement of placeholderTreeElements) {
this._timelinesTreeOutline.removeChild(treeElement);
let placeholderGraph = treeElement[WI.TimelineOverview.PlaceholderOverviewGraph];
console.assert(placeholderGraph);
this._graphsContainerView.removeSubview(placeholderGraph);
if (treeElement.status.checked) {
let instrument = WI.Instrument.createForTimelineType(treeElement.representedObject.type);
this._recording.addInstrument(instrument);
}
}
let instrumentTypes = instruments.map((instrument) => instrument.timelineRecordType);
WI.timelineManager.enabledTimelineTypes = instrumentTypes;
this._editingInstrumentsDidChange();
}
_handleTimelineCapturingStateChanged(event)
{
switch (WI.timelineManager.capturingState) {
case WI.TimelineManager.CapturingState.Active:
this._editInstrumentsButton.enabled = false;
this._stopEditingInstruments();
break;
case WI.TimelineManager.CapturingState.Inactive:
this._editInstrumentsButton.enabled = true;
break;
}
}
_recordingImported(event)
{
let {overviewData} = event.data;
if (overviewData.secondsPerPixel !== undefined)
this.secondsPerPixel = overviewData.secondsPerPixel;
if (overviewData.scrollStartTime !== undefined)
this.scrollStartTime = overviewData.scrollStartTime;
if (overviewData.selectionStartTime !== undefined)
this.selectionStartTime = overviewData.selectionStartTime;
if (overviewData.selectionDuration !== undefined) {
if (overviewData.selectionDuration === Number.MAX_VALUE)
this._timelineRuler.selectEntireRange();
else
this.selectionDuration = overviewData.selectionDuration;
}
if (overviewData.selectedTimelineType !== undefined) {
let timeline = this._recording.timelineForRecordType(overviewData.selectedTimelineType);
if (timeline)
this.selectedTimeline = timeline;
}
}
_compareTimelineTreeElements(a, b)
{
let aTimelineType = a.representedObject.type;
let bTimelineType = b.representedObject.type;
// Always sort the Rendering Frames timeline last.
if (aTimelineType === WI.TimelineRecord.Type.RenderingFrame)
return 1;
if (bTimelineType === WI.TimelineRecord.Type.RenderingFrame)
return -1;
if (a.placeholder !== b.placeholder)
return a.placeholder ? 1 : -1;
let aTimelineIndex = this._instrumentTypes.indexOf(aTimelineType);
let bTimelineIndex = this._instrumentTypes.indexOf(bTimelineType);
return aTimelineIndex - bTimelineIndex;
}
_timelineTreeElementEnabledDidChange(event)
{
let enabled = this._timelinesTreeOutline.children.some((treeElement) => {
let timelineType = treeElement.representedObject.type;
return this._canShowTimelineType(timelineType) && treeElement.status.checked;
});
this._editInstrumentsButton.enabled = enabled;
}
};
WI.TimelineOverview.PlaceholderOverviewGraph = Symbol("placeholder-overview-graph");
WI.TimelineOverview.ScrollDeltaDenominator = 500;
WI.TimelineOverview.EditInstrumentsStyleClassName = "edit-instruments";
WI.TimelineOverview.MinimumDurationPerPixel = 0.0001;
WI.TimelineOverview.MaximumDurationPerPixel = 60;
WI.TimelineOverview.ViewMode = {
Timelines: "timeline-overview-view-mode-timelines",
RenderingFrames: "timeline-overview-view-mode-rendering-frames"
};
WI.TimelineOverview.Event = {
EditingInstrumentsDidChange: "editing-instruments-did-change",
RecordSelected: "timeline-overview-record-selected",
TimelineSelected: "timeline-overview-timeline-selected",
TimeRangeSelectionChanged: "timeline-overview-time-range-selection-changed"
};
|