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

Side by Side 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, 5 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 unified diff | Download patch
« no previous file with comments | « ui/app_list/views/search_box_view.h ('k') | ui/app_list/views/search_box_view_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/app_list/views/search_box_view.h" 5 #include "ui/app_list/views/search_box_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 constexpr int kBackgroundBorderCornerRadius = 2; 55 constexpr int kBackgroundBorderCornerRadius = 2;
56 constexpr int kBackgroundBorderCornerRadiusFullscreen = 24; 56 constexpr int kBackgroundBorderCornerRadiusFullscreen = 24;
57 constexpr int kGoogleIconSize = 24; 57 constexpr int kGoogleIconSize = 24;
58 constexpr int kMicIconSize = 24; 58 constexpr int kMicIconSize = 24;
59 59
60 // Default color used when wallpaper customized color is not available for 60 // Default color used when wallpaper customized color is not available for
61 // searchbox, #000 at 87% opacity. 61 // searchbox, #000 at 87% opacity.
62 constexpr SkColor kDefaultSearchboxColor = 62 constexpr SkColor kDefaultSearchboxColor =
63 SkColorSetARGBMacro(0xDE, 0x00, 0x00, 0x00); 63 SkColorSetARGBMacro(0xDE, 0x00, 0x00, 0x00);
64 64
65 // Color of placeholder text in zero query state.
66 constexpr SkColor kZeroQuerySearchboxColor =
67 SkColorSetARGBMacro(0x8A, 0x00, 0x00, 0x00);
68
65 // A background that paints a solid white rounded rect with a thin grey border. 69 // A background that paints a solid white rounded rect with a thin grey border.
66 class SearchBoxBackground : public views::Background { 70 class SearchBoxBackground : public views::Background {
67 public: 71 public:
68 SearchBoxBackground() 72 SearchBoxBackground()
69 : background_border_corner_radius_( 73 : background_border_corner_radius_(
70 features::IsFullscreenAppListEnabled() 74 features::IsFullscreenAppListEnabled()
71 ? kBackgroundBorderCornerRadiusFullscreen 75 ? kBackgroundBorderCornerRadiusFullscreen
72 : kBackgroundBorderCornerRadius) {} 76 : kBackgroundBorderCornerRadius) {}
73 ~SearchBoxBackground() override {} 77 ~SearchBoxBackground() override {}
74 78
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 if (is_fullscreen_app_list_enabled_) { 179 if (is_fullscreen_app_list_enabled_) {
176 google_icon_ = new views::ImageView(); 180 google_icon_ = new views::ImageView();
177 google_icon_->SetImage(gfx::CreateVectorIcon( 181 google_icon_->SetImage(gfx::CreateVectorIcon(
178 kIcGoogleBlackIcon, kGoogleIconSize, kDefaultSearchboxColor)); 182 kIcGoogleBlackIcon, kGoogleIconSize, kDefaultSearchboxColor));
179 content_container_->AddChildView(google_icon_); 183 content_container_->AddChildView(google_icon_);
180 184
181 search_box_->set_placeholder_text_color(kDefaultSearchboxColor); 185 search_box_->set_placeholder_text_color(kDefaultSearchboxColor);
182 search_box_->set_placeholder_text_draw_flags( 186 search_box_->set_placeholder_text_draw_flags(
183 gfx::Canvas::TEXT_ALIGN_CENTER); 187 gfx::Canvas::TEXT_ALIGN_CENTER);
184 search_box_->SetFontList(search_box_->GetFontList().DeriveWithSizeDelta(2)); 188 search_box_->SetFontList(search_box_->GetFontList().DeriveWithSizeDelta(2));
189 search_box_->SetCursorEnabled(is_search_box_active_);
185 } else { 190 } else {
186 back_button_ = new SearchBoxImageButton(this); 191 back_button_ = new SearchBoxImageButton(this);
187 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 192 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
188 back_button_->SetImage( 193 back_button_->SetImage(
189 views::ImageButton::STATE_NORMAL, 194 views::ImageButton::STATE_NORMAL,
190 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL)); 195 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL));
191 back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, 196 back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
192 views::ImageButton::ALIGN_MIDDLE); 197 views::ImageButton::ALIGN_MIDDLE);
193 SetBackButtonLabel(false); 198 SetBackButtonLabel(false);
194 content_container_->AddChildView(back_button_); 199 content_container_->AddChildView(back_button_);
(...skipping 27 matching lines...) Expand all
222 return !search_box_->text().empty(); 227 return !search_box_->text().empty();
223 } 228 }
224 229
225 void SearchBoxView::ClearSearch() { 230 void SearchBoxView::ClearSearch() {
226 search_box_->SetText(base::string16()); 231 search_box_->SetText(base::string16());
227 view_delegate_->AutoLaunchCanceled(); 232 view_delegate_->AutoLaunchCanceled();
228 // Updates model and fires query changed manually because SetText() above 233 // Updates model and fires query changed manually because SetText() above
229 // does not generate ContentsChanged() notification. 234 // does not generate ContentsChanged() notification.
230 UpdateModel(); 235 UpdateModel();
231 NotifyQueryChanged(); 236 NotifyQueryChanged();
237 if (is_fullscreen_app_list_enabled_) {
238 SetSearchBoxActive(!search_box_->text().empty());
239 if (app_list_view_)
240 app_list_view_->SetStateFromSearchBoxView(search_box_->text().empty());
241 }
232 } 242 }
233 243
234 void SearchBoxView::SetShadow(const gfx::ShadowValue& shadow) { 244 void SearchBoxView::SetShadow(const gfx::ShadowValue& shadow) {
235 if (is_fullscreen_app_list_enabled_) 245 if (is_fullscreen_app_list_enabled_)
236 return; 246 return;
237 247
238 SetBorder(base::MakeUnique<views::ShadowBorder>(shadow)); 248 SetBorder(base::MakeUnique<views::ShadowBorder>(shadow));
239 Layout(); 249 Layout();
240 } 250 }
241 251
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 if (!back_button_) 335 if (!back_button_)
326 return; 336 return;
327 337
328 base::string16 back_button_label(l10n_util::GetStringUTF16( 338 base::string16 back_button_label(l10n_util::GetStringUTF16(
329 folder ? IDS_APP_LIST_FOLDER_CLOSE_FOLDER_ACCESSIBILE_NAME 339 folder ? IDS_APP_LIST_FOLDER_CLOSE_FOLDER_ACCESSIBILE_NAME
330 : IDS_APP_LIST_BACK)); 340 : IDS_APP_LIST_BACK));
331 back_button_->SetAccessibleName(back_button_label); 341 back_button_->SetAccessibleName(back_button_label);
332 back_button_->SetTooltipText(back_button_label); 342 back_button_->SetTooltipText(back_button_label);
333 } 343 }
334 344
345 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.
346 search_box_->set_placeholder_text_draw_flags(
347 active ? gfx::Canvas::TEXT_ALIGN_LEFT : gfx::Canvas::TEXT_ALIGN_CENTER);
348 search_box_->set_placeholder_text_color(active ? kZeroQuerySearchboxColor
349 : kDefaultSearchboxColor);
350 is_search_box_active_ = active;
351 search_box_->SetCursorEnabled(active);
352 search_box_->SchedulePaint();
353 }
354
335 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) { 355 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) {
336 if (contents_view_) 356 if (contents_view_)
337 return contents_view_->OnMouseWheel(event); 357 return contents_view_->OnMouseWheel(event);
338 358
339 return false; 359 return false;
340 } 360 }
341 361
342 void SearchBoxView::OnEnabledChanged() { 362 void SearchBoxView::OnEnabledChanged() {
343 search_box_->SetEnabled(enabled()); 363 search_box_->SetEnabled(enabled());
344 if (speech_button_) 364 if (speech_button_)
345 speech_button_->SetEnabled(enabled()); 365 speech_button_->SetEnabled(enabled());
346 } 366 }
347 367
348 const char* SearchBoxView::GetClassName() const { 368 const char* SearchBoxView::GetClassName() const {
349 return "SearchBoxView"; 369 return "SearchBoxView";
350 } 370 }
351 371
372 void SearchBoxView::OnGestureEvent(ui::GestureEvent* event) {
373 if (!is_fullscreen_app_list_enabled_ || event->type() != ui::ET_GESTURE_TAP)
374 return;
375
376 // If the search box is empty and the cursor is not enabled, enable the cursor
377 // and shift the placeholder text left.
378 if (search_box_->text().empty() && !is_search_box_active_)
379 SetSearchBoxActive(true);
380 }
381
382 void SearchBoxView::OnMouseEvent(ui::MouseEvent* event) {
383 if (!is_fullscreen_app_list_enabled_ || event->type() != ui::ET_MOUSE_PRESSED)
384 return;
385
386 // If the search box is empty and the cursor is not enabled, enable the cursor
387 // and shift the placeholder text left.
388 if (search_box_->text().empty() && !is_search_box_active_)
389 SetSearchBoxActive(true);
390 }
391
352 void SearchBoxView::UpdateModel() { 392 void SearchBoxView::UpdateModel() {
353 // Temporarily remove from observer to ignore notifications caused by us. 393 // Temporarily remove from observer to ignore notifications caused by us.
354 model_->search_box()->RemoveObserver(this); 394 model_->search_box()->RemoveObserver(this);
355 model_->search_box()->Update(search_box_->text(), false); 395 model_->search_box()->Update(search_box_->text(), false);
356 model_->search_box()->SetSelectionModel(search_box_->GetSelectionModel()); 396 model_->search_box()->SetSelectionModel(search_box_->GetSelectionModel());
357 model_->search_box()->AddObserver(this); 397 model_->search_box()->AddObserver(this);
358 } 398 }
359 399
360 void SearchBoxView::NotifyQueryChanged() { 400 void SearchBoxView::NotifyQueryChanged() {
361 DCHECK(delegate_); 401 DCHECK(delegate_);
362 delegate_->QueryChanged(this); 402 delegate_->QueryChanged(this);
363 } 403 }
364 404
365 void SearchBoxView::ContentsChanged(views::Textfield* sender, 405 void SearchBoxView::ContentsChanged(views::Textfield* sender,
366 const base::string16& new_contents) { 406 const base::string16& new_contents) {
367 UpdateModel(); 407 UpdateModel();
368 view_delegate_->AutoLaunchCanceled(); 408 view_delegate_->AutoLaunchCanceled();
369 NotifyQueryChanged(); 409 NotifyQueryChanged();
370 if (is_fullscreen_app_list_enabled_) 410 if (is_fullscreen_app_list_enabled_) {
371 app_list_view_->SetStateFromSearchBoxView(search_box_->text().empty()); 411 SetSearchBoxActive(!search_box_->text().empty());
412 if (app_list_view_)
413 app_list_view_->SetStateFromSearchBoxView(search_box_->text().empty());
414 }
372 } 415 }
373 416
374 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, 417 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender,
375 const ui::KeyEvent& key_event) { 418 const ui::KeyEvent& key_event) {
376 if (key_event.type() == ui::ET_KEY_PRESSED) { 419 if (key_event.type() == ui::ET_KEY_PRESSED) {
377 if (key_event.key_code() == ui::VKEY_TAB && 420 if (key_event.key_code() == ui::VKEY_TAB &&
378 focused_view_ != FOCUS_CONTENTS_VIEW && 421 focused_view_ != FOCUS_CONTENTS_VIEW &&
379 MoveTabFocus(key_event.IsShiftDown())) 422 MoveTabFocus(key_event.IsShiftDown()))
380 return true; 423 return true;
381 424
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 speech_button_->OnKeyReleased(key_event)) 458 speech_button_->OnKeyReleased(key_event))
416 return true; 459 return true;
417 460
418 return contents_view_ && contents_view_->visible() && 461 return contents_view_ && contents_view_->visible() &&
419 contents_view_->OnKeyReleased(key_event); 462 contents_view_->OnKeyReleased(key_event);
420 } 463 }
421 464
422 return false; 465 return false;
423 } 466 }
424 467
468 bool SearchBoxView::HandleMouseEvent(views::Textfield* sender,
469 const ui::MouseEvent& mouse_event) {
470 if (!is_fullscreen_app_list_enabled_)
471 return false;
472
473 if (search_box_->text().empty() && !is_search_box_active_)
474 SetSearchBoxActive(true);
475
476 return true;
477 }
478
479 bool SearchBoxView::HandleGestureEvent(views::Textfield* sender,
480 const ui::GestureEvent& gesture_event) {
481 if (!is_fullscreen_app_list_enabled_)
482 return false;
483
484 if (search_box_->text().empty() && !is_search_box_active_) {
485 SetSearchBoxActive(true);
486 return true;
487 } else {
488 return false;
489 }
490 }
491
425 void SearchBoxView::ButtonPressed(views::Button* sender, 492 void SearchBoxView::ButtonPressed(views::Button* sender,
426 const ui::Event& event) { 493 const ui::Event& event) {
427 if (back_button_ && sender == back_button_) 494 if (back_button_ && sender == back_button_)
428 delegate_->BackButtonPressed(); 495 delegate_->BackButtonPressed();
429 else if (speech_button_ && sender == speech_button_) 496 else if (speech_button_ && sender == speech_button_)
430 view_delegate_->StartSpeechRecognition(); 497 view_delegate_->StartSpeechRecognition();
431 else 498 else
432 NOTREACHED(); 499 NOTREACHED();
433 } 500 }
434 501
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 NotifyQueryChanged(); 556 NotifyQueryChanged();
490 } 557 }
491 558
492 void SearchBoxView::OnSpeechRecognitionStateChanged( 559 void SearchBoxView::OnSpeechRecognitionStateChanged(
493 SpeechRecognitionState new_state) { 560 SpeechRecognitionState new_state) {
494 SpeechRecognitionButtonPropChanged(); 561 SpeechRecognitionButtonPropChanged();
495 SchedulePaint(); 562 SchedulePaint();
496 } 563 }
497 564
498 } // namespace app_list 565 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/views/search_box_view.h ('k') | ui/app_list/views/search_box_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698