Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(266)

Side by Side Diff: tracing/tracing/ui/base/list_view.html

Issue 2776653002: [ESLint] Fix violations when enabling curly rule in eslint. (Closed)
Patch Set: Fix test Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <!-- 2 <!--
3 Copyright (c) 2014 The Chromium Authors. All rights reserved. 3 Copyright (c) 2014 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be 4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file. 5 found in the LICENSE file.
6 --> 6 -->
7 7
8 <link rel="stylesheet" href="/tracing/ui/base/list_view.css"> 8 <link rel="stylesheet" href="/tracing/ui/base/list_view.css">
9 9
10 <link rel="import" href="/tracing/base/event.html"> 10 <link rel="import" href="/tracing/base/event.html">
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 Polymer.dom(item).classList.add('list-item'); 44 Polymer.dom(item).classList.add('list-item');
45 item.addEventListener('click', this.onItemClicked_, true); 45 item.addEventListener('click', this.onItemClicked_, true);
46 46
47 var listView = this; 47 var listView = this;
48 Object.defineProperty( 48 Object.defineProperty(
49 item, 49 item,
50 'selected', { 50 'selected', {
51 configurable: true, 51 configurable: true,
52 set: function(value) { 52 set: function(value) {
53 var oldSelection = listView.selectedElement; 53 var oldSelection = listView.selectedElement;
54 if (oldSelection && oldSelection !== this && value) 54 if (oldSelection && oldSelection !== this && value) {
55 Polymer.dom(listView.selectedElement).removeAttribute( 55 Polymer.dom(listView.selectedElement).removeAttribute(
56 'selected'); 56 'selected');
57 if (value) 57 }
58 if (value) {
58 Polymer.dom(this).setAttribute('selected', 'selected'); 59 Polymer.dom(this).setAttribute('selected', 'selected');
59 else 60 } else {
60 Polymer.dom(this).removeAttribute('selected'); 61 Polymer.dom(this).removeAttribute('selected');
62 }
61 var newSelection = listView.selectedElement; 63 var newSelection = listView.selectedElement;
62 if (newSelection !== oldSelection) 64 if (newSelection !== oldSelection) {
63 tr.b.dispatchSimpleEvent(listView, 'selection-changed', false); 65 tr.b.dispatchSimpleEvent(listView, 'selection-changed', false);
66 }
64 }, 67 },
65 get: function() { 68 get: function() {
66 return this.hasAttribute('selected'); 69 return this.hasAttribute('selected');
67 } 70 }
68 }); 71 });
69 }, 72 },
70 73
71 undecorateChild_: function(item) { 74 undecorateChild_: function(item) {
72 this.selectionChanged_ |= item.selected; 75 this.selectionChanged_ |= item.selected;
73 76
74 Polymer.dom(item).classList.remove('list-item'); 77 Polymer.dom(item).classList.remove('list-item');
75 item.removeEventListener('click', this.onItemClicked_); 78 item.removeEventListener('click', this.onItemClicked_);
76 delete item.selected; 79 delete item.selected;
77 }, 80 },
78 81
79 beginDecorating_: function() { 82 beginDecorating_: function() {
80 this.selectionChanged_ = false; 83 this.selectionChanged_ = false;
81 }, 84 },
82 85
83 doneDecoratingForNow_: function() { 86 doneDecoratingForNow_: function() {
84 if (this.selectionChanged_) 87 if (this.selectionChanged_) {
85 tr.b.dispatchSimpleEvent(this, 'selection-changed', false); 88 tr.b.dispatchSimpleEvent(this, 'selection-changed', false);
89 }
86 }, 90 },
87 91
88 get selectedElement() { 92 get selectedElement() {
89 var el = Polymer.dom(this).querySelector('.list-item[selected]'); 93 var el = Polymer.dom(this).querySelector('.list-item[selected]');
90 if (!el) 94 if (!el) return undefined;
91 return undefined;
92 return el; 95 return el;
93 }, 96 },
94 97
95 set selectedElement(el) { 98 set selectedElement(el) {
96 if (!el) { 99 if (!el) {
97 if (this.selectedElement) 100 if (this.selectedElement) {
98 this.selectedElement.selected = false; 101 this.selectedElement.selected = false;
102 }
99 return; 103 return;
100 } 104 }
101 105
102 if (el.parentElement !== this) 106 if (el.parentElement !== this) {
103 throw new Error( 107 throw new Error(
104 'Can only select elements that are children of this list view'); 108 'Can only select elements that are children of this list view');
109 }
105 el.selected = true; 110 el.selected = true;
106 }, 111 },
107 112
108 getElementByIndex: function(index) { 113 getElementByIndex: function(index) {
109 return Polymer.dom(this) 114 return Polymer.dom(this)
110 .querySelector('.list-item:nth-child(' + index + ')'); 115 .querySelector('.list-item:nth-child(' + index + ')');
111 }, 116 },
112 117
113 clear: function() { 118 clear: function() {
114 var changed = this.selectedElement !== undefined; 119 var changed = this.selectedElement !== undefined;
115 tr.ui.b.ContainerThatDecoratesItsChildren.prototype.clear.call(this); 120 tr.ui.b.ContainerThatDecoratesItsChildren.prototype.clear.call(this);
116 if (changed) 121 if (changed) {
117 tr.b.dispatchSimpleEvent(this, 'selection-changed', false); 122 tr.b.dispatchSimpleEvent(this, 'selection-changed', false);
123 }
118 }, 124 },
119 125
120 onItemClicked_: function(e) { 126 onItemClicked_: function(e) {
121 var currentSelectedElement = this.selectedElement; 127 var currentSelectedElement = this.selectedElement;
122 if (currentSelectedElement) 128 if (currentSelectedElement) {
123 Polymer.dom(currentSelectedElement).removeAttribute('selected'); 129 Polymer.dom(currentSelectedElement).removeAttribute('selected');
130 }
124 var element = e.target; 131 var element = e.target;
125 while (element.parentElement !== this) 132 while (element.parentElement !== this) {
126 element = element.parentElement; 133 element = element.parentElement;
127 if (element !== currentSelectedElement) 134 }
135 if (element !== currentSelectedElement) {
128 Polymer.dom(element).setAttribute('selected', 'selected'); 136 Polymer.dom(element).setAttribute('selected', 'selected');
137 }
129 tr.b.dispatchSimpleEvent(this, 'selection-changed', false); 138 tr.b.dispatchSimpleEvent(this, 'selection-changed', false);
130 }, 139 },
131 140
132 onKeyDown_: function(e) { 141 onKeyDown_: function(e) {
133 if (this.selectedElement === undefined) 142 if (this.selectedElement === undefined) return;
134 return;
135 143
136 if (e.keyCode === 38) { // Up arrow. 144 if (e.keyCode === 38) { // Up arrow.
137 var prev = Polymer.dom(this.selectedElement).previousSibling; 145 var prev = Polymer.dom(this.selectedElement).previousSibling;
138 if (prev) { 146 if (prev) {
139 prev.selected = true; 147 prev.selected = true;
140 tr.ui.b.scrollIntoViewIfNeeded(prev); 148 tr.ui.b.scrollIntoViewIfNeeded(prev);
141 e.preventDefault(); 149 e.preventDefault();
142 return true; 150 return true;
143 } 151 }
144 } else if (e.keyCode === 40) { // Down arrow. 152 } else if (e.keyCode === 40) { // Down arrow.
(...skipping 14 matching lines...) Expand all
159 return item; 167 return item;
160 } 168 }
161 169
162 }; 170 };
163 171
164 return { 172 return {
165 ListView, 173 ListView,
166 }; 174 };
167 }); 175 });
168 </script> 176 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698