blob: a6fd63497c6ceae707093f5c6fa0df41f0d5c623 [file] [log] [blame]
Tommy Li533c3feb2020-04-06 20:49:031// Copyright 2020 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_ROW_VIEW_H_
6#define CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_ROW_VIEW_H_
7
8#include "base/optional.h"
9#include "base/strings/string16.h"
Peter Kastingacec004f2021-01-25 20:46:4310#include "ui/views/metadata/metadata_header_macros.h"
Tommy Li533c3feb2020-04-06 20:49:0311#include "ui/views/view.h"
12
Tommy Lid05db582020-05-14 23:51:3513class OmniboxPopupModel;
Tommy Li533c3feb2020-04-06 20:49:0314class OmniboxResultView;
Tommy Li9a084b22020-04-14 18:55:3715class PrefService;
Tommy Li533c3feb2020-04-06 20:49:0316
17// The View that's a direct child of the OmniboxPopupContentsView, one per row.
18// This, in turn, has a child OmniboxResultView and an optional header that is
19// painted right above it. The header is not a child of OmniboxResultView
20// because it's logically not part of the result view:
21// - Hovering the header doesn't highlight the result view.
22// - Clicking the header doesn't navigate to the match.
23// - It's the header for multiple matches, it's just painted above this row.
24class OmniboxRowView : public views::View {
25 public:
Peter Kastingacec004f2021-01-25 20:46:4326 METADATA_HEADER(OmniboxRowView);
Tommy Lid05db582020-05-14 23:51:3527 OmniboxRowView(size_t line,
28 OmniboxPopupModel* popup_model,
29 std::unique_ptr<OmniboxResultView> result_view,
Tommy Li9a084b22020-04-14 18:55:3730 PrefService* pref_service);
Tommy Li533c3feb2020-04-06 20:49:0331
Tommy Li3fd25672020-04-06 23:17:3932 // Sets the header that appears above this row. Also shows the header.
Tommy Li993e97c2020-04-09 01:08:0533 void ShowHeader(int suggestion_group_id, const base::string16& header_text);
Tommy Li3fd25672020-04-06 23:17:3934
35 // Hides the header.
36 void HideHeader();
Tommy Li533c3feb2020-04-06 20:49:0337
38 // The result view associated with this row.
39 OmniboxResultView* result_view() const { return result_view_; }
40
Tommy Lid05db582020-05-14 23:51:3541 // Invoked when the model's selection state has changed.
42 void OnSelectionStateChanged();
43
Tommy C. Li787080b2020-06-11 23:26:3144 // Fetches the active descendant button for accessibility purposes.
45 // Returns nullptr if no descendant auxiliary button is active.
46 views::View* GetActiveAuxiliaryButtonForAccessibility() const;
47
Tommy Li7fd07772020-05-01 20:24:2748 // views::View:
49 gfx::Insets GetInsets() const override;
50
Tommy Li533c3feb2020-04-06 20:49:0351 private:
Tommy Li3fd25672020-04-06 23:17:3952 class HeaderView;
53
Tommy Lid05db582020-05-14 23:51:3554 // Line number of this row.
55 const size_t line_;
56
57 // Non-owning pointer to the backing popup model.
58 OmniboxPopupModel* const popup_model_;
59
Tommy Li3fd25672020-04-06 23:17:3960 // Non-owning pointer to the header view for this row. This is initially
61 // nullptr, and lazily created when a header is first set for this row.
62 // Lazily creating these speeds up browser startup: https://crbug.com/1021323
63 HeaderView* header_view_ = nullptr;
64
Tommy Li533c3feb2020-04-06 20:49:0365 // Non-owning pointer to the result view for this row. This is never nullptr.
66 OmniboxResultView* result_view_;
Tommy Li9a084b22020-04-14 18:55:3767
68 // Non-owning pointer to the preference service used for toggling headers.
69 // May be nullptr in tests.
70 PrefService* const pref_service_;
Tommy Li533c3feb2020-04-06 20:49:0371};
72
73#endif // CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_ROW_VIEW_H_