Skip to content

Commit

Permalink
chromeos: Show assistant icon in bubble launcher search box
Browse files Browse the repository at this point in the history
Show it when the search box is active but empty. It doesn't do anything
yet.

Screenshot: https://screenshot.googleplex.com/BiaDweS3p97kewh

Also clean up SearchBoxView::Init(), which doesn't need to take a bool
for tablet mode because it already has a view_delegate that knows the
state.

Bug: 1216082
Test: added to ash_unittests
Change-Id: I91cb25d8e3264f685c4077a1a50bc5972bd332b5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2986899
Reviewed-by: Yulun Wu <yulunwu@chromium.org>
Commit-Queue: James Cook <jamescook@chromium.org>
Cr-Commit-Position: refs/heads/master@{#895839}
  • Loading branch information
James Cook authored and Chromium LUCI CQ committed Jun 24, 2021
1 parent c46cc27 commit caa0f35
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 12 deletions.
4 changes: 3 additions & 1 deletion ash/app_list/bubble/app_list_bubble_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ AppListBubbleView::AppListBubbleView(AppListViewDelegate* view_delegate,

search_box_view_ = AddChildView(std::make_unique<SearchBoxView>(
/*delegate=*/this, view_delegate, /*app_list_view=*/nullptr));
search_box_view_->Init(/*is_tablet_mode=*/false);
// Show the assistant button until the user types text.
search_box_view_->set_show_close_button_when_active(false);
search_box_view_->Init();

apps_page_ =
AddChildView(std::make_unique<AppListBubbleAppsPage>(view_delegate));
Expand Down
21 changes: 21 additions & 0 deletions ash/app_list/bubble/app_list_bubble_view_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,27 @@ TEST_F(AppListBubbleViewTest, OpeningBubbleFocusesSearchBox) {
EXPECT_TRUE(search_box_view->is_search_box_active());
}

TEST_F(AppListBubbleViewTest, SearchBoxShowsAssistantButton) {
// Simulate assistant being enabled.
Shell::Get()
->app_list_controller()
->GetSearchModel()
->search_box()
->SetShowAssistantButton(true);

ShowAppList();

// By default the assistant button is visible.
SearchBoxView* view = GetSearchBoxView();
EXPECT_TRUE(view->assistant_button()->GetVisible());
EXPECT_FALSE(view->close_button()->GetVisible());

// Typing text shows the close button instead.
PressAndReleaseKey(ui::VKEY_A);
EXPECT_FALSE(view->assistant_button()->GetVisible());
EXPECT_TRUE(view->close_button()->GetVisible());
}

TEST_F(AppListBubbleViewTest, AppsPageShownByDefault) {
ShowAppList();

Expand Down
3 changes: 2 additions & 1 deletion ash/app_list/views/app_list_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,8 @@ void AppListView::InitContents() {
auto app_list_main_view = std::make_unique<AppListMainView>(delegate_, this);
search_box_view_ =
new SearchBoxView(app_list_main_view.get(), delegate_, this);
search_box_view_->Init(delegate_->IsInTabletMode());
search_box_view_->set_show_close_button_when_active(true);
search_box_view_->Init();

// Assign |app_list_main_view_| here since it is accessed during Init().
app_list_main_view_ = app_list_main_view.get();
Expand Down
9 changes: 3 additions & 6 deletions ash/app_list/views/search_box_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,14 @@ SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate,
AppListView* app_list_view)
: SearchBoxViewBase(delegate),
view_delegate_(view_delegate),
app_list_view_(app_list_view) {
DCHECK(view_delegate_);
}
app_list_view_(app_list_view),
is_tablet_mode_(view_delegate_->IsInTabletMode()) {}

SearchBoxView::~SearchBoxView() {
search_model_->search_box()->RemoveObserver(this);
}

void SearchBoxView::Init(bool is_tablet_mode) {
is_tablet_mode_ = is_tablet_mode;
set_show_close_button_when_active(true);
void SearchBoxView::Init() {
SearchBoxViewBase::Init();
UpdatePlaceholderTextAndAccessibleName();
current_query_ = search_box()->GetText();
Expand Down
4 changes: 2 additions & 2 deletions ash/app_list/views/search_box_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ASH_EXPORT SearchBoxView : public SearchBoxViewBase,
AppListView* app_list_view = nullptr);
~SearchBoxView() override;

void Init(bool is_tablet_mode);
void Init();

// Must be called before the user interacts with the search box. Cannot be
// part of Init() because the controller isn't available until after Init()
Expand Down Expand Up @@ -189,7 +189,7 @@ class ASH_EXPORT SearchBoxView : public SearchBoxViewBase,
ContentsView* contents_view_ = nullptr;

// Whether tablet mode is active.
bool is_tablet_mode_ = false;
bool is_tablet_mode_;

// Set by SearchResultPageView when the accessibility selection moves to a
// search result view.
Expand Down
3 changes: 2 additions & 1 deletion ash/app_list/views/search_box_view_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ class SearchBoxViewTest : public views::test::WidgetTest,

auto view =
std::make_unique<SearchBoxView>(this, &view_delegate_, app_list_view());
view->Init(/*is_tablet_mode=*/false);
view->set_show_close_button_when_active(true);
view->Init();
view_ = widget_->GetContentsView()->AddChildView(std::move(view));

counter_view_ = widget_->GetContentsView()->AddChildView(
Expand Down
2 changes: 1 addition & 1 deletion ash/search_box/search_box_view_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class SearchBoxViewBase : public views::View,

// Whether the search box is active.
bool is_search_box_active_ = false;
// Whether to show close button if the search box is active.
// Whether to show close button if the search box is active and empty.
bool show_close_button_when_active_ = false;
// Whether to show assistant button.
bool show_assistant_button_ = false;
Expand Down

0 comments on commit caa0f35

Please sign in to comment.