chromium/chrome/browser/shortcuts/icon_badging.cc

// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#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 {};

// Returns the icon sizes needed for shortcut creation on the desktop. k32 is
// needed for the icon in the Create Shortcut dialog.
#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) {}

// For icon sizes > 128, use a badge size that is 1/4, else use a badge size
// that is 1/2.
BadgeSize GetBadgeSizeFromShortcutSize(ShortcutSize icon_size) {}

constexpr int resource_map_size =;

SizeToResourceMap;

// At very low pixels < 16, there is probably no need to recreate the
// resource files necessary for these icons. Resizing them instead would
// work just as better, without the need to increase the chrome binary
// size.
#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  // BUILDFLAG(GOOGLE_CHROME_BRANDING)

SizeToResourceMap GetResourceMapForCurrentChannel() {}

gfx::ImageSkia GetMaskForBadging(ShortcutSize icon_size) {}

int FindClosestIconSizeToUse(const std::vector<int>& sorted_icons,
                             int size_to_use) {}

ShortcutSizes;
}  // namespace

gfx::ImageFamily ApplyProductLogoBadgeToIcons(std::vector<SkBitmap> icons) {}

}  // namespace shortcuts