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/model/event_set.html">
9<link rel="import" href="/tracing/ui/analysis/analysis_link.html">
10<link rel="import" href="/tracing/ui/analysis/analysis_sub_view.html">
11<link rel="import" href="/tracing/ui/analysis/generic_object_view.html">
12<link rel="import" href="/tracing/ui/analysis/object_instance_view.html">
13<link rel="import" href="/tracing/ui/analysis/object_snapshot_view.html">
14<link rel="import" href="/tracing/ui/analysis/single_event_sub_view.html">
15<link rel="import" href="/tracing/value/ui/scalar_span.html">
16<link rel="import" href="/tracing/value/unit.html">
17
18<polymer-element name="tr-ui-a-single-object-snapshot-sub-view"
19    extends="tr-ui-a-sub-view">
20  <template>
21    <style>
22    #args {
23      white-space: pre;
24    }
25
26    :host {
27      overflow: auto;
28      display: flex;
29    }
30
31    ::content * {
32      -webkit-user-select: text;
33    }
34
35    ::content .title {
36      border-bottom: 1px solid rgb(128, 128, 128);
37      font-size: 110%;
38      font-weight: bold;
39    }
40
41    ::content td, th {
42      font-family: monospace;
43      vertical-align: top;
44    }
45    </style>
46    <content></content>
47  </template>
48  <script>
49  'use strict';
50
51  Polymer({
52    created: function() {
53      this.currentSelection_ = undefined;
54    },
55
56    get requiresTallView() {
57      if (this.children.length === 0)
58        return false;
59      if (this.children[0] instanceof tr.ui.analysis.ObjectSnapshotView)
60        return this.children[0].requiresTallView;
61    },
62
63    get selection() {
64      return this.currentSelection_;
65    },
66
67    set selection(selection) {
68      if (selection.length !== 1)
69        throw new Error('Only supports single item selections');
70      if (!(selection[0] instanceof tr.model.ObjectSnapshot))
71        throw new Error('Only supports object instances');
72
73      this.textContent = '';
74      this.currentSelection_ = selection;
75
76      var snapshot = selection[0];
77
78      var typeInfo = tr.ui.analysis.ObjectSnapshotView.getTypeInfo(
79          snapshot.objectInstance.category, snapshot.objectInstance.typeName);
80      if (typeInfo) {
81        var customView = new typeInfo.constructor();
82        this.appendChild(customView);
83        customView.modelEvent = snapshot;
84      } else {
85        this.appendGenericAnalysis_(snapshot);
86      }
87    },
88
89    appendGenericAnalysis_: function(snapshot) {
90      var instance = snapshot.objectInstance;
91
92      this.textContent = '';
93
94      var titleEl = document.createElement('div');
95      titleEl.classList.add('title');
96      titleEl.appendChild(document.createTextNode('Snapshot of '));
97      this.appendChild(titleEl);
98
99      var instanceLinkEl = document.createElement('tr-ui-a-analysis-link');
100      instanceLinkEl.selection = new tr.model.EventSet(instance);
101      titleEl.appendChild(instanceLinkEl);
102
103      titleEl.appendChild(document.createTextNode(' @ '));
104
105      titleEl.appendChild(tr.v.ui.createScalarSpan(snapshot.ts, {
106        unit: tr.v.Unit.byName.timeStampInMs,
107        ownerDocument: this.ownerDocument
108      }));
109
110      var tableEl = document.createElement('table');
111      this.appendChild(tableEl);
112
113      var rowEl = document.createElement('tr');
114      tableEl.appendChild(rowEl);
115
116      var labelEl = document.createElement('td');
117      labelEl.textContent = 'args:';
118      rowEl.appendChild(labelEl);
119
120      var argsEl = document.createElement('td');
121      argsEl.id = 'args';
122      rowEl.appendChild(argsEl);
123
124      var objectViewEl = document.createElement('tr-ui-a-generic-object-view');
125      objectViewEl.object = snapshot.args;
126      argsEl.appendChild(objectViewEl);
127    }
128  });
129  </script>
130</polymer-element>
131