Skip to content

Commit 630b1a8

Browse files
committed
Bug 1869574 - Refactor the headerText setter to cater for more panelview needs r=twisniewski,Gijs,translations-reviewers
This introduces `mainview-with-header` attribute for panels that their mainview should have a header (no matter where they appear); and `has-custom-header` for panels that their panelview (not necessarily a mainview) has a custom design for a header, one that headerText setter can't anticipate in advance (due to UX needs that may arise). If one of these attributes are set on the panel, this signals headerText that the panelview's header should NOT be removed and that the markup should be respected. Differential Revision: https://phabricator.services.mozilla.com/D196671
1 parent 60e4672 commit 630b1a8

File tree

8 files changed

+70
-48
lines changed

8 files changed

+70
-48
lines changed

browser/base/content/appmenu-viewcache.inc.xhtml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,9 @@
260260
/>
261261
</panelview>
262262

263-
<panelview id="PanelUI-profiler" showheader="true">
263+
<panelview id="PanelUI-profiler"
264+
mainview-with-header="true"
265+
has-customized-header="true">
264266
<vbox id="PanelUI-profiler-header" animationready="false">
265267
<hbox id="PanelUI-profiler-header-bar"
266268
class="panel-header panel-header-with-additional-element panel-header-with-info-button">
@@ -718,7 +720,7 @@
718720
</vbox>
719721
</panelview>
720722

721-
<panelview id="PanelUI-whatsNew" class="PanelUI-subView" showheader="true">
723+
<panelview id="PanelUI-whatsNew" class="PanelUI-subView" mainview-with-header="true">
722724
<hbox id="PanelUI-whatsNew-title" class="panel-header">
723725
<html:h1>
724726
<html:span data-l10n-id="whatsnew-panel-header"></html:span>

browser/components/controlcenter/content/identityPanel.inc.xhtml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,16 @@
1515

1616
<panelmultiview id="identity-popup-multiView"
1717
mainViewId="identity-popup-mainView">
18-
<panelview id="identity-popup-mainView" class="PanelUI-subView" role="document" showheader="true">
18+
<panelview id="identity-popup-mainView"
19+
class="PanelUI-subView"
20+
role="document"
21+
mainview-with-header="true">
22+
<!-- The panel header text value changes dynamically by browser-siteIdentity.js,
23+
- that's why the panel header box needs to remain hardcoded in the markup.
24+
- instead of being handled by PanelMultiView.sys.mjs. -->
1925
<box id="identity-popup-mainView-panel-header" class="panel-header">
2026
<html:h1>
21-
<html:span id="identity-popup-mainView-panel-header-span" role="heading" aria-level="1"/>
27+
<html:span id="identity-popup-mainView-panel-header-span"/>
2228
</html:h1>
2329
</box>
2430
<toolbarseparator/>

browser/components/controlcenter/content/permissionPanel.inc.xhtml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616
mainViewId="permission-popup-mainView">
1717
<panelview id="permission-popup-mainView"
1818
role="document"
19-
showheader="true">
19+
mainview-with-header="true">
20+
<!-- The panel header text value changes dynamically by browser-sitePermissionPanel.js,
21+
- that's why the panel header box needs to remain hardcoded in the markup.
22+
- instead of being handled by PanelMultiView.sys.mjs. -->
2023
<box id="permission-popup-mainView-panel-header" class="panel-header">
2124
<html:h1>
22-
<html:span id="permission-popup-mainView-panel-header-span" role="heading" aria-level="1"/>
25+
<html:span id="permission-popup-mainView-panel-header-span"/>
2326
</html:h1>
2427
</box>
2528
<toolbarseparator></toolbarseparator>

browser/components/controlcenter/content/protectionsPanel.inc.xhtml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
<panelview id="protections-popup-mainView"
1919
class="PanelUI-subView"
2020
role="document"
21-
showheader="true">
21+
mainview-with-header="true"
22+
has-custom-header="true">
2223
<vbox id="protections-popup-mainView-panel-header-section">
2324
<box id="protections-popup-mainView-panel-header"
2425
class="panel-header panel-header-with-additional-element panel-header-with-info-button"
2526
onclick="gProtectionsHandler.onHeaderClicked(event);">
26-
<html:h1 id="protections-popup-main-header-label"
27-
role="heading" aria-level="1">
27+
<html:h1 id="protections-popup-main-header-label">
2828
<html:span id="protections-popup-mainView-panel-header-span"/>
2929
</html:h1>
3030
<toolbarbutton id="protections-popup-info-button" class="panel-info-button"

browser/components/customizableui/PanelMultiView.sys.mjs

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,59 +1405,68 @@ export var PanelView = class extends AssociatedToNode {
14051405
};
14061406

14071407
// If the header already exists, update or remove it as requested.
1408+
let isMainView = this.node.getAttribute("mainview");
14081409
let header = this.node.querySelector(".panel-header");
14091410
if (header) {
1410-
let headerInfoButton = header.querySelector(".panel-info-button");
14111411
let headerBackButton = header.querySelector(".subviewbutton-back");
1412-
if (headerBackButton && this.node.getAttribute("mainview")) {
1413-
// A back button should not appear in a mainview.
1414-
// This codepath can be reached if a user enters a panelview in
1415-
// the overflow panel, and then unpins it back to the toolbar.
1416-
headerBackButton.remove();
1412+
if (isMainView) {
1413+
if (headerBackButton) {
1414+
// A back button should not appear in a mainview.
1415+
// This codepath can be reached if a user enters a panelview in
1416+
// the overflow panel (like the Profiler), and then unpins it back to the toolbar.
1417+
headerBackButton.remove();
1418+
}
14171419
}
1418-
if (!this.node.getAttribute("mainview")) {
1419-
if (value) {
1420-
let headerWantsBackButton =
1421-
headerInfoButton || header.hasAttribute("wants-back-button");
1422-
if (headerWantsBackButton && !headerBackButton) {
1423-
// If we're not in a mainview and an info button is present, or the
1424-
// panel says that it wants one, that means the panel header is a
1425-
// custom one and a back button should be added, if not already present.
1426-
header.prepend(this.createHeaderBackButton());
1427-
}
1428-
// Set the header title based on the value given.
1429-
header.querySelector(".panel-header > h1 > span").textContent = value;
1430-
ensureHeaderSeparator(header);
1431-
} else {
1432-
if (header.nextSibling.tagName == "toolbarseparator") {
1433-
header.nextSibling.remove();
1434-
}
1435-
header.remove();
1420+
if (value) {
1421+
if (
1422+
!isMainView &&
1423+
!headerBackButton &&
1424+
!this.node.getAttribute("no-back-button")
1425+
) {
1426+
// Add a back button when not in mainview (if it doesn't exist already),
1427+
// also when a panelview specifies it doesn't want a back button,
1428+
// like the Report Broken Site (sent) panelview.
1429+
header.prepend(this.createHeaderBackButton());
14361430
}
1437-
return;
1438-
} else if (!this.node.getAttribute("showheader")) {
1431+
// Set the header title based on the value given.
1432+
header.querySelector(".panel-header > h1 > span").textContent = value;
1433+
ensureHeaderSeparator(header);
1434+
} else if (
1435+
!this.node.getAttribute("has-custom-header") &&
1436+
!this.node.getAttribute("mainview-with-header")
1437+
) {
1438+
// No value supplied, and the panelview doesn't have a certain requirement
1439+
// for any kind of header, so remove it and the following toolbarseparator.
14391440
if (header.nextSibling.tagName == "toolbarseparator") {
14401441
header.nextSibling.remove();
14411442
}
14421443
header.remove();
1444+
return;
14431445
}
1446+
// Either the header exists and has been adjusted accordingly by now,
1447+
// or it doesn't (or shouldn't) exist. Bail out to not create a duplicate header.
1448+
return;
14441449
}
14451450

1446-
// The header doesn't exist, only create it if needed.
1451+
// The header doesn't and shouldn't exist, only create it if needed.
14471452
if (!value) {
14481453
return;
14491454
}
14501455

14511456
header = this.document.createXULElement("box");
14521457
header.classList.add("panel-header");
14531458

1454-
let backButton = this.createHeaderBackButton();
1459+
if (!isMainView) {
1460+
let backButton = this.createHeaderBackButton();
1461+
header.append(backButton);
1462+
}
1463+
14551464
let h1 = this.document.createElement("h1");
14561465
let span = this.document.createElement("span");
14571466
span.textContent = value;
14581467
h1.appendChild(span);
14591468

1460-
header.append(backButton, h1);
1469+
header.append(h1);
14611470
this.node.prepend(header);
14621471

14631472
ensureHeaderSeparator(header);

browser/components/customizableui/content/panelUI.inc.xhtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
<panelmultiview mainViewId="unified-extensions-view">
7676
<panelview id="unified-extensions-view"
7777
class="cui-widget-panelview"
78-
showheader="true">
78+
mainview-with-header="true">
7979
<box class="panel-header">
8080
<html:h1>
8181
<html:span data-l10n-id="unified-extensions-header-title"/>

browser/components/reportbrokensite/content/reportBrokenSitePanel.inc.xhtml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88
aria-describedby="report-broken-site-panel-intro"
99
data-l10n-id="report-broken-site-panel-header"
1010
data-l10n-attrs="title"
11-
showheader="true">
12-
<!-- wants-back-button will be removed in bug 1869574
13-
(and also from PanelMultiView.sys.mjs)
14-
-->
15-
<box class="panel-header" wants-back-button="true">
11+
mainview-with-header="true">
12+
<!-- The panel can be opened from the Help menubar, so with the current
13+
- headerText implementation in PanelMultiView.sys.mjs the markup must
14+
- be added manually. -->
15+
<box class="panel-header">
1616
<html:h1>
1717
<html:span data-l10n-id="report-broken-site-mainview-title"/>
1818
</html:h1>
1919
</box>
20-
<toolbarseparator></toolbarseparator>
20+
<toolbarseparator/>
2121
<vbox id="report-broken-site-panel-container"
2222
class="panel-subview-body">
2323
<html:p id="report-broken-site-panel-intro"
@@ -102,7 +102,8 @@
102102
data-l10n-id="report-broken-site-panel-report-sent-header"
103103
data-l10n-attrs="title"
104104
aria-describedby="report-broken-site-panel-report-sent-text"
105-
showheader="true">
105+
has-customized-header="true"
106+
no-back-button="true">
106107
<box class="panel-header panel-header-with-additional-element">
107108
<image class="checkmark-icon additional-element-on-inline-start"></image>
108109
<html:h1>

browser/components/translations/content/translationsPanel.inc.xhtml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
<panelview id="translations-panel-view-default"
1919
class="PanelUI-subView translations-panel-view"
2020
role="document"
21-
showheader="true">
21+
mainview-with-header="true"
22+
has-custom-header="true">
2223
<hbox class="panel-header translations-panel-header">
2324
<html:h1 class="translations-panel-header-wrapper">
2425
<html:span id="translations-panel-header"></html:span>
@@ -106,7 +107,7 @@
106107
<panelview id="translations-panel-view-unsupported-language"
107108
class="PanelUI-subView translations-panel-view"
108109
role="document"
109-
showheader="true">
110+
has-custom-header="true">
110111
<hbox class="panel-header translations-panel-header">
111112
<image class="translations-panel-error-icon" />
112113
<html:h1 id="translations-panel-unsupported-language-header">

0 commit comments

Comments
 (0)