Index: chrome/browser/resources/md_bookmarks/list.js |
diff --git a/chrome/browser/resources/md_bookmarks/list.js b/chrome/browser/resources/md_bookmarks/list.js |
index 07951140491ba312e760b37f12ed3423dcf921ae..75810eaaddfd5c0710b7cc919e29a4d1c6105137 100644 |
--- a/chrome/browser/resources/md_bookmarks/list.js |
+++ b/chrome/browser/resources/md_bookmarks/list.js |
@@ -50,6 +50,9 @@ Polymer({ |
return state.search.term; |
}); |
this.updateFromStore(); |
+ |
+ this.$.bookmarksCard.addEventListener( |
+ 'keydown', this.onItemKeydown_.bind(this), true); |
}, |
/** @return {HTMLElement} */ |
@@ -100,4 +103,81 @@ Polymer({ |
deselectItems_: function() { |
this.dispatch(bookmarks.actions.deselectItems()); |
}, |
+ |
+ /** @private */ |
+ selectAllItems_: function() { |
+ this.dispatch( |
+ bookmarks.actions.selectAll(this.displayedIds_, this.getState())); |
+ }, |
+ |
+ /** |
+ * @param{HTMLElement} el |
+ * @private |
+ */ |
+ getIndexForItemElement_: function(el) { |
+ return this.$.bookmarksCard.modelForElement(el).index; |
+ }, |
+ |
+ /** |
+ * @param {KeyboardEvent} e |
+ * @private |
+ */ |
+ onItemKeydown_: function(e) { |
+ var handled = true; |
+ var list = this.$.bookmarksCard; |
+ var focusMoved = false; |
+ var focusedIndex = |
+ this.getIndexForItemElement_(/** @type {HTMLElement} */ (e.target)); |
+ if (e.key == 'ArrowUp') { |
+ focusedIndex--; |
+ focusMoved = true; |
+ } else if (e.key == 'ArrowDown') { |
+ focusedIndex++; |
+ focusMoved = true; |
+ e.preventDefault(); |
+ } else if (e.key == 'Home') { |
+ focusedIndex = 0; |
+ focusMoved = true; |
+ } else if (e.key == 'End') { |
+ focusedIndex = list.items.length - 1; |
+ focusMoved = true; |
+ } else if (e.key == ' ' && e.ctrlKey) { |
+ this.dispatch(bookmarks.actions.selectItem( |
+ this.displayedIds_[focusedIndex], this.getState(), { |
+ clear: false, |
+ range: false, |
+ toggle: true, |
+ })); |
+ } else if (e.key == 'a' && e.ctrlKey) { |
+ this.selectAllItems_(); |
+ } else if (e.key == 'Escape') { |
+ this.deselectItems_(); |
+ } else { |
+ handled = false; |
+ } |
+ |
+ if (focusMoved) { |
+ focusedIndex = Math.min(list.items.length - 1, Math.max(0, focusedIndex)); |
+ list.focusItem(focusedIndex); |
+ |
+ if (e.ctrlKey && !e.shiftKey) { |
+ this.dispatch( |
+ bookmarks.actions.updateAnchor(this.displayedIds_[focusedIndex])); |
+ } else { |
+ // If the focus moved from something other than a Ctrl + move event, |
+ // update the selection. |
+ var config = { |
+ clear: !e.ctrlKey, |
+ range: e.shiftKey, |
+ toggle: false, |
+ }; |
+ |
+ this.dispatch(bookmarks.actions.selectItem( |
+ this.displayedIds_[focusedIndex], this.getState(), config)); |
+ } |
+ } |
+ |
+ if (handled) |
+ e.stopPropagation(); |
+ }, |
}); |