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" | 
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" | 
| 12 #include "ui/app_list/app_list_constants.h" | 12 #include "ui/app_list/app_list_constants.h" | 
| 13 #include "ui/app_list/app_list_features.h" | |
| 13 #include "ui/app_list/app_list_model.h" | 14 #include "ui/app_list/app_list_model.h" | 
| 14 #include "ui/app_list/app_list_switches.h" | 15 #include "ui/app_list/app_list_switches.h" | 
| 15 #include "ui/app_list/app_list_view_delegate.h" | 16 #include "ui/app_list/app_list_view_delegate.h" | 
| 16 #include "ui/app_list/resources/grit/app_list_resources.h" | 17 #include "ui/app_list/resources/grit/app_list_resources.h" | 
| 17 #include "ui/app_list/search_box_model.h" | 18 #include "ui/app_list/search_box_model.h" | 
| 18 #include "ui/app_list/speech_ui_model.h" | 19 #include "ui/app_list/speech_ui_model.h" | 
| 20 #include "ui/app_list/views/app_list_view.h" | |
| 19 #include "ui/app_list/views/contents_view.h" | 21 #include "ui/app_list/views/contents_view.h" | 
| 20 #include "ui/app_list/views/search_box_view_delegate.h" | 22 #include "ui/app_list/views/search_box_view_delegate.h" | 
| 21 #include "ui/base/ime/text_input_flags.h" | 23 #include "ui/base/ime/text_input_flags.h" | 
| 22 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" | 
| 23 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" | 
| 24 #include "ui/events/event.h" | 26 #include "ui/events/event.h" | 
| 25 #include "ui/gfx/canvas.h" | 27 #include "ui/gfx/canvas.h" | 
| 26 #include "ui/gfx/shadow_value.h" | 28 #include "ui/gfx/shadow_value.h" | 
| 27 #include "ui/strings/grit/ui_strings.h" | 29 #include "ui/strings/grit/ui_strings.h" | 
| 28 #include "ui/views/background.h" | 30 #include "ui/views/background.h" | 
| 29 #include "ui/views/border.h" | 31 #include "ui/views/border.h" | 
| 30 #include "ui/views/controls/button/image_button.h" | 32 #include "ui/views/controls/button/image_button.h" | 
| 31 #include "ui/views/controls/image_view.h" | 33 #include "ui/views/controls/image_view.h" | 
| 32 #include "ui/views/controls/textfield/textfield.h" | 34 #include "ui/views/controls/textfield/textfield.h" | 
| 33 #include "ui/views/layout/box_layout.h" | 35 #include "ui/views/layout/box_layout.h" | 
| 34 #include "ui/views/layout/fill_layout.h" | 36 #include "ui/views/layout/fill_layout.h" | 
| 35 #include "ui/views/shadow_border.h" | 37 #include "ui/views/shadow_border.h" | 
| 38 #include "ui/views/widget/widget.h" | |
| 36 | 39 | 
| 37 namespace app_list { | 40 namespace app_list { | 
| 38 | 41 | 
| 39 namespace { | 42 namespace { | 
| 40 | 43 | 
| 41 const int kPadding = 16; | 44 const int kPadding = 16; | 
| 42 const int kInnerPadding = 24; | 45 const int kInnerPadding = 24; | 
| 43 const int kPreferredWidth = 360; | 46 const int kPreferredWidth = 360; | 
| 47 const int kPreferredWidthFullscreen = 544; | |
| 44 const int kPreferredHeight = 48; | 48 const int kPreferredHeight = 48; | 
| 45 | 49 | 
| 46 const SkColor kHintTextColor = SkColorSetRGB(0xA0, 0xA0, 0xA0); | 50 const SkColor kHintTextColor = SkColorSetRGB(0xA0, 0xA0, 0xA0); | 
| 47 | 51 | 
| 48 const int kBackgroundBorderCornerRadius = 2; | 52 const int kBackgroundBorderCornerRadius = 2; | 
| 53 const int kBackgroundBorderCornerRadiusFullscreen = 20; | |
| 49 | 54 | 
| 50 // A background that paints a solid white rounded rect with a thin grey border. | 55 // A background that paints a solid white rounded rect with a thin grey border. | 
| 51 class SearchBoxBackground : public views::Background { | 56 class SearchBoxBackground : public views::Background { | 
| 52 public: | 57 public: | 
| 53 SearchBoxBackground() {} | 58 SearchBoxBackground() {} | 
| 54 ~SearchBoxBackground() override {} | 59 ~SearchBoxBackground() override {} | 
| 55 | 60 | 
| 56 private: | 61 private: | 
| 57 // views::Background overrides: | 62 // views::Background overrides: | 
| 58 void Paint(gfx::Canvas* canvas, views::View* view) const override { | 63 void Paint(gfx::Canvas* canvas, views::View* view) const override { | 
| 59 gfx::Rect bounds = view->GetContentsBounds(); | 64 gfx::Rect bounds = view->GetContentsBounds(); | 
| 60 | 65 | 
| 61 cc::PaintFlags flags; | 66 cc::PaintFlags flags; | 
| 62 flags.setAntiAlias(true); | 67 flags.setAntiAlias(true); | 
| 63 flags.setColor(kSearchBoxBackground); | 68 flags.setColor(kSearchBoxBackground); | 
| 64 canvas->DrawRoundRect(bounds, kBackgroundBorderCornerRadius, flags); | 69 canvas->DrawRoundRect(bounds, | 
| 70 features::IsFullscreenAppListEnabled() | |
| 
 
vadimt
2017/05/22 23:36:58
Is Paint() called frequently enough to start worry
 
newcomer
2017/05/25 23:10:53
Good question. I'm not sure but I'll ask around. I
 
vadimt
2017/05/26 01:27:56
And make sure that a SearchBoxBackground instance
 
newcomer
2017/05/26 23:20:20
They aren't. SearchBoxBackground is created when a
 
 | |
| 71 ? kBackgroundBorderCornerRadiusFullscreen | |
| 72 : kBackgroundBorderCornerRadius, | |
| 73 flags); | |
| 65 } | 74 } | 
| 66 | 75 | 
| 67 DISALLOW_COPY_AND_ASSIGN(SearchBoxBackground); | 76 DISALLOW_COPY_AND_ASSIGN(SearchBoxBackground); | 
| 68 }; | 77 }; | 
| 69 | 78 | 
| 70 } // namespace | 79 } // namespace | 
| 71 | 80 | 
| 72 // To paint grey background on mic and back buttons | 81 // To paint grey background on mic and back buttons | 
| 73 class SearchBoxImageButton : public views::ImageButton { | 82 class SearchBoxImageButton : public views::ImageButton { | 
| 74 public: | 83 public: | 
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 106 } | 115 } | 
| 107 | 116 | 
| 108 const char* GetClassName() const override { return "SearchBoxImageButton"; } | 117 const char* GetClassName() const override { return "SearchBoxImageButton"; } | 
| 109 | 118 | 
| 110 bool selected_; | 119 bool selected_; | 
| 111 | 120 | 
| 112 DISALLOW_COPY_AND_ASSIGN(SearchBoxImageButton); | 121 DISALLOW_COPY_AND_ASSIGN(SearchBoxImageButton); | 
| 113 }; | 122 }; | 
| 114 | 123 | 
| 115 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate, | 124 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate, | 
| 116 AppListViewDelegate* view_delegate) | 125 AppListViewDelegate* view_delegate ) | 
| 
 
vadimt
2017/05/22 23:36:58
git cl format . to remove added space
 
newcomer
2017/05/25 23:10:53
Done.
 
 | |
| 117 : delegate_(delegate), | 126 : delegate_(delegate), | 
| 118 view_delegate_(view_delegate), | 127 view_delegate_(view_delegate), | 
| 119 model_(NULL), | 128 model_(NULL), | 
| 120 content_container_(new views::View), | 129 content_container_(new views::View), | 
| 121 back_button_(NULL), | 130 back_button_(NULL), | 
| 122 speech_button_(NULL), | 131 speech_button_(NULL), | 
| 123 search_box_(new views::Textfield), | 132 search_box_(new views::Textfield), | 
| 124 contents_view_(NULL), | 133 contents_view_(NULL), | 
| 134 app_list_view_(), | |
| 
 
vadimt
2017/05/22 23:36:58
This leaves it uninitialized. Replace with '=nullp
 
newcomer
2017/05/25 23:10:53
The other pointers are set to NULL in the construc
 
vadimt
2017/05/26 01:27:56
Just old code. nullptr is a new way, and is my pre
 
newcomer
2017/05/26 23:20:20
It is now initialized as a constant pointer to the
 
 | |
| 125 focused_view_(FOCUS_SEARCH_BOX) { | 135 focused_view_(FOCUS_SEARCH_BOX) { | 
| 126 SetLayoutManager(new views::FillLayout); | 136 SetLayoutManager(new views::FillLayout); | 
| 127 AddChildView(content_container_); | 137 AddChildView(content_container_); | 
| 128 | 138 | 
| 129 SetShadow(GetShadowForZHeight(2)); | 139 SetShadow(GetShadowForZHeight(2)); | 
| 130 back_button_ = new SearchBoxImageButton(this); | 140 back_button_ = new SearchBoxImageButton(this); | 
| 131 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 141 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 
| 132 back_button_->SetImage(views::ImageButton::STATE_NORMAL, | 142 back_button_->SetImage(views::ImageButton::STATE_NORMAL, | 
| 133 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL)); | 143 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL)); | 
| 134 back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, | 144 back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, | 
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 | 191 | 
| 182 void SearchBoxView::ClearSearch() { | 192 void SearchBoxView::ClearSearch() { | 
| 183 search_box_->SetText(base::string16()); | 193 search_box_->SetText(base::string16()); | 
| 184 view_delegate_->AutoLaunchCanceled(); | 194 view_delegate_->AutoLaunchCanceled(); | 
| 185 // Updates model and fires query changed manually because SetText() above | 195 // Updates model and fires query changed manually because SetText() above | 
| 186 // does not generate ContentsChanged() notification. | 196 // does not generate ContentsChanged() notification. | 
| 187 UpdateModel(); | 197 UpdateModel(); | 
| 188 NotifyQueryChanged(); | 198 NotifyQueryChanged(); | 
| 189 } | 199 } | 
| 190 | 200 | 
| 201 void SearchBoxView::SetAppListView(AppListView* app_list_view) { | |
| 202 app_list_view_ = app_list_view; | |
| 203 } | |
| 204 | |
| 191 void SearchBoxView::SetShadow(const gfx::ShadowValue& shadow) { | 205 void SearchBoxView::SetShadow(const gfx::ShadowValue& shadow) { | 
| 192 SetBorder(base::MakeUnique<views::ShadowBorder>(shadow)); | 206 SetBorder(base::MakeUnique<views::ShadowBorder>(shadow)); | 
| 193 Layout(); | 207 Layout(); | 
| 194 } | 208 } | 
| 195 | 209 | 
| 196 gfx::Rect SearchBoxView::GetViewBoundsForSearchBoxContentsBounds( | 210 gfx::Rect SearchBoxView::GetViewBoundsForSearchBoxContentsBounds( | 
| 197 const gfx::Rect& rect) const { | 211 const gfx::Rect& rect) const { | 
| 198 gfx::Rect view_bounds = rect; | 212 gfx::Rect view_bounds = rect; | 
| 199 view_bounds.Inset(-GetInsets()); | 213 view_bounds.Inset(-GetInsets()); | 
| 200 return view_bounds; | 214 return view_bounds; | 
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 return; | 294 return; | 
| 281 | 295 | 
| 282 base::string16 back_button_label(l10n_util::GetStringUTF16( | 296 base::string16 back_button_label(l10n_util::GetStringUTF16( | 
| 283 folder ? IDS_APP_LIST_FOLDER_CLOSE_FOLDER_ACCESSIBILE_NAME | 297 folder ? IDS_APP_LIST_FOLDER_CLOSE_FOLDER_ACCESSIBILE_NAME | 
| 284 : IDS_APP_LIST_BACK)); | 298 : IDS_APP_LIST_BACK)); | 
| 285 back_button_->SetAccessibleName(back_button_label); | 299 back_button_->SetAccessibleName(back_button_label); | 
| 286 back_button_->SetTooltipText(back_button_label); | 300 back_button_->SetTooltipText(back_button_label); | 
| 287 } | 301 } | 
| 288 | 302 | 
| 289 gfx::Size SearchBoxView::GetPreferredSize() const { | 303 gfx::Size SearchBoxView::GetPreferredSize() const { | 
| 290 return gfx::Size(kPreferredWidth, kPreferredHeight); | 304 return gfx::Size(features::IsFullscreenAppListEnabled() | 
| 305 ? kPreferredWidthFullscreen | |
| 306 : kPreferredWidth, | |
| 307 kPreferredHeight); | |
| 291 } | 308 } | 
| 292 | 309 | 
| 293 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) { | 310 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) { | 
| 294 if (contents_view_) | 311 if (contents_view_) | 
| 295 return contents_view_->OnMouseWheel(event); | 312 return contents_view_->OnMouseWheel(event); | 
| 296 | 313 | 
| 297 return false; | 314 return false; | 
| 298 } | 315 } | 
| 299 | 316 | 
| 300 void SearchBoxView::OnEnabledChanged() { | 317 void SearchBoxView::OnEnabledChanged() { | 
| (...skipping 17 matching lines...) Expand all Loading... | |
| 318 void SearchBoxView::NotifyQueryChanged() { | 335 void SearchBoxView::NotifyQueryChanged() { | 
| 319 DCHECK(delegate_); | 336 DCHECK(delegate_); | 
| 320 delegate_->QueryChanged(this); | 337 delegate_->QueryChanged(this); | 
| 321 } | 338 } | 
| 322 | 339 | 
| 323 void SearchBoxView::ContentsChanged(views::Textfield* sender, | 340 void SearchBoxView::ContentsChanged(views::Textfield* sender, | 
| 324 const base::string16& new_contents) { | 341 const base::string16& new_contents) { | 
| 325 UpdateModel(); | 342 UpdateModel(); | 
| 326 view_delegate_->AutoLaunchCanceled(); | 343 view_delegate_->AutoLaunchCanceled(); | 
| 327 NotifyQueryChanged(); | 344 NotifyQueryChanged(); | 
| 345 | |
| 346 if (features::IsFullscreenAppListEnabled() && | |
| 347 !app_list_view_->IsFullscreen()) { | |
| 348 // If the app list is in the peeking state, switch it to fullscreen. | |
| 349 app_list_view_->ToFullscreen(); | |
| 350 } | |
| 328 } | 351 } | 
| 329 | 352 | 
| 330 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, | 353 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, | 
| 331 const ui::KeyEvent& key_event) { | 354 const ui::KeyEvent& key_event) { | 
| 332 if (key_event.type() == ui::ET_KEY_PRESSED) { | 355 if (key_event.type() == ui::ET_KEY_PRESSED) { | 
| 333 if (key_event.key_code() == ui::VKEY_TAB && | 356 if (key_event.key_code() == ui::VKEY_TAB && | 
| 334 focused_view_ != FOCUS_CONTENTS_VIEW && | 357 focused_view_ != FOCUS_CONTENTS_VIEW && | 
| 335 MoveTabFocus(key_event.IsShiftDown())) | 358 MoveTabFocus(key_event.IsShiftDown())) | 
| 336 return true; | 359 return true; | 
| 337 | 360 | 
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 433 NotifyQueryChanged(); | 456 NotifyQueryChanged(); | 
| 434 } | 457 } | 
| 435 | 458 | 
| 436 void SearchBoxView::OnSpeechRecognitionStateChanged( | 459 void SearchBoxView::OnSpeechRecognitionStateChanged( | 
| 437 SpeechRecognitionState new_state) { | 460 SpeechRecognitionState new_state) { | 
| 438 SpeechRecognitionButtonPropChanged(); | 461 SpeechRecognitionButtonPropChanged(); | 
| 439 SchedulePaint(); | 462 SchedulePaint(); | 
| 440 } | 463 } | 
| 441 | 464 | 
| 442 } // namespace app_list | 465 } // namespace app_list | 
| OLD | NEW |