fix: get background color from GtkMenuBar#menubar (#14812)

This commit is contained in:
Shelley Vohr 2018-09-26 10:03:33 -07:00 committed by GitHub
parent 0f291f9d63
commit 35cb671529
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,12 +4,19 @@
#include "atom/browser/ui/views/menu_bar.h" #include "atom/browser/ui/views/menu_bar.h"
#include <memory>
#include <string>
#include "atom/browser/ui/views/menu_delegate.h" #include "atom/browser/ui/views/menu_delegate.h"
#include "atom/browser/ui/views/submenu_button.h" #include "atom/browser/ui/views/submenu_button.h"
#include "ui/base/models/menu_model.h" #include "ui/base/models/menu_model.h"
#include "ui/views/background.h" #include "ui/views/background.h"
#include "ui/views/layout/box_layout.h" #include "ui/views/layout/box_layout.h"
#if defined(USE_X11)
#include "chrome/browser/ui/libgtkui/gtk_util.h"
#endif
#if defined(OS_WIN) #if defined(OS_WIN)
#include "ui/gfx/color_utils.h" #include "ui/gfx/color_utils.h"
#endif #endif
@ -29,8 +36,8 @@ MenuBar::MenuBar(views::View* window)
: background_color_(kDefaultColor), window_(window) { : background_color_(kDefaultColor), window_(window) {
RefreshColorCache(); RefreshColorCache();
UpdateViewColors(); UpdateViewColors();
SetLayoutManager(std::make_unique<views::BoxLayout>( SetLayoutManager(
views::BoxLayout::kHorizontal)); std::make_unique<views::BoxLayout>(views::BoxLayout::kHorizontal));
window_->GetFocusManager()->AddFocusChangeListener(this); window_->GetFocusManager()->AddFocusChangeListener(this);
} }
@ -121,13 +128,17 @@ void MenuBar::RefreshColorCache(const ui::NativeTheme* theme) {
if (!theme) if (!theme)
theme = ui::NativeTheme::GetInstanceForNativeUi(); theme = ui::NativeTheme::GetInstanceForNativeUi();
if (theme) { if (theme) {
background_color_ =
theme->GetSystemColor(ui::NativeTheme::kColorId_MenuBackgroundColor);
#if defined(USE_X11) #if defined(USE_X11)
const std::string menubar_selector = "GtkMenuBar#menubar";
background_color_ = libgtkui::GetBgColor(menubar_selector);
enabled_color_ = theme->GetSystemColor( enabled_color_ = theme->GetSystemColor(
ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor); ui::NativeTheme::kColorId_EnabledMenuItemForegroundColor);
disabled_color_ = theme->GetSystemColor( disabled_color_ = theme->GetSystemColor(
ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor); ui::NativeTheme::kColorId_DisabledMenuItemForegroundColor);
#else
background_color_ =
theme->GetSystemColor(ui::NativeTheme::kColorId_MenuBackgroundColor);
#endif #endif
} }
#if defined(OS_WIN) #if defined(OS_WIN)