// 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.

#ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_TRIGGER_SOURCE_H_
#define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_TRIGGER_SOURCE_H_

#include "components/autofill/core/common/aliases.h"

namespace autofill {

// Specifies the source that triggered autofilling a form. Differently from
// `AutofillSuggestionTriggerSource` this enum does not mean the action that
// triggered autofill (for example
// AutofillSuggestionTriggerSource::kFormControlElementClicked) but only the
// internal surface that provided the autofill experience (like `kPopup`) or
// internal mechanisms/business logic (like kSelectOptionsChanged). For example
// AutofillSuggestionTriggerSource::kFormControlElementClicked "action" can lead
// autofill to be "surfaced" from `kKeyboardAccessoryOrBottomSheet` or
// `kPopup`.
enum class AutofillTriggerSource {
  kNone = 0,
  // Autofill was triggered from accepting a suggestion in the Autofill popup.
  kPopup = 1,
  // Autofill was triggered from accepting a suggestion in the keyboard
  // accessory or from the bottom sheet.
  kKeyboardAccessoryOrBottomSheet = 2,
  // Autofill was triggered from accepting a suggestion in the touch to fill for
  // credit cards bottom sheet.
  // kTouchToFillCreditCard = 3, // DEPRECATED
  // Refill was triggered from the forms seen event. This includes cases where a
  // refill was triggered right after a non-refill Autofill invocation - in this
  // case the original trigger source got lost.
  kFormsSeen = 4,
  // Refill was triggered from blink when the selected option of a <select>
  // control is changed.
  kSelectOptionsChanged = 5,
  // Refill was triggered from blink when the input element is in the autofilled
  // state and the value has been changed by JavaScript.
  kJavaScriptChangedAutofilledValue = 6,
  // kCreditCardCvcPopup = 7, // DEPRECATED
  // Autofill was triggered from a Fast Checkout run.
  // kFastCheckout = 8, // DEPRECATED
  // Filling/preview was triggered through a suggestion generated by manual
  // fallbacks from the Chrome context menu. Contrary to regular address
  // Autofill, Autofill with this trigger source fills both classified and
  // unclassified form fields.
  kManualFallback = 9,
  // Autofill AI was triggered.
  // kAutofillAi = 10, // DEPRECATED.
  // Autofill was triggered with devtools trigger command.
  kDevtools = 11,
  // Autofill was triggered by successfully scanning a credit card.
  kScanCreditCard = 12,
  // Autofill was triggered after Password Manager detected failed login for a
  // password that has a recovery password.
  kProactivePasswordRecovery = 13,
  // Autofill was triggered by accepting the credit card Save and Fill dialog.
  kCreditCardSaveAndFill = 14,
  // Autofill was triggered by GLIC.
  kGlic = 15,
  // A refill was triggered by JavaScript.
  kProgrammaticRefill = 16,
  // Autofill was triggered from accepting a suggestion in the Omnibox Autofill
  // bubble.
  kOmniboxAutofill = 17,
};

// The `AutofillTriggerSource` indicates what caused an Autofill fill or preview
// to happen. This can happen by selecting a suggestion, but also through a
// dynamic change (refills) or through a surface that doesn't use suggestions,
// like TTF. This function is concerned with the first case: A suggestion that
// was generated through the `suggestion_trigger_source` got selected. This
// function returns the appropriate `AutofillTriggerSource`.
// Note that an `AutofillSuggestionTriggerSource` is different from a
// `AutofillTriggerSource`. The former describes what caused the suggestion
// itself to appear. For example, depending on the completeness of the form,
// clicking into a field (the suggestion trigger source) can cause
// the keyboard accessory or TTF/fast checkout to appear (the trigger source).
AutofillTriggerSource TriggerSourceFromSuggestionTriggerSource(
    AutofillSuggestionTriggerSource suggestion_trigger_source);

}  // namespace autofill

#endif  // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_TRIGGER_SOURCE_H_
