1<!DOCTYPE html>
2<!--
3Copyright (c) 2013 The Chromium Authors. All rights reserved.
4Use of this source code is governed by a BSD-style license that can be
5found in the LICENSE file.
6-->
7
8<link rel="import" href="/tracing/base/guid.html">
9<link rel="import" href="/tracing/model/event.html">
10<link rel="import" href="/tracing/value/time_display_mode.html">
11
12<script>
13'use strict';
14
15tr.exportTo('tr.model', function() {
16  /**
17   * TimedEvent is a base type for any entity in the trace model with a specific
18   * start and duration.
19   *
20   * @constructor
21   */
22  function TimedEvent(start) {
23    tr.model.Event.call(this);
24    this.start = start;
25    this.duration = 0;
26    this.cpuStart = undefined;
27    this.cpuDuration = undefined;
28  }
29
30  TimedEvent.prototype = {
31    __proto__: tr.model.Event.prototype,
32
33    get end() {
34      return this.start + this.duration;
35    },
36
37    addBoundsToRange: function(range) {
38      range.addValue(this.start);
39      range.addValue(this.end);
40    },
41
42    // Returns true if 'that' TimedEvent is fully contained within 'this' timed
43    // event.
44    bounds: function(that, opt_precisionUnit) {
45      if (opt_precisionUnit === undefined)
46        opt_precisionUnit = tr.v.TimeDisplayModes.ms;
47
48      var startsBefore = opt_precisionUnit.roundedLess(that.start, this.start);
49      var endsAfter = opt_precisionUnit.roundedLess(this.end, that.end);
50      return !startsBefore && !endsAfter;
51    }
52  };
53
54  return {
55    TimedEvent: TimedEvent
56  };
57});
58</script>
59