OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 Polymer({ | 5 Polymer({ |
6 is: 'bookmarks-list', | 6 is: 'bookmarks-list', |
7 | 7 |
8 behaviors: [ | 8 behaviors: [ |
9 bookmarks.StoreClient, | 9 bookmarks.StoreClient, |
10 ], | 10 ], |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 var list = /** @type {IronListElement} */ (this.$.bookmarksCard); | 43 var list = /** @type {IronListElement} */ (this.$.bookmarksCard); |
44 list.scrollTarget = this; | 44 list.scrollTarget = this; |
45 | 45 |
46 this.watch('displayedIds_', function(state) { | 46 this.watch('displayedIds_', function(state) { |
47 return bookmarks.util.getDisplayedList(state); | 47 return bookmarks.util.getDisplayedList(state); |
48 }); | 48 }); |
49 this.watch('searchTerm_', function(state) { | 49 this.watch('searchTerm_', function(state) { |
50 return state.search.term; | 50 return state.search.term; |
51 }); | 51 }); |
52 this.updateFromStore(); | 52 this.updateFromStore(); |
53 | |
54 this.$.bookmarksCard.addEventListener( | |
55 'keydown', this.onItemKeydown_.bind(this), true); | |
53 }, | 56 }, |
54 | 57 |
55 /** @return {HTMLElement} */ | 58 /** @return {HTMLElement} */ |
56 getDropTarget: function() { | 59 getDropTarget: function() { |
57 return this.$.message; | 60 return this.$.message; |
58 }, | 61 }, |
59 | 62 |
60 /** | 63 /** |
61 * Updates `displayedList_` using splices to be equivalent to `newValue`. This | 64 * Updates `displayedList_` using splices to be equivalent to `newValue`. This |
62 * allows the iron-list to delete sublists of items which preserves scroll and | 65 * allows the iron-list to delete sublists of items which preserves scroll and |
(...skipping 30 matching lines...) Expand all Loading... | |
93 | 96 |
94 /** @private */ | 97 /** @private */ |
95 isEmptyList_: function() { | 98 isEmptyList_: function() { |
96 return this.displayedList_.length == 0; | 99 return this.displayedList_.length == 0; |
97 }, | 100 }, |
98 | 101 |
99 /** @private */ | 102 /** @private */ |
100 deselectItems_: function() { | 103 deselectItems_: function() { |
101 this.dispatch(bookmarks.actions.deselectItems()); | 104 this.dispatch(bookmarks.actions.deselectItems()); |
102 }, | 105 }, |
106 | |
107 /** @private */ | |
108 selectAllItems_: function() { | |
109 this.dispatch( | |
110 bookmarks.actions.selectAll(this.displayedIds_, this.getState())); | |
111 }, | |
112 | |
113 | |
tsergeant
2017/05/23 07:25:17
Nit: There's an extra \n here
calamity
2017/05/25 07:36:30
Done.
| |
114 getIndexForItemElement_: function(el) { | |
tsergeant
2017/05/23 07:25:17
Nit: Closure annotations here.
calamity
2017/05/25 07:36:30
Done.
| |
115 return this.$.bookmarksCard.modelForElement(el).index; | |
116 }, | |
117 | |
118 /** | |
119 * @param {KeyboardEvent} e | |
120 * @private | |
121 */ | |
122 onItemKeydown_: function(e) { | |
123 var handled = true; | |
124 var list = this.$.bookmarksCard; | |
125 var focusMoved = false; | |
126 var focusedIndex = this.getIndexForItemElement_(e.target); | |
127 if (e.key == 'ArrowUp') { | |
128 focusedIndex--; | |
129 focusMoved = true; | |
130 } else if (e.key == 'ArrowDown') { | |
131 focusedIndex++; | |
132 focusMoved = true; | |
133 e.preventDefault(); | |
134 } else if (e.key == 'Home') { | |
135 focusedIndex = 0; | |
136 focusMoved = true; | |
137 } else if (e.key == 'End') { | |
138 focusedIndex = list.items.length - 1; | |
139 focusMoved = true; | |
140 } else if (e.key == ' ' && e.ctrlKey) { | |
141 this.dispatch(bookmarks.actions.selectItem( | |
142 this.displayedIds_[focusedIndex], this.getState(), { | |
143 clear: false, | |
144 range: false, | |
145 toggle: true, | |
146 })); | |
147 } else if (e.key == 'a' && e.ctrlKey) { | |
148 this.selectAllItems_(); | |
149 } else if (e.key == 'Escape') { | |
150 this.deselectItems_(); | |
151 } else { | |
152 handled = false; | |
153 } | |
154 | |
155 if (focusMoved) { | |
156 focusedIndex = Math.min(list.items.length - 1, Math.max(0, focusedIndex)); | |
157 list.focusItem(focusedIndex); | |
158 | |
159 if (e.ctrlKey && !e.shiftKey) { | |
160 this.dispatch( | |
161 bookmarks.actions.updateAnchor(this.displayedIds_[focusedIndex])); | |
162 } else { | |
163 // If the focus moved from something other than a Ctrl + move event, | |
164 // update the selection. | |
165 var config = { | |
166 clear: !e.ctrlKey, | |
167 range: e.shiftKey, | |
168 toggle: false, | |
169 }; | |
170 | |
171 this.dispatch(bookmarks.actions.selectItem( | |
172 this.displayedIds_[focusedIndex], this.getState(), config)); | |
173 } | |
174 } | |
175 | |
176 if (handled) | |
177 e.stopPropagation(); | |
178 }, | |
103 }); | 179 }); |
OLD | NEW |