File: autofill_popup_controller.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (115 lines) | stat: -rw-r--r-- 5,333 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_H_
#define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_H_

#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/autofill/autofill_suggestion_controller.h"
#include "components/autofill/core/browser/ui/suggestion_button_action.h"

namespace input {
struct NativeWebKeyboardEvent;
}  // namespace input

namespace autofill {

// The interface implemented by Desktop implementations of the
// `AutofillSuggestionController` - that is, the methods found below are
// specific to Desktop.
class AutofillPopupController : public AutofillSuggestionController {
 public:
  // The suggestion filter is implemented as a string directly reflecting user
  // input. It could be refactored into a more complex data structure to enable
  // advanced search functionality.
  using SuggestionFilter =
      base::StrongAlias<struct SuggestionFilterTag, std::u16string>;

  // Suggestions consist of multiple parts (e.g., main text, labels). The filter
  // match structure reveals how a suggestion was found, enabling
  // the highlighting of these parts.
  struct SuggestionFilterMatch {
    // Shows the filter match location within the 'Suggestion::main_text'.
    gfx::Range main_text_match;

    bool operator==(const SuggestionFilterMatch& other) const = default;
  };

  // Selects the suggestion with `index`. For fillable items, this will trigger
  // preview. For other items, it does not do anything.
  virtual void SelectSuggestion(int index) = 0;

  // Unselect currently selected suggestion, noop if nothing is selected.
  virtual void UnselectSuggestion() = 0;

  // Creates and shows a sub-popup adjacent to `anchor_bounds`. The sub-popup
  // represents another level of `suggestions` which must be semantically
  // connected to a parent level suggestion, e.g. an address suggestion
  // break down providing more granular fillings.
  // The popup created via this method and this popup instance are linked
  // as child-parent. The child's lifetime depends on its parent, i.e. when
  // the parent dies the child dies also.
  virtual base::WeakPtr<AutofillSuggestionController> OpenSubPopup(
      const gfx::RectF& anchor_bounds,
      std::vector<Suggestion> suggestions,
      AutoselectFirstSuggestion autoselect_first_suggestion) = 0;

  // Hides open by `OpenSubPopup()` popup, noop if there is no open sub-popup.
  virtual void HideSubPopup() = 0;

  // Returns whether the popup should ignore the check that the mouse was
  // observed out of bounds - see `PopupRowView` for more detail.
  virtual bool ShouldIgnoreMouseObservedOutsideItemBoundsCheck() const = 0;

  // Executes the `button_action` associated with the button that is displayed
  // in the suggestion at `index`.
  virtual void PerformButtonActionForSuggestion(
      int index,
      const SuggestionButtonAction& button_action) = 0;

  // If the filter is set, returns the same number of items as returned by
  // `AutofillSuggestionController::GetSuggestions()`, indicating how each
  // suggestion meets the filter criteria. Otherwise, if the filter is
  // `std::nullopt` (its default value), returns an empty vector.
  // `SetFilter()` calls invalidate previously returned data.
  virtual const std::vector<SuggestionFilterMatch>& GetSuggestionFilterMatches()
      const = 0;

  // Sets the suggestion filter or removes it with `std::nullopt`. The filter
  // determines which suggestions are returned by GetSuggestions() and other
  // related methods (like `GetLineCount()`). When the filter changes, previous
  // suggestion indices (used in many `AutofillSuggestionController` methods,
  // e.g. `RemoveSuggestion()`) become invalid.
  virtual void SetFilter(std::optional<SuggestionFilter> filter) = 0;

  // Returns whethere there is at least one suggestion filtered out. It implies
  // that the filter is not empty, and if it's set to `nullopt`,
  // `GetSuggestions()` will return more suggestions.
  virtual bool HasFilteredOutSuggestions() const = 0;

  // Handles a key press event and returns whether the event should be swallowed
  // (meaning that no other handler, in particular not the default handler, can
  // process it).
  // TODO(crbug.com/325246516): Change the event type to `ui::KeyEvent` as
  // events can come not only from blink, but from native UI too.
  virtual bool HandleKeyPressEvent(
      const input::NativeWebKeyboardEvent& event) = 0;

  // Starts the time measurement that prevents accepting suggestions too early.
  // If the time measurement is already ongoing or has been made, this method is
  // a no-op.
  virtual void OnPopupPainted() = 0;

  // Indicates if the view should prevent accepting suggestions that are not
  // easily seen or noticed. The specific criteria for determining what's poorly
  // visible is up to the view's implementation. To avoid timer specific issues,
  // this method should return `false` in the test environment.
  virtual bool IsViewVisibilityAcceptingThresholdEnabled() const = 0;

  virtual base::WeakPtr<AutofillPopupController> GetWeakPtr() = 0;
};

}  // namespace autofill

#endif  // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_H_