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/base/ui.html"> 10<link rel="import" href="/tracing/ui/brushing_state_controller.html"> 11 12<polymer-element name="tr-ui-a-analysis-link" is="a" 13 on-click="{{onClicked_}}" 14 on-mouseenter="{{onMouseEnter_}}" 15 on-mouseleave="{{onMouseLeave_}}"> 16 <template> 17 <style> 18 :host { 19 display: inline; 20 color: -webkit-link; 21 cursor: pointer; 22 text-decoration: underline; 23 cursor: pointer; 24 } 25 </style> 26 <content></content> 27 </template> 28 <script> 29 'use strict'; 30 Polymer({ 31 ready: function() { 32 this.selection_ = undefined; 33 }, 34 35 attached: function() { 36 // Save an instance of the controller since it's going to be used in 37 // detached() where it can no longer be obtained. 38 this.controller_ = 39 tr.c.BrushingStateController.getControllerForElement(this); 40 }, 41 42 detached: function() { 43 // Reset highlights. 44 this.clearHighlight_(); 45 this.controller_ = undefined; 46 }, 47 48 get selection() { 49 return this.selection_; 50 }, 51 52 set selection(selection) { 53 // Selection can be either an EventSet or a function. 54 this.selection_ = selection; 55 this.textContent = selection.userFriendlyName; 56 }, 57 58 setSelectionAndContent: function(selection, opt_textContent) { 59 this.selection_ = selection; 60 if (opt_textContent) 61 this.textContent = opt_textContent; 62 }, 63 64 getCurrentSelection_: function() { 65 // Gets the current selection, invoking the selection function if needed. 66 if (typeof this.selection_ === 'function') 67 return this.selection_(); 68 return this.selection_; 69 }, 70 71 setHighlight_: function(opt_eventSet) { 72 if (this.controller_) 73 this.controller_.changeAnalysisLinkHoveredEvents(opt_eventSet); 74 }, 75 76 clearHighlight_: function(opt_eventSet) { 77 this.setHighlight_(); 78 }, 79 80 onClicked_: function() { 81 if (!this.selection_) 82 return; 83 84 var event = new tr.model.RequestSelectionChangeEvent(); 85 event.selection = this.getCurrentSelection_(); 86 this.dispatchEvent(event); 87 }, 88 89 onMouseEnter_: function() { 90 this.setHighlight_(this.getCurrentSelection_()); 91 }, 92 93 onMouseLeave_: function() { 94 this.clearHighlight_(); 95 } 96 }); 97 </script> 98</polymer-element> 99