Skip to content

Commit 375e996

Browse files
author
Marc Seibert
committed
Bug 1861530 - Implement the updated UX spec for Switch to tab in containers feature.r=mak,desktop-theme-reviewers,fluent-reviewers,bolsson,dao
Differential Revision: https://phabricator.services.mozilla.com/D192026
1 parent fe5461a commit 375e996

File tree

4 files changed

+97
-67
lines changed

4 files changed

+97
-67
lines changed

browser/components/contextualidentity/test/browser/browser_switchTab_across_user_context.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ add_task(async function test_switch_tab() {
6969
);
7070
let element = UrlbarTestUtils.getRowAt(window, resultIndex);
7171
is(
72-
element.querySelectorAll(".urlbarView-action").length,
73-
2,
74-
"Has switch to tab and user-context chiclet"
72+
element.querySelectorAll(".urlbarView-action.urlbarView-userContext")
73+
.length,
74+
1,
75+
"Has switch to tab with user-context chiclet"
7576
);
7677
let tabSwitchDonePromise = BrowserTestUtils.waitForEvent(
7778
window,

browser/components/urlbar/UrlbarView.sys.mjs

Lines changed: 59 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,10 +1372,6 @@ export class UrlbarView {
13721372
noWrap.appendChild(action);
13731373
item._elements.set("action", action);
13741374

1375-
let userContextBox = this.#createElement("span");
1376-
noWrap.appendChild(userContextBox);
1377-
item._elements.set("user-context", userContextBox);
1378-
13791375
let url = this.#createElement("span");
13801376
url.className = "urlbarView-url";
13811377
item._content.appendChild(url);
@@ -1711,13 +1707,6 @@ export class UrlbarView {
17111707
let favicon = item._elements.get("favicon");
17121708
favicon.src = this.#iconForResult(result);
17131709

1714-
let userContextBox = item._elements.get("user-context");
1715-
if (result.type == lazy.UrlbarUtils.RESULT_TYPE.TAB_SWITCH) {
1716-
this.#setResultUserContextBox(result, userContextBox);
1717-
} else if (userContextBox) {
1718-
this.#removeElementL10n(userContextBox);
1719-
}
1720-
17211710
let title = item._elements.get("title");
17221711
this.#setResultTitle(result, title);
17231712

@@ -1759,9 +1748,7 @@ export class UrlbarView {
17591748
switch (result.type) {
17601749
case lazy.UrlbarUtils.RESULT_TYPE.TAB_SWITCH:
17611750
actionSetter = () => {
1762-
this.#setElementL10n(action, {
1763-
id: "urlbar-result-action-switch-tab",
1764-
});
1751+
this.#setSwitchTabActionChiclet(result, action);
17651752
};
17661753
setURL = true;
17671754
break;
@@ -2626,58 +2613,86 @@ export class UrlbarView {
26262613
}
26272614

26282615
/**
2629-
* Sets `result`'s userContext in `userContextNode`'s DOM.
2616+
* Sets the content of the 'Switch To Tab' chiclet.
26302617
*
26312618
* @param {UrlbarResult} result
26322619
* The result for which the userContext is being set.
2633-
* @param {Element} userContextNode
2634-
* The DOM node for the result's userContext.
2620+
* @param {Element} actionNode
2621+
* The DOM node for the result's action.
26352622
*/
2636-
#setResultUserContextBox(result, userContextNode) {
2637-
// clear the element
2638-
while (userContextNode.firstChild) {
2639-
userContextNode.firstChild.remove();
2640-
}
2623+
#setSwitchTabActionChiclet(result, actionNode) {
26412624
if (
26422625
lazy.UrlbarPrefs.get("switchTabs.searchAllContainers") &&
26432626
result.type == lazy.UrlbarUtils.RESULT_TYPE.TAB_SWITCH &&
26442627
result.payload.userContextId
26452628
) {
2646-
let userContextBox = this.#createElement("span");
2647-
userContextBox.classList.add("urlbarView-userContext-indicator");
2648-
let identity = lazy.ContextualIdentityService.getPublicIdentityFromId(
2649-
result.payload.userContextId
2650-
);
26512629
let label = lazy.ContextualIdentityService.getUserContextLabel(
26522630
result.payload.userContextId
2631+
).toLowerCase();
2632+
// To avoid flicker don't update the label unless necessary.
2633+
if (
2634+
actionNode.classList.contains("urlbarView-userContext") &&
2635+
label &&
2636+
actionNode.querySelector("span").innerText == label
2637+
) {
2638+
return;
2639+
}
2640+
actionNode.innerHTML = "";
2641+
let identity = lazy.ContextualIdentityService.getPublicIdentityFromId(
2642+
result.payload.userContextId
26532643
);
26542644
if (identity) {
2655-
userContextNode.classList.add("urlbarView-action");
2656-
let userContextLabel = this.#createElement("label");
2657-
userContextLabel.classList.add("urlbarView-userContext-label");
2658-
userContextBox.appendChild(userContextLabel);
2645+
actionNode.classList.add("urlbarView-userContext");
2646+
if (identity.color) {
2647+
actionNode.className = actionNode.className.replace(
2648+
/identity-color-\w*/g,
2649+
""
2650+
);
2651+
actionNode.classList.add("identity-color-" + identity.color);
2652+
}
2653+
2654+
let textModeLabel = this.#createElement("div");
2655+
textModeLabel.classList.add("urlbarView-userContext-textMode");
26592656

2660-
let userContextIcon = this.#createElement("img");
2661-
userContextIcon.classList.add("urlbarView-userContext-icons");
2662-
userContextBox.appendChild(userContextIcon);
2657+
if (label) {
2658+
this.#setElementL10n(textModeLabel, {
2659+
id: "urlbar-result-action-switch-tab-with-container",
2660+
args: {
2661+
container: label.toLowerCase(),
2662+
},
2663+
});
2664+
actionNode.appendChild(textModeLabel);
2665+
}
26632666

2667+
let iconModeLabel = this.#createElement("div");
2668+
iconModeLabel.classList.add("urlbarView-userContext-iconMode");
2669+
actionNode.appendChild(iconModeLabel);
26642670
if (identity.icon) {
2671+
let userContextIcon = this.#createElement("img");
2672+
userContextIcon.classList.add("urlbarView-userContext-icon");
2673+
26652674
userContextIcon.classList.add("identity-icon-" + identity.icon);
26662675
userContextIcon.src =
26672676
"resource://usercontext-content/" + identity.icon + ".svg";
2677+
this.#setElementL10n(iconModeLabel, {
2678+
id: "urlbar-result-action-switch-tab",
2679+
});
2680+
iconModeLabel.appendChild(userContextIcon);
26682681
}
2669-
if (identity.color) {
2670-
userContextBox.classList.add("identity-color-" + identity.color);
2671-
}
2672-
if (label) {
2673-
userContextLabel.setAttribute("value", label);
2674-
userContextLabel.innerText = label;
2675-
}
2676-
userContextBox.setAttribute("tooltiptext", label);
2677-
userContextNode.appendChild(userContextBox);
2682+
actionNode.setAttribute("tooltiptext", label);
26782683
}
26792684
} else {
2680-
userContextNode.classList.remove("urlbarView-action");
2685+
actionNode.classList.remove("urlbarView-userContext");
2686+
// identity needs to be removed as well..
2687+
actionNode
2688+
.querySelectorAll(
2689+
".urlbarView-userContext-textMode, .urlbarView-userContext-iconMode"
2690+
)
2691+
.forEach(node => node.remove());
2692+
2693+
this.#setElementL10n(actionNode, {
2694+
id: "urlbar-result-action-switch-tab",
2695+
});
26812696
}
26822697
}
26832698

browser/locales/en-US/browser/browser.ftl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,11 @@ urlbar-result-action-search-w-engine = Search with { $engine }
603603
urlbar-result-action-sponsored = Sponsored
604604
urlbar-result-action-switch-tab = Switch to Tab
605605
urlbar-result-action-visit = Visit
606+
# "Switch to tab with container" is used when the target tab is located in a
607+
# different container.
608+
# Variables
609+
# $container (String): the name of the target container
610+
urlbar-result-action-switch-tab-with-container = Switch to Tab · <span>{ $container }</span>
606611
# Allows the user to visit a URL that was previously copied to the clipboard.
607612
urlbar-result-action-visit-from-clipboard = Visit from clipboard
608613
# Directs a user to press the Tab key to perform a search with the specified

browser/themes/shared/urlbarView.css

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -224,16 +224,6 @@
224224
}
225225
}
226226

227-
/* Display userContext icon instead of text, when window is too narrow. */
228-
.urlbarView-results[wrap] > .urlbarView-row[type=switchtab] {
229-
.urlbarView-userContext-label {
230-
display: none;
231-
}
232-
.urlbarView-userContext-icons {
233-
display: inline-block;
234-
}
235-
}
236-
237227
.urlbarView-overflowable,
238228
.urlbarView-url {
239229
overflow: hidden;
@@ -549,26 +539,41 @@
549539
}
550540

551541
/* user context box */
552-
.urlbarView-userContext-indicator {
553-
align-items: center;
554-
}
555-
556-
.urlbarView-userContext-label {
557-
color: var(--identity-tab-color);
542+
.urlbarView-userContext {
543+
border-top: 4px solid var(--identity-tab-color);
558544
}
559545

560-
.urlbarView-userContext-icons {
561-
height: var(--urlbarView-favicon-width);
562-
vertical-align: middle;
546+
.urlbarView-userContext-icon {
547+
height: 14px;
563548
background-image: var(--identity-icon);
564549
-moz-context-properties: fill;
565-
fill: var(--identity-icon-color);
566550
background-size: contain;
567551
background-repeat: no-repeat;
568552
background-position: center center;
553+
vertical-align: top;
554+
margin-inline-start: 0.35em;
555+
}
556+
557+
.urlbarView-userContext-iconMode {
569558
display: none;
570559
}
571560

561+
.urlbarView-userContext-textMode {
562+
display: inline-block;
563+
> span {
564+
font-variant: small-caps;
565+
}
566+
}
567+
568+
/* Display userContext icon instead of text, when window is too narrow. */
569+
.urlbarView-results[wrap] {
570+
.urlbarView-userContext-textMode {
571+
display: none;
572+
}
573+
.urlbarView-userContext-iconMode {
574+
display: inline-block;
575+
}
576+
}
572577

573578
/* Tail suggestions */
574579

@@ -661,6 +666,10 @@
661666
background-color: var(--urlbar-box-focus-bgcolor);
662667
border-radius: var(--toolbarbutton-border-radius);
663668
padding: 6px 8px;
669+
670+
&.urlbarView-userContext {
671+
padding-top: 2px;
672+
}
664673
margin-block: -6px;
665674
margin-inline-start: 8px;
666675

0 commit comments

Comments
 (0)