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..a8641a2aa5e247b69f36bc7625fe9b7b6a71eba4 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,11 @@ void SearchBoxView::ClearSearch() { |
| // does not generate ContentsChanged() notification. |
| UpdateModel(); |
| NotifyQueryChanged(); |
| + if (is_fullscreen_app_list_enabled_) { |
| + SetSearchBoxActive(!search_box_->text().empty()); |
| + if (app_list_view_) |
| + app_list_view_->SetStateFromSearchBoxView(search_box_->text().empty()); |
| + } |
| } |
| void SearchBoxView::SetShadow(const gfx::ShadowValue& shadow) { |
| @@ -332,6 +342,16 @@ void SearchBoxView::SetBackButtonLabel(bool folder) { |
| back_button_->SetTooltipText(back_button_label); |
| } |
| +void SearchBoxView::SetSearchBoxActive(bool active) { |
|
vadimt
2017/06/24 00:31:17
Early return if active == is_search_box_active_, o
newcomer
2017/06/27 22:12:49
Done.
|
| + 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); |
| + is_search_box_active_ = active; |
| + search_box_->SetCursorEnabled(active); |
| + search_box_->SchedulePaint(); |
| +} |
| + |
| bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) { |
| if (contents_view_) |
| return contents_view_->OnMouseWheel(event); |
| @@ -349,6 +369,26 @@ const char* SearchBoxView::GetClassName() const { |
| return "SearchBoxView"; |
| } |
| +void SearchBoxView::OnGestureEvent(ui::GestureEvent* event) { |
| + if (!is_fullscreen_app_list_enabled_ || event->type() != ui::ET_GESTURE_TAP) |
| + return; |
| + |
| + // If the search box is empty and the cursor is not enabled, enable the cursor |
| + // and shift the placeholder text left. |
| + if (search_box_->text().empty() && !is_search_box_active_) |
| + SetSearchBoxActive(true); |
| +} |
| + |
| +void SearchBoxView::OnMouseEvent(ui::MouseEvent* event) { |
| + if (!is_fullscreen_app_list_enabled_ || event->type() != ui::ET_MOUSE_PRESSED) |
| + return; |
| + |
| + // If the search box is empty and the cursor is not enabled, enable the cursor |
| + // and shift the placeholder text left. |
| + if (search_box_->text().empty() && !is_search_box_active_) |
| + SetSearchBoxActive(true); |
| +} |
| + |
| void SearchBoxView::UpdateModel() { |
| // Temporarily remove from observer to ignore notifications caused by us. |
| model_->search_box()->RemoveObserver(this); |
| @@ -367,8 +407,11 @@ void SearchBoxView::ContentsChanged(views::Textfield* sender, |
| UpdateModel(); |
| view_delegate_->AutoLaunchCanceled(); |
| NotifyQueryChanged(); |
| - if (is_fullscreen_app_list_enabled_) |
| - app_list_view_->SetStateFromSearchBoxView(search_box_->text().empty()); |
| + if (is_fullscreen_app_list_enabled_) { |
| + SetSearchBoxActive(!search_box_->text().empty()); |
| + if (app_list_view_) |
| + app_list_view_->SetStateFromSearchBoxView(search_box_->text().empty()); |
| + } |
| } |
| bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, |
| @@ -422,6 +465,30 @@ 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; |
| + |
| + if (search_box_->text().empty() && !is_search_box_active_) |
| + SetSearchBoxActive(true); |
| + |
| + return true; |
| +} |
| + |
| +bool SearchBoxView::HandleGestureEvent(views::Textfield* sender, |
| + const ui::GestureEvent& gesture_event) { |
| + if (!is_fullscreen_app_list_enabled_) |
| + return false; |
| + |
| + if (search_box_->text().empty() && !is_search_box_active_) { |
| + SetSearchBoxActive(true); |
| + return true; |
| + } else { |
| + return false; |
| + } |
| +} |
| + |
| void SearchBoxView::ButtonPressed(views::Button* sender, |
| const ui::Event& event) { |
| if (back_button_ && sender == back_button_) |