forked from mirrors/gecko-dev
Bug 1792748 - Persist sidebar style attribute rather than width attribute. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D158291
This commit is contained in:
parent
3b13923820
commit
ddbec758d4
6 changed files with 68 additions and 7 deletions
|
|
@ -3,7 +3,7 @@
|
|||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
<hbox flex="1" id="browser">
|
||||
<vbox id="sidebar-box" hidden="true" style="min-width: 14em; width: 18em; max-width: 36em" class="chromeclass-extrachrome">
|
||||
<vbox id="sidebar-box" hidden="true" class="chromeclass-extrachrome">
|
||||
<box id="sidebar-header" align="center">
|
||||
<toolbarbutton id="sidebar-switcher-target" class="tabbable">
|
||||
<image id="sidebar-icon" consumeanchor="sidebar-switcher-target"/>
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ var SidebarUI = {
|
|||
xulStore.removeValue(document.documentURI, "sidebar-box", "checked");
|
||||
}
|
||||
|
||||
xulStore.persist(this._box, "width");
|
||||
xulStore.persist(this._box, "style");
|
||||
xulStore.persist(this._title, "value");
|
||||
}
|
||||
|
||||
|
|
@ -345,10 +345,7 @@ var SidebarUI = {
|
|||
return true;
|
||||
}
|
||||
|
||||
this._box.setAttribute(
|
||||
"width",
|
||||
sourceUI._box.getBoundingClientRect().width
|
||||
);
|
||||
this._box.style.width = sourceUI._box.getBoundingClientRect().width + "px";
|
||||
this.showInitially(commandID);
|
||||
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -1482,6 +1482,12 @@ printpreview-pagination:focus-within,
|
|||
}
|
||||
}
|
||||
|
||||
#sidebar-box {
|
||||
min-width: 14em;
|
||||
max-width: 36em;
|
||||
width: 18em;
|
||||
}
|
||||
|
||||
/* WebExtension Sidebars */
|
||||
#sidebar-box[sidebarcommand$="-sidebar-action"] > #sidebar-header > #sidebar-switcher-target > #sidebar-icon {
|
||||
list-style-image: var(--webextension-menuitem-image, inherit);
|
||||
|
|
|
|||
|
|
@ -4,4 +4,5 @@
|
|||
[browser_sidebar_app_locale_changed.js]
|
||||
[browser_sidebar_keys.js]
|
||||
[browser_sidebar_move.js]
|
||||
[browser_sidebar_persist.js]
|
||||
[browser_sidebar_switcher.js]
|
||||
|
|
|
|||
37
browser/base/content/test/sidebar/browser_sidebar_persist.js
Normal file
37
browser/base/content/test/sidebar/browser_sidebar_persist.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
add_task(async function persist_sidebar_width() {
|
||||
{
|
||||
// Make the main test window not count as a browser window any longer,
|
||||
// which allows the persitence code to kick in.
|
||||
const docEl = document.documentElement;
|
||||
const oldWinType = docEl.getAttribute("windowtype");
|
||||
docEl.setAttribute("windowtype", "navigator:testrunner");
|
||||
registerCleanupFunction(() => {
|
||||
docEl.setAttribute("windowtype", oldWinType);
|
||||
});
|
||||
}
|
||||
|
||||
{
|
||||
info("Showing new window and setting sidebar box");
|
||||
const win = await BrowserTestUtils.openNewBrowserWindow();
|
||||
await win.SidebarUI.show("viewBookmarksSidebar");
|
||||
win.document.getElementById("sidebar-box").style.width = "100px";
|
||||
await BrowserTestUtils.closeWindow(win);
|
||||
}
|
||||
|
||||
{
|
||||
info("Showing new window and seeing persisted width");
|
||||
const win = await BrowserTestUtils.openNewBrowserWindow();
|
||||
await win.SidebarUI.show("viewBookmarksSidebar");
|
||||
is(
|
||||
win.document.getElementById("sidebar-box").style.width,
|
||||
"100px",
|
||||
"Width style should be persisted"
|
||||
);
|
||||
await BrowserTestUtils.closeWindow(win);
|
||||
}
|
||||
});
|
||||
|
|
@ -3511,7 +3511,7 @@ BrowserGlue.prototype = {
|
|||
_migrateUI: function BG__migrateUI() {
|
||||
// Use an increasing number to keep track of the current migration state.
|
||||
// Completely unrelated to the current Firefox release number.
|
||||
const UI_VERSION = 128;
|
||||
const UI_VERSION = 129;
|
||||
const BROWSER_DOCURL = AppConstants.BROWSER_CHROME_URL;
|
||||
|
||||
const PROFILE_DIR = Services.dirsvc.get("ProfD", Ci.nsIFile).path;
|
||||
|
|
@ -4287,6 +4287,26 @@ BrowserGlue.prototype = {
|
|||
}
|
||||
}
|
||||
|
||||
function migrateXULAttributeToStyle(id, attr) {
|
||||
try {
|
||||
let value = Services.xulStore.getValue(BROWSER_DOCURL, id, attr);
|
||||
if (value) {
|
||||
Services.xulStore.setValue(
|
||||
BROWSER_DOCURL,
|
||||
"style",
|
||||
`width: ${value}px;`
|
||||
);
|
||||
}
|
||||
} catch (ex) {
|
||||
Cu.reportError(`Error migrating ${id}'s ${attr} value: ` + ex);
|
||||
}
|
||||
}
|
||||
|
||||
// Bug 1792748, migrate sidebar persisted attribute from width to style.
|
||||
if (currentUIVersion < 129) {
|
||||
migrateXULAttributeToStyle("sidebar-box", "width");
|
||||
}
|
||||
|
||||
// Update the migration version.
|
||||
Services.prefs.setIntPref("browser.migration.version", UI_VERSION);
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue