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