Home | History | Annotate | Download | only in timeline
      1 /*
      2  * Copyright 2014 The Chromium Authors. All rights reserved.
      3  * Use of this source code is governed by a BSD-style license that can be
      4  * found in the LICENSE file.
      5  */
      6 
      7 /**
      8  * @constructor
      9  * @extends {WebInspector.VBox}
     10  */
     11 WebInspector.TimelineLayersView = function()
     12 {
     13     WebInspector.VBox.call(this);
     14     this._layers3DView = new WebInspector.Layers3DView();
     15     this._layers3DView.addEventListener(WebInspector.Layers3DView.Events.ObjectSelected, this._onObjectSelected, this);
     16     this._layers3DView.addEventListener(WebInspector.Layers3DView.Events.ObjectHovered, this._onObjectHovered, this);
     17     this._layers3DView.show(this.element);
     18 }
     19 
     20 WebInspector.TimelineLayersView.prototype = {
     21     /**
     22      * @param {!WebInspector.DeferredLayerTree} deferredLayerTree
     23      */
     24     showLayerTree: function(deferredLayerTree)
     25     {
     26         this._target = deferredLayerTree.target();
     27         deferredLayerTree.resolve(onLayersReady.bind(this));
     28         /**
     29          * @param {!WebInspector.LayerTreeBase} layerTree
     30          * @this {WebInspector.TimelineLayersView} this
     31          */
     32         function onLayersReady(layerTree)
     33         {
     34             this._layers3DView.setLayerTree(layerTree);
     35         }
     36     },
     37 
     38     /**
     39      * @param {?WebInspector.Layers3DView.ActiveObject} activeObject
     40      */
     41     _selectObject: function(activeObject)
     42     {
     43         var layer = activeObject && activeObject.layer;
     44         if (this._currentlySelectedLayer === activeObject)
     45             return;
     46         this._currentlySelectedLayer = activeObject;
     47         var node = layer ? layer.nodeForSelfOrAncestor() : null;
     48         if (node)
     49             node.highlightForTwoSeconds();
     50         else
     51             this._target.domModel.hideDOMNodeHighlight();
     52         this._layers3DView.selectObject(activeObject);
     53     },
     54 
     55     /**
     56      * @param {?WebInspector.Layers3DView.ActiveObject} activeObject
     57      */
     58     _hoverObject: function(activeObject)
     59     {
     60         var layer = activeObject && activeObject.layer;
     61         if (this._currentlyHoveredLayer === activeObject)
     62             return;
     63         this._currentlyHoveredLayer = activeObject;
     64         var node = layer ? layer.nodeForSelfOrAncestor() : null;
     65         if (node)
     66             node.highlight();
     67         else
     68             this._target.domModel.hideDOMNodeHighlight();
     69         this._layers3DView.hoverObject(activeObject);
     70     },
     71 
     72     /**
     73      * @param {!WebInspector.Event} event
     74      */
     75     _onObjectSelected: function(event)
     76     {
     77         var activeObject = /** @type {!WebInspector.Layers3DView.ActiveObject} */ (event.data);
     78         this._selectObject(activeObject);
     79     },
     80 
     81     /**
     82      * @param {!WebInspector.Event} event
     83      */
     84     _onObjectHovered: function(event)
     85     {
     86         var activeObject = /** @type {!WebInspector.Layers3DView.ActiveObject} */ (event.data);
     87         this._hoverObject(activeObject);
     88     },
     89 
     90     __proto__: WebInspector.VBox.prototype
     91 }
     92