Chromium Code Reviews| Index: ui/app_list/views/search_box_view.cc |
| diff --git a/ui/app_list/views/search_box_view.cc b/ui/app_list/views/search_box_view.cc |
| index 7841388bd63fffa5cdfefc49a25236866a59fb02..9e55f31d7347c5bcbb63fbf1cc837c38405d5f1a 100644 |
| --- a/ui/app_list/views/search_box_view.cc |
| +++ b/ui/app_list/views/search_box_view.cc |
| @@ -62,6 +62,10 @@ constexpr int kMicIconSize = 24; |
| constexpr SkColor kDefaultSearchboxColor = |
| SkColorSetARGBMacro(0xDE, 0x00, 0x00, 0x00); |
| +// Color of placeholder text in zero query state. |
| +constexpr SkColor kZeroQuerySearchboxColor = |
| + SkColorSetARGBMacro(0x8A, 0x00, 0x00, 0x00); |
| + |
| // A background that paints a solid white rounded rect with a thin grey border. |
| class SearchBoxBackground : public views::Background { |
| public: |
| @@ -182,6 +186,7 @@ SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate, |
| search_box_->set_placeholder_text_draw_flags( |
| gfx::Canvas::TEXT_ALIGN_CENTER); |
| search_box_->SetFontList(search_box_->GetFontList().DeriveWithSizeDelta(2)); |
| + search_box_->SetCursorEnabled(is_search_box_active_); |
| } else { |
| back_button_ = new SearchBoxImageButton(this); |
| ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| @@ -229,6 +234,8 @@ void SearchBoxView::ClearSearch() { |
| // does not generate ContentsChanged() notification. |
| UpdateModel(); |
| NotifyQueryChanged(); |
| + if (is_fullscreen_app_list_enabled_) |
| + SetSearchBoxActive(false); |
| } |
| void SearchBoxView::SetShadow(const gfx::ShadowValue& shadow) { |
| @@ -332,6 +339,54 @@ void SearchBoxView::SetBackButtonLabel(bool folder) { |
| back_button_->SetTooltipText(back_button_label); |
| } |
| +void SearchBoxView::SetSearchBoxActive(bool active) { |
| + if (!is_fullscreen_app_list_enabled_) |
| + return; |
| + |
| + if (active == is_search_box_active_) |
| + return; |
| + |
| + is_search_box_active_ = active; |
| + search_box_->set_placeholder_text_draw_flags( |
| + active ? gfx::Canvas::TEXT_ALIGN_LEFT : gfx::Canvas::TEXT_ALIGN_CENTER); |
| + search_box_->set_placeholder_text_color(active ? kZeroQuerySearchboxColor |
| + : kDefaultSearchboxColor); |
| + search_box_->SetCursorEnabled(active); |
| + search_box_->SchedulePaint(); |
| +} |
| + |
| +void SearchBoxView::HandleSearchBoxEvent(ui::LocatedEvent* located_event) { |
| + if (!is_fullscreen_app_list_enabled_) |
| + return; |
| + |
| + if (located_event->type != ui::ET_MOUSE_PRESSED && |
| + located_event->type != ui::ET_GESTURE_TAP) |
| + return; |
| + |
| + bool event_is_in_searchbox_bounds = |
| + GetWidget()->GetWindowBoundsInScreen().Contains( |
| + located_event->root_location()); |
| + |
| + if (!is_search_box_active_ && event_is_in_searchbox_bounds && |
| + search_box_->text().empty()) { |
| + // If the event was within the searchbox bounds and in an inactive empty |
| + // search box, enable the search box. |
| + SetSearchBoxActive(true); |
| + located_event->SetHandled(); |
| + } |
| +} |
| + |
| +bool SearchBoxView::OnTextfieldEvent() { |
| + if (!is_fullscreen_app_list_enabled_) |
| + return false; |
| + |
| + if (is_search_box_active_) |
| + return false; |
| + |
| + SetSearchBoxActive(true); |
| + return true; |
| +} |
| + |
| bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) { |
| if (contents_view_) |
| return contents_view_->OnMouseWheel(event); |
| @@ -349,6 +404,14 @@ const char* SearchBoxView::GetClassName() const { |
| return "SearchBoxView"; |
| } |
| +void SearchBoxView::OnGestureEvent(ui::GestureEvent* event) { |
| + HandleSearchBoxEvent(event); |
| +} |
| + |
| +void SearchBoxView::OnMouseEvent(ui::MouseEvent* event) { |
| + HandleSearchBoxEvent(event); |
| +} |
| + |
| void SearchBoxView::UpdateModel() { |
| // Temporarily remove from observer to ignore notifications caused by us. |
| model_->search_box()->RemoveObserver(this); |
| @@ -367,8 +430,11 @@ void SearchBoxView::ContentsChanged(views::Textfield* sender, |
| UpdateModel(); |
| view_delegate_->AutoLaunchCanceled(); |
| NotifyQueryChanged(); |
| - if (is_fullscreen_app_list_enabled_) |
| + if (is_fullscreen_app_list_enabled_) { |
| + if (is_search_box_active_ == search_box_->text().empty()) |
| + SetSearchBoxActive(!search_box_->text().empty()); |
| app_list_view_->SetStateFromSearchBoxView(search_box_->text().empty()); |
| + } |
| } |
| bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, |
| @@ -422,6 +488,22 @@ bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, |
| return false; |
| } |
| +bool SearchBoxView::HandleMouseEvent(views::Textfield* sender, |
| + const ui::MouseEvent& mouse_event) { |
| + if (!is_fullscreen_app_list_enabled_) |
| + return false; |
|
oshima
2017/07/05 19:11:59
OnTextfieldEvent checks this, so you don't need th
newcomer
2017/07/05 22:03:57
Done.
|
| + |
| + return OnTextfieldEvent(); |
| +} |
| + |
| +bool SearchBoxView::HandleGestureEvent(views::Textfield* sender, |
| + const ui::GestureEvent& gesture_event) { |
| + if (!is_fullscreen_app_list_enabled_) |
|
oshima
2017/07/05 19:11:59
ditto
newcomer
2017/07/05 22:03:57
Done.
|
| + return false; |
| + |
| + return OnTextfieldEvent(); |
| +} |
| + |
| void SearchBoxView::ButtonPressed(views::Button* sender, |
| const ui::Event& event) { |
| if (back_button_ && sender == back_button_) |