Commit 33a12527 authored by Weidong Guo's avatar Weidong Guo Committed by Commit Bot

Fix close button wrong behavior in HALF mode

Changes:
1. Makes the launcher go back to PEEKING state when you click close
button in HALF mode.
2. Modifies the corresponding unit test.

BUG=745156
TEST=SearchBoxViewFullscreenTest.CloseButtonTest

Change-Id: I12b6743cdf49ddbac254004d053d60db2df602e5
Reviewed-on: https://chromium-review.googlesource.com/576115
Commit-Queue: Weidong Guo <weidongg@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#487971}
parent 14020f57
...@@ -268,8 +268,8 @@ views::ImageButton* SearchBoxView::back_button() { ...@@ -268,8 +268,8 @@ views::ImageButton* SearchBoxView::back_button() {
return static_cast<views::ImageButton*>(back_button_); return static_cast<views::ImageButton*>(back_button_);
} }
bool SearchBoxView::IsCloseButtonVisible() const { views::ImageButton* SearchBoxView::close_button() {
return close_button_ && close_button_->visible(); return static_cast<views::ImageButton*>(close_button_);
} }
// Returns true if set internally, i.e. if focused_view_ != CONTENTS_VIEW. // Returns true if set internally, i.e. if focused_view_ != CONTENTS_VIEW.
...@@ -493,6 +493,20 @@ void SearchBoxView::UpdateBackground(double progress, ...@@ -493,6 +493,20 @@ void SearchBoxView::UpdateBackground(double progress,
search_box_->SetBackgroundColor(color); search_box_->SetBackgroundColor(color);
} }
void SearchBoxView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (back_button_ && sender == back_button_) {
delegate_->BackButtonPressed();
} else if (speech_button_ && sender == speech_button_) {
view_delegate_->StartSpeechRecognition();
} else if (close_button_ && sender == close_button_) {
ClearSearch();
app_list_view_->SetStateFromSearchBoxView(true);
} else {
NOTREACHED();
}
}
void SearchBoxView::UpdateModel() { void SearchBoxView::UpdateModel() {
// Temporarily remove from observer to ignore notifications caused by us. // Temporarily remove from observer to ignore notifications caused by us.
model_->search_box()->RemoveObserver(this); model_->search_box()->RemoveObserver(this);
...@@ -594,18 +608,6 @@ bool SearchBoxView::HandleGestureEvent(views::Textfield* sender, ...@@ -594,18 +608,6 @@ bool SearchBoxView::HandleGestureEvent(views::Textfield* sender,
return OnTextfieldEvent(); return OnTextfieldEvent();
} }
void SearchBoxView::ButtonPressed(views::Button* sender,
const ui::Event& event) {
if (back_button_ && sender == back_button_)
delegate_->BackButtonPressed();
else if (speech_button_ && sender == speech_button_)
view_delegate_->StartSpeechRecognition();
else if (close_button_ && sender == close_button_)
ClearSearch();
else
NOTREACHED();
}
void SearchBoxView::SpeechRecognitionButtonPropChanged() { void SearchBoxView::SpeechRecognitionButtonPropChanged() {
const SearchBoxModel::SpeechButtonProperty* speech_button_prop = const SearchBoxModel::SpeechButtonProperty* speech_button_prop =
model_->search_box()->speech_button(); model_->search_box()->speech_button();
......
...@@ -68,8 +68,8 @@ class APP_LIST_EXPORT SearchBoxView : public views::View, ...@@ -68,8 +68,8 @@ class APP_LIST_EXPORT SearchBoxView : public views::View,
const gfx::Rect& rect) const; const gfx::Rect& rect) const;
views::ImageButton* back_button(); views::ImageButton* back_button();
views::ImageButton* close_button();
views::Textfield* search_box() { return search_box_; } views::Textfield* search_box() { return search_box_; }
bool IsCloseButtonVisible() const;
void set_contents_view(views::View* contents_view) { void set_contents_view(views::View* contents_view) {
contents_view_ = contents_view; contents_view_ = contents_view;
...@@ -124,6 +124,9 @@ class APP_LIST_EXPORT SearchBoxView : public views::View, ...@@ -124,6 +124,9 @@ class APP_LIST_EXPORT SearchBoxView : public views::View,
// Used only in the tests to get the current search icon. // Used only in the tests to get the current search icon.
views::ImageView* get_search_icon_for_test() { return search_icon_; } views::ImageView* get_search_icon_for_test() { return search_icon_; }
// Overridden from views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
private: private:
// Updates model text and selection model with current Textfield info. // Updates model text and selection model with current Textfield info.
void UpdateModel(); void UpdateModel();
...@@ -154,9 +157,6 @@ class APP_LIST_EXPORT SearchBoxView : public views::View, ...@@ -154,9 +157,6 @@ class APP_LIST_EXPORT SearchBoxView : public views::View,
bool HandleGestureEvent(views::Textfield* sender, bool HandleGestureEvent(views::Textfield* sender,
const ui::GestureEvent& gesture_event) override; const ui::GestureEvent& gesture_event) override;
// Overridden from views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
// Overridden from SearchBoxModelObserver: // Overridden from SearchBoxModelObserver:
void SpeechRecognitionButtonPropChanged() override; void SpeechRecognitionButtonPropChanged() override;
void HintTextChanged() override; void HintTextChanged() override;
......
...@@ -191,6 +191,7 @@ class SearchBoxViewFullscreenTest : public views::test::WidgetTest, ...@@ -191,6 +191,7 @@ class SearchBoxViewFullscreenTest : public views::test::WidgetTest,
} }
protected: protected:
views::Widget* widget() { return widget_; }
SearchBoxView* view() { return view_.get(); } SearchBoxView* view() { return view_.get(); }
AppListView* app_list_view() { return app_list_view_; } AppListView* app_list_view() { return app_list_view_; }
...@@ -270,11 +271,21 @@ TEST_P(SearchBoxViewTest, CancelAutoLaunch) { ...@@ -270,11 +271,21 @@ TEST_P(SearchBoxViewTest, CancelAutoLaunch) {
} }
TEST_F(SearchBoxViewFullscreenTest, CloseButtonTest) { TEST_F(SearchBoxViewFullscreenTest, CloseButtonTest) {
KeyPress(ui::VKEY_A); EXPECT_FALSE(view()->close_button()->visible());
EXPECT_TRUE(view()->IsCloseButtonVisible()); EXPECT_EQ(AppListView::PEEKING, app_list_view()->app_list_state());
view()->ClearSearch(); KeyPress(ui::VKEY_A);
EXPECT_FALSE(view()->IsCloseButtonVisible()); EXPECT_TRUE(view()->close_button()->visible());
EXPECT_EQ(AppListView::HALF, app_list_view()->app_list_state());
// Click the close button in search box view.
view()->ButtonPressed(
view()->close_button(),
ui::MouseEvent(ui::ET_MOUSE_PRESSED, gfx::Point(), gfx::Point(),
base::TimeTicks(), ui::EF_LEFT_MOUSE_BUTTON,
ui::EF_LEFT_MOUSE_BUTTON));
EXPECT_FALSE(view()->close_button()->visible());
EXPECT_EQ(AppListView::PEEKING, app_list_view()->app_list_state());
} }
// Tests that the search box is inactive by default. // Tests that the search box is inactive by default.
......
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