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..ea3526f3464bd3910214b46e441a4da484c10272 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 used for 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: |
| @@ -147,7 +151,9 @@ SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate, |
| contents_view_(nullptr), |
| app_list_view_(app_list_view), |
| focused_view_(FOCUS_SEARCH_BOX), |
| - is_fullscreen_app_list_enabled_(features::IsFullscreenAppListEnabled()) { |
| + is_fullscreen_app_list_enabled_(features::IsFullscreenAppListEnabled()), |
| + is_cursor_enabled_(false), |
| + unit_tests_running_(false) { |
| SetLayoutManager(new views::FillLayout); |
| SetPreferredSize(gfx::Size(is_fullscreen_app_list_enabled_ |
| ? kPreferredWidthFullscreen |
| @@ -182,6 +188,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_cursor_enabled_); |
| } else { |
| back_button_ = new SearchBoxImageButton(this); |
| ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| @@ -229,6 +236,11 @@ void SearchBoxView::ClearSearch() { |
| // does not generate ContentsChanged() notification. |
| UpdateModel(); |
| NotifyQueryChanged(); |
| + if (is_fullscreen_app_list_enabled_) { |
| + SetPlaceholderTextAndEnableCursor(!search_box_->text().empty()); |
| + if (!unit_tests_running_) |
| + app_list_view_->SetStateFromSearchBoxView(search_box_->text().empty()); |
| + } |
| } |
| void SearchBoxView::SetShadow(const gfx::ShadowValue& shadow) { |
| @@ -332,6 +344,20 @@ void SearchBoxView::SetBackButtonLabel(bool folder) { |
| back_button_->SetTooltipText(back_button_label); |
| } |
| +void SearchBoxView::SetPlaceholderTextAndEnableCursor(bool enable) { |
| + search_box_->set_placeholder_text_draw_flags( |
| + enable ? gfx::Canvas::TEXT_ALIGN_LEFT : gfx::Canvas::TEXT_ALIGN_CENTER); |
| + search_box_->set_placeholder_text_color(enable ? kZeroQuerySearchboxColor |
| + : kDefaultSearchboxColor); |
| + is_cursor_enabled_ = enable; |
| + search_box_->SetCursorEnabled(enable); |
| + search_box_->SchedulePaint(); |
| +} |
| + |
| +bool SearchBoxView::PassMouseEventForTesting(ui::MouseEvent& mouse_event) { |
|
vadimt
2017/06/22 00:53:05
I assume you tried to find a way to inject a mouse
newcomer
2017/06/22 16:17:21
I couldn't find a way to do this without completel
|
| + return HandleMouseEvent(search_box_, mouse_event); |
| +} |
| + |
| bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) { |
| if (contents_view_) |
| return contents_view_->OnMouseWheel(event); |
| @@ -349,6 +375,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_cursor_enabled_) |
| + SetPlaceholderTextAndEnableCursor(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_cursor_enabled_) |
| + SetPlaceholderTextAndEnableCursor(true); |
| +} |
| + |
| void SearchBoxView::UpdateModel() { |
| // Temporarily remove from observer to ignore notifications caused by us. |
| model_->search_box()->RemoveObserver(this); |
| @@ -367,8 +413,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_) { |
| + SetPlaceholderTextAndEnableCursor(!search_box_->text().empty()); |
| + if (!unit_tests_running_) |
| + app_list_view_->SetStateFromSearchBoxView(search_box_->text().empty()); |
| + } |
| } |
| bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, |
| @@ -422,6 +471,25 @@ 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_cursor_enabled_) |
| + SetPlaceholderTextAndEnableCursor(true); |
| + |
| + return true; |
| +} |
| + |
| +void SearchBoxView::NotifyOfGestureEvent() { |
| + if (!is_fullscreen_app_list_enabled_) |
| + return; |
| + |
| + if (search_box_->text().empty() && !is_cursor_enabled_) |
| + SetPlaceholderTextAndEnableCursor(true); |
| +} |
| + |
| void SearchBoxView::ButtonPressed(views::Button* sender, |
| const ui::Event& event) { |
| if (back_button_ && sender == back_button_) |