• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2013 The Chromium 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
5'use strict';
6
7base.requireStylesheet('tracing.analysis.analysis_link');
8
9base.require('base.events');
10base.require('tracing.selection');
11base.require('tracing.analysis.util');
12base.require('ui');
13
14base.exportTo('tracing.analysis', function() {
15
16  var tsRound = tracing.analysis.tsRound;
17
18  var RequestSelectionChangeEvent = base.Event.bind(
19      undefined, 'requestSelectionChange', true, false);
20
21  /**
22   * A clickable link that requests a change of selection to the return value of
23   * this.selectionGenerator when clicked.
24   *
25   * @constructor
26   */
27  var AnalysisLink = ui.define('a');
28
29  AnalysisLink.prototype = {
30    __proto__: HTMLAnchorElement.prototype,
31    decorate: function() {
32      this.classList.add('analysis-link');
33      this.selectionGenerator;
34      this.addEventListener('click', this.onClicked_.bind(this));
35    },
36    onClicked_: function() {
37      var event = new RequestSelectionChangeEvent();
38      event.selection = this.selectionGenerator();
39      this.dispatchEvent(event);
40    }
41  };
42
43  /**
44   * Changes the selection to the given ObjectSnapshot when clicked.
45   * @constructor
46   */
47  var ObjectSnapshotLink = ui.define(
48      'object-snapshot-link', AnalysisLink);
49
50  ObjectSnapshotLink.prototype = {
51    __proto__: AnalysisLink.prototype,
52
53    decorate: function() {
54      AnalysisLink.prototype.decorate.apply(this);
55    },
56
57    set objectSnapshot(snapshot) {
58      this.textContent =
59          snapshot.objectInstance.typeName + ' ' +
60          snapshot.objectInstance.id + ' @ ' +
61          tsRound(snapshot.ts) + ' ms';
62      this.selectionGenerator = function() {
63        return tracing.createSelectionFromObjectAndView(snapshot, this);
64      }.bind(this);
65    }
66  };
67
68  /**
69   * Changes the selection to the given ObjectInstance when clicked.
70   * @constructor
71   */
72  var ObjectInstanceLink = ui.define(
73      'object-instance-link', AnalysisLink);
74
75  ObjectInstanceLink.prototype = {
76    __proto__: AnalysisLink.prototype,
77
78    decorate: function() {
79      AnalysisLink.prototype.decorate.apply(this);
80    },
81
82    set objectInstance(instance) {
83      this.textContent = instance.typeName + ' ' + instance.id;
84      this.selectionGenerator = function() {
85        return tracing.createSelectionFromObjectAndView(instance, this);
86      }.bind(this);
87    }
88  };
89
90  return {
91    RequestSelectionChangeEvent: RequestSelectionChangeEvent,
92    AnalysisLink: AnalysisLink,
93    ObjectSnapshotLink: ObjectSnapshotLink,
94    ObjectInstanceLink: ObjectInstanceLink
95  };
96});
97