1<!DOCTYPE html> 2<!-- 3Copyright (c) 2015 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/selection_state.html"> 9 10<script> 11'use strict'; 12 13/** 14 * @fileoverview Provides the SelectableItem class. 15 */ 16tr.exportTo('tr.model', function() { 17 var SelectionState = tr.model.SelectionState; 18 19 /** 20 * A SelectableItem is the abstract base class for any non-container data that 21 * has an associated model item in the trace model (possibly itself). 22 * 23 * Subclasses must provide a selectionState property (or getter). 24 * 25 * @constructor 26 */ 27 function SelectableItem(modelItem) { 28 this.modelItem_ = modelItem; 29 } 30 31 SelectableItem.prototype = { 32 get modelItem() { 33 return this.modelItem_; 34 }, 35 36 get selected() { 37 return this.selectionState === SelectionState.SELECTED; 38 }, 39 40 addToSelection: function(selection) { 41 var modelItem = this.modelItem_; 42 if (!modelItem) 43 return; 44 selection.push(modelItem); 45 }, 46 47 addToTrackMap: function(eventToTrackMap, track) { 48 var modelItem = this.modelItem_; 49 if (!modelItem) 50 return; 51 eventToTrackMap.addEvent(modelItem, track); 52 } 53 }; 54 55 return { 56 SelectableItem: SelectableItem 57 }; 58}); 59</script> 60