2020-06-29 19:21:56 +00:00
|
|
|
// Copyright 2020 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2020-07-28 12:46:10 +00:00
|
|
|
|
2020-08-25 06:31:43 +00:00
|
|
|
import { defineCustomElement, V8CustomElement } from './helper.mjs';
|
2020-09-02 06:56:20 +00:00
|
|
|
import { SynchronizeSelectionEvent } from './events.mjs';
|
2020-07-28 12:46:10 +00:00
|
|
|
import './timeline/timeline-track.mjs';
|
2020-06-29 19:21:56 +00:00
|
|
|
|
|
|
|
defineCustomElement('timeline-panel', (templateText) =>
|
2020-08-25 06:31:43 +00:00
|
|
|
class TimelinePanel extends V8CustomElement {
|
2020-09-02 06:56:20 +00:00
|
|
|
#timeSelection = { start: 0, end: Infinity };
|
2020-08-25 06:31:43 +00:00
|
|
|
constructor() {
|
|
|
|
super(templateText);
|
|
|
|
this.timelineOverview.addEventListener(
|
|
|
|
'mousemove', e => this.handleTimelineIndicatorMove(e));
|
|
|
|
this.addEventListener(
|
|
|
|
'overviewupdate', e => this.handleOverviewBackgroundUpdate(e));
|
|
|
|
this.addEventListener(
|
|
|
|
'scrolltrack', e => this.handleTrackScroll(e));
|
2020-09-02 06:56:20 +00:00
|
|
|
this.addEventListener(
|
|
|
|
SynchronizeSelectionEvent.name, e => this.handleMouseMoveSelection(e));
|
2020-08-25 06:31:43 +00:00
|
|
|
this.backgroundCanvas = document.createElement('canvas');
|
|
|
|
this.isLocked = false;
|
|
|
|
}
|
2020-06-29 19:21:56 +00:00
|
|
|
|
2020-08-25 06:31:43 +00:00
|
|
|
get timelineOverview() {
|
|
|
|
return this.$('#timelineOverview');
|
|
|
|
}
|
2020-06-29 19:21:56 +00:00
|
|
|
|
2020-08-25 06:31:43 +00:00
|
|
|
get timelineOverviewIndicator() {
|
|
|
|
return this.$('#timelineOverviewIndicator');
|
|
|
|
}
|
2020-06-29 19:21:56 +00:00
|
|
|
|
2020-09-02 06:56:20 +00:00
|
|
|
//TODO(zcankara) Remove dependency to timelineCanvas here
|
2020-08-25 06:31:43 +00:00
|
|
|
get timelineCanvas() {
|
|
|
|
return this.timelineTracks[0].timelineCanvas;
|
|
|
|
}
|
2020-09-02 06:56:20 +00:00
|
|
|
//TODO(zcankara) Remove dependency to timeline here
|
2020-08-25 06:31:43 +00:00
|
|
|
get timeline() {
|
|
|
|
return this.timelineTracks[0].timeline;
|
|
|
|
}
|
|
|
|
set nofChunks(count) {
|
|
|
|
for (const track of this.timelineTracks) {
|
|
|
|
track.nofChunks = count;
|
|
|
|
}
|
2020-07-28 12:46:10 +00:00
|
|
|
}
|
2020-08-25 06:31:43 +00:00
|
|
|
get nofChunks() {
|
|
|
|
return this.timelineTracks[0].nofChunks;
|
2020-08-06 04:49:39 +00:00
|
|
|
}
|
2020-08-25 06:31:43 +00:00
|
|
|
get timelineTracks() {
|
|
|
|
return this.$("slot").assignedNodes().filter(
|
|
|
|
track => track.nodeType === Node.ELEMENT_NODE);
|
|
|
|
}
|
|
|
|
handleTrackScroll(event) {
|
|
|
|
//TODO(zcankara) add forEachTrack helper method
|
|
|
|
for (const track of this.timelineTracks) {
|
|
|
|
track.scrollLeft = event.detail;
|
|
|
|
}
|
|
|
|
}
|
2020-09-02 06:56:20 +00:00
|
|
|
|
|
|
|
handleMouseMoveSelection(event) {
|
|
|
|
this.selectionMouseMove(event.start, event.end);
|
|
|
|
}
|
|
|
|
|
|
|
|
selectionMouseMove(start, end) {
|
|
|
|
for (const track of this.timelineTracks) {
|
|
|
|
track.startTime = start;
|
|
|
|
track.endTime = end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-25 06:31:43 +00:00
|
|
|
handleTimelineIndicatorMove(event) {
|
|
|
|
if (event.buttons == 0) return;
|
|
|
|
let timelineTotalWidth = this.timelineCanvas.offsetWidth;
|
|
|
|
let factor = this.timelineOverview.offsetWidth / timelineTotalWidth;
|
|
|
|
for (const track of this.timelineTracks) {
|
|
|
|
track.timelineIndicatorMove(event.movementX / factor);
|
|
|
|
}
|
2020-07-28 12:46:10 +00:00
|
|
|
}
|
2020-06-29 19:21:56 +00:00
|
|
|
|
2020-08-25 06:31:43 +00:00
|
|
|
updateOverviewWindow() {
|
|
|
|
let indicator = this.timelineOverviewIndicator;
|
|
|
|
let totalIndicatorWidth =
|
2020-07-16 19:24:09 +00:00
|
|
|
this.timelineOverview.offsetWidth;
|
2020-08-25 06:31:43 +00:00
|
|
|
let div = this.timeline;
|
|
|
|
let timelineTotalWidth = this.timelineCanvas.offsetWidth;
|
|
|
|
let factor = totalIndicatorWidth / timelineTotalWidth;
|
|
|
|
let width = div.offsetWidth * factor;
|
|
|
|
let left = div.scrollLeft * factor;
|
|
|
|
indicator.style.width = width + 'px';
|
|
|
|
indicator.style.left = left + 'px';
|
|
|
|
}
|
2020-07-16 19:24:09 +00:00
|
|
|
|
2020-08-25 06:31:43 +00:00
|
|
|
handleOverviewBackgroundUpdate(e) {
|
|
|
|
this.timelineOverview.style.backgroundImage =
|
|
|
|
'url(' + e.detail + ')';
|
|
|
|
}
|
2020-07-23 06:37:37 +00:00
|
|
|
|
2020-08-25 06:31:43 +00:00
|
|
|
});
|