Skip to content

Commit

Permalink
Adapt Brave-specific customization for folder icons in bookmarks bar
Browse files Browse the repository at this point in the history
Tested on Linux and it preserves the original behaviour from PR #9424.

[1] #9424

Chromium change:

https://source.chromium.org/chromium/chromium/src/+/2a4b9bfb525d77dfeec91be45068f9c95b00a8e9

commit 2a4b9bfb525d77dfeec91be45068f9c95b00a8e9
Author: Peter Kasting <[email protected]>
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
  • Loading branch information
mariospr committed Jul 27, 2021
1 parent e62353d commit 91a3f0b
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions chromium_src/chrome/browser/ui/bookmarks/bookmark_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<RTLFlipSource>(folder), folder.size()));
ui::ImageModel GetBookmarkFolderIcon(BookmarkFolderIconType icon_type,
absl::variant<int, SkColor> color) {
int default_id = IDR_BRAVE_BOOKMARK_FOLDER_CLOSED;
const auto generator = [](int default_id, BookmarkFolderIconType icon_type,
absl::variant<int, SkColor> color,
const ui::NativeTheme* native_theme) {
gfx::ImageSkia folder;
SkColor sk_color;
if (absl::holds_alternative<SkColor>(color)) {
sk_color = absl::get<SkColor>(color);
} else {
DCHECK(native_theme);
sk_color = native_theme->GetSystemColor(
static_cast<ui::NativeTheme::ColorId>(absl::get<int>(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<RTLFlipSource>(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

Expand Down

0 comments on commit 91a3f0b

Please sign in to comment.