#include "chrome/browser/shortcuts/icon_badging.h"
#include <algorithm>
#include <cmath>
#include <vector>
#include "base/check_op.h"
#include "base/containers/contains.h"
#include "base/containers/enum_set.h"
#include "base/containers/fixed_flat_map.h"
#include "base/containers/flat_map.h"
#include "base/notreached.h"
#include "base/numerics/safe_conversions.h"
#include "base/version_info/channel.h"
#include "build/branding_buildflags.h"
#include "build/buildflag.h"
#include "chrome/common/channel_info.h"
#include "chrome/grit/chrome_unscaled_resources.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkImage.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_family.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/image/image_skia_operations.h"
namespace shortcuts {
namespace {
enum class ShortcutSize { … };
enum class BadgeSize { … };
#if BUILDFLAG(IS_MAC)
constexpr ShortcutSize kSizesNeededForShortcutCreation[] = {
ShortcutSize::k16, ShortcutSize::k32, ShortcutSize::k128,
ShortcutSize::k256, ShortcutSize::k512};
#elif BUILDFLAG(IS_LINUX)
constexpr ShortcutSize kSizesNeededForShortcutCreation[] = …;
#elif BUILDFLAG(IS_WIN)
constexpr ShortcutSize kSizesNeededForShortcutCreation[] = {
ShortcutSize::k16, ShortcutSize::k32, ShortcutSize::k48,
ShortcutSize::k256};
#endif
int ToInt(ShortcutSize size) { … }
int ToInt(BadgeSize size) { … }
BadgeSize GetBadgeSizeFromShortcutSize(ShortcutSize icon_size) { … }
constexpr int resource_map_size = …;
SizeToResourceMap;
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
constexpr SizeToResourceMap kStableResourceMap =
base::MakeFixedFlatMap<BadgeSize, int>(
{{BadgeSize::k8, IDR_PRODUCT_LOGO_16_STABLE_SHORTCUTS},
{BadgeSize::k16, IDR_PRODUCT_LOGO_16_STABLE_SHORTCUTS},
{BadgeSize::k24, IDR_PRODUCT_LOGO_24_STABLE_SHORTCUTS},
{BadgeSize::k64, IDR_PRODUCT_LOGO_64_STABLE_SHORTCUTS},
{BadgeSize::k128, IDR_PRODUCT_LOGO_128_STABLE_SHORTCUTS}});
constexpr SizeToResourceMap kCanaryResourceMap =
base::MakeFixedFlatMap<BadgeSize, int>(
{{BadgeSize::k8, IDR_PRODUCT_LOGO_CANARY_16_SHORTCUTS},
{BadgeSize::k16, IDR_PRODUCT_LOGO_CANARY_16_SHORTCUTS},
{BadgeSize::k24, IDR_PRODUCT_LOGO_CANARY_24_SHORTCUTS},
{BadgeSize::k64, IDR_PRODUCT_LOGO_CANARY_64_SHORTCUTS},
{BadgeSize::k128, IDR_PRODUCT_LOGO_CANARY_128_SHORTCUTS}});
constexpr SizeToResourceMap kBetaResourceMap =
base::MakeFixedFlatMap<BadgeSize, int>(
{{BadgeSize::k8, IDR_PRODUCT_LOGO_BETA_16_SHORTCUTS},
{BadgeSize::k16, IDR_PRODUCT_LOGO_BETA_16_SHORTCUTS},
{BadgeSize::k24, IDR_PRODUCT_LOGO_BETA_24_SHORTCUTS},
{BadgeSize::k64, IDR_PRODUCT_LOGO_BETA_64_SHORTCUTS},
{BadgeSize::k128, IDR_PRODUCT_LOGO_BETA_128_SHORTCUTS}});
constexpr SizeToResourceMap kDevResourceMap =
base::MakeFixedFlatMap<BadgeSize, int>(
{{BadgeSize::k8, IDR_PRODUCT_LOGO_DEV_16_SHORTCUTS},
{BadgeSize::k16, IDR_PRODUCT_LOGO_DEV_16_SHORTCUTS},
{BadgeSize::k24, IDR_PRODUCT_LOGO_DEV_24_SHORTCUTS},
{BadgeSize::k64, IDR_PRODUCT_LOGO_DEV_64_SHORTCUTS},
{BadgeSize::k128, IDR_PRODUCT_LOGO_DEV_128_SHORTCUTS}});
static_assert(static_cast<int>(kStableResourceMap.size()) == resource_map_size,
"Ensure icon resources are filled for all entries in BadgeSize "
"for stable resource map");
static_assert(static_cast<int>(kCanaryResourceMap.size()) == resource_map_size,
"Ensure icon resources are filled for all entries in BadgeSize "
"for canary resource map");
static_assert(static_cast<int>(kBetaResourceMap.size()) == resource_map_size,
"Ensure icon resources are filled for all entries in BadgeSize "
"for beta resource map");
static_assert(static_cast<int>(kDevResourceMap.size()) == resource_map_size,
"Ensure icon resources are filled for all entries in BadgeSize "
"for dev resource map");
#elif BUILDFLAG(GOOGLE_CHROME_FOR_TESTING_BRANDING)
constexpr SizeToResourceMap kChromeForTestingBrandedResourceMap =
base::MakeFixedFlatMap<BadgeSize, int>(
{{BadgeSize::k8, IDR_PRODUCT_LOGO_16_CFT_SHORTCUTS},
{BadgeSize::k16, IDR_PRODUCT_LOGO_16_CFT_SHORTCUTS},
{BadgeSize::k24, IDR_PRODUCT_LOGO_24_CFT_SHORTCUTS},
{BadgeSize::k64, IDR_PRODUCT_LOGO_64_CFT_SHORTCUTS},
{BadgeSize::k128, IDR_PRODUCT_LOGO_128_CFT_SHORTCUTS}});
static_assert(static_cast<int>(kChromeForTestingBrandedResourceMap.size()) ==
resource_map_size,
"Ensure icon resources are filled for all entries in BadgeSize "
"for Chrome for testing resource map");
#else
constexpr SizeToResourceMap kChromiumResourceMap = …;
static_assert …;
#endif
SizeToResourceMap GetResourceMapForCurrentChannel() { … }
gfx::ImageSkia GetMaskForBadging(ShortcutSize icon_size) { … }
int FindClosestIconSizeToUse(const std::vector<int>& sorted_icons,
int size_to_use) { … }
ShortcutSizes;
}
gfx::ImageFamily ApplyProductLogoBadgeToIcons(std::vector<SkBitmap> icons) { … }
}