File: omnibox_result_view.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (170 lines) | stat: -rw-r--r-- 6,076 bytes parent folder | download | duplicates (3)
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// Copyright 2012 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_VIEWS_OMNIBOX_OMNIBOX_RESULT_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_RESULT_VIEW_H_

#include <stddef.h>

#include <memory>
#include <utility>

#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/views/omnibox/omnibox_mouse_enter_exit_handler.h"
#include "components/omnibox/browser/autocomplete_match.h"
#include "components/omnibox/browser/omnibox_popup_selection.h"
#include "components/omnibox/browser/suggestion_answer.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/base/window_open_disposition.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/views/background.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/view.h"

class OmniboxLocalAnswerHeaderView;
class OmniboxMatchCellView;
class OmniboxPopupViewViews;
class OmniboxResultSelectionIndicator;
class OmniboxSuggestionButtonRowView;
enum class OmniboxPart;
enum class OmniboxPartState;

namespace gfx {
class Image;
}

namespace views {
class Button;
class ImageButton;
}  // namespace views

class OmniboxResultView : public views::View {
  METADATA_HEADER(OmniboxResultView, views::View)

 public:
  OmniboxResultView(OmniboxPopupViewViews* popup_view, size_t model_index);
  OmniboxResultView(const OmniboxResultView&) = delete;
  OmniboxResultView& operator=(const OmniboxResultView&) = delete;
  ~OmniboxResultView() override;

  // Static method to share logic about how to set backgrounds of popup cells.
  static std::unique_ptr<views::Background> GetPopupCellBackground(
      const views::View* view,
      OmniboxPartState part_state);

  // Updates the match used to paint the contents of this result view. We copy
  // the match so that we can continue to paint the last result even after the
  // model has changed.
  void SetMatch(const AutocompleteMatch& match);

  // Applies the current theme to the current text and widget colors.
  // Also refreshes the icons which may need to be re-colored as well.
  void ApplyThemeAndRefreshIcons(bool force_reapply_styles = false);

  // Invoked when this result view has been selected or unselected.
  void OnSelectionStateChanged();

  // Whether this result view should be considered 'selected'. This returns
  // false if this line's header is selected (instead of the match itself).
  bool GetMatchSelected() const;

  // Returns the focused button or nullptr if none exists for this suggestion.
  views::Button* GetActiveAuxiliaryButtonForAccessibility();
  const views::Button* GetActiveAuxiliaryButtonForAccessibility() const;

  OmniboxPartState GetThemeState() const;

  // Notification that the match icon has changed and schedules a repaint.
  void OnMatchIconUpdated();

  // Stores the image in a local data member and schedules a repaint.
  void SetRichSuggestionImage(const gfx::ImageSkia& image);

  void ButtonPressed(OmniboxPopupSelection::LineState state,
                     const ui::Event& event);

  void UpdateAccessibilityProperties();

  void UpdateAccessibleName();

  // views::View:
  bool OnMousePressed(const ui::MouseEvent& event) override;
  bool OnMouseDragged(const ui::MouseEvent& event) override;
  void OnMouseReleased(const ui::MouseEvent& event) override;
  void OnMouseEntered(const ui::MouseEvent& event) override;
  void OnMouseExited(const ui::MouseEvent& event) override;
  void OnThemeChanged() override;

 private:
  FRIEND_TEST_ALL_PREFIXES(OmniboxPopupViewViewsTest, DeleteSuggestion);

  void OpenIphLink();

  gfx::Image GetIcon() const;

  // Updates the highlight state of the row, as well as conditionally shows
  // controls that are only visible on row hover.
  void UpdateHoverState();

  // Sets the visibility of the |thumbs_up_button_| and |thumbs_down_button_|
  // based on the current state.
  void UpdateFeedbackButtonsVisibility();

  // Sets the visibility of the |remove_suggestion_button_| based on the current
  // state.
  void UpdateRemoveSuggestionVisibility();

  // Updates the 'selected' state of the view as applicable based on whether or
  // not the view is selected.
  void UpdateAccessibilitySelectedState();

  // views::View:
  void OnBoundsChanged(const gfx::Rect& previous_bounds) override;

  // The parent view.
  const raw_ptr<OmniboxPopupViewViews> popup_view_;

  // This result's model index.
  const size_t model_index_;

  // The data this class is built to display (the "Omnibox Result").
  AutocompleteMatch match_;

  // Weak pointers for easy reference.

  // The blue bar used to indicate selection.
  raw_ptr<OmniboxResultSelectionIndicator> selection_indicator_ = nullptr;

  // A container view for layout.
  raw_ptr<views::View> local_answer_header_and_suggestion_and_buttons_;

  // The answer header; e.g. 'Summary' or 'Generating...'. Lazily initialized.
  raw_ptr<OmniboxLocalAnswerHeaderView> local_answer_header_ = nullptr;

  // The icon, contents, description, etc depicting the match.
  raw_ptr<OmniboxMatchCellView> suggestion_view_;

  // The row of buttons that appears when actions such as tab switch or Pedals
  // are on the suggestion. It is owned by the base view, not this raw pointer.
  raw_ptr<OmniboxSuggestionButtonRowView> button_row_ = nullptr;

  // The thumbs up button used to submit feedback for suggestions.
  raw_ptr<views::ImageButton> thumbs_up_button_;

  // The thumbs down button used to submit feedback for suggestions.
  raw_ptr<views::ImageButton> thumbs_down_button_;

  // The "X" button at the end of the match cell, used to remove suggestions.
  raw_ptr<views::ImageButton> remove_suggestion_button_;

  // Keeps track of mouse-enter and mouse-exit events of child Views.
  OmniboxMouseEnterExitHandler mouse_enter_exit_handler_;

  base::WeakPtrFactory<OmniboxResultView> weak_factory_{this};
};

#endif  // CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_RESULT_VIEW_H_