From a433d3b555807fad32de6b21fe94aead6b4c8331 Mon Sep 17 00:00:00 2001 From: Mario Sanchez Prada Date: Thu, 15 Jul 2021 18:15:09 +0200 Subject: [PATCH] Adapt Brave-specific customization for folder icons in bookmarks bar Tested on Linux and it preserves the original behaviour from PR #9424. [1] https://github.com/brave/brave-core/pull/9424 Chromium change: https://source.chromium.org/chromium/chromium/src/+/2a4b9bfb525d77dfeec91be45068f9c95b00a8e9 commit 2a4b9bfb525d77dfeec91be45068f9c95b00a8e9 Author: Peter Kasting Date: Sat Jul 10 01:41:59 2021 +0000 Avoid accessing NativeTheme too early from bookmarks-related functions. This must only be accessed when the caller is in a Widget. Fixing this required significantly reworking how bookmark folder images are handled. This also modifies the color of bookmark folders on non-Win, non-Mac platforms: they are grey 700 by default (in light mode), like other icons, instead of being something closer to grey 600; and when a custom theme modifies the bookmark bar text color, folder icons in the overflow menu do not change similarly (but keep their standard menu colors). The menu does not necessarily have the same background color as the bookmark bar, so matching the bar's foreground color doesn't make sense, doubly so when done just for the folder icons and nothing else. Bug: 1211091 --- .../browser/ui/bookmarks/bookmark_utils.cc | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/chromium_src/chrome/browser/ui/bookmarks/bookmark_utils.cc b/chromium_src/chrome/browser/ui/bookmarks/bookmark_utils.cc index 94f8929754c5..a5f3858418da 100644 --- a/chromium_src/chrome/browser/ui/bookmarks/bookmark_utils.cc +++ b/chromium_src/chrome/browser/ui/bookmarks/bookmark_utils.cc @@ -35,15 +35,36 @@ bool ShouldShowAppsShortcutInBookmarkBar(Profile* profile) { } #if defined(TOOLKIT_VIEWS) -ui::ImageModel GetBookmarkFolderIcon(SkColor text_color) { - int resource_id = color_utils::IsDark(text_color) - ? IDR_BRAVE_BOOKMARK_FOLDER_CLOSED - : IDR_BRAVE_BOOKMARK_FOLDER_CLOSED_WHITE; - gfx::ImageSkia folder = *ui::ResourceBundle::GetSharedInstance() - .GetNativeImageNamed(resource_id) - .ToImageSkia(); - return ui::ImageModel::FromImageSkia( - gfx::ImageSkia(std::make_unique(folder), folder.size())); +ui::ImageModel GetBookmarkFolderIcon(BookmarkFolderIconType icon_type, + absl::variant color) { + int default_id = IDR_BRAVE_BOOKMARK_FOLDER_CLOSED; + const auto generator = [](int default_id, BookmarkFolderIconType icon_type, + absl::variant color, + const ui::NativeTheme* native_theme) { + gfx::ImageSkia folder; + SkColor sk_color; + if (absl::holds_alternative(color)) { + sk_color = absl::get(color); + } else { + DCHECK(native_theme); + sk_color = native_theme->GetSystemColor( + static_cast(absl::get(color))); + } + + const int resource_id = color_utils::IsDark(sk_color) + ? IDR_BRAVE_BOOKMARK_FOLDER_CLOSED + : IDR_BRAVE_BOOKMARK_FOLDER_CLOSED_WHITE; + folder = *ui::ResourceBundle::GetSharedInstance() + .GetNativeImageNamed(resource_id) + .ToImageSkia(); + return gfx::ImageSkia(std::make_unique(folder), + folder.size()); + }; + const gfx::Size size = + ui::ResourceBundle::GetSharedInstance().GetImageNamed(default_id).Size(); + return ui::ImageModel::FromImageGenerator( + base::BindRepeating(generator, default_id, icon_type, std::move(color)), + size); } #endif