Skip to content

Commit

Permalink
fix: set background color for menu bar on Windows (#37991)
Browse files Browse the repository at this point in the history
  • Loading branch information
GhostlyDark committed Apr 17, 2023
1 parent c6b4467 commit 7fd1f3d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
15 changes: 12 additions & 3 deletions shell/browser/ui/views/menu_bar.cc
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 7fd1f3d

Please sign in to comment.