chromium/chrome/browser/ui/views/autofill/popup/popup_row_factory_utils.cc

// Copyright 2023 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/autofill/popup/popup_row_factory_utils.h"

#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <vector>

#include "base/check.h"
#include "base/check_op.h"
#include "base/containers/fixed_flat_set.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_forward.h"
#include "base/location.h"
#include "base/memory/weak_ptr.h"
#include "base/notreached.h"
#include "base/ranges/algorithm.h"
#include "base/task/sequenced_task_runner.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/ui/autofill/autofill_popup_controller.h"
#include "chrome/browser/ui/autofill/autofill_suggestion_controller_utils.h"
#include "chrome/browser/ui/views/autofill/popup/lazy_loading_image_view.h"
#include "chrome/browser/ui/views/autofill/popup/popup_base_view.h"
#include "chrome/browser/ui/views/autofill/popup/popup_cell_utils.h"
#include "chrome/browser/ui/views/autofill/popup/popup_row_content_view.h"
#include "chrome/browser/ui/views/autofill/popup/popup_row_view.h"
#include "chrome/browser/ui/views/autofill/popup/popup_row_with_button_view.h"
#include "chrome/browser/ui/views/autofill/popup/popup_view_utils.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/chrome_typography.h"
#include "chrome/browser/user_education/user_education_service.h"
#include "components/autofill/core/browser/filling_product.h"
#include "components/autofill/core/browser/metrics/autofill_metrics.h"
#include "components/autofill/core/browser/ui/suggestion.h"
#include "components/autofill/core/browser/ui/suggestion_button_action.h"
#include "components/autofill/core/browser/ui/suggestion_type.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_payments_features.h"
#include "components/compose/core/browser/compose_features.h"
#include "components/favicon_base/favicon_types.h"
#include "components/password_manager/core/common/password_manager_constants.h"
#include "components/strings/grit/components_strings.h"
#include "components/user_education/common/new_badge_controller.h"
#include "components/user_education/views/new_badge_label.h"
#include "components/vector_icons/vector_icons.h"
#include "content/public/browser/web_contents.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/color/color_id.h"
#include "ui/gfx/geometry/size.h"
#include "ui/gfx/text_constants.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/image_button_factory.h"
#include "ui/views/controls/highlight_path_generator.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/menu/menu_config.h"
#include "ui/views/controls/throbber.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/box_layout_view.h"
#include "ui/views/style/typography.h"
#include "ui/views/vector_icons.h"
#include "ui/views/view.h"

namespace autofill {

namespace {

constexpr int kCustomIconSize =;

// The size of a close or delete icon.
constexpr int kCloseIconSize =;

// Popup items that use a leading icon instead of a trailing one.
constexpr auto kPopupItemTypesUsingLeadingIcons =;

// Max width for the username and masked password.
constexpr int kAutofillPopupUsernameMaxWidth =;
constexpr int kAutofillPopupPasswordMaxWidth =;

// Max width for the Autofill suggestion text.
constexpr int kAutofillSuggestionMaxWidth =;

// Max width for address profile suggestion text when granular filling is
// enabled.
constexpr int kAutofillPopupAddressProfileGranularFillingEnabledMaxWidth =;

constexpr auto kMainTextStyle =;
constexpr auto kMainTextStyleLight =;
constexpr auto kMainTextStyleHighlighted =;
constexpr auto kMinorTextStyle =;
constexpr auto kDisabledTextStyle =;

// Returns a wrapper around `closure` that posts it to the default message
// queue instead of executing it directly. This is to avoid that the callback's
// caller can suicide by (unwittingly) deleting itself or its parent.
base::RepeatingClosure CreateExecuteSoonWrapper(base::RepeatingClosure task) {}

bool IsDeactivatedPasswordOrPasskey(const Suggestion& suggestion) {}

void FormatLabel(views::Label& label,
                 const Suggestion::Text& text,
                 FillingProduct main_filling_product,
                 int maximum_width_single_line) {}

int GetMaxPopupAddressProfileWidth(bool should_use_new_popup_max_size) {}

// Returns true when `features::kAutofillGranularFillingAvailable` is true or
// the user is using manual fallbacks for unclassified address or payments
// fields. Note that `is_suggestion_acceptable` is not enough because
// suggestions like `SuggestionType::kDevtoolsTestAddresses` are also not
// acceptable. This method will always return the same values for all
// suggestions in a popup because:
// 1. If the user triggers address manual fallback on an unclassified field, all
// available suggestions will be of such type (address filling product, not
// acceptable and not a `SuggestionType::kDevtoolsTestAddresses` suggestion).
// 2. Same goes for credit card manual fallback suggestions. They will not be
// mixed with other ones.
// 3. If `features::kAutofillGranularFillingAvailable` is true, then this method
// also returns true regardless of the `FillingProduct` and whether a suggestion
// is acceptable.
//
// Note `SuggestionType::kDevtoolsTestAddresses` is not
// acceptable, and is the parent of `SuggestionType::kDevtoolsTestAddressEntry`
// (which can be accepted). We specifically remove it because its filling
// product is also `FillingProduct::kAddress`.
// TODO(crbug.com/40274514): Remove once clean up happens.
bool ShouldApplyNewPopupMaxWidth(SuggestionType suggestion_type,
                                 bool is_suggestion_acceptable) {}

// Creates a label for the suggestion's main text.
std::unique_ptr<views::Label> CreateMainTextLabel(
    const Suggestion& suggestion,
    std::optional<user_education::DisplayNewBadge> show_new_badge,
    views::style::TextStyle primary_text_style = kMainTextStyle) {}

// Creates a label for the suggestion's minor text.
std::unique_ptr<views::Label> CreateMinorTextLabel(
    const Suggestion& suggestion) {}

// Creates sub-text views and passes their references to `PopupRowContentView`
// for centralized style management.
std::vector<std::unique_ptr<views::View>> CreateSubtextViews(
    PopupRowContentView& content_view,
    const Suggestion& suggestion,
    FillingProduct main_filling_product) {}

std::unique_ptr<PopupRowContentView> CreateFooterPopupRowContentView(
    const Suggestion& suggestion) {}

std::unique_ptr<views::Label> CreatePasswordDescriptionLabel(
    const Suggestion& suggestion) {}

std::vector<std::unique_ptr<views::View>> CreateAndTrackPasswordSubtextViews(
    const Suggestion& suggestion,
    PopupRowContentView& content_view) {}

// If the `Suggestion::custom_icon` holds the `FaviconDetails` alternative,
// the icon should be loaded lazily. For this case, this method creates a
// `LazyLoadingImageView` to be passed to `CreatePasswordPopupRowContentView()`
// as the `icon`. Otherwise, it returns an icon created by `GetIconImageView()`.
std::unique_ptr<views::View> GetPasswordIconView(
    const Suggestion& suggestion,
    PasswordFaviconLoader* favicon_loader) {}

std::unique_ptr<PopupRowContentView> CreatePasswordPopupRowContentView(
    const Suggestion& suggestion,
    std::optional<user_education::DisplayNewBadge> show_new_badge,
    std::optional<AutofillPopupController::SuggestionFilterMatch> filter_match,
    PasswordFaviconLoader* favicon_loader) {}

std::unique_ptr<PopupRowContentView> CreateComposePopupRowContentView(
    const Suggestion& suggestion,
    std::optional<user_education::DisplayNewBadge> show_new_badge) {}

// Creates the content view for regular address and credit card suggestions.
// Content views for suggestions of other types and special suggestions are
// created by corresponding `Create*PopupRowContentView()` methods.
std::unique_ptr<PopupRowContentView> CreatePopupRowContentView(
    const Suggestion& suggestion,
    std::optional<user_education::DisplayNewBadge> show_new_badge,
    FillingProduct main_filling_product,
    std::optional<AutofillPopupController::SuggestionFilterMatch>
        filter_match) {}

// Creates the row for an Autocomplete entry with a delete button.
std::unique_ptr<PopupRowWithButtonView> CreateAutocompleteRowWithDeleteButton(
    base::WeakPtr<AutofillPopupController> controller,
    PopupRowView::AccessibilitySelectionDelegate& a11y_selection_delegate,
    PopupRowView::SelectionDelegate& selection_delegate,
    int line_number) {}

// Creates the row for creating a plus address inline.
// TODO(crbug.com/362445807): Add pixel tests once the layout is complete.
std::unique_ptr<PopupRowWithButtonView> CreateNewPlusAddressInlineSuggestion(
    base::WeakPtr<AutofillPopupController> controller,
    PopupRowView::AccessibilitySelectionDelegate& a11y_selection_delegate,
    PopupRowView::SelectionDelegate& selection_delegate,
    int line_number) {}

}  // namespace

std::unique_ptr<PopupRowView> CreatePopupRowView(
    base::WeakPtr<AutofillPopupController> controller,
    PopupRowView::AccessibilitySelectionDelegate& a11y_selection_delegate,
    PopupRowView::SelectionDelegate& selection_delegate,
    int line_number,
    std::optional<AutofillPopupController::SuggestionFilterMatch> filter_match,
    PasswordFaviconLoader* favicon_loader) {}

}  // namespace autofill