Commit 9a084b2c authored by Tommy Li's avatar Tommy Li Committed by Commit Bot

[omnibox] Hook up OmniboxRowView toggle button to the preference service

This CL just hooks up the toggle button to the preference service.
Nothing more.

Bug: 1052522
Change-Id: Ic58565b7f9420c76f0ec7fbff15346722ddc7626
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2147688
Auto-Submit: Tommy Li <tommycli@chromium.org>
Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Commit-Queue: Tommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#758940}
parent 3aa29eee
...@@ -301,13 +301,16 @@ void OmniboxPopupContentsView::UpdatePopupAppearance() { ...@@ -301,13 +301,16 @@ void OmniboxPopupContentsView::UpdatePopupAppearance() {
} }
} else { } else {
base::Optional<int> previous_row_group_id = base::nullopt; base::Optional<int> previous_row_group_id = base::nullopt;
PrefService* pref_service = nullptr;
if (location_bar_view_->profile())
pref_service = location_bar_view_->profile()->GetPrefs();
for (size_t i = 0; i < result_size; ++i) { for (size_t i = 0; i < result_size; ++i) {
// Create child views lazily. Since especially the first result view may // Create child views lazily. Since especially the first result view may
// be expensive to create due to loading font data, this saves time and // be expensive to create due to loading font data, this saves time and
// memory during browser startup. https://crbug.com/1021323 // memory during browser startup. https://crbug.com/1021323
if (children().size() == i) { if (children().size() == i) {
AddChildView(std::make_unique<OmniboxRowView>( AddChildView(std::make_unique<OmniboxRowView>(
std::make_unique<OmniboxResultView>(this, i))); std::make_unique<OmniboxResultView>(this, i), pref_service));
} }
OmniboxRowView* const row_view = OmniboxRowView* const row_view =
......
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
#include "chrome/browser/ui/layout_constants.h" #include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/omnibox/omnibox_theme.h" #include "chrome/browser/ui/omnibox/omnibox_theme.h"
#include "chrome/browser/ui/views/omnibox/omnibox_result_view.h" #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h"
#include "components/omnibox/browser/omnibox_prefs.h"
#include "components/omnibox/browser/vector_icons.h" #include "components/omnibox/browser/vector_icons.h"
#include "components/prefs/pref_service.h"
#include "ui/gfx/image/image_skia_operations.h" #include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
...@@ -20,7 +22,7 @@ ...@@ -20,7 +22,7 @@
class OmniboxRowView::HeaderView : public views::View, class OmniboxRowView::HeaderView : public views::View,
public views::ButtonListener { public views::ButtonListener {
public: public:
HeaderView() { explicit HeaderView(PrefService* pref_service) : pref_service_(pref_service) {
views::BoxLayout* layout = views::BoxLayout* layout =
SetLayoutManager(std::make_unique<views::BoxLayout>( SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kHorizontal)); views::BoxLayout::Orientation::kHorizontal));
...@@ -37,6 +39,11 @@ class OmniboxRowView::HeaderView : public views::View, ...@@ -37,6 +39,11 @@ class OmniboxRowView::HeaderView : public views::View,
void SetHeader(int suggestion_group_id, const base::string16& header_text) { void SetHeader(int suggestion_group_id, const base::string16& header_text) {
suggestion_group_id_ = suggestion_group_id; suggestion_group_id_ = suggestion_group_id;
header_text_->SetText(header_text); header_text_->SetText(header_text);
if (pref_service_) {
hide_button_->SetToggled(omnibox::IsSuggestionGroupIdHidden(
pref_service_, suggestion_group_id_));
}
} }
// views::View: // views::View:
...@@ -59,7 +66,13 @@ class OmniboxRowView::HeaderView : public views::View, ...@@ -59,7 +66,13 @@ class OmniboxRowView::HeaderView : public views::View,
void ButtonPressed(views::Button* sender, const ui::Event& event) override { void ButtonPressed(views::Button* sender, const ui::Event& event) override {
DCHECK_EQ(sender, hide_button_); DCHECK_EQ(sender, hide_button_);
// TODO(tommycli): Implement toggling the pref here. if (!pref_service_)
return;
omnibox::ToggleSuggestionGroupIdVisibility(pref_service_,
suggestion_group_id_);
hide_button_->SetToggled(omnibox::IsSuggestionGroupIdHidden(
pref_service_, suggestion_group_id_));
} }
private: private:
...@@ -89,6 +102,10 @@ class OmniboxRowView::HeaderView : public views::View, ...@@ -89,6 +102,10 @@ class OmniboxRowView::HeaderView : public views::View,
SetBackground(OmniboxResultView::GetPopupCellBackground(this, part_state)); SetBackground(OmniboxResultView::GetPopupCellBackground(this, part_state));
} }
// Non-owning pointer to the preference service used for toggling headers.
// May be nullptr in tests.
PrefService* const pref_service_;
// The Label containing the header text. This is never nullptr. // The Label containing the header text. This is never nullptr.
views::Label* header_text_; views::Label* header_text_;
...@@ -99,8 +116,11 @@ class OmniboxRowView::HeaderView : public views::View, ...@@ -99,8 +116,11 @@ class OmniboxRowView::HeaderView : public views::View,
int suggestion_group_id_ = 0; int suggestion_group_id_ = 0;
}; };
OmniboxRowView::OmniboxRowView(std::unique_ptr<OmniboxResultView> result_view) { OmniboxRowView::OmniboxRowView(std::unique_ptr<OmniboxResultView> result_view,
PrefService* pref_service)
: pref_service_(pref_service) {
DCHECK(result_view); DCHECK(result_view);
DCHECK(pref_service);
SetLayoutManager(std::make_unique<views::BoxLayout>( SetLayoutManager(std::make_unique<views::BoxLayout>(
views::BoxLayout::Orientation::kVertical)); views::BoxLayout::Orientation::kVertical));
...@@ -111,8 +131,10 @@ OmniboxRowView::OmniboxRowView(std::unique_ptr<OmniboxResultView> result_view) { ...@@ -111,8 +131,10 @@ OmniboxRowView::OmniboxRowView(std::unique_ptr<OmniboxResultView> result_view) {
void OmniboxRowView::ShowHeader(int suggestion_group_id, void OmniboxRowView::ShowHeader(int suggestion_group_id,
const base::string16& header_text) { const base::string16& header_text) {
// Create the header (at index 0) if it doesn't exist. // Create the header (at index 0) if it doesn't exist.
if (header_view_ == nullptr) if (header_view_ == nullptr) {
header_view_ = AddChildViewAt(std::make_unique<HeaderView>(), 0); header_view_ =
AddChildViewAt(std::make_unique<HeaderView>(pref_service_), 0);
}
header_view_->SetHeader(suggestion_group_id, header_text); header_view_->SetHeader(suggestion_group_id, header_text);
header_view_->SetVisible(true); header_view_->SetVisible(true);
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "ui/views/view.h" #include "ui/views/view.h"
class OmniboxResultView; class OmniboxResultView;
class PrefService;
// The View that's a direct child of the OmniboxPopupContentsView, one per row. // The View that's a direct child of the OmniboxPopupContentsView, one per row.
// This, in turn, has a child OmniboxResultView and an optional header that is // This, in turn, has a child OmniboxResultView and an optional header that is
...@@ -20,7 +21,8 @@ class OmniboxResultView; ...@@ -20,7 +21,8 @@ class OmniboxResultView;
// - It's the header for multiple matches, it's just painted above this row. // - It's the header for multiple matches, it's just painted above this row.
class OmniboxRowView : public views::View { class OmniboxRowView : public views::View {
public: public:
explicit OmniboxRowView(std::unique_ptr<OmniboxResultView> result_view); OmniboxRowView(std::unique_ptr<OmniboxResultView> result_view,
PrefService* pref_service);
// Sets the header that appears above this row. Also shows the header. // Sets the header that appears above this row. Also shows the header.
void ShowHeader(int suggestion_group_id, const base::string16& header_text); void ShowHeader(int suggestion_group_id, const base::string16& header_text);
...@@ -41,6 +43,10 @@ class OmniboxRowView : public views::View { ...@@ -41,6 +43,10 @@ class OmniboxRowView : public views::View {
// Non-owning pointer to the result view for this row. This is never nullptr. // Non-owning pointer to the result view for this row. This is never nullptr.
OmniboxResultView* result_view_; OmniboxResultView* result_view_;
// Non-owning pointer to the preference service used for toggling headers.
// May be nullptr in tests.
PrefService* const pref_service_;
}; };
#endif // CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_ROW_VIEW_H_ #endif // CHROME_BROWSER_UI_VIEWS_OMNIBOX_OMNIBOX_ROW_VIEW_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment