11cb0ef41Sopenharmony_ci// Copyright 2021 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 {CSSColor, DOM, SVG, V8CustomElement} from '../helper.mjs';
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciimport {TimelineTrackBase} from './timeline-track-base.mjs'
81cb0ef41Sopenharmony_ciimport {TimelineTrackStackedBase} from './timeline-track-stacked-base.mjs'
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ciDOM.defineCustomElement(
111cb0ef41Sopenharmony_ci    'view/timeline/timeline-track', 'timeline-track-timer',
121cb0ef41Sopenharmony_ci    (templateText) =>
131cb0ef41Sopenharmony_ci        class TimelineTrackTimer extends TimelineTrackStackedBase {
141cb0ef41Sopenharmony_ci      constructor() {
151cb0ef41Sopenharmony_ci        super(templateText);
161cb0ef41Sopenharmony_ci      }
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ci      _prepareDrawableItems() {
191cb0ef41Sopenharmony_ci        const stack = [];
201cb0ef41Sopenharmony_ci        let maxDepth = 0;
211cb0ef41Sopenharmony_ci        for (let i = 0; i < this._timeline.length; i++) {
221cb0ef41Sopenharmony_ci          const timer = this._timeline.at(i);
231cb0ef41Sopenharmony_ci          let insertDepth = -1;
241cb0ef41Sopenharmony_ci          for (let depth = 0; depth < stack.length; depth++) {
251cb0ef41Sopenharmony_ci            const pendingTimer = stack[depth];
261cb0ef41Sopenharmony_ci            if (pendingTimer === undefined) {
271cb0ef41Sopenharmony_ci              if (insertDepth === -1) insertDepth = depth;
281cb0ef41Sopenharmony_ci            } else if (pendingTimer.endTime <= timer.startTime) {
291cb0ef41Sopenharmony_ci              stack[depth] == undefined;
301cb0ef41Sopenharmony_ci              if (insertDepth === -1) insertDepth = depth;
311cb0ef41Sopenharmony_ci            }
321cb0ef41Sopenharmony_ci          }
331cb0ef41Sopenharmony_ci          if (insertDepth === -1) insertDepth = stack.length;
341cb0ef41Sopenharmony_ci          stack[insertDepth] = timer;
351cb0ef41Sopenharmony_ci          timer.depth = insertDepth;
361cb0ef41Sopenharmony_ci          maxDepth = Math.max(maxDepth, insertDepth);
371cb0ef41Sopenharmony_ci        }
381cb0ef41Sopenharmony_ci        this._drawableItems = this._timeline;
391cb0ef41Sopenharmony_ci        this._adjustStackDepth(maxDepth++);
401cb0ef41Sopenharmony_ci      }
411cb0ef41Sopenharmony_ci    });