Chromium Code Reviews| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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(false); | |
| 232 } | 239 } |
| 233 | 240 |
| 234 void SearchBoxView::SetShadow(const gfx::ShadowValue& shadow) { | 241 void SearchBoxView::SetShadow(const gfx::ShadowValue& shadow) { |
| 235 if (is_fullscreen_app_list_enabled_) | 242 if (is_fullscreen_app_list_enabled_) |
| 236 return; | 243 return; |
| 237 | 244 |
| 238 SetBorder(base::MakeUnique<views::ShadowBorder>(shadow)); | 245 SetBorder(base::MakeUnique<views::ShadowBorder>(shadow)); |
| 239 Layout(); | 246 Layout(); |
| 240 } | 247 } |
| 241 | 248 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 if (!back_button_) | 332 if (!back_button_) |
| 326 return; | 333 return; |
| 327 | 334 |
| 328 base::string16 back_button_label(l10n_util::GetStringUTF16( | 335 base::string16 back_button_label(l10n_util::GetStringUTF16( |
| 329 folder ? IDS_APP_LIST_FOLDER_CLOSE_FOLDER_ACCESSIBILE_NAME | 336 folder ? IDS_APP_LIST_FOLDER_CLOSE_FOLDER_ACCESSIBILE_NAME |
| 330 : IDS_APP_LIST_BACK)); | 337 : IDS_APP_LIST_BACK)); |
| 331 back_button_->SetAccessibleName(back_button_label); | 338 back_button_->SetAccessibleName(back_button_label); |
| 332 back_button_->SetTooltipText(back_button_label); | 339 back_button_->SetTooltipText(back_button_label); |
| 333 } | 340 } |
| 334 | 341 |
| 342 void SearchBoxView::SetSearchBoxActive(bool active) { | |
| 343 if (!is_fullscreen_app_list_enabled_) | |
| 344 return; | |
| 345 | |
| 346 if (active == is_search_box_active_) | |
| 347 return; | |
| 348 | |
| 349 is_search_box_active_ = active; | |
| 350 search_box_->set_placeholder_text_draw_flags( | |
| 351 active ? gfx::Canvas::TEXT_ALIGN_LEFT : gfx::Canvas::TEXT_ALIGN_CENTER); | |
| 352 search_box_->set_placeholder_text_color(active ? kZeroQuerySearchboxColor | |
| 353 : kDefaultSearchboxColor); | |
| 354 search_box_->SetCursorEnabled(active); | |
| 355 search_box_->SchedulePaint(); | |
| 356 } | |
| 357 | |
| 358 void SearchBoxView::HandleSearchBoxEvent(ui::LocatedEvent* located_event) { | |
| 359 if (!is_fullscreen_app_list_enabled_) | |
| 360 return; | |
| 361 | |
| 362 if (located_event->type != ui::ET_MOUSE_PRESSED && | |
| 363 located_event->type != ui::ET_GESTURE_TAP) | |
| 364 return; | |
| 365 | |
| 366 bool event_is_in_searchbox_bounds = | |
| 367 GetWidget()->GetWindowBoundsInScreen().Contains( | |
| 368 located_event->root_location()); | |
| 369 | |
| 370 if (!is_search_box_active_ && event_is_in_searchbox_bounds && | |
| 371 search_box_->text().empty()) { | |
| 372 // If the event was within the searchbox bounds and in an inactive empty | |
| 373 // search box, enable the search box. | |
| 374 SetSearchBoxActive(true); | |
| 375 located_event->SetHandled(); | |
| 376 } | |
| 377 } | |
| 378 | |
| 379 bool SearchBoxView::OnTextfieldEvent() { | |
| 380 if (!is_fullscreen_app_list_enabled_) | |
| 381 return false; | |
| 382 | |
| 383 if (is_search_box_active_) | |
| 384 return false; | |
| 385 | |
| 386 SetSearchBoxActive(true); | |
| 387 return true; | |
| 388 } | |
| 389 | |
| 335 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) { | 390 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) { |
| 336 if (contents_view_) | 391 if (contents_view_) |
| 337 return contents_view_->OnMouseWheel(event); | 392 return contents_view_->OnMouseWheel(event); |
| 338 | 393 |
| 339 return false; | 394 return false; |
| 340 } | 395 } |
| 341 | 396 |
| 342 void SearchBoxView::OnEnabledChanged() { | 397 void SearchBoxView::OnEnabledChanged() { |
| 343 search_box_->SetEnabled(enabled()); | 398 search_box_->SetEnabled(enabled()); |
| 344 if (speech_button_) | 399 if (speech_button_) |
| 345 speech_button_->SetEnabled(enabled()); | 400 speech_button_->SetEnabled(enabled()); |
| 346 } | 401 } |
| 347 | 402 |
| 348 const char* SearchBoxView::GetClassName() const { | 403 const char* SearchBoxView::GetClassName() const { |
| 349 return "SearchBoxView"; | 404 return "SearchBoxView"; |
| 350 } | 405 } |
| 351 | 406 |
| 407 void SearchBoxView::OnGestureEvent(ui::GestureEvent* event) { | |
| 408 HandleSearchBoxEvent(event); | |
| 409 } | |
| 410 | |
| 411 void SearchBoxView::OnMouseEvent(ui::MouseEvent* event) { | |
| 412 HandleSearchBoxEvent(event); | |
| 413 } | |
| 414 | |
| 352 void SearchBoxView::UpdateModel() { | 415 void SearchBoxView::UpdateModel() { |
| 353 // Temporarily remove from observer to ignore notifications caused by us. | 416 // Temporarily remove from observer to ignore notifications caused by us. |
| 354 model_->search_box()->RemoveObserver(this); | 417 model_->search_box()->RemoveObserver(this); |
| 355 model_->search_box()->Update(search_box_->text(), false); | 418 model_->search_box()->Update(search_box_->text(), false); |
| 356 model_->search_box()->SetSelectionModel(search_box_->GetSelectionModel()); | 419 model_->search_box()->SetSelectionModel(search_box_->GetSelectionModel()); |
| 357 model_->search_box()->AddObserver(this); | 420 model_->search_box()->AddObserver(this); |
| 358 } | 421 } |
| 359 | 422 |
| 360 void SearchBoxView::NotifyQueryChanged() { | 423 void SearchBoxView::NotifyQueryChanged() { |
| 361 DCHECK(delegate_); | 424 DCHECK(delegate_); |
| 362 delegate_->QueryChanged(this); | 425 delegate_->QueryChanged(this); |
| 363 } | 426 } |
| 364 | 427 |
| 365 void SearchBoxView::ContentsChanged(views::Textfield* sender, | 428 void SearchBoxView::ContentsChanged(views::Textfield* sender, |
| 366 const base::string16& new_contents) { | 429 const base::string16& new_contents) { |
| 367 UpdateModel(); | 430 UpdateModel(); |
| 368 view_delegate_->AutoLaunchCanceled(); | 431 view_delegate_->AutoLaunchCanceled(); |
| 369 NotifyQueryChanged(); | 432 NotifyQueryChanged(); |
| 370 if (is_fullscreen_app_list_enabled_) | 433 if (is_fullscreen_app_list_enabled_) { |
| 434 if (is_search_box_active_ == search_box_->text().empty()) | |
| 435 SetSearchBoxActive(!search_box_->text().empty()); | |
| 371 app_list_view_->SetStateFromSearchBoxView(search_box_->text().empty()); | 436 app_list_view_->SetStateFromSearchBoxView(search_box_->text().empty()); |
| 437 } | |
| 372 } | 438 } |
| 373 | 439 |
| 374 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, | 440 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, |
| 375 const ui::KeyEvent& key_event) { | 441 const ui::KeyEvent& key_event) { |
| 376 if (key_event.type() == ui::ET_KEY_PRESSED) { | 442 if (key_event.type() == ui::ET_KEY_PRESSED) { |
| 377 if (key_event.key_code() == ui::VKEY_TAB && | 443 if (key_event.key_code() == ui::VKEY_TAB && |
| 378 focused_view_ != FOCUS_CONTENTS_VIEW && | 444 focused_view_ != FOCUS_CONTENTS_VIEW && |
| 379 MoveTabFocus(key_event.IsShiftDown())) | 445 MoveTabFocus(key_event.IsShiftDown())) |
| 380 return true; | 446 return true; |
| 381 | 447 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 415 speech_button_->OnKeyReleased(key_event)) | 481 speech_button_->OnKeyReleased(key_event)) |
| 416 return true; | 482 return true; |
| 417 | 483 |
| 418 return contents_view_ && contents_view_->visible() && | 484 return contents_view_ && contents_view_->visible() && |
| 419 contents_view_->OnKeyReleased(key_event); | 485 contents_view_->OnKeyReleased(key_event); |
| 420 } | 486 } |
| 421 | 487 |
| 422 return false; | 488 return false; |
| 423 } | 489 } |
| 424 | 490 |
| 491 bool SearchBoxView::HandleMouseEvent(views::Textfield* sender, | |
| 492 const ui::MouseEvent& mouse_event) { | |
| 493 if (!is_fullscreen_app_list_enabled_) | |
| 494 return false; | |
|
oshima
2017/07/05 19:11:59
OnTextfieldEvent checks this, so you don't need th
newcomer
2017/07/05 22:03:57
Done.
| |
| 495 | |
| 496 return OnTextfieldEvent(); | |
| 497 } | |
| 498 | |
| 499 bool SearchBoxView::HandleGestureEvent(views::Textfield* sender, | |
| 500 const ui::GestureEvent& gesture_event) { | |
| 501 if (!is_fullscreen_app_list_enabled_) | |
|
oshima
2017/07/05 19:11:59
ditto
newcomer
2017/07/05 22:03:57
Done.
| |
| 502 return false; | |
| 503 | |
| 504 return OnTextfieldEvent(); | |
| 505 } | |
| 506 | |
| 425 void SearchBoxView::ButtonPressed(views::Button* sender, | 507 void SearchBoxView::ButtonPressed(views::Button* sender, |
| 426 const ui::Event& event) { | 508 const ui::Event& event) { |
| 427 if (back_button_ && sender == back_button_) | 509 if (back_button_ && sender == back_button_) |
| 428 delegate_->BackButtonPressed(); | 510 delegate_->BackButtonPressed(); |
| 429 else if (speech_button_ && sender == speech_button_) | 511 else if (speech_button_ && sender == speech_button_) |
| 430 view_delegate_->StartSpeechRecognition(); | 512 view_delegate_->StartSpeechRecognition(); |
| 431 else | 513 else |
| 432 NOTREACHED(); | 514 NOTREACHED(); |
| 433 } | 515 } |
| 434 | 516 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 NotifyQueryChanged(); | 571 NotifyQueryChanged(); |
| 490 } | 572 } |
| 491 | 573 |
| 492 void SearchBoxView::OnSpeechRecognitionStateChanged( | 574 void SearchBoxView::OnSpeechRecognitionStateChanged( |
| 493 SpeechRecognitionState new_state) { | 575 SpeechRecognitionState new_state) { |
| 494 SpeechRecognitionButtonPropChanged(); | 576 SpeechRecognitionButtonPropChanged(); |
| 495 SchedulePaint(); | 577 SchedulePaint(); |
| 496 } | 578 } |
| 497 | 579 |
| 498 } // namespace app_list | 580 } // namespace app_list |
| OLD | NEW |