Upstream version 9.37.197.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / cc / layer_tree_host_impl_view.js
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
7 tvcm.requireStylesheet('cc.layer_tree_host_impl_view');
8
9 tvcm.require('cc.layer_tree_host_impl');
10 tvcm.require('cc.layer_picker');
11 tvcm.require('cc.layer_view');
12 tvcm.require('cc.tile');
13 tvcm.require('tracing.analysis.object_snapshot_view');
14 tvcm.require('tvcm.ui.drag_handle');
15
16 tvcm.exportTo('cc', function() {
17   /*
18    * Displays a LayerTreeHostImpl snapshot in a human readable form.
19    * @constructor
20    */
21   var LayerTreeHostImplSnapshotView = tvcm.ui.define(
22       'layer-tree-host-impl-snapshot-view',
23       tracing.analysis.ObjectSnapshotView);
24
25   LayerTreeHostImplSnapshotView.prototype = {
26     __proto__: tracing.analysis.ObjectSnapshotView.prototype,
27
28     decorate: function() {
29       this.classList.add('lthi-s-view');
30
31       this.selection_ = undefined;
32
33       this.layerPicker_ = new cc.LayerPicker();
34       this.layerPicker_.addEventListener(
35           'selection-changed',
36           this.onLayerPickerSelectionChanged_.bind(this));
37
38       this.layerView_ = new cc.LayerView();
39       this.layerView_.addEventListener(
40           'selection-changed',
41           this.onLayerViewSelectionChanged_.bind(this));
42       this.dragHandle_ = new tvcm.ui.DragHandle();
43       this.dragHandle_.horizontal = false;
44       this.dragHandle_.target = this.layerView_;
45
46       this.appendChild(this.layerPicker_);
47       this.appendChild(this.dragHandle_);
48       this.appendChild(this.layerView_);
49
50       // Make sure we have the current values from layerView_ and layerPicker_,
51       // since those might have been created before we added the listener.
52       this.onLayerViewSelectionChanged_();
53       this.onLayerPickerSelectionChanged_();
54
55     },
56
57     get objectSnapshot() {
58       return this.objectSnapshot_;
59     },
60
61     set objectSnapshot(objectSnapshot) {
62       this.objectSnapshot_ = objectSnapshot;
63
64       var lthi = this.objectSnapshot;
65       var layerTreeImpl;
66       if (lthi)
67         layerTreeImpl = lthi.getTree(this.layerPicker_.whichTree);
68
69       this.layerPicker_.lthiSnapshot = lthi;
70       this.layerView_.whichTree = this.layerPicker_.whichTree;
71       this.layerView_.layerTreeImpl = layerTreeImpl;
72       this.layerView_.regenerateContent();
73
74       if (!this.selection_)
75         return;
76       this.selection = this.selection_.findEquivalent(lthi);
77     },
78
79     get selection() {
80       return this.selection_;
81     },
82
83     set selection(selection) {
84       this.selection_ = selection;
85       this.layerPicker_.selection = selection;
86       this.layerView_.selection = selection;
87     },
88
89     onLayerPickerSelectionChanged_: function() {
90       this.selection_ = this.layerPicker_.selection;
91       this.layerView_.selection = this.selection;
92       this.layerView_.isRenderPassQuads = this.layerPicker_.isRenderPassQuads;
93       this.layerView_.regenerateContent();
94     },
95
96     onLayerViewSelectionChanged_: function() {
97       this.selection_ = this.layerView_.selection;
98       this.layerPicker_.selection = this.selection;
99     }
100
101   };
102
103   tracing.analysis.ObjectSnapshotView.register(
104       'cc::LayerTreeHostImpl', LayerTreeHostImplSnapshotView);
105
106   return {
107     LayerTreeHostImplSnapshotView: LayerTreeHostImplSnapshotView
108   };
109 });