Bug 1858462 - Make shopping sidebar resizable. r=desktop-theme-reviewers,dao

Differential Revision: https://phabricator.services.mozilla.com/D193095
This commit is contained in:
Niklas Baumgardner 2023-11-16 21:43:54 +00:00
parent ebc47eaafd
commit 1e673cf70f
3 changed files with 24 additions and 1 deletions

View File

@ -192,8 +192,10 @@ class ShoppingSidebarManagerClass {
if (isProduct && this.isActive) {
if (!sidebar) {
sidebar = document.createXULElement("shopping-sidebar");
sidebar.setAttribute("style", "width: 320px");
sidebar.hidden = false;
let splitter = document.createXULElement("splitter");
splitter.classList.add("sidebar-splitter");
browserPanel.appendChild(splitter);
browserPanel.appendChild(sidebar);
} else {
actor?.updateProductURL(aLocationURI, aFlags);

View File

@ -7,6 +7,8 @@
// This is loaded into chrome windows with the subscript loader. Wrap in
// a block to prevent accidentally leaking globals onto `window`.
{
const SHOPPING_SIDEBAR_WIDTH_PREF =
"browser.shopping.experience2023.sidebarWidth";
class ShoppingSidebar extends MozXULElement {
#browser;
#initialized;
@ -41,11 +43,27 @@
if (this.#initialized) {
return;
}
this.resizeObserverFn = this.resizeObserverFn.bind(this);
this.appendChild(this.constructor.fragment);
this.#browser = this.querySelector(".shopping-sidebar");
let previousWidth = Services.prefs.getIntPref(
SHOPPING_SIDEBAR_WIDTH_PREF,
0
);
if (previousWidth > 0) {
this.style.width = `${previousWidth}px`;
}
this.resizeObserver = new ResizeObserver(this.resizeObserverFn);
this.resizeObserver.observe(this);
this.#initialized = true;
}
resizeObserverFn() {
Services.prefs.setIntPref(SHOPPING_SIDEBAR_WIDTH_PREF, this.scrollWidth);
}
}
customElements.define("shopping-sidebar", ShoppingSidebar);

View File

@ -1081,4 +1081,7 @@ panel toolbarseparator {
/* Shopping sidebar */
shopping-sidebar {
border-inline-start: 1px solid var(--chrome-content-separator-color);
min-width: 16.92em;
max-width: 32.31em;
width: 26.67em;
}