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

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: rebased. 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_result_page_view.h » ('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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 constexpr int kGoogleIconSize = 24; 61 constexpr int kGoogleIconSize = 24;
62 constexpr int kMicIconSize = 24; 62 constexpr int kMicIconSize = 24;
63 63
64 // Default color used when wallpaper customized color is not available for 64 // Default color used when wallpaper customized color is not available for
65 // searchbox, #000 at 87% opacity. 65 // searchbox, #000 at 87% opacity.
66 constexpr SkColor kDefaultSearchboxColor = 66 constexpr SkColor kDefaultSearchboxColor =
67 SkColorSetARGBMacro(0xDE, 0x00, 0x00, 0x00); 67 SkColorSetARGBMacro(0xDE, 0x00, 0x00, 0x00);
68 68
69 constexpr int kLightVibrantBlendAlpha = 0xB3; 69 constexpr int kLightVibrantBlendAlpha = 0xB3;
70 70
71 // Color of placeholder text in zero query state.
72 constexpr SkColor kZeroQuerySearchboxColor =
73 SkColorSetARGBMacro(0x8A, 0x00, 0x00, 0x00);
74
71 // A background that paints a solid white rounded rect with a thin grey border. 75 // A background that paints a solid white rounded rect with a thin grey border.
72 class SearchBoxBackground : public views::Background { 76 class SearchBoxBackground : public views::Background {
73 public: 77 public:
74 explicit SearchBoxBackground(SkColor color) 78 explicit SearchBoxBackground(SkColor color)
75 : background_border_corner_radius_( 79 : background_border_corner_radius_(
76 features::IsFullscreenAppListEnabled() 80 features::IsFullscreenAppListEnabled()
77 ? kBackgroundBorderCornerRadiusFullscreen 81 ? kBackgroundBorderCornerRadiusFullscreen
78 : kBackgroundBorderCornerRadius), 82 : kBackgroundBorderCornerRadius),
79 color_(color) {} 83 color_(color) {}
80 ~SearchBoxBackground() override {} 84 ~SearchBoxBackground() override {}
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 google_icon_ = new views::ImageView(); 198 google_icon_ = new views::ImageView();
195 google_icon_->SetImage(gfx::CreateVectorIcon( 199 google_icon_->SetImage(gfx::CreateVectorIcon(
196 kIcGoogleBlackIcon, kGoogleIconSize, kDefaultSearchboxColor)); 200 kIcGoogleBlackIcon, kGoogleIconSize, kDefaultSearchboxColor));
197 content_container_->AddChildView(google_icon_); 201 content_container_->AddChildView(google_icon_);
198 202
199 search_box_->set_placeholder_text_color(kDefaultSearchboxColor); 203 search_box_->set_placeholder_text_color(kDefaultSearchboxColor);
200 search_box_->set_placeholder_text_draw_flags( 204 search_box_->set_placeholder_text_draw_flags(
201 gfx::Canvas::TEXT_ALIGN_CENTER); 205 gfx::Canvas::TEXT_ALIGN_CENTER);
202 search_box_->SetFontList(search_box_->GetFontList().DeriveWithSizeDelta(2)); 206 search_box_->SetFontList(search_box_->GetFontList().DeriveWithSizeDelta(2));
203 back_button_->SetVisible(false); 207 back_button_->SetVisible(false);
208 search_box_->SetCursorEnabled(is_search_box_active_);
204 } else { 209 } else {
205 search_box_->set_placeholder_text_color(kHintTextColor); 210 search_box_->set_placeholder_text_color(kHintTextColor);
206 } 211 }
207 content_container_->AddChildView(search_box_); 212 content_container_->AddChildView(search_box_);
208 layout->SetFlexForView(search_box_, 1); 213 layout->SetFlexForView(search_box_, 1);
209 214
210 view_delegate_->GetSpeechUI()->AddObserver(this); 215 view_delegate_->GetSpeechUI()->AddObserver(this);
211 ModelChanged(); 216 ModelChanged();
212 } 217 }
213 218
(...skipping 18 matching lines...) Expand all
232 return !search_box_->text().empty(); 237 return !search_box_->text().empty();
233 } 238 }
234 239
235 void SearchBoxView::ClearSearch() { 240 void SearchBoxView::ClearSearch() {
236 search_box_->SetText(base::string16()); 241 search_box_->SetText(base::string16());
237 view_delegate_->AutoLaunchCanceled(); 242 view_delegate_->AutoLaunchCanceled();
238 // Updates model and fires query changed manually because SetText() above 243 // Updates model and fires query changed manually because SetText() above
239 // does not generate ContentsChanged() notification. 244 // does not generate ContentsChanged() notification.
240 UpdateModel(); 245 UpdateModel();
241 NotifyQueryChanged(); 246 NotifyQueryChanged();
247 if (is_fullscreen_app_list_enabled_)
248 SetSearchBoxActive(false);
242 } 249 }
243 250
244 void SearchBoxView::SetShadow(const gfx::ShadowValue& shadow) { 251 void SearchBoxView::SetShadow(const gfx::ShadowValue& shadow) {
245 if (is_fullscreen_app_list_enabled_) 252 if (is_fullscreen_app_list_enabled_)
246 return; 253 return;
247 254
248 SetBorder(base::MakeUnique<views::ShadowBorder>(shadow)); 255 SetBorder(base::MakeUnique<views::ShadowBorder>(shadow));
249 Layout(); 256 Layout();
250 } 257 }
251 258
(...skipping 17 matching lines...) Expand all
269 if (speech_button_) 276 if (speech_button_)
270 speech_button_->SetSelected(false); 277 speech_button_->SetSelected(false);
271 278
272 switch (focused_view_) { 279 switch (focused_view_) {
273 case FOCUS_BACK_BUTTON: 280 case FOCUS_BACK_BUTTON:
274 focused_view_ = move_backwards ? FOCUS_BACK_BUTTON : FOCUS_SEARCH_BOX; 281 focused_view_ = move_backwards ? FOCUS_BACK_BUTTON : FOCUS_SEARCH_BOX;
275 break; 282 break;
276 case FOCUS_SEARCH_BOX: 283 case FOCUS_SEARCH_BOX:
277 if (move_backwards) { 284 if (move_backwards) {
278 focused_view_ = back_button_ && back_button_->visible() 285 focused_view_ = back_button_ && back_button_->visible()
279 ? FOCUS_BACK_BUTTON : FOCUS_SEARCH_BOX; 286 ? FOCUS_BACK_BUTTON
287 : FOCUS_SEARCH_BOX;
280 } else { 288 } else {
281 focused_view_ = speech_button_ && speech_button_->visible() 289 focused_view_ = speech_button_ && speech_button_->visible()
282 ? FOCUS_MIC_BUTTON : FOCUS_CONTENTS_VIEW; 290 ? FOCUS_MIC_BUTTON
291 : FOCUS_CONTENTS_VIEW;
283 } 292 }
284 break; 293 break;
285 case FOCUS_MIC_BUTTON: 294 case FOCUS_MIC_BUTTON:
286 focused_view_ = move_backwards ? FOCUS_SEARCH_BOX : FOCUS_CONTENTS_VIEW; 295 focused_view_ = move_backwards ? FOCUS_SEARCH_BOX : FOCUS_CONTENTS_VIEW;
287 break; 296 break;
288 case FOCUS_CONTENTS_VIEW: 297 case FOCUS_CONTENTS_VIEW:
289 focused_view_ = move_backwards 298 focused_view_ =
290 ? (speech_button_ && speech_button_->visible() ? 299 move_backwards
291 FOCUS_MIC_BUTTON : FOCUS_SEARCH_BOX) 300 ? (speech_button_ && speech_button_->visible() ? FOCUS_MIC_BUTTON
292 : FOCUS_CONTENTS_VIEW; 301 : FOCUS_SEARCH_BOX)
302 : FOCUS_CONTENTS_VIEW;
293 break; 303 break;
294 default: 304 default:
295 DCHECK(false); 305 DCHECK(false);
296 } 306 }
297 307
298 switch (focused_view_) { 308 switch (focused_view_) {
299 case FOCUS_BACK_BUTTON: 309 case FOCUS_BACK_BUTTON:
300 if (back_button_) 310 if (back_button_)
301 back_button_->SetSelected(true); 311 back_button_->SetSelected(true);
302 break; 312 break;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 354
345 void SearchBoxView::ShowBackOrGoogleIcon(bool show_back_button) { 355 void SearchBoxView::ShowBackOrGoogleIcon(bool show_back_button) {
346 if (!is_fullscreen_app_list_enabled_) 356 if (!is_fullscreen_app_list_enabled_)
347 return; 357 return;
348 358
349 google_icon_->SetVisible(!show_back_button); 359 google_icon_->SetVisible(!show_back_button);
350 back_button_->SetVisible(show_back_button); 360 back_button_->SetVisible(show_back_button);
351 content_container_->Layout(); 361 content_container_->Layout();
352 } 362 }
353 363
364 void SearchBoxView::SetSearchBoxActive(bool active) {
365 if (!is_fullscreen_app_list_enabled_)
366 return;
367
368 if (active == is_search_box_active_)
369 return;
370
371 is_search_box_active_ = active;
372 search_box_->set_placeholder_text_draw_flags(
373 active ? gfx::Canvas::TEXT_ALIGN_LEFT : gfx::Canvas::TEXT_ALIGN_CENTER);
374 search_box_->set_placeholder_text_color(active ? kZeroQuerySearchboxColor
375 : kDefaultSearchboxColor);
376 search_box_->SetCursorEnabled(active);
377 search_box_->SchedulePaint();
378 }
379
380 void SearchBoxView::HandleSearchBoxEvent(ui::LocatedEvent* located_event) {
381 if (!is_fullscreen_app_list_enabled_)
382 return;
383
384 if (located_event->type() != ui::ET_MOUSE_PRESSED &&
385 located_event->type() != ui::ET_GESTURE_TAP)
386 return;
387
388 bool event_is_in_searchbox_bounds =
389 GetWidget()->GetWindowBoundsInScreen().Contains(
390 located_event->root_location());
391
392 if (!is_search_box_active_ && event_is_in_searchbox_bounds &&
393 search_box_->text().empty()) {
394 // If the event was within the searchbox bounds and in an inactive empty
395 // search box, enable the search box.
396 SetSearchBoxActive(true);
397 located_event->SetHandled();
398 }
399 }
400
401 bool SearchBoxView::OnTextfieldEvent() {
402 if (!is_fullscreen_app_list_enabled_)
403 return false;
404
405 if (is_search_box_active_)
406 return false;
407
408 SetSearchBoxActive(true);
409 return true;
410 }
411
354 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) { 412 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) {
355 if (contents_view_) 413 if (contents_view_)
356 return contents_view_->OnMouseWheel(event); 414 return contents_view_->OnMouseWheel(event);
357 415
358 return false; 416 return false;
359 } 417 }
360 418
361 void SearchBoxView::OnEnabledChanged() { 419 void SearchBoxView::OnEnabledChanged() {
362 search_box_->SetEnabled(enabled()); 420 search_box_->SetEnabled(enabled());
363 if (speech_button_) 421 if (speech_button_)
364 speech_button_->SetEnabled(enabled()); 422 speech_button_->SetEnabled(enabled());
365 } 423 }
366 424
367 const char* SearchBoxView::GetClassName() const { 425 const char* SearchBoxView::GetClassName() const {
368 return "SearchBoxView"; 426 return "SearchBoxView";
369 } 427 }
370 428
429 void SearchBoxView::OnGestureEvent(ui::GestureEvent* event) {
430 HandleSearchBoxEvent(event);
431 }
432
433 void SearchBoxView::OnMouseEvent(ui::MouseEvent* event) {
434 HandleSearchBoxEvent(event);
435 }
436
371 void SearchBoxView::UpdateModel() { 437 void SearchBoxView::UpdateModel() {
372 // Temporarily remove from observer to ignore notifications caused by us. 438 // Temporarily remove from observer to ignore notifications caused by us.
373 model_->search_box()->RemoveObserver(this); 439 model_->search_box()->RemoveObserver(this);
374 model_->search_box()->Update(search_box_->text(), false); 440 model_->search_box()->Update(search_box_->text(), false);
375 model_->search_box()->SetSelectionModel(search_box_->GetSelectionModel()); 441 model_->search_box()->SetSelectionModel(search_box_->GetSelectionModel());
376 model_->search_box()->AddObserver(this); 442 model_->search_box()->AddObserver(this);
377 } 443 }
378 444
379 void SearchBoxView::NotifyQueryChanged() { 445 void SearchBoxView::NotifyQueryChanged() {
380 DCHECK(delegate_); 446 DCHECK(delegate_);
381 delegate_->QueryChanged(this); 447 delegate_->QueryChanged(this);
382 } 448 }
383 449
384 void SearchBoxView::ContentsChanged(views::Textfield* sender, 450 void SearchBoxView::ContentsChanged(views::Textfield* sender,
385 const base::string16& new_contents) { 451 const base::string16& new_contents) {
386 UpdateModel(); 452 UpdateModel();
387 view_delegate_->AutoLaunchCanceled(); 453 view_delegate_->AutoLaunchCanceled();
388 NotifyQueryChanged(); 454 NotifyQueryChanged();
389 if (is_fullscreen_app_list_enabled_) 455 if (is_fullscreen_app_list_enabled_) {
456 if (is_search_box_active_ == search_box_->text().empty())
457 SetSearchBoxActive(!search_box_->text().empty());
390 app_list_view_->SetStateFromSearchBoxView(search_box_->text().empty()); 458 app_list_view_->SetStateFromSearchBoxView(search_box_->text().empty());
459 }
391 } 460 }
392 461
393 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, 462 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender,
394 const ui::KeyEvent& key_event) { 463 const ui::KeyEvent& key_event) {
395 if (key_event.type() == ui::ET_KEY_PRESSED) { 464 if (key_event.type() == ui::ET_KEY_PRESSED) {
396 if (key_event.key_code() == ui::VKEY_TAB && 465 if (key_event.key_code() == ui::VKEY_TAB &&
397 focused_view_ != FOCUS_CONTENTS_VIEW && 466 focused_view_ != FOCUS_CONTENTS_VIEW &&
398 MoveTabFocus(key_event.IsShiftDown())) 467 MoveTabFocus(key_event.IsShiftDown()))
399 return true; 468 return true;
400 469
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 speech_button_->OnKeyReleased(key_event)) 503 speech_button_->OnKeyReleased(key_event))
435 return true; 504 return true;
436 505
437 return contents_view_ && contents_view_->visible() && 506 return contents_view_ && contents_view_->visible() &&
438 contents_view_->OnKeyReleased(key_event); 507 contents_view_->OnKeyReleased(key_event);
439 } 508 }
440 509
441 return false; 510 return false;
442 } 511 }
443 512
513 bool SearchBoxView::HandleMouseEvent(views::Textfield* sender,
514 const ui::MouseEvent& mouse_event) {
515 return OnTextfieldEvent();
516 }
517
518 bool SearchBoxView::HandleGestureEvent(views::Textfield* sender,
519 const ui::GestureEvent& gesture_event) {
520 return OnTextfieldEvent();
521 }
522
444 void SearchBoxView::ButtonPressed(views::Button* sender, 523 void SearchBoxView::ButtonPressed(views::Button* sender,
445 const ui::Event& event) { 524 const ui::Event& event) {
446 if (back_button_ && sender == back_button_) 525 if (back_button_ && sender == back_button_)
447 delegate_->BackButtonPressed(); 526 delegate_->BackButtonPressed();
448 else if (speech_button_ && sender == speech_button_) 527 else if (speech_button_ && sender == speech_button_)
449 view_delegate_->StartSpeechRecognition(); 528 view_delegate_->StartSpeechRecognition();
450 else 529 else
451 NOTREACHED(); 530 NOTREACHED();
452 } 531 }
453 532
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 SchedulePaint(); 627 SchedulePaint();
549 } 628 }
550 629
551 void SearchBoxView::OnSpeechRecognitionStateChanged( 630 void SearchBoxView::OnSpeechRecognitionStateChanged(
552 SpeechRecognitionState new_state) { 631 SpeechRecognitionState new_state) {
553 SpeechRecognitionButtonPropChanged(); 632 SpeechRecognitionButtonPropChanged();
554 SchedulePaint(); 633 SchedulePaint();
555 } 634 }
556 635
557 } // namespace app_list 636 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/views/search_box_view.h ('k') | ui/app_list/views/search_result_page_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698