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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 const int kInnerPadding = 24; | 46 const int kInnerPadding = 24; |
| 47 const int kPreferredWidth = 360; | 47 const int kPreferredWidth = 360; |
| 48 const int kPreferredWidthFullscreen = 544; | 48 const int kPreferredWidthFullscreen = 544; |
| 49 const int kPreferredHeight = 48; | 49 const int kPreferredHeight = 48; |
| 50 | 50 |
| 51 const SkColor kHintTextColor = SkColorSetRGB(0xA0, 0xA0, 0xA0); | 51 const SkColor kHintTextColor = SkColorSetRGB(0xA0, 0xA0, 0xA0); |
| 52 | 52 |
| 53 const int kBackgroundBorderCornerRadius = 2; | 53 const int kBackgroundBorderCornerRadius = 2; |
| 54 const int kBackgroundBorderCornerRadiusFullscreen = 20; | 54 const int kBackgroundBorderCornerRadiusFullscreen = 20; |
| 55 | 55 |
| 56 // Sets the switch that is used to check if the fullscreen app list feature is | |
| 57 // enabled. | |
| 56 bool IsFullscreenAppListEnabled() { | 58 bool IsFullscreenAppListEnabled() { |
|
xiyuan
2017/06/12 22:33:15
We probably can get rid of this.
newcomer
2017/06/12 23:48:17
Done.
| |
| 57 // Cache this value to avoid repeated lookup. | 59 // Cache this value to avoid repeated lookup. |
|
xiyuan
2017/06/12 22:33:15
nit: Wrong comment if we keep the function.
newcomer
2017/06/12 23:48:17
Done.
| |
| 58 static bool cached_value = features::IsFullscreenAppListEnabled(); | 60 return features::IsFullscreenAppListEnabled(); |
| 59 return cached_value; | |
| 60 } | 61 } |
| 61 | 62 |
| 62 // A background that paints a solid white rounded rect with a thin grey border. | 63 // A background that paints a solid white rounded rect with a thin grey border. |
| 63 class SearchBoxBackground : public views::Background { | 64 class SearchBoxBackground : public views::Background { |
| 64 public: | 65 public: |
| 65 SearchBoxBackground() | 66 SearchBoxBackground() |
| 66 : background_border_corner_radius_( | 67 : background_border_corner_radius_( |
| 67 IsFullscreenAppListEnabled() | 68 IsFullscreenAppListEnabled() |
| 68 ? kBackgroundBorderCornerRadiusFullscreen | 69 ? kBackgroundBorderCornerRadiusFullscreen |
| 69 : kBackgroundBorderCornerRadius) {} | 70 : kBackgroundBorderCornerRadius) {} |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 136 : delegate_(delegate), | 137 : delegate_(delegate), |
| 137 view_delegate_(view_delegate), | 138 view_delegate_(view_delegate), |
| 138 model_(NULL), | 139 model_(NULL), |
| 139 content_container_(new views::View), | 140 content_container_(new views::View), |
| 140 back_button_(NULL), | 141 back_button_(NULL), |
| 141 speech_button_(NULL), | 142 speech_button_(NULL), |
| 142 search_box_(new views::Textfield), | 143 search_box_(new views::Textfield), |
| 143 contents_view_(NULL), | 144 contents_view_(NULL), |
| 144 app_list_view_(app_list_view), | 145 app_list_view_(app_list_view), |
| 145 focused_view_(FOCUS_SEARCH_BOX) { | 146 focused_view_(FOCUS_SEARCH_BOX) { |
| 147 is_fullscreen_app_list_enabled_ = IsFullscreenAppListEnabled(); | |
|
xiyuan
2017/06/12 22:33:15
nit: make |is_fullscreen_app_list_enabled_| a cons
newcomer
2017/06/12 23:48:17
Done.
| |
| 146 SetLayoutManager(new views::FillLayout); | 148 SetLayoutManager(new views::FillLayout); |
| 147 SetPreferredSize(gfx::Size(IsFullscreenAppListEnabled() | 149 SetPreferredSize(gfx::Size(is_fullscreen_app_list_enabled_ |
| 148 ? kPreferredWidthFullscreen | 150 ? kPreferredWidthFullscreen |
| 149 : kPreferredWidth, | 151 : kPreferredWidth, |
| 150 kPreferredHeight)); | 152 kPreferredHeight)); |
| 151 AddChildView(content_container_); | 153 AddChildView(content_container_); |
| 152 | 154 |
| 153 SetShadow(GetShadowForZHeight(2)); | 155 SetShadow(GetShadowForZHeight(2)); |
| 154 back_button_ = new SearchBoxImageButton(this); | 156 back_button_ = new SearchBoxImageButton(this); |
| 155 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 157 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 156 back_button_->SetImage(views::ImageButton::STATE_NORMAL, | 158 back_button_->SetImage(views::ImageButton::STATE_NORMAL, |
| 157 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL)); | 159 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL)); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 DCHECK(delegate_); | 341 DCHECK(delegate_); |
| 340 delegate_->QueryChanged(this); | 342 delegate_->QueryChanged(this); |
| 341 } | 343 } |
| 342 | 344 |
| 343 void SearchBoxView::ContentsChanged(views::Textfield* sender, | 345 void SearchBoxView::ContentsChanged(views::Textfield* sender, |
| 344 const base::string16& new_contents) { | 346 const base::string16& new_contents) { |
| 345 UpdateModel(); | 347 UpdateModel(); |
| 346 view_delegate_->AutoLaunchCanceled(); | 348 view_delegate_->AutoLaunchCanceled(); |
| 347 NotifyQueryChanged(); | 349 NotifyQueryChanged(); |
| 348 | 350 |
| 349 if (IsFullscreenAppListEnabled() && !app_list_view_->is_fullscreen()) { | 351 if (is_fullscreen_app_list_enabled_ && !app_list_view_->is_fullscreen()) { |
| 350 // If the app list is in the peeking state, switch it to fullscreen. | 352 // If the app list is in the peeking state, switch it to fullscreen. |
| 351 app_list_view_->SetState(AppListView::FULLSCREEN); | 353 app_list_view_->SetState(AppListView::FULLSCREEN); |
| 352 } | 354 } |
| 353 } | 355 } |
| 354 | 356 |
| 355 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, | 357 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, |
| 356 const ui::KeyEvent& key_event) { | 358 const ui::KeyEvent& key_event) { |
| 357 if (key_event.type() == ui::ET_KEY_PRESSED) { | 359 if (key_event.type() == ui::ET_KEY_PRESSED) { |
| 358 if (key_event.key_code() == ui::VKEY_TAB && | 360 if (key_event.key_code() == ui::VKEY_TAB && |
| 359 focused_view_ != FOCUS_CONTENTS_VIEW && | 361 focused_view_ != FOCUS_CONTENTS_VIEW && |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 458 NotifyQueryChanged(); | 460 NotifyQueryChanged(); |
| 459 } | 461 } |
| 460 | 462 |
| 461 void SearchBoxView::OnSpeechRecognitionStateChanged( | 463 void SearchBoxView::OnSpeechRecognitionStateChanged( |
| 462 SpeechRecognitionState new_state) { | 464 SpeechRecognitionState new_state) { |
| 463 SpeechRecognitionButtonPropChanged(); | 465 SpeechRecognitionButtonPropChanged(); |
| 464 SchedulePaint(); | 466 SchedulePaint(); |
| 465 } | 467 } |
| 466 | 468 |
| 467 } // namespace app_list | 469 } // namespace app_list |
| OLD | NEW |