@@ -1372,10 +1372,6 @@ export class UrlbarView {
1372
1372
noWrap . appendChild ( action ) ;
1373
1373
item . _elements . set ( "action" , action ) ;
1374
1374
1375
- let userContextBox = this . #createElement( "span" ) ;
1376
- noWrap . appendChild ( userContextBox ) ;
1377
- item . _elements . set ( "user-context" , userContextBox ) ;
1378
-
1379
1375
let url = this . #createElement( "span" ) ;
1380
1376
url . className = "urlbarView-url" ;
1381
1377
item . _content . appendChild ( url ) ;
@@ -1711,13 +1707,6 @@ export class UrlbarView {
1711
1707
let favicon = item . _elements . get ( "favicon" ) ;
1712
1708
favicon . src = this . #iconForResult( result ) ;
1713
1709
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
-
1721
1710
let title = item . _elements . get ( "title" ) ;
1722
1711
this . #setResultTitle( result , title ) ;
1723
1712
@@ -1759,9 +1748,7 @@ export class UrlbarView {
1759
1748
switch ( result . type ) {
1760
1749
case lazy . UrlbarUtils . RESULT_TYPE . TAB_SWITCH :
1761
1750
actionSetter = ( ) => {
1762
- this . #setElementL10n( action , {
1763
- id : "urlbar-result-action-switch-tab" ,
1764
- } ) ;
1751
+ this . #setSwitchTabActionChiclet( result , action ) ;
1765
1752
} ;
1766
1753
setURL = true ;
1767
1754
break ;
@@ -2626,58 +2613,86 @@ export class UrlbarView {
2626
2613
}
2627
2614
2628
2615
/**
2629
- * Sets `result`'s userContext in `userContextNode`'s DOM .
2616
+ * Sets the content of the 'Switch To Tab' chiclet .
2630
2617
*
2631
2618
* @param {UrlbarResult } result
2632
2619
* 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 .
2635
2622
*/
2636
- #setResultUserContextBox( result , userContextNode ) {
2637
- // clear the element
2638
- while ( userContextNode . firstChild ) {
2639
- userContextNode . firstChild . remove ( ) ;
2640
- }
2623
+ #setSwitchTabActionChiclet( result , actionNode ) {
2641
2624
if (
2642
2625
lazy . UrlbarPrefs . get ( "switchTabs.searchAllContainers" ) &&
2643
2626
result . type == lazy . UrlbarUtils . RESULT_TYPE . TAB_SWITCH &&
2644
2627
result . payload . userContextId
2645
2628
) {
2646
- let userContextBox = this . #createElement( "span" ) ;
2647
- userContextBox . classList . add ( "urlbarView-userContext-indicator" ) ;
2648
- let identity = lazy . ContextualIdentityService . getPublicIdentityFromId (
2649
- result . payload . userContextId
2650
- ) ;
2651
2629
let label = lazy . ContextualIdentityService . getUserContextLabel (
2652
2630
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
2653
2643
) ;
2654
2644
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
+ / i d e n t i t y - c o l o r - \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" ) ;
2659
2656
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
+ }
2663
2666
2667
+ let iconModeLabel = this . #createElement( "div" ) ;
2668
+ iconModeLabel . classList . add ( "urlbarView-userContext-iconMode" ) ;
2669
+ actionNode . appendChild ( iconModeLabel ) ;
2664
2670
if ( identity . icon ) {
2671
+ let userContextIcon = this . #createElement( "img" ) ;
2672
+ userContextIcon . classList . add ( "urlbarView-userContext-icon" ) ;
2673
+
2665
2674
userContextIcon . classList . add ( "identity-icon-" + identity . icon ) ;
2666
2675
userContextIcon . src =
2667
2676
"resource://usercontext-content/" + identity . icon + ".svg" ;
2677
+ this . #setElementL10n( iconModeLabel , {
2678
+ id : "urlbar-result-action-switch-tab" ,
2679
+ } ) ;
2680
+ iconModeLabel . appendChild ( userContextIcon ) ;
2668
2681
}
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 ) ;
2678
2683
}
2679
2684
} 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
+ } ) ;
2681
2696
}
2682
2697
}
2683
2698
0 commit comments