| Index: chrome/browser/resources/md_history/history_item.js
|
| diff --git a/chrome/browser/resources/md_history/history_item.js b/chrome/browser/resources/md_history/history_item.js
|
| index e7bc2da94e621d70fe34ba1f1389c2b557c7daa1..be5f426535b0ec6ee8d6a7f70036a1db317d93c2 100644
|
| --- a/chrome/browser/resources/md_history/history_item.js
|
| +++ b/chrome/browser/resources/md_history/history_item.js
|
| @@ -2,7 +2,79 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| +/**
|
| + * @param {!Element} root
|
| + * @param {?Element} boundary
|
| + * @param {cr.ui.FocusRow.Delegate} delegate
|
| + * @constructor
|
| + * @extends {cr.ui.FocusRow}
|
| + */
|
| +function HistoryFocusRow(root, boundary, delegate) {
|
| + cr.ui.FocusRow.call(this, root, boundary, delegate);
|
| + this.addItems();
|
| +}
|
| +
|
| +HistoryFocusRow.prototype = {
|
| + __proto__: cr.ui.FocusRow.prototype,
|
| +
|
| + /** @override */
|
| + getCustomEquivalent: function(sampleElement) {
|
| + var equivalent;
|
| +
|
| + if (this.getTypeForElement(sampleElement) == 'star')
|
| + equivalent = this.getFirstFocusable('title');
|
| +
|
| + return equivalent ||
|
| + cr.ui.FocusRow.prototype.getCustomEquivalent.call(
|
| + this, sampleElement);
|
| + },
|
| +
|
| + addItems: function() {
|
| + this.destroy();
|
| +
|
| + assert(this.addItem('checkbox', '#checkbox'));
|
| + assert(this.addItem('title', '#title'));
|
| + assert(this.addItem('menu-button', '#menu-button'));
|
| +
|
| + this.addItem('star', '#bookmark-star');
|
| + },
|
| +};
|
| +
|
| cr.define('md_history', function() {
|
| + /**
|
| + * @param {{lastFocused: Object}} historyItemElement
|
| + * @constructor
|
| + * @implements {cr.ui.FocusRow.Delegate}
|
| + */
|
| + function FocusRowDelegate(historyItemElement) {
|
| + this.historyItemElement = historyItemElement;
|
| + }
|
| +
|
| + FocusRowDelegate.prototype = {
|
| + /**
|
| + * @override
|
| + * @param {!cr.ui.FocusRow} row
|
| + * @param {!Event} e
|
| + */
|
| + onFocus: function(row, e) {
|
| + this.historyItemElement.lastFocused = e.path[0];
|
| + },
|
| +
|
| + /**
|
| + * @override
|
| + * @param {!cr.ui.FocusRow} row The row that detected a keydown.
|
| + * @param {!Event} e
|
| + * @return {boolean} Whether the event was handled.
|
| + */
|
| + onKeydown: function(row, e) {
|
| + // Prevent iron-list from changing the focus on enter.
|
| + if (e.key == 'Enter')
|
| + e.stopPropagation();
|
| +
|
| + return false;
|
| + },
|
| + };
|
| +
|
| var HistoryItem = Polymer({
|
| is: 'history-item',
|
|
|
| @@ -32,6 +104,67 @@ cr.define('md_history', function() {
|
| path: String,
|
|
|
| index: Number,
|
| +
|
| + /** @type {Element} */
|
| + lastFocused: {
|
| + type: Object,
|
| + notify: true,
|
| + },
|
| +
|
| + ironListTabIndex: {
|
| + type: Number,
|
| + observer: 'ironListTabIndexChanged_',
|
| + },
|
| + },
|
| +
|
| + /** @private {?HistoryFocusRow} */
|
| + row_: null,
|
| +
|
| + /** @override */
|
| + attached: function() {
|
| + Polymer.RenderStatus.afterNextRender(this, function() {
|
| + this.row_ = new HistoryFocusRow(
|
| + this.$['sizing-container'], null, new FocusRowDelegate(this));
|
| + this.row_.makeActive(this.ironListTabIndex == 0);
|
| + this.listen(this, 'focus', 'onFocus_');
|
| + this.listen(this, 'dom-change', 'onDomChange_');
|
| + });
|
| + },
|
| +
|
| + /** @override */
|
| + detached: function() {
|
| + this.unlisten(this, 'focus', 'onFocus_');
|
| + this.unlisten(this, 'dom-change', 'onDomChange_');
|
| + if (this.row_)
|
| + this.row_.destroy();
|
| + },
|
| +
|
| + /**
|
| + * @private
|
| + */
|
| + onFocus_: function() {
|
| + if (this.lastFocused)
|
| + this.row_.getEquivalentElement(this.lastFocused).focus();
|
| + else
|
| + this.row_.getFirstFocusable().focus();
|
| +
|
| + this.tabIndex = -1;
|
| + },
|
| +
|
| + /**
|
| + * @private
|
| + */
|
| + ironListTabIndexChanged_: function() {
|
| + if (this.row_)
|
| + this.row_.makeActive(this.ironListTabIndex == 0);
|
| + },
|
| +
|
| + /**
|
| + * @private
|
| + */
|
| + onDomChange_: function() {
|
| + if (this.row_)
|
| + this.row_.addItems();
|
| },
|
|
|
| /**
|
| @@ -116,7 +249,7 @@ cr.define('md_history', function() {
|
|
|
| /**
|
| * Record metrics when a result is clicked. This is deliberately tied to
|
| - * on-click rather than on-tap, as on-click triggers from middle clicks.
|
| + * on-click rather than on-tap, as on-click triggers from middle clicks.
|
| */
|
| onLinkClick_: function() {
|
| var browserService = md_history.BrowserService.getInstance();
|
|
|