OLD | NEW |
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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 search_box_->set_placeholder_text_color(active ? kZeroQuerySearchboxColor | 374 search_box_->set_placeholder_text_color(active ? kZeroQuerySearchboxColor |
375 : kDefaultSearchboxColor); | 375 : kDefaultSearchboxColor); |
376 search_box_->SetCursorEnabled(active); | 376 search_box_->SetCursorEnabled(active); |
377 search_box_->SchedulePaint(); | 377 search_box_->SchedulePaint(); |
378 } | 378 } |
379 | 379 |
380 void SearchBoxView::HandleSearchBoxEvent(ui::LocatedEvent* located_event) { | 380 void SearchBoxView::HandleSearchBoxEvent(ui::LocatedEvent* located_event) { |
381 if (!is_fullscreen_app_list_enabled_) | 381 if (!is_fullscreen_app_list_enabled_) |
382 return; | 382 return; |
383 | 383 |
384 if (located_event->type() != ui::ET_MOUSE_PRESSED && | 384 if (located_event->type() == ui::ET_MOUSEWHEEL) { |
385 located_event->type() != ui::ET_GESTURE_TAP) | 385 if (!app_list_view_->HandleScroll(located_event)) |
386 return; | 386 return; |
387 | 387 |
388 bool event_is_in_searchbox_bounds = | 388 } else if (located_event->type() == ui::ET_MOUSE_PRESSED || |
389 GetWidget()->GetWindowBoundsInScreen().Contains( | 389 located_event->type() == ui::ET_GESTURE_TAP) { |
390 located_event->root_location()); | 390 bool event_is_in_searchbox_bounds = |
391 | 391 GetWidget()->GetWindowBoundsInScreen().Contains( |
392 if (!is_search_box_active_ && event_is_in_searchbox_bounds && | 392 located_event->root_location()); |
393 search_box_->text().empty()) { | 393 if (is_search_box_active_ || !event_is_in_searchbox_bounds || |
| 394 !search_box_->text().empty()) |
| 395 return; |
394 // If the event was within the searchbox bounds and in an inactive empty | 396 // If the event was within the searchbox bounds and in an inactive empty |
395 // search box, enable the search box. | 397 // search box, enable the search box. |
396 SetSearchBoxActive(true); | 398 SetSearchBoxActive(true); |
397 located_event->SetHandled(); | |
398 } | 399 } |
| 400 located_event->SetHandled(); |
399 } | 401 } |
400 | 402 |
401 bool SearchBoxView::OnTextfieldEvent() { | 403 bool SearchBoxView::OnTextfieldEvent() { |
402 if (!is_fullscreen_app_list_enabled_) | 404 if (!is_fullscreen_app_list_enabled_) |
403 return false; | 405 return false; |
404 | 406 |
405 if (is_search_box_active_) | 407 if (is_search_box_active_) |
406 return false; | 408 return false; |
407 | 409 |
408 SetSearchBoxActive(true); | 410 SetSearchBoxActive(true); |
409 return true; | 411 return true; |
410 } | 412 } |
411 | 413 |
412 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) { | 414 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) { |
413 if (contents_view_) | 415 if (contents_view_) |
414 return contents_view_->OnMouseWheel(event); | 416 return contents_view_->OnMouseWheel(event); |
415 | |
416 return false; | 417 return false; |
417 } | 418 } |
418 | 419 |
419 void SearchBoxView::OnEnabledChanged() { | 420 void SearchBoxView::OnEnabledChanged() { |
420 search_box_->SetEnabled(enabled()); | 421 search_box_->SetEnabled(enabled()); |
421 if (speech_button_) | 422 if (speech_button_) |
422 speech_button_->SetEnabled(enabled()); | 423 speech_button_->SetEnabled(enabled()); |
423 } | 424 } |
424 | 425 |
425 const char* SearchBoxView::GetClassName() const { | 426 const char* SearchBoxView::GetClassName() const { |
426 return "SearchBoxView"; | 427 return "SearchBoxView"; |
427 } | 428 } |
428 | 429 |
429 void SearchBoxView::OnGestureEvent(ui::GestureEvent* event) { | 430 void SearchBoxView::OnGestureEvent(ui::GestureEvent* event) { |
| 431 if (!is_fullscreen_app_list_enabled_) |
| 432 return; |
| 433 |
430 HandleSearchBoxEvent(event); | 434 HandleSearchBoxEvent(event); |
431 } | 435 } |
432 | 436 |
433 void SearchBoxView::OnMouseEvent(ui::MouseEvent* event) { | 437 void SearchBoxView::OnMouseEvent(ui::MouseEvent* event) { |
434 HandleSearchBoxEvent(event); | 438 HandleSearchBoxEvent(event); |
435 } | 439 } |
436 | 440 |
437 void SearchBoxView::UpdateModel() { | 441 void SearchBoxView::UpdateModel() { |
438 // Temporarily remove from observer to ignore notifications caused by us. | 442 // Temporarily remove from observer to ignore notifications caused by us. |
439 model_->search_box()->RemoveObserver(this); | 443 model_->search_box()->RemoveObserver(this); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 | 509 |
506 return contents_view_ && contents_view_->visible() && | 510 return contents_view_ && contents_view_->visible() && |
507 contents_view_->OnKeyReleased(key_event); | 511 contents_view_->OnKeyReleased(key_event); |
508 } | 512 } |
509 | 513 |
510 return false; | 514 return false; |
511 } | 515 } |
512 | 516 |
513 bool SearchBoxView::HandleMouseEvent(views::Textfield* sender, | 517 bool SearchBoxView::HandleMouseEvent(views::Textfield* sender, |
514 const ui::MouseEvent& mouse_event) { | 518 const ui::MouseEvent& mouse_event) { |
515 return OnTextfieldEvent(); | 519 if (!is_fullscreen_app_list_enabled_) |
| 520 return false; |
| 521 |
| 522 if (mouse_event.type() == ui::ET_MOUSEWHEEL) { |
| 523 return app_list_view_->HandleScroll(&mouse_event); |
| 524 } else { |
| 525 return OnTextfieldEvent(); |
| 526 } |
516 } | 527 } |
517 | 528 |
518 bool SearchBoxView::HandleGestureEvent(views::Textfield* sender, | 529 bool SearchBoxView::HandleGestureEvent(views::Textfield* sender, |
519 const ui::GestureEvent& gesture_event) { | 530 const ui::GestureEvent& gesture_event) { |
520 return OnTextfieldEvent(); | 531 return OnTextfieldEvent(); |
521 } | 532 } |
522 | 533 |
523 void SearchBoxView::ButtonPressed(views::Button* sender, | 534 void SearchBoxView::ButtonPressed(views::Button* sender, |
524 const ui::Event& event) { | 535 const ui::Event& event) { |
525 if (back_button_ && sender == back_button_) | 536 if (back_button_ && sender == back_button_) |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 SchedulePaint(); | 638 SchedulePaint(); |
628 } | 639 } |
629 | 640 |
630 void SearchBoxView::OnSpeechRecognitionStateChanged( | 641 void SearchBoxView::OnSpeechRecognitionStateChanged( |
631 SpeechRecognitionState new_state) { | 642 SpeechRecognitionState new_state) { |
632 SpeechRecognitionButtonPropChanged(); | 643 SpeechRecognitionButtonPropChanged(); |
633 SchedulePaint(); | 644 SchedulePaint(); |
634 } | 645 } |
635 | 646 |
636 } // namespace app_list | 647 } // namespace app_list |
OLD | NEW |