Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set background color for menu bar on Windows #37784

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 12 additions & 3 deletions shell/browser/ui/views/menu_bar.cc
Expand Up @@ -35,12 +35,11 @@ const char MenuBar::kViewClassName[] = "ElectronMenuBar";
MenuBar::MenuBar(NativeWindow* window, RootView* root_view)
: background_color_(kDefaultColor), window_(window), root_view_(root_view) {
const ui::NativeTheme* theme = root_view_->GetNativeTheme();
RefreshColorCache(theme);
UpdateViewColors();
#if BUILDFLAG(IS_WIN)
SetBackground(views::CreateThemedSolidBackground(ui::kColorMenuBackground));
background_color_ = GetBackground()->get_color();
#endif
RefreshColorCache(theme);
UpdateViewColors();
SetFocusBehavior(FocusBehavior::ALWAYS);
SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal));
Expand Down Expand Up @@ -209,6 +208,14 @@ void MenuBar::ButtonPressed(size_t id, const ui::Event& event) {
menu_delegate->AddObserver(this);
}

void MenuBar::ViewHierarchyChanged(
const views::ViewHierarchyChangedDetails& details) {
views::AccessiblePaneView::ViewHierarchyChanged(details);
#if BUILDFLAG(IS_WIN)
background_color_ = GetBackground()->get_color();
#endif
}

void MenuBar::RefreshColorCache(const ui::NativeTheme* theme) {
if (theme) {
#if BUILDFLAG(IS_LINUX)
Expand All @@ -217,6 +224,8 @@ void MenuBar::RefreshColorCache(const ui::NativeTheme* theme) {
gtk::GetFgColor("GtkMenuBar#menubar GtkMenuItem#menuitem GtkLabel");
disabled_color_ = gtk::GetFgColor(
"GtkMenuBar#menubar GtkMenuItem#menuitem:disabled GtkLabel");
#elif BUILDFLAG(IS_WIN)
background_color_ = GetBackground()->get_color();
#endif
}
}
Expand Down
3 changes: 3 additions & 0 deletions shell/browser/ui/views/menu_bar.h
Expand Up @@ -50,6 +50,9 @@ class MenuBar : public views::AccessiblePaneView,
ElectronMenuModel** menu_model,
views::MenuButton** button);

void ViewHierarchyChanged(
const views::ViewHierarchyChangedDetails& details) override;

private:
// MenuDelegate::Observer:
void OnBeforeExecuteCommand() override;
Expand Down