#include "chrome/browser/ui/autofill/autofill_popup_controller_impl.h"
#include <algorithm>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "base/check_deref.h"
#include "base/check_op.h"
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/i18n/case_conversion.h"
#include "base/i18n/rtl.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "chrome/browser/accessibility/accessibility_state_utils.h"
#include "chrome/browser/ui/autofill/autofill_popup_view.h"
#include "chrome/browser/ui/autofill/autofill_suggestion_controller_utils.h"
#include "chrome/browser/ui/autofill/next_idle_barrier.h"
#include "chrome/browser/ui/autofill/popup_controller_common.h"
#include "components/autofill/core/browser/autofill_manager.h"
#include "components/autofill/core/browser/filling_product.h"
#include "components/autofill/core/browser/metrics/autofill_metrics.h"
#include "components/autofill/core/browser/ui/autofill_suggestion_delegate.h"
#include "components/autofill/core/browser/ui/popup_interaction.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/autofill_features.h"
#include "components/compose/core/browser/compose_features.h"
#include "components/compose/core/browser/config.h"
#include "components/input/native_web_keyboard_event.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "content/public/browser/web_contents.h"
#include "ui/accessibility/ax_active_popup.h"
#include "ui/accessibility/ax_tree_id.h"
#include "ui/accessibility/ax_tree_manager_map.h"
#include "ui/accessibility/platform/ax_platform_node.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/events/event.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/text_utils.h"
#include "ui/views/accessibility/view_accessibility.h"
namespace autofill {
namespace {
SuggestionFiltrationResult;
SuggestionFiltrationResult FilterSuggestions(
const std::vector<Suggestion>& suggestions,
const AutofillPopupController::SuggestionFilter& filter) { … }
bool ShouldLogPopupInteractionShown(
AutofillSuggestionTriggerSource trigger_source) { … }
}
#if !BUILDFLAG(IS_MAC) && !BUILDFLAG(IS_ANDROID)
base::WeakPtr<AutofillSuggestionController>
AutofillSuggestionController::GetOrCreate(
base::WeakPtr<AutofillSuggestionController> previous,
base::WeakPtr<AutofillSuggestionDelegate> delegate,
content::WebContents* web_contents,
PopupControllerCommon controller_common,
int32_t form_control_ax_id) { … }
#endif
AutofillPopupControllerImpl::AutofillPopupControllerImpl(
base::WeakPtr<AutofillSuggestionDelegate> delegate,
content::WebContents* web_contents,
PopupControllerCommon controller_common,
int32_t form_control_ax_id,
std::optional<base::WeakPtr<ExpandablePopupParentControllerImpl>> parent)
: … { … }
AutofillPopupControllerImpl::~AutofillPopupControllerImpl() = default;
void AutofillPopupControllerImpl::Show(
std::vector<Suggestion> suggestions,
AutofillSuggestionTriggerSource trigger_source,
AutoselectFirstSuggestion autoselect_first_suggestion) { … }
void AutofillPopupControllerImpl::SetKeepPopupOpenForTesting(
bool keep_popup_open_for_testing) { … }
void AutofillPopupControllerImpl::UpdateDataListValues(
base::span<const SelectOption> options) { … }
void AutofillPopupControllerImpl::PinView() { … }
bool AutofillPopupControllerImpl::IsViewVisibilityAcceptingThresholdEnabled()
const { … }
void AutofillPopupControllerImpl::Hide(SuggestionHidingReason reason) { … }
void AutofillPopupControllerImpl::ViewDestroyed() { … }
void AutofillPopupControllerImpl::OnSuggestionsChanged() { … }
void AutofillPopupControllerImpl::AcceptSuggestion(int index) { … }
gfx::NativeView AutofillPopupControllerImpl::container_view() const { … }
content::WebContents* AutofillPopupControllerImpl::GetWebContents() const { … }
const gfx::RectF& AutofillPopupControllerImpl::element_bounds() const { … }
PopupAnchorType AutofillPopupControllerImpl::anchor_type() const { … }
base::i18n::TextDirection AutofillPopupControllerImpl::GetElementTextDirection()
const { … }
bool AutofillPopupControllerImpl::IsRootPopup() const { … }
const std::vector<Suggestion>& AutofillPopupControllerImpl::GetSuggestions()
const { … }
void AutofillPopupControllerImpl::OnSuggestionsChanged(
bool prefer_prev_arrow_side) { … }
void AutofillPopupControllerImpl::UpdateFilteredSuggestions(
bool notify_suggestions_changed) { … }
int AutofillPopupControllerImpl::GetLineCount() const { … }
const Suggestion& AutofillPopupControllerImpl::GetSuggestionAt(int row) const { … }
bool AutofillPopupControllerImpl::RemoveSuggestion(
int list_index,
AutofillMetrics::SingleEntryRemovalMethod removal_method) { … }
FillingProduct AutofillPopupControllerImpl::GetMainFillingProduct() const { … }
std::optional<AutofillClient::PopupScreenLocation>
AutofillPopupControllerImpl::GetPopupScreenLocation() const { … }
bool AutofillPopupControllerImpl::HasSuggestions() const { … }
void AutofillPopupControllerImpl::SetSuggestions(
std::vector<Suggestion> suggestions) { … }
base::WeakPtr<AutofillPopupController>
AutofillPopupControllerImpl::GetWeakPtr() { … }
void AutofillPopupControllerImpl::ClearState() { … }
void AutofillPopupControllerImpl::HideViewAndDie() { … }
base::WeakPtr<AutofillPopupView>
AutofillPopupControllerImpl::CreateSubPopupView(
base::WeakPtr<AutofillPopupController> controller) { … }
int AutofillPopupControllerImpl::GetPopupLevel() const { … }
void AutofillPopupControllerImpl::FireControlsChangedEvent(bool is_show) { … }
ui::AXPlatformNode*
AutofillPopupControllerImpl::GetRootAXPlatformNodeForWebContents() { … }
AutofillPopupControllerImpl::KeyPressObserver::KeyPressObserver(
AutofillPopupControllerImpl* observer)
: … { … }
AutofillPopupControllerImpl::KeyPressObserver::~KeyPressObserver() { … }
void AutofillPopupControllerImpl::KeyPressObserver::Observe(
content::RenderFrameHost* rfh) { … }
void AutofillPopupControllerImpl::KeyPressObserver::Reset() { … }
void AutofillPopupControllerImpl::SelectSuggestion(int index) { … }
void AutofillPopupControllerImpl::UnselectSuggestion() { … }
base::WeakPtr<AutofillSuggestionController>
AutofillPopupControllerImpl::OpenSubPopup(
const gfx::RectF& anchor_bounds,
std::vector<Suggestion> suggestions,
AutoselectFirstSuggestion autoselect_first_suggestion) { … }
void AutofillPopupControllerImpl::HideSubPopup() { … }
bool AutofillPopupControllerImpl::
ShouldIgnoreMouseObservedOutsideItemBoundsCheck() const { … }
void AutofillPopupControllerImpl::PerformButtonActionForSuggestion(
int index,
const SuggestionButtonAction& button_action) { … }
const std::vector<AutofillPopupController::SuggestionFilterMatch>&
AutofillPopupControllerImpl::GetSuggestionFilterMatches() const { … }
void AutofillPopupControllerImpl::SetFilter(
std::optional<SuggestionFilter> filter) { … }
bool AutofillPopupControllerImpl::HandleKeyPressEvent(
const input::NativeWebKeyboardEvent& event) { … }
void AutofillPopupControllerImpl::OnPopupPainted() { … }
bool AutofillPopupControllerImpl::HasFilteredOutSuggestions() const { … }
}