11cb0ef41Sopenharmony_ci// Copyright 2020 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciimport './timeline/timeline-track.mjs'; 61cb0ef41Sopenharmony_ciimport './timeline/timeline-track-map.mjs'; 71cb0ef41Sopenharmony_ciimport './timeline/timeline-track-tick.mjs'; 81cb0ef41Sopenharmony_ciimport './timeline/timeline-track-timer.mjs'; 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciimport {SynchronizeSelectionEvent} from './events.mjs'; 111cb0ef41Sopenharmony_ciimport {DOM, V8CustomElement} from './helper.mjs'; 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciDOM.defineCustomElement( 141cb0ef41Sopenharmony_ci 'view/timeline-panel', 151cb0ef41Sopenharmony_ci (templateText) => class TimelinePanel extends V8CustomElement { 161cb0ef41Sopenharmony_ci constructor() { 171cb0ef41Sopenharmony_ci super(templateText); 181cb0ef41Sopenharmony_ci this.addEventListener('scrolltrack', e => this.handleTrackScroll(e)); 191cb0ef41Sopenharmony_ci this.addEventListener( 201cb0ef41Sopenharmony_ci SynchronizeSelectionEvent.name, 211cb0ef41Sopenharmony_ci e => this.handleSelectionSyncronization(e)); 221cb0ef41Sopenharmony_ci this.$('#zoomIn').onclick = () => this.nofChunks *= 1.5; 231cb0ef41Sopenharmony_ci this.$('#zoomOut').onclick = () => this.nofChunks /= 1.5; 241cb0ef41Sopenharmony_ci } 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci set nofChunks(count) { 271cb0ef41Sopenharmony_ci for (const track of this.timelineTracks) { 281cb0ef41Sopenharmony_ci track.nofChunks = count; 291cb0ef41Sopenharmony_ci } 301cb0ef41Sopenharmony_ci } 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci get nofChunks() { 331cb0ef41Sopenharmony_ci return this.timelineTracks[0].nofChunks; 341cb0ef41Sopenharmony_ci } 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci set currentTime(time) { 371cb0ef41Sopenharmony_ci for (const track of this.timelineTracks) { 381cb0ef41Sopenharmony_ci track.currentTime = time; 391cb0ef41Sopenharmony_ci } 401cb0ef41Sopenharmony_ci } 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ci get currentTime() { 431cb0ef41Sopenharmony_ci return this.timelineTracks[0].currentTime; 441cb0ef41Sopenharmony_ci } 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci get timelineTracks() { 471cb0ef41Sopenharmony_ci return this.$('slot').assignedNodes().filter( 481cb0ef41Sopenharmony_ci node => node.nodeType === Node.ELEMENT_NODE); 491cb0ef41Sopenharmony_ci } 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ci handleTrackScroll(event) { 521cb0ef41Sopenharmony_ci for (const track of this.timelineTracks) { 531cb0ef41Sopenharmony_ci track.scrollLeft = event.detail; 541cb0ef41Sopenharmony_ci } 551cb0ef41Sopenharmony_ci } 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_ci handleSelectionSyncronization(event) { 581cb0ef41Sopenharmony_ci this.timeSelection = {start: event.start, end: event.end}; 591cb0ef41Sopenharmony_ci } 601cb0ef41Sopenharmony_ci 611cb0ef41Sopenharmony_ci set timeSelection(selection) { 621cb0ef41Sopenharmony_ci if (selection.start > selection.end) { 631cb0ef41Sopenharmony_ci throw new Error('Invalid time range'); 641cb0ef41Sopenharmony_ci } 651cb0ef41Sopenharmony_ci const tracks = Array.from(this.timelineTracks); 661cb0ef41Sopenharmony_ci if (selection.zoom) { 671cb0ef41Sopenharmony_ci // To avoid inconsistencies copy the zoom/nofChunks from the first 681cb0ef41Sopenharmony_ci // track 691cb0ef41Sopenharmony_ci const firstTrack = tracks.pop(); 701cb0ef41Sopenharmony_ci firstTrack.timeSelection = selection; 711cb0ef41Sopenharmony_ci selection.zoom = false; 721cb0ef41Sopenharmony_ci for (const track of tracks) track.timeSelection = selection; 731cb0ef41Sopenharmony_ci this.nofChunks = firstTrack.nofChunks; 741cb0ef41Sopenharmony_ci } else { 751cb0ef41Sopenharmony_ci for (const track of this.timelineTracks) { 761cb0ef41Sopenharmony_ci track.timeSelection = selection; 771cb0ef41Sopenharmony_ci } 781cb0ef41Sopenharmony_ci } 791cb0ef41Sopenharmony_ci } 801cb0ef41Sopenharmony_ci }); 81