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 used for placeholder text in zero query state. | |
|
vadimt
2017/06/22 22:47:40
Color of placeholder ...
newcomer
2017/06/23 23:59:36
Done.
| |
| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 view_delegate_(view_delegate), | 144 view_delegate_(view_delegate), |
| 141 model_(nullptr), | 145 model_(nullptr), |
| 142 content_container_(new views::View), | 146 content_container_(new views::View), |
| 143 google_icon_(nullptr), | 147 google_icon_(nullptr), |
| 144 back_button_(nullptr), | 148 back_button_(nullptr), |
| 145 speech_button_(nullptr), | 149 speech_button_(nullptr), |
| 146 search_box_(new views::Textfield), | 150 search_box_(new views::Textfield), |
| 147 contents_view_(nullptr), | 151 contents_view_(nullptr), |
| 148 app_list_view_(app_list_view), | 152 app_list_view_(app_list_view), |
| 149 focused_view_(FOCUS_SEARCH_BOX), | 153 focused_view_(FOCUS_SEARCH_BOX), |
| 150 is_fullscreen_app_list_enabled_(features::IsFullscreenAppListEnabled()) { | 154 is_fullscreen_app_list_enabled_(features::IsFullscreenAppListEnabled()), |
| 155 is_cursor_enabled_(false) { | |
|
vadimt
2017/06/22 22:47:40
= false in .h
newcomer
2017/06/23 23:59:37
Done.
| |
| 151 SetLayoutManager(new views::FillLayout); | 156 SetLayoutManager(new views::FillLayout); |
| 152 SetPreferredSize(gfx::Size(is_fullscreen_app_list_enabled_ | 157 SetPreferredSize(gfx::Size(is_fullscreen_app_list_enabled_ |
| 153 ? kPreferredWidthFullscreen | 158 ? kPreferredWidthFullscreen |
| 154 : kPreferredWidth, | 159 : kPreferredWidth, |
| 155 kPreferredHeight)); | 160 kPreferredHeight)); |
| 156 AddChildView(content_container_); | 161 AddChildView(content_container_); |
| 157 | 162 |
| 158 SetShadow(GetShadowForZHeight(2)); | 163 SetShadow(GetShadowForZHeight(2)); |
| 159 content_container_->SetBackground(base::MakeUnique<SearchBoxBackground>()); | 164 content_container_->SetBackground(base::MakeUnique<SearchBoxBackground>()); |
| 160 | 165 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 175 if (is_fullscreen_app_list_enabled_) { | 180 if (is_fullscreen_app_list_enabled_) { |
| 176 google_icon_ = new views::ImageView(); | 181 google_icon_ = new views::ImageView(); |
| 177 google_icon_->SetImage(gfx::CreateVectorIcon( | 182 google_icon_->SetImage(gfx::CreateVectorIcon( |
| 178 kIcGoogleBlackIcon, kGoogleIconSize, kDefaultSearchboxColor)); | 183 kIcGoogleBlackIcon, kGoogleIconSize, kDefaultSearchboxColor)); |
| 179 content_container_->AddChildView(google_icon_); | 184 content_container_->AddChildView(google_icon_); |
| 180 | 185 |
| 181 search_box_->set_placeholder_text_color(kDefaultSearchboxColor); | 186 search_box_->set_placeholder_text_color(kDefaultSearchboxColor); |
| 182 search_box_->set_placeholder_text_draw_flags( | 187 search_box_->set_placeholder_text_draw_flags( |
| 183 gfx::Canvas::TEXT_ALIGN_CENTER); | 188 gfx::Canvas::TEXT_ALIGN_CENTER); |
| 184 search_box_->SetFontList(search_box_->GetFontList().DeriveWithSizeDelta(2)); | 189 search_box_->SetFontList(search_box_->GetFontList().DeriveWithSizeDelta(2)); |
| 190 search_box_->SetCursorEnabled(is_cursor_enabled_); | |
| 185 } else { | 191 } else { |
| 186 back_button_ = new SearchBoxImageButton(this); | 192 back_button_ = new SearchBoxImageButton(this); |
| 187 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 193 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 188 back_button_->SetImage( | 194 back_button_->SetImage( |
| 189 views::ImageButton::STATE_NORMAL, | 195 views::ImageButton::STATE_NORMAL, |
| 190 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL)); | 196 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL)); |
| 191 back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, | 197 back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, |
| 192 views::ImageButton::ALIGN_MIDDLE); | 198 views::ImageButton::ALIGN_MIDDLE); |
| 193 SetBackButtonLabel(false); | 199 SetBackButtonLabel(false); |
| 194 content_container_->AddChildView(back_button_); | 200 content_container_->AddChildView(back_button_); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 222 return !search_box_->text().empty(); | 228 return !search_box_->text().empty(); |
| 223 } | 229 } |
| 224 | 230 |
| 225 void SearchBoxView::ClearSearch() { | 231 void SearchBoxView::ClearSearch() { |
| 226 search_box_->SetText(base::string16()); | 232 search_box_->SetText(base::string16()); |
| 227 view_delegate_->AutoLaunchCanceled(); | 233 view_delegate_->AutoLaunchCanceled(); |
| 228 // Updates model and fires query changed manually because SetText() above | 234 // Updates model and fires query changed manually because SetText() above |
| 229 // does not generate ContentsChanged() notification. | 235 // does not generate ContentsChanged() notification. |
| 230 UpdateModel(); | 236 UpdateModel(); |
| 231 NotifyQueryChanged(); | 237 NotifyQueryChanged(); |
| 238 if (is_fullscreen_app_list_enabled_) { | |
| 239 SetPlaceholderTextAndEnableCursor(!search_box_->text().empty()); | |
| 240 if (app_list_view_) | |
|
vadimt
2017/06/22 22:47:40
Is there a way for unit test to make app_list_view
newcomer
2017/06/23 23:59:36
One solution is to create a class that is a Search
| |
| 241 app_list_view_->SetStateFromSearchBoxView(search_box_->text().empty()); | |
| 242 } | |
| 232 } | 243 } |
| 233 | 244 |
| 234 void SearchBoxView::SetShadow(const gfx::ShadowValue& shadow) { | 245 void SearchBoxView::SetShadow(const gfx::ShadowValue& shadow) { |
| 235 if (is_fullscreen_app_list_enabled_) | 246 if (is_fullscreen_app_list_enabled_) |
| 236 return; | 247 return; |
| 237 | 248 |
| 238 SetBorder(base::MakeUnique<views::ShadowBorder>(shadow)); | 249 SetBorder(base::MakeUnique<views::ShadowBorder>(shadow)); |
| 239 Layout(); | 250 Layout(); |
| 240 } | 251 } |
| 241 | 252 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 325 if (!back_button_) | 336 if (!back_button_) |
| 326 return; | 337 return; |
| 327 | 338 |
| 328 base::string16 back_button_label(l10n_util::GetStringUTF16( | 339 base::string16 back_button_label(l10n_util::GetStringUTF16( |
| 329 folder ? IDS_APP_LIST_FOLDER_CLOSE_FOLDER_ACCESSIBILE_NAME | 340 folder ? IDS_APP_LIST_FOLDER_CLOSE_FOLDER_ACCESSIBILE_NAME |
| 330 : IDS_APP_LIST_BACK)); | 341 : IDS_APP_LIST_BACK)); |
| 331 back_button_->SetAccessibleName(back_button_label); | 342 back_button_->SetAccessibleName(back_button_label); |
| 332 back_button_->SetTooltipText(back_button_label); | 343 back_button_->SetTooltipText(back_button_label); |
| 333 } | 344 } |
| 334 | 345 |
| 346 void SearchBoxView::SetPlaceholderTextAndEnableCursor(bool enable) { | |
|
vadimt
2017/06/22 22:47:40
The name is misleading, as you don't set (change)
newcomer
2017/06/23 23:59:37
Renamed to SetSearchBoxActive(bool active)
| |
| 347 search_box_->set_placeholder_text_draw_flags( | |
| 348 enable ? gfx::Canvas::TEXT_ALIGN_LEFT : gfx::Canvas::TEXT_ALIGN_CENTER); | |
| 349 search_box_->set_placeholder_text_color(enable ? kZeroQuerySearchboxColor | |
| 350 : kDefaultSearchboxColor); | |
| 351 is_cursor_enabled_ = enable; | |
| 352 search_box_->SetCursorEnabled(enable); | |
| 353 search_box_->SchedulePaint(); | |
| 354 } | |
| 355 | |
| 356 bool SearchBoxView::PassMouseEventForTesting(ui::MouseEvent& mouse_event) { | |
| 357 return HandleMouseEvent(search_box_, mouse_event); | |
| 358 } | |
| 359 | |
| 335 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) { | 360 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) { |
| 336 if (contents_view_) | 361 if (contents_view_) |
| 337 return contents_view_->OnMouseWheel(event); | 362 return contents_view_->OnMouseWheel(event); |
| 338 | 363 |
| 339 return false; | 364 return false; |
| 340 } | 365 } |
| 341 | 366 |
| 342 void SearchBoxView::OnEnabledChanged() { | 367 void SearchBoxView::OnEnabledChanged() { |
| 343 search_box_->SetEnabled(enabled()); | 368 search_box_->SetEnabled(enabled()); |
| 344 if (speech_button_) | 369 if (speech_button_) |
| 345 speech_button_->SetEnabled(enabled()); | 370 speech_button_->SetEnabled(enabled()); |
| 346 } | 371 } |
| 347 | 372 |
| 348 const char* SearchBoxView::GetClassName() const { | 373 const char* SearchBoxView::GetClassName() const { |
| 349 return "SearchBoxView"; | 374 return "SearchBoxView"; |
| 350 } | 375 } |
| 351 | 376 |
| 377 void SearchBoxView::OnGestureEvent(ui::GestureEvent* event) { | |
| 378 if (!is_fullscreen_app_list_enabled_ || event->type() != ui::ET_GESTURE_TAP) | |
| 379 return; | |
| 380 | |
| 381 // If the search box is empty and the cursor is not enabled, enable the cursor | |
| 382 // and shift the placeholder text left. | |
| 383 if (search_box_->text().empty() && !is_cursor_enabled_) | |
| 384 SetPlaceholderTextAndEnableCursor(true); | |
| 385 } | |
| 386 | |
| 387 void SearchBoxView::OnMouseEvent(ui::MouseEvent* event) { | |
| 388 if (!is_fullscreen_app_list_enabled_ || event->type() != ui::ET_MOUSE_PRESSED) | |
| 389 return; | |
| 390 | |
| 391 // If the search box is empty and the cursor is not enabled, enable the cursor | |
| 392 // and shift the placeholder text left. | |
| 393 if (search_box_->text().empty() && !is_cursor_enabled_) | |
| 394 SetPlaceholderTextAndEnableCursor(true); | |
|
vadimt
2017/06/22 22:47:40
Please make a note: what to do when Meta+Arrow acc
newcomer
2017/06/23 23:59:36
Created a bug for this.
| |
| 395 } | |
| 396 | |
| 352 void SearchBoxView::UpdateModel() { | 397 void SearchBoxView::UpdateModel() { |
| 353 // Temporarily remove from observer to ignore notifications caused by us. | 398 // Temporarily remove from observer to ignore notifications caused by us. |
| 354 model_->search_box()->RemoveObserver(this); | 399 model_->search_box()->RemoveObserver(this); |
| 355 model_->search_box()->Update(search_box_->text(), false); | 400 model_->search_box()->Update(search_box_->text(), false); |
| 356 model_->search_box()->SetSelectionModel(search_box_->GetSelectionModel()); | 401 model_->search_box()->SetSelectionModel(search_box_->GetSelectionModel()); |
| 357 model_->search_box()->AddObserver(this); | 402 model_->search_box()->AddObserver(this); |
| 358 } | 403 } |
| 359 | 404 |
| 360 void SearchBoxView::NotifyQueryChanged() { | 405 void SearchBoxView::NotifyQueryChanged() { |
| 361 DCHECK(delegate_); | 406 DCHECK(delegate_); |
| 362 delegate_->QueryChanged(this); | 407 delegate_->QueryChanged(this); |
| 363 } | 408 } |
| 364 | 409 |
| 365 void SearchBoxView::ContentsChanged(views::Textfield* sender, | 410 void SearchBoxView::ContentsChanged(views::Textfield* sender, |
| 366 const base::string16& new_contents) { | 411 const base::string16& new_contents) { |
| 367 UpdateModel(); | 412 UpdateModel(); |
| 368 view_delegate_->AutoLaunchCanceled(); | 413 view_delegate_->AutoLaunchCanceled(); |
| 369 NotifyQueryChanged(); | 414 NotifyQueryChanged(); |
| 370 if (is_fullscreen_app_list_enabled_) | 415 if (is_fullscreen_app_list_enabled_) { |
| 371 app_list_view_->SetStateFromSearchBoxView(search_box_->text().empty()); | 416 SetPlaceholderTextAndEnableCursor(!search_box_->text().empty()); |
| 417 if (app_list_view_) | |
| 418 app_list_view_->SetStateFromSearchBoxView(search_box_->text().empty()); | |
| 419 } | |
| 372 } | 420 } |
| 373 | 421 |
| 374 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, | 422 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, |
| 375 const ui::KeyEvent& key_event) { | 423 const ui::KeyEvent& key_event) { |
| 376 if (key_event.type() == ui::ET_KEY_PRESSED) { | 424 if (key_event.type() == ui::ET_KEY_PRESSED) { |
| 377 if (key_event.key_code() == ui::VKEY_TAB && | 425 if (key_event.key_code() == ui::VKEY_TAB && |
| 378 focused_view_ != FOCUS_CONTENTS_VIEW && | 426 focused_view_ != FOCUS_CONTENTS_VIEW && |
| 379 MoveTabFocus(key_event.IsShiftDown())) | 427 MoveTabFocus(key_event.IsShiftDown())) |
| 380 return true; | 428 return true; |
| 381 | 429 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 415 speech_button_->OnKeyReleased(key_event)) | 463 speech_button_->OnKeyReleased(key_event)) |
| 416 return true; | 464 return true; |
| 417 | 465 |
| 418 return contents_view_ && contents_view_->visible() && | 466 return contents_view_ && contents_view_->visible() && |
| 419 contents_view_->OnKeyReleased(key_event); | 467 contents_view_->OnKeyReleased(key_event); |
| 420 } | 468 } |
| 421 | 469 |
| 422 return false; | 470 return false; |
| 423 } | 471 } |
| 424 | 472 |
| 473 bool SearchBoxView::HandleMouseEvent(views::Textfield* sender, | |
| 474 const ui::MouseEvent& mouse_event) { | |
| 475 if (!is_fullscreen_app_list_enabled_) | |
| 476 return false; | |
| 477 | |
| 478 if (search_box_->text().empty() && !is_cursor_enabled_) | |
| 479 SetPlaceholderTextAndEnableCursor(true); | |
| 480 | |
| 481 return true; | |
| 482 } | |
| 483 | |
| 484 void SearchBoxView::NotifyOnGestureEvent() { | |
|
vadimt
2017/06/22 22:47:40
Do we need both this and SearchBoxView::OnGestureE
newcomer
2017/06/23 23:59:37
refactored to HandleGestureEvent like the other fu
| |
| 485 if (!is_fullscreen_app_list_enabled_) | |
| 486 return; | |
| 487 | |
| 488 if (search_box_->text().empty() && !is_cursor_enabled_) | |
| 489 SetPlaceholderTextAndEnableCursor(true); | |
| 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 Loading... | |
| 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 |
| OLD | NEW |