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('cc.layer_tree_host_impl_view'); 8 9base.require('cc.layer_tree_host_impl'); 10base.require('cc.layer_picker'); 11base.require('cc.layer_viewer'); 12base.require('cc.tile'); 13base.require('tracing.analysis.object_snapshot_view'); 14base.require('ui.drag_handle'); 15 16base.exportTo('cc', function() { 17 /* 18 * Displays a LayerTreeHostImpl snapshot in a human readable form. 19 * @constructor 20 */ 21 var LayerTreeHostImplSnapshotView = 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.dragHandle_ = new ui.DragHandle(); 39 this.dragHandle_.horizontal = false; 40 this.dragHandle_.target = this.layerPicker_; 41 42 this.layerViewer_ = new cc.LayerViewer(); 43 this.layerViewer_.addEventListener( 44 'selection-changed', 45 this.onLayerViewerSelectionChanged_.bind(this)); 46 47 this.appendChild(this.layerPicker_); 48 this.appendChild(this.dragHandle_); 49 this.appendChild(this.layerViewer_); 50 }, 51 52 get objectSnapshot() { 53 return this.objectSnapshot_; 54 }, 55 56 set objectSnapshot(objectSnapshot) { 57 this.objectSnapshot_ = objectSnapshot; 58 59 var lthi = this.objectSnapshot; 60 var layerTreeImpl; 61 if (lthi) 62 layerTreeImpl = lthi.getTree(this.layerPicker_.whichTree); 63 this.layerPicker_.lthiSnapshot = lthi; 64 this.layerViewer_.layerTreeImpl = layerTreeImpl; 65 66 if (!this.selection_) 67 return; 68 this.selection = this.selection_.findEquivalent(lthi); 69 }, 70 71 get selection() { 72 return this.selection_; 73 }, 74 75 set selection(selection) { 76 this.selection_ = selection; 77 this.layerPicker_.selection = selection; 78 this.layerViewer_.selection = selection; 79 }, 80 81 onLayerPickerSelectionChanged_: function() { 82 this.selection_ = this.layerPicker_.selection; 83 this.layerViewer_.selection = this.selection; 84 }, 85 86 onLayerViewerSelectionChanged_: function() { 87 this.selection_ = this.layerViewer_.selection; 88 this.layerPicker_.selection = this.selection; 89 } 90 91 }; 92 93 tracing.analysis.ObjectSnapshotView.register( 94 'cc::LayerTreeHostImpl', LayerTreeHostImplSnapshotView); 95 96 return { 97 LayerTreeHostImplSnapshotView: LayerTreeHostImplSnapshotView 98 }; 99}); 100