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

// Copyright 2017 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_view_views.h"

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

#include "base/auto_reset.h"
#include "base/containers/contains.h"
#include "base/containers/to_vector.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/notreached.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/favicon/large_icon_service_factory.h"
#include "chrome/browser/image_fetcher/image_fetcher_service_factory.h"
#include "chrome/browser/media/webrtc/desktop_capture_access_handler.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_key.h"
#include "chrome/browser/sync/sync_service_factory.h"
#include "chrome/browser/ui/autofill/autofill_popup_controller.h"
#include "chrome/browser/ui/autofill/autofill_suggestion_controller_utils.h"
#include "chrome/browser/ui/browser_element_identifiers.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/passwords/ui_utils.h"
#include "chrome/browser/ui/views/autofill/popup/popup_base_view.h"
#include "chrome/browser/ui/views/autofill/popup/popup_no_suggestions_view.h"
#include "chrome/browser/ui/views/autofill/popup/popup_row_factory_utils.h"
#include "chrome/browser/ui/views/autofill/popup/popup_row_view.h"
#include "chrome/browser/ui/views/autofill/popup/popup_search_bar_view.h"
#include "chrome/browser/ui/views/autofill/popup/popup_separator_view.h"
#include "chrome/browser/ui/views/autofill/popup/popup_title_view.h"
#include "chrome/browser/ui/views/autofill/popup/popup_view_utils.h"
#include "chrome/browser/ui/views/autofill/popup/popup_warning_view.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "components/autofill/core/browser/autofill_experiments.h"
#include "components/autofill/core/browser/data_model/credit_card.h"
#include "components/autofill/core/browser/metrics/autofill_metrics.h"
#include "components/autofill/core/browser/ui/autofill_resource_utils.h"
#include "components/autofill/core/browser/ui/suggestion.h"
#include "components/autofill/core/browser/ui/suggestion_hiding_reason.h"
#include "components/autofill/core/browser/ui/suggestion_type.h"
#include "components/autofill/core/common/aliases.h"
#include "components/autofill/core/common/autofill_features.h"
#include "components/autofill/core/common/autofill_payments_features.h"
#include "components/favicon/core/large_icon_service.h"
#include "components/feature_engagement/public/feature_constants.h"
#include "components/image_fetcher/core/image_fetcher_service.h"
#include "components/input/native_web_keyboard_event.h"
#include "components/password_manager/core/browser/password_sync_util.h"
#include "components/strings/grit/components_strings.h"
#include "components/sync/service/sync_service.h"
#include "components/user_education/common/feature_promo_controller.h"
#include "content/public/browser/web_contents.h"
#include "third_party/abseil-cpp/absl/types/variant.h"
#include "third_party/blink/public/common/input/web_input_event.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/base/ui_base_features.h"
#include "ui/color/color_id.h"
#include "ui/events/blink/web_input_event.h"
#include "ui/events/event.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/events/types/event_type.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/rect_conversions.h"
#include "ui/gfx/geometry/rounded_corners_f.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
#include "ui/views/bubble/bubble_border.h"
#include "ui/views/bubble/bubble_border_arrow_utils.h"
#include "ui/views/controls/scroll_view.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/box_layout_view.h"
#include "ui/views/layout/flex_layout.h"
#include "ui/views/view.h"
#include "ui/views/view_class_properties.h"
#include "ui/views/widget/widget.h"

BubbleBorder;

namespace autofill {

namespace {

// The minimum width should exceed the maximum size of a cursor, which is 128
// (see crbug.com/1434330).
constexpr int kAutofillPopupMinWidth =;
static_assert;
// TODO(crbug.com/41382463): move handling the max width to the base class.
constexpr int kAutofillPopupMaxWidth =;

// Preferred position relative to the control sides of the sub-popup.
constexpr std::array<views::BubbleArrowSide, 2> kDefaultSubPopupSides =;
constexpr std::array<views::BubbleArrowSide, 2> kDefaultSubPopupSidesRTL =;

int GetContentsVerticalPadding() {}

bool CanShowRootPopup(AutofillSuggestionController& controller) {}

// Returns true when the suggestion should open a sub popup menu automatically
// when hovering the content area. This is used for manual fallback
// suggestions.
bool ContentCellShouldOpenSubPopupSuggestion(const Suggestion& suggestion) {}

BrowserView* GetLastActiveBrowserView() {}

// If `is_root_popup` is `true`, the result list corresponds to sides defined in
// `PopupBaseView::kDefaultPreferredPopupSides`, when `prefer_prev_arrow_side`
// is also `true` the side of the `prev_arrow` is added at the beginning of
// the list. Having the previous arrow side preferred allows to avoid popup
// jumpings in most cases when the updated suggestions change the popup size
// as well and a new side is considered optimal.
// For non root popups, the values are taken from `kDefaultSubPopupSides[RTL]`.
std::vector<views::BubbleArrowSide> GetPreferredPopupSides(
    bool is_root_popup,
    bool prefer_prev_arrow_side,
    BubbleBorder::Arrow prev_arrow) {}

}  // namespace

// Creates a new popup view instance. The Widget parent is taken either from
// the top level widget for the root popup or from the parent for sub-popups.
// Setting Widget's parent enables its internal child-lifetime management,
// see `Widget::InitParams::parent` doc comment for details.
PopupViewViews::PopupViewViews(
    base::WeakPtr<AutofillPopupController> controller,
    base::WeakPtr<ExpandablePopupParentView> parent,
    views::Widget* parent_widget)
    :{}

PopupViewViews::PopupViewViews(
    base::WeakPtr<AutofillPopupController> controller,
    std::optional<const AutofillPopupView::SearchBarConfig> search_bar_config)
    :{}

PopupViewViews::~PopupViewViews() = default;

void PopupViewViews::GetAccessibleNodeData(ui::AXNodeData* node_data) {}

void PopupViewViews::OnMouseEntered(const ui::MouseEvent& event) {}

void PopupViewViews::OnMouseExited(const ui::MouseEvent& event) {}

void PopupViewViews::OnPaint(gfx::Canvas* canvas) {}

bool PopupViewViews::Show(
    AutoselectFirstSuggestion autoselect_first_suggestion) {}

void PopupViewViews::Hide() {}

std::optional<PopupViewViews::CellIndex> PopupViewViews::GetSelectedCell()
    const {}

void PopupViewViews::SetSelectedCell(std::optional<CellIndex> cell_index,
                                     PopupCellSelectionSource source) {}

bool PopupViewViews::HandleKeyPressEvent(
    const input::NativeWebKeyboardEvent& event) {}

bool PopupViewViews::HandleKeyPressEventForCompose(
    const input::NativeWebKeyboardEvent& event) {}

void PopupViewViews::SelectPreviousRow() {}

void PopupViewViews::SelectNextRow(PopupCellSelectionSource source) {}

bool PopupViewViews::SelectNextHorizontalCell() {}

bool PopupViewViews::SelectPreviousHorizontalCell() {}

bool PopupViewViews::AcceptSelectedContentOrCreditCardCell() {}

bool PopupViewViews::RemoveSelectedCell() {}

void PopupViewViews::OnSuggestionsChanged(bool prefer_prev_arrow_side) {}

bool PopupViewViews::OverlapsWithPictureInPictureWindow() const {}

std::optional<int32_t> PopupViewViews::GetAxUniqueId() {}

void PopupViewViews::AxAnnounce(const std::u16string& text) {}

void PopupViewViews::AnnouncePolitely(const std::u16string& text) {}

base::WeakPtr<AutofillPopupView> PopupViewViews::CreateSubPopupView(
    base::WeakPtr<AutofillSuggestionController> controller) {}

std::optional<AutofillClient::PopupScreenLocation>
PopupViewViews::GetPopupScreenLocation() const {}

bool PopupViewViews::HasFocus() const {}

void PopupViewViews::OnWidgetVisibilityChanged(views::Widget* widget,
                                               bool visible) {}

void PopupViewViews::SearchBarOnInputChanged(const std::u16string& query) {}

void PopupViewViews::SearchBarOnFocusLost() {}

bool PopupViewViews::SearchBarHandleKeyPressed(const ui::KeyEvent& event) {}

void PopupViewViews::SetSelectedCell(
    std::optional<CellIndex> cell_index,
    PopupCellSelectionSource source,
    AutoselectFirstSuggestion autoselect_first_suggestion,
    bool suppress_popup) {}

void PopupViewViews::UpdateExpandedCollapsedAccessibleState() const {}

bool PopupViewViews::HasSelectablePopupRowViewAt(size_t index) const {}

void PopupViewViews::InitViews() {}

void PopupViewViews::CreateSuggestionViews() {}

gfx::Size PopupViewViews::CalculatePreferredSize(
    const views::SizeBounds& available_size) const {}

bool PopupViewViews::DoUpdateBoundsAndRedrawPopup() {}

bool PopupViewViews::DoUpdateBoundsAndRedrawPopup(bool prefer_prev_arrow_side) {}

void PopupViewViews::OnMouseEnteredInChildren() {}

void PopupViewViews::OnMouseExitedInChildren() {}

bool PopupViewViews::IsFooterScrollable() const {}

bool PopupViewViews::CanShowDropdownInBounds(const gfx::Rect& bounds) const {}

void PopupViewViews::SetRowWithOpenSubPopup(
    std::optional<size_t> row_index,
    AutoselectFirstSuggestion autoselect_first_suggestion) {}

bool PopupViewViews::SelectParentPopupContentCell() {}

base::WeakPtr<AutofillPopupView> PopupViewViews::GetWeakPtr() {}

BEGIN_METADATA()

// static
base::WeakPtr<AutofillPopupView> AutofillPopupView::Create(
    base::WeakPtr<AutofillSuggestionController> controller,
    std::optional<const AutofillPopupView::SearchBarConfig> search_bar_config) {}

}  // namespace autofill