1// Copyright 2020 the V8 project authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5import './timeline/timeline-track.mjs'; 6import './timeline/timeline-track-map.mjs'; 7import './timeline/timeline-track-tick.mjs'; 8import './timeline/timeline-track-timer.mjs'; 9 10import {SynchronizeSelectionEvent} from './events.mjs'; 11import {DOM, V8CustomElement} from './helper.mjs'; 12 13DOM.defineCustomElement( 14 'view/timeline-panel', 15 (templateText) => class TimelinePanel extends V8CustomElement { 16 constructor() { 17 super(templateText); 18 this.addEventListener('scrolltrack', e => this.handleTrackScroll(e)); 19 this.addEventListener( 20 SynchronizeSelectionEvent.name, 21 e => this.handleSelectionSyncronization(e)); 22 this.$('#zoomIn').onclick = () => this.nofChunks *= 1.5; 23 this.$('#zoomOut').onclick = () => this.nofChunks /= 1.5; 24 } 25 26 set nofChunks(count) { 27 for (const track of this.timelineTracks) { 28 track.nofChunks = count; 29 } 30 } 31 32 get nofChunks() { 33 return this.timelineTracks[0].nofChunks; 34 } 35 36 set currentTime(time) { 37 for (const track of this.timelineTracks) { 38 track.currentTime = time; 39 } 40 } 41 42 get currentTime() { 43 return this.timelineTracks[0].currentTime; 44 } 45 46 get timelineTracks() { 47 return this.$('slot').assignedNodes().filter( 48 node => node.nodeType === Node.ELEMENT_NODE); 49 } 50 51 handleTrackScroll(event) { 52 for (const track of this.timelineTracks) { 53 track.scrollLeft = event.detail; 54 } 55 } 56 57 handleSelectionSyncronization(event) { 58 this.timeSelection = {start: event.start, end: event.end}; 59 } 60 61 set timeSelection(selection) { 62 if (selection.start > selection.end) { 63 throw new Error('Invalid time range'); 64 } 65 const tracks = Array.from(this.timelineTracks); 66 if (selection.zoom) { 67 // To avoid inconsistencies copy the zoom/nofChunks from the first 68 // track 69 const firstTrack = tracks.pop(); 70 firstTrack.timeSelection = selection; 71 selection.zoom = false; 72 for (const track of tracks) track.timeSelection = selection; 73 this.nofChunks = firstTrack.nofChunks; 74 } else { 75 for (const track of this.timelineTracks) { 76 track.timeSelection = selection; 77 } 78 } 79 } 80 }); 81