chromium/chrome/browser/ui/views/profiles/profile_menu_view_base.cc

// Copyright 2019 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/ui/views/profiles/profile_menu_view_base.h"

#include <algorithm>
#include <memory>
#include <utility>

#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ref.h"
#include "base/metrics/histogram_functions.h"
#include "base/scoped_observation.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/signin/signin_ui_util.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/chrome_pages.h"
#include "chrome/browser/ui/color/chrome_color_id.h"
#include "chrome/browser/ui/profiles/profile_colors_util.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/chrome_typography.h"
#include "chrome/browser/ui/views/controls/hover_button.h"
#include "chrome/browser/ui/views/promos/bubble_signin_promo_signin_button_view.h"
#include "chrome/grit/generated_resources.h"
#include "components/signin/public/base/signin_switches.h"
#include "components/supervised_user/core/browser/supervised_user_capabilities.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/base/models/image_model.h"
#include "ui/base/mojom/dialog_button.mojom.h"
#include "ui/base/themed_vector_icon.h"
#include "ui/base/ui_base_features.h"
#include "ui/color/color_id.h"
#include "ui/color/color_provider.h"
#include "ui/display/display.h"
#include "ui/display/screen.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/image/canvas_image_source.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/vector_icon_types.h"
#include "ui/strings/grit/ui_strings.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/animation/ink_drop.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/animation/ink_drop_host.h"
#include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/button/md_text_button.h"
#include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/controls/link.h"
#include "ui/views/controls/scroll_view.h"
#include "ui/views/controls/separator.h"
#include "ui/views/controls/styled_label.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/layout/flex_layout.h"
#include "ui/views/layout/flex_layout_types.h"
#include "ui/views/layout/layout_manager.h"
#include "ui/views/layout/table_layout.h"
#include "ui/views/style/typography.h"
#include "ui/views/view.h"
#include "ui/views/view_class_properties.h"

#if !BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/ui/views/profiles/badged_profile_photo.h"
#endif  // !BUILDFLAG(IS_CHROMEOS)

namespace {

// Helpers --------------------------------------------------------------------

constexpr int kMenuWidth =;
constexpr int kMaxImageSize =;
constexpr int kDefaultMargin =;
constexpr int kAccountCardMargin =;
constexpr int kBadgeSize =;
constexpr int kCircularImageButtonSize =;
constexpr int kCircularImageButtonRefreshSize =;
constexpr int kCircularImageButtonTransparentRefreshSize =;
constexpr float kShortcutIconToImageRatio =;
constexpr float kShortcutIconToImageRefreshRatio =;
constexpr float kShortcutIconToImageTransparentRefreshRatio =;
// TODO(crbug.com/40148993): Remove this constant by extracting art height from
// |avatar_header_art|.
constexpr int kHeaderArtHeight =;
constexpr int kIdentityImageBorder =;
constexpr int kIdentityImageSizeInclBorder =;
constexpr int kHalfOfAvatarImageViewSize =;

// If the bubble is too large to fit on the screen, it still needs to be at
// least this tall to show one row.
constexpr int kMinimumScrollableContentHeight =;

// Spacing between the edge of the user menu and the top/bottom or left/right of
// the menu items.
constexpr int kMenuEdgeMargin =;

constexpr int kSyncInfoInsidePadding =;
constexpr int kSyncInfoRefreshInsidePadding =;

// The bottom background edge should match the center of the identity image.
constexpr auto kBackgroundInsets =;

constexpr char kProfileMenuClickedActionableItemHistogram[] =;
#if !BUILDFLAG(IS_CHROMEOS_LACROS)
constexpr char kProfileMenuClickedActionableItemSupervisedHistogram[] =;
#endif

gfx::ImageSkia SizeImage(const gfx::ImageSkia& image, int size) {}

gfx::ImageSkia ColorImage(const gfx::ImageSkia& image, SkColor color) {}

class CircleImageSource : public gfx::CanvasImageSource {};

void CircleImageSource::Draw(gfx::Canvas* canvas) {}

gfx::ImageSkia CreateCircle(int size, SkColor color) {}

gfx::ImageSkia CropCircle(const gfx::ImageSkia& image) {}

gfx::ImageSkia AddCircularBackground(const gfx::ImageSkia& image,
                                     SkColor bg_color,
                                     int size) {}

std::unique_ptr<views::BoxLayout> CreateBoxLayout(
    views::BoxLayout::Orientation orientation,
    views::BoxLayout::CrossAxisAlignment cross_axis_alignment,
    gfx::Insets insets = gfx::Insets()) {}

const gfx::ImageSkia ImageForMenu(const gfx::VectorIcon& icon,
                                  float icon_to_image_ratio,
                                  SkColor color) {}

ui::ImageModel SizeImageModel(const ui::ImageModel& image_model, int size) {}

const ui::ImageModel ProfileManagementImageFromIcon(
    const gfx::VectorIcon& icon,
    const ui::ColorProvider* color_provider) {}

// TODO(crbug.com/40156444): Adjust button size to be 16x16.
class CircularImageButton : public views::ImageButton {};

BEGIN_METADATA()

class FeatureButtonIconView : public views::ImageView {};

class ProfileManagementFeatureButton : public HoverButton {};
BEGIN_METADATA()

class ProfileManagementIconView : public views::ImageView {};

BEGIN_METADATA()

// AvatarImageView is used to ensure avatar adornments are kept in sync with
// current theme colors.
class AvatarImageView : public views::ImageView {};

BEGIN_METADATA()

class SyncButton : public HoverButton {};

BEGIN_METADATA()

class SyncImageView : public views::ImageView {};

BEGIN_METADATA()

void BuildProfileTitleAndSubtitle(Browser* browser,
                                  views::View* parent,
                                  const std::u16string& title,
                                  const std::u16string& subtitle,
                                  const std::u16string& management_label) {}

}  // namespace

// ProfileMenuViewBase ---------------------------------------------------------

ProfileMenuViewBase::EditButtonParams::EditButtonParams(
    const gfx::VectorIcon* edit_icon,
    const std::u16string& edit_tooltip_text,
    base::RepeatingClosure edit_action)
    :{}

ProfileMenuViewBase::EditButtonParams::~EditButtonParams() = default;

ProfileMenuViewBase::EditButtonParams::EditButtonParams(
    const EditButtonParams&) = default;

ProfileMenuViewBase::ProfileMenuViewBase(views::Button* anchor_button,
                                         Browser* browser)
    :{}

ProfileMenuViewBase::~ProfileMenuViewBase() = default;

gfx::ImageSkia ProfileMenuViewBase::GetSyncIcon() const {}

// This function deals with the somewhat complicated layout to build the part of
// the profile identity info that has a colored background.
void ProfileMenuViewBase::BuildProfileBackgroundContainer(
    std::unique_ptr<views::View> heading_label,
    SkColor background_color,
    std::unique_ptr<views::View> avatar_image_view,
    std::unique_ptr<views::View> edit_button,
    const ui::ThemedVectorIcon& avatar_header_art) {}

void ProfileMenuViewBase::SetProfileIdentityInfo(
    const std::u16string& profile_name,
    SkColor profile_background_color,
    std::optional<EditButtonParams> edit_button_params,
    const ui::ImageModel& image_model,
    const ui::ImageModel& management_badge,
    const std::u16string& title,
    const std::u16string& subtitle,
    const std::u16string& management_label,
    const ui::ThemedVectorIcon& avatar_header_art) {}

void ProfileMenuViewBase::BuildSyncInfoWithCallToAction(
    const std::u16string& description,
    const std::u16string& button_text,
    const base::RepeatingClosure& action,
    bool show_sync_badge,
    AccountInfo account) {}

void ProfileMenuViewBase::BuildSyncInfoWithoutCallToAction(
    const std::u16string& text,
    const base::RepeatingClosure& action) {}

void ProfileMenuViewBase::AddShortcutFeatureButton(
    const gfx::VectorIcon& icon,
    const std::u16string& text,
    base::RepeatingClosure action) {}

void ProfileMenuViewBase::AddFeatureButton(const std::u16string& text,
                                           base::RepeatingClosure action,
                                           const gfx::VectorIcon& icon,
                                           float icon_to_image_ratio) {}

void ProfileMenuViewBase::SetProfileManagementHeading(
    const std::u16string& heading) {}

void ProfileMenuViewBase::AddAvailableProfile(const ui::ImageModel& image_model,
                                              const std::u16string& name,
                                              bool is_guest,
                                              bool is_enabled,
                                              base::RepeatingClosure action) {}

void ProfileMenuViewBase::AddProfileManagementShortcutFeatureButton(
    const gfx::VectorIcon& icon,
    const std::u16string& text,
    base::RepeatingClosure action) {}

void ProfileMenuViewBase::AddProfileManagementManagedHint(
    const gfx::VectorIcon& icon,
    const std::u16string& text) {}

void ProfileMenuViewBase::AddProfileManagementFeaturesSeparator() {}

void ProfileMenuViewBase::AddProfileManagementFeatureButton(
    const gfx::VectorIcon& icon,
    const std::u16string& text,
    base::RepeatingClosure action) {}

gfx::ImageSkia ProfileMenuViewBase::ColoredImageForMenu(
    const gfx::VectorIcon& icon,
    ui::ColorId color) const {}

void ProfileMenuViewBase::RecordClick(ActionableItem item) {}

int ProfileMenuViewBase::GetMaxHeight() const {}

void ProfileMenuViewBase::Reset() {}

void ProfileMenuViewBase::FocusFirstProfileButton() {}

void ProfileMenuViewBase::BuildIdentityInfoColorCallback(
    const ui::ColorProvider* color_provider) {}

void ProfileMenuViewBase::BuildSyncInfoCallToActionBackground(
    const ui::ColorProvider* color_provider) {}

void ProfileMenuViewBase::Init() {}

void ProfileMenuViewBase::OnThemeChanged() {}

void ProfileMenuViewBase::OnWindowClosing() {}

bool ProfileMenuViewBase::HandleContextMenu(
    content::RenderFrameHost& render_frame_host,
    const content::ContextMenuParams& params) {}

void ProfileMenuViewBase::ButtonPressed(base::RepeatingClosure action) {}

void ProfileMenuViewBase::CreateAXWidgetObserver(views::Widget* widget) {}

// Despite ProfileMenuViewBase being a dialog, we are enforcing it to behave
// like a menu from the accessibility POV because it fits better with a menu UX.
// The dialog exposes the kMenuBar role, and the top-level container is kMenu.
// This class is responsible for emitting menu accessible events when the dialog
// is activated or deactivated.
class ProfileMenuViewBase::AXMenuWidgetObserver : public views::WidgetObserver {};

BEGIN_METADATA()