Skip to content

Fix inactive window icons#34165

Merged
simonhong merged 11 commits intomasterfrom
fix-inactive-window-icons
Mar 2, 2026
Merged

Fix inactive window icons#34165
simonhong merged 11 commits intomasterfrom
fix-inactive-window-icons

Conversation

@aguscruiz
Copy link
Collaborator

Resolves brave/brave-browser#53109

Active window

Image

Inactive window

Image

@aguscruiz aguscruiz self-assigned this Feb 24, 2026
@aguscruiz aguscruiz requested a review from a team as a code owner February 24, 2026 20:11
@github-actions
Copy link
Contributor

github-actions bot commented Feb 24, 2026

📋 Code Owners Summary

13 file(s) changed, 1 with assigned owners

1 team(s) affected: @brave/chromium-src-reviewers


Owners and Their Files

@brave/chromium-src-reviewers — 1 file(s)

@aguscruiz aguscruiz requested a review from netzenbot February 25, 2026 12:07
Copy link
Contributor

@fallaciousreasoning fallaciousreasoning left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm so this mostly looks good to me but I wonder if we should be trying to add something to ToolbarButton so this is done automatically for new buttons?

Probably also need @sangwoo or @simonhong to take a look 'cause they actually know what they're doing in views land :D

@sangwoo108 sangwoo108 self-requested a review February 25, 2026 23:59
Copy link
Collaborator

@sangwoo108 sangwoo108 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the dimming is only affecting Mac. Let me check how it works.

@sangwoo108
Copy link
Collaborator

sangwoo108 commented Feb 26, 2026

I think LaberButton::GetVisualState() already considers widget activation state.
Maybe we just need to set STATE_DISABLED image for children classes of LabelButton(bookmark folder button, VPN, Wallet, BookmarkButton...)

@sangwoo108
Copy link
Collaborator

@aguscruiz If you find it ai doesn't work well for my comments, please let me know. I could work on this

@simonhong
Copy link
Member

I think we can follow how chromium handles inactive button's color.
LabelButton treats inactive window's normal button state as STATE_DISABLED.
That's why chromium's toolbar button has dimmed icon color in inactive window.
ToolbarButton's foreground disabled color is kColorToolbarButtonIconInactive
If we don't customize icon color from toolbar button's subclass,
toolbar button will pick kColorToolbarButtonIconInactive when it's in inactive window.
Our side panel or ai chat button works like that.
However, vpn or wallet button have active icon color when it's in inactive window
because it customize like below.

Instead of observing widget activation state in each button,
I think we just need to give kColorToolbarButtonIconInactive in proper method like UpdateImageAndText()
because most of buttons we use are LabelButton?

void WalletButton::UpdateImageAndText(bool activated) {
  views::HighlightPathGenerator::Install(
      this, std::make_unique<BraveWalletButtonHighlightPathGenerator>(
                (counter_ > 0)));

  const ui::ColorProvider* color_provider = GetColorProvider();

  ui::ColorId color_id = kColorToolbarButtonIcon;
  if (activated) {
    color_id = kColorToolbarButtonActivated;
  }
  ...
Button::ButtonState LabelButton::GetVisualState() const {
  const auto* widget = GetWidget();
  if (!widget || !widget->ShouldViewsStyleFollowWidgetActivation() ||
      !appear_disabled_in_inactive_widget_) {
    return GetState();
  }

  // Paint as inactive if neither this widget nor its parent should paint as
  // active.
  if (!widget->ShouldPaintAsActive() &&
      !(widget->parent() && widget->parent()->ShouldPaintAsActive())) {
    return STATE_DISABLED;
  }

  return GetState();
}

@aguscruiz
Copy link
Collaborator Author

[AI-assisted response]

Refactored as suggested. For all ToolbarButton subclasses (BraveBookmarkButton, BraveVPNButton, WalletButton) and bookmark bar folder buttons:

  • Removed the PaintAsActiveChangedCallback subscription, AddedToWidget()/RemovedFromWidget() overrides, and paint_as_active_subscription_ members.
  • Instead of checking ShouldPaintAsActive() manually, each button's update method now sets both STATE_NORMAL (with the active color) and STATE_DISABLED (with the inactive/dimmed color). LabelButton::GetVisualState() automatically returns STATE_DISABLED when the window is inactive on macOS (via PlatformStyle::kInactiveWidgetControlsAppearDisabled), so the dimmed image is shown without any manual observation.

This matches the upstream ToolbarButton::UpdateIconsWithStandardColors() pattern, which sets all four button states including STATE_DISABLED with kColorToolbarButtonIconInactive.

Note: For the sidebar buttons (SidebarItemAddButton, SidebarControlView settings button), the callback approach is still used because SidebarButtonView extends ImageButton (not LabelButton), so GetVisualState() doesn't apply to them.

Net result: -130 lines, +42 lines compared to the previous approach.

@aguscruiz
Copy link
Collaborator Author

[AI-assisted response]

Thank you for the detailed explanation @simonhong — this was very helpful. Refactored accordingly:

  • For WalletButton::UpdateImageAndText(), BraveVPNButton::UpdateColorsAndInsets(), and BraveBookmarkButton::UpdateImageAndText(): removed the ShouldPaintAsActive() checks and callback subscriptions. Instead, each method now sets STATE_DISABLED image models with the dimmed appearance alongside STATE_NORMAL.
  • LabelButton::GetVisualState() handles the rest — on macOS where kInactiveWidgetControlsAppearDisabled is true, the button automatically renders with the STATE_DISABLED image when the window is inactive.
  • This follows the same pattern as ToolbarButton::UpdateIconsWithStandardColors() which sets GetForegroundColor(STATE_DISABLED)kColorToolbarButtonIconInactive.

The sidebar buttons (SidebarButtonViewImageButton) still use the callback approach since ImageButton does not have GetVisualState().

@aguscruiz
Copy link
Collaborator Author

[AI-assisted response]

Thank you @sangwoo108 — the latest commit addresses both your and @simonhong's feedback by adopting the LabelButton::GetVisualState() + STATE_DISABLED approach for all ToolbarButton subclasses. The callback-based observation pattern has been removed from the toolbar buttons entirely. Please take another look when you get a chance.

@aguscruiz aguscruiz requested a review from sangwoo108 February 26, 2026 18:41
@github-actions
Copy link
Contributor

Chromium major version is behind target branch (145.0.7632.120 vs 146.0.7680.32). Please rebase.

@github-actions github-actions bot added the chromium-version-mismatch The Chromium version on the PR branch does not match the version on the target branch label Feb 26, 2026
Some icons on desktop weren't dimming when the window is set to inactive (the browser is in the background). This PR attempts to solve that issue
@aguscruiz aguscruiz force-pushed the fix-inactive-window-icons branch from ca477fe to ec1aca8 Compare February 26, 2026 21:22
@github-actions github-actions bot removed the chromium-version-mismatch The Chromium version on the PR branch does not match the version on the target branch label Feb 26, 2026
@aguscruiz aguscruiz requested a review from sangwoo108 February 27, 2026 13:10
@simonhong
Copy link
Member

@aguscruiz @sangwoo108 Pushed some changes for simplifying disabled icon color handling.
For bookmark folder icon update, GetBookmarkFolderIcon() would be best place to replace with ours.
For sidebar buttons, changed its base class to LabelButton. PTAL :)

@aguscruiz
Copy link
Collaborator Author

Thank you Simon! This is working great on my build. @sangwoo108 @brave/chromium-src-reviewers would you mind taking a look at the latest?

Copy link
Collaborator

@sangwoo108 sangwoo108 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with nits 👍

Copy link
Member

@goodov goodov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chromium_src lgtm

@simonhong simonhong merged commit 1671539 into master Mar 2, 2026
22 checks passed
@simonhong simonhong deleted the fix-inactive-window-icons branch March 2, 2026 10:30
@github-actions github-actions bot added this to the 1.89.x - Nightly milestone Mar 2, 2026
@brave-builds
Copy link
Collaborator

Released in v1.89.90

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Some browser icons don't dim when the window is inactive while some do

8 participants