Commit 2bcb4b7e authored by mukai's avatar mukai Committed by Commit bot

Clears focus on gesture event.

This will cancel the virtual keyboard.

BUG=404110, 403813
R=oshima@chromium.org
TEST=manually && athena_unittests

Review URL: https://codereview.chromium.org/512963002

Cr-Commit-Position: refs/heads/master@{#292483}
parent 9f9a14ca
......@@ -211,6 +211,7 @@ AthenaStartPageView::AthenaStartPageView(
search_box_view_ = new app_list::SearchBoxView(this, view_delegate);
search_box_view_->set_contents_view(this);
search_box_view_->search_box()->set_id(kHomeCardSearchBoxId);
search_box_container_ = new SearchBoxContainer(search_box_view_);
search_box_container_->SetPaintToLayer(true);
search_box_container_->SetFillsBoundsOpaquely(false);
......
......@@ -8,5 +8,6 @@ namespace athena {
const int kHomeCardHeight = 100;
const int kHomeCardMinimizedHeight = 6;
const int kHomeCardSearchBoxId = 1000;
} // namespace athena
......@@ -15,6 +15,9 @@ ATHENA_EXPORT extern const int kHomeCardHeight;
// The height of the home card of MINIMIZED state.
ATHENA_EXPORT extern const int kHomeCardMinimizedHeight;
// The view ID for the seach box in the home card.
ATHENA_EXPORT extern const int kHomeCardSearchBoxId;
} // namespace athena
#endif // ATHENA_HOME_HOME_CARD_CONSTANTS_H_
......@@ -156,6 +156,11 @@ class HomeCardView : public views::WidgetDelegateView {
void SetStateProgress(HomeCard::State from_state,
HomeCard::State to_state,
float progress) {
// TODO(mukai): not clear the focus, but simply close the virtual keyboard.
if (from_state != HomeCard::VISIBLE_CENTERED ||
to_state != HomeCard::VISIBLE_CENTERED) {
GetFocusManager()->ClearFocus();
}
if (from_state == HomeCard::VISIBLE_CENTERED)
main_view_->SetLayoutState(1.0f - progress);
else if (to_state == HomeCard::VISIBLE_CENTERED)
......@@ -178,6 +183,11 @@ class HomeCardView : public views::WidgetDelegateView {
}
void SetStateWithAnimation(HomeCard::State state) {
if (state == HomeCard::VISIBLE_CENTERED)
main_view_->RequestFocusOnSearchBox();
else
GetWidget()->GetFocusManager()->ClearFocus();
if (state == HomeCard::VISIBLE_MINIMIZED)
return;
......
......@@ -14,6 +14,9 @@
#include "ui/events/test/event_generator.h"
#include "ui/gfx/display.h"
#include "ui/gfx/screen.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/focus/focus_manager.h"
#include "ui/views/widget/widget.h"
namespace athena {
......@@ -22,6 +25,12 @@ aura::Window* GetHomeCardWindow() {
GetHomeCardWindowForTest();
}
// Returns true if the keyboard focus is on the search box.
bool IsSearchBoxFocused(aura::Window* home_card) {
return views::Widget::GetWidgetForNativeWindow(home_card)->
GetContentsView()->GetViewByID(kHomeCardSearchBoxId)->HasFocus();
}
typedef test::AthenaTestBase HomeCardTest;
TEST_F(HomeCardTest, BasicTransition) {
......@@ -220,4 +229,33 @@ TEST_F(HomeCardTest, GesturesToFullDirectly) {
EXPECT_TRUE(WindowManager::GetInstance()->IsOverviewModeActive());
}
TEST_F(HomeCardTest, KeyboardFocus) {
ASSERT_EQ(HomeCard::VISIBLE_MINIMIZED, HomeCard::Get()->GetState());
aura::Window* home_card = GetHomeCardWindow();
ASSERT_FALSE(IsSearchBoxFocused(home_card));
WindowManager::GetInstance()->ToggleOverview();
ASSERT_FALSE(IsSearchBoxFocused(home_card));
ui::test::EventGenerator generator(root_window());
gfx::Rect screen_rect(root_window()->bounds());
const int bottom = screen_rect.bottom();
const int x = screen_rect.x() + 1;
generator.GestureScrollSequence(gfx::Point(x, bottom - 40),
gfx::Point(x, 10),
base::TimeDelta::FromSeconds(1),
10);
EXPECT_EQ(HomeCard::VISIBLE_CENTERED, HomeCard::Get()->GetState());
EXPECT_TRUE(IsSearchBoxFocused(home_card));
generator.GestureScrollSequence(gfx::Point(x, 10),
gfx::Point(x, bottom - 100),
base::TimeDelta::FromSeconds(1),
10);
EXPECT_EQ(HomeCard::VISIBLE_BOTTOM, HomeCard::Get()->GetState());
EXPECT_FALSE(IsSearchBoxFocused(home_card));
}
} // namespace athena
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