Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(520)

Unified Diff: ui/app_list/views/search_box_view.cc

Issue 2952763002: SearchBoxView now enables/disables cursor based on user interaction. (Closed)
Patch Set: SearchBoxView now enables/disables cursor based on user interaction. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..ad21dd5b12ab14078052afc3ed3fd591e149fc36 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,8 @@ 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) {
SetLayoutManager(new views::FillLayout);
SetPreferredSize(gfx::Size(is_fullscreen_app_list_enabled_
? kPreferredWidthFullscreen
@@ -182,6 +187,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();
@@ -332,6 +338,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) {
+ return HandleMouseEvent(search_box_, mouse_event);
+}
+
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_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 +407,10 @@ void SearchBoxView::ContentsChanged(views::Textfield* sender,
UpdateModel();
view_delegate_->AutoLaunchCanceled();
NotifyQueryChanged();
- if (is_fullscreen_app_list_enabled_)
+ if (is_fullscreen_app_list_enabled_) {
+ SetPlaceholderTextAndEnableCursor(!search_box_->text().empty());
app_list_view_->SetStateFromSearchBoxView(search_box_->text().empty());
+ }
}
bool SearchBoxView::HandleKeyEvent(views::Textfield* sender,
@@ -422,6 +464,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_)
@@ -494,5 +555,4 @@ void SearchBoxView::OnSpeechRecognitionStateChanged(
SpeechRecognitionButtonPropChanged();
SchedulePaint();
}
-
} // namespace app_list

Powered by Google App Engine
This is Rietveld 408576698