/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import { classMap, html, ifDefined, when, } from "chrome://global/content/vendor/lit.all.mjs"; import { FxviewTabListBase, FxviewTabRowBase, } from "chrome://browser/content/firefoxview/fxview-tab-list.mjs"; export class SidebarTabList extends FxviewTabListBase { constructor() { super(); // Panel is open, assume we always want to react to updates. this.updatesPaused = false; } static queries = { ...FxviewTabListBase.queries, rowEls: { all: "sidebar-tab-row", }, }; /** * Only handle vertical navigation in sidebar. * * @param {KeyboardEvent} e */ handleFocusElementInRow(e) { if ( (e.code == "ArrowUp" && this.activeIndex > 0) || (e.code == "ArrowDown" && this.activeIndex < this.rowEls.length - 1) ) { super.handleFocusElementInRow(e); } else if (e.code == "ArrowUp" && this.activeIndex == 0) { let parentCard = e.target.getRootNode().host.closest("moz-card"); if (parentCard) { parentCard.summaryEl.focus(); } } else if ( e.code == "ArrowDown" && this.activeIndex == this.rowEls.length - 1 ) { let parentCard = e.target.getRootNode().host.closest("moz-card"); if ( this.sortOption == "datesite" && parentCard.classList.contains("last-card") ) { // If we're going down from the last site, then focus the next date. const dateCard = parentCard.parentElement; const nextDate = dateCard.nextElementSibling; nextDate?.summaryEl.focus(); } let nextCard = parentCard.nextElementSibling; if (nextCard && nextCard.localName == "moz-card") { nextCard.summaryEl.focus(); } } } itemTemplate = (tabItem, i) => { let tabIndex = -1; if (this.sortOption == "lastvisited" && i == 0) { // Last Visited doesn't have a header. Make the first row focusable. tabIndex = 0; } return html` e.currentTarget.primaryActionHandler(e)} > `; }; stylesheets() { return [ super.stylesheets(), html``, ]; } } customElements.define("sidebar-tab-list", SidebarTabList); export class SidebarTabRow extends FxviewTabRowBase { /** * Fallback to the native implementation in sidebar. We want to focus the * entire row instead of delegating it to link or hover buttons. */ focus() { HTMLElement.prototype.focus.call(this); } secondaryButtonTemplate() { return html`${when( this.secondaryL10nId && this.secondaryActionClass, () => html`` )}`; } render() { return html` ${this.stylesheets()} ${this.faviconTemplate()} ${this.titleTemplate()} ${this.secondaryButtonTemplate()} `; } } customElements.define("sidebar-tab-row", SidebarTabRow);