Tommy Li | 533c3feb | 2020-04-06 20:49:03 | [diff] [blame] | 1 | // 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 Kasting | acec004f | 2021-01-25 20:46:43 | [diff] [blame] | 10 | #include "ui/views/metadata/metadata_header_macros.h" |
Tommy Li | 533c3feb | 2020-04-06 20:49:03 | [diff] [blame] | 11 | #include "ui/views/view.h" |
| 12 | |
Tommy Li | d05db58 | 2020-05-14 23:51:35 | [diff] [blame] | 13 | class OmniboxPopupModel; |
Tommy Li | 533c3feb | 2020-04-06 20:49:03 | [diff] [blame] | 14 | class OmniboxResultView; |
Tommy Li | 9a084b2 | 2020-04-14 18:55:37 | [diff] [blame] | 15 | class PrefService; |
Tommy Li | 533c3feb | 2020-04-06 20:49:03 | [diff] [blame] | 16 | |
| 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. |
| 24 | class OmniboxRowView : public views::View { |
| 25 | public: |
Peter Kasting | acec004f | 2021-01-25 20:46:43 | [diff] [blame] | 26 | METADATA_HEADER(OmniboxRowView); |
Tommy Li | d05db58 | 2020-05-14 23:51:35 | [diff] [blame] | 27 | OmniboxRowView(size_t line, |
| 28 | OmniboxPopupModel* popup_model, |
| 29 | std::unique_ptr<OmniboxResultView> result_view, |
Tommy Li | 9a084b2 | 2020-04-14 18:55:37 | [diff] [blame] | 30 | PrefService* pref_service); |
Tommy Li | 533c3feb | 2020-04-06 20:49:03 | [diff] [blame] | 31 | |
Tommy Li | 3fd2567 | 2020-04-06 23:17:39 | [diff] [blame] | 32 | // Sets the header that appears above this row. Also shows the header. |
Tommy Li | 993e97c | 2020-04-09 01:08:05 | [diff] [blame] | 33 | void ShowHeader(int suggestion_group_id, const base::string16& header_text); |
Tommy Li | 3fd2567 | 2020-04-06 23:17:39 | [diff] [blame] | 34 | |
| 35 | // Hides the header. |
| 36 | void HideHeader(); |
Tommy Li | 533c3feb | 2020-04-06 20:49:03 | [diff] [blame] | 37 | |
| 38 | // The result view associated with this row. |
| 39 | OmniboxResultView* result_view() const { return result_view_; } |
| 40 | |
Tommy Li | d05db58 | 2020-05-14 23:51:35 | [diff] [blame] | 41 | // Invoked when the model's selection state has changed. |
| 42 | void OnSelectionStateChanged(); |
| 43 | |
Tommy C. Li | 787080b | 2020-06-11 23:26:31 | [diff] [blame] | 44 | // 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 Li | 7fd0777 | 2020-05-01 20:24:27 | [diff] [blame] | 48 | // views::View: |
| 49 | gfx::Insets GetInsets() const override; |
| 50 | |
Tommy Li | 533c3feb | 2020-04-06 20:49:03 | [diff] [blame] | 51 | private: |
Tommy Li | 3fd2567 | 2020-04-06 23:17:39 | [diff] [blame] | 52 | class HeaderView; |
| 53 | |
Tommy Li | d05db58 | 2020-05-14 23:51:35 | [diff] [blame] | 54 | // 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 Li | 3fd2567 | 2020-04-06 23:17:39 | [diff] [blame] | 60 | // 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 Li | 533c3feb | 2020-04-06 20:49:03 | [diff] [blame] | 65 | // Non-owning pointer to the result view for this row. This is never nullptr. |
| 66 | OmniboxResultView* result_view_; |
Tommy Li | 9a084b2 | 2020-04-14 18:55:37 | [diff] [blame] | 67 | |
| 68 | // Non-owning pointer to the preference service used for toggling headers. |
| 69 | // May be nullptr in tests. |
| 70 | PrefService* const pref_service_; |
Tommy Li | 533c3feb | 2020-04-06 20:49:03 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | #endif // CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_ROW_VIEW_H_ |