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() { | 
| 59 is_fullscreen_enabled_ = features::IsFullscreenAppListEnabled(); | |
| 60 } | |
| 54 ~SearchBoxBackground() override {} | 61 ~SearchBoxBackground() override {} | 
| 55 | 62 | 
| 56 private: | 63 private: | 
| 57 // views::Background overrides: | 64 // views::Background overrides: | 
| 58 void Paint(gfx::Canvas* canvas, views::View* view) const override { | 65 void Paint(gfx::Canvas* canvas, views::View* view) const override { | 
| 59 gfx::Rect bounds = view->GetContentsBounds(); | 66 gfx::Rect bounds = view->GetContentsBounds(); | 
| 60 | 67 | 
| 61 cc::PaintFlags flags; | 68 cc::PaintFlags flags; | 
| 62 flags.setAntiAlias(true); | 69 flags.setAntiAlias(true); | 
| 63 flags.setColor(kSearchBoxBackground); | 70 flags.setColor(kSearchBoxBackground); | 
| 64 canvas->DrawRoundRect(bounds, kBackgroundBorderCornerRadius, flags); | 71 canvas->DrawRoundRect(bounds, | 
| 72 is_fullscreen_enabled_ | |
| 73 ? kBackgroundBorderCornerRadiusFullscreen | |
| 74 : kBackgroundBorderCornerRadius, | |
| 75 flags); | |
| 65 } | 76 } | 
| 77 bool is_fullscreen_enabled_; | |
| 
 
vadimt
2017/05/26 01:27:57
const
 
newcomer
2017/05/26 17:11:28
Done.
 
 | |
| 66 | 78 | 
| 67 DISALLOW_COPY_AND_ASSIGN(SearchBoxBackground); | 79 DISALLOW_COPY_AND_ASSIGN(SearchBoxBackground); | 
| 68 }; | 80 }; | 
| 69 | 81 | 
| 70 } // namespace | 82 } // namespace | 
| 71 | 83 | 
| 72 // To paint grey background on mic and back buttons | 84 // To paint grey background on mic and back buttons | 
| 73 class SearchBoxImageButton : public views::ImageButton { | 85 class SearchBoxImageButton : public views::ImageButton { | 
| 74 public: | 86 public: | 
| 75 explicit SearchBoxImageButton(views::ButtonListener* listener) | 87 explicit SearchBoxImageButton(views::ButtonListener* listener) | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate, | 127 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate, | 
| 116 AppListViewDelegate* view_delegate) | 128 AppListViewDelegate* view_delegate) | 
| 117 : delegate_(delegate), | 129 : delegate_(delegate), | 
| 118 view_delegate_(view_delegate), | 130 view_delegate_(view_delegate), | 
| 119 model_(NULL), | 131 model_(NULL), | 
| 120 content_container_(new views::View), | 132 content_container_(new views::View), | 
| 121 back_button_(NULL), | 133 back_button_(NULL), | 
| 122 speech_button_(NULL), | 134 speech_button_(NULL), | 
| 123 search_box_(new views::Textfield), | 135 search_box_(new views::Textfield), | 
| 124 contents_view_(NULL), | 136 contents_view_(NULL), | 
| 137 app_list_view_(NULL), | |
| 125 focused_view_(FOCUS_SEARCH_BOX) { | 138 focused_view_(FOCUS_SEARCH_BOX) { | 
| 126 SetLayoutManager(new views::FillLayout); | 139 SetLayoutManager(new views::FillLayout); | 
| 127 AddChildView(content_container_); | 140 AddChildView(content_container_); | 
| 128 | 141 | 
| 129 SetShadow(GetShadowForZHeight(2)); | 142 SetShadow(GetShadowForZHeight(2)); | 
| 130 back_button_ = new SearchBoxImageButton(this); | 143 back_button_ = new SearchBoxImageButton(this); | 
| 131 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 144 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 
| 132 back_button_->SetImage(views::ImageButton::STATE_NORMAL, | 145 back_button_->SetImage(views::ImageButton::STATE_NORMAL, | 
| 133 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL)); | 146 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL)); | 
| 134 back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, | 147 back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, | 
| (...skipping 15 matching lines...) Expand all Loading... | |
| 150 search_box_->SetBackgroundColor(kSearchBoxBackground); | 163 search_box_->SetBackgroundColor(kSearchBoxBackground); | 
| 151 search_box_->set_placeholder_text_color(kHintTextColor); | 164 search_box_->set_placeholder_text_color(kHintTextColor); | 
| 152 search_box_->set_controller(this); | 165 search_box_->set_controller(this); | 
| 153 search_box_->SetTextInputType(ui::TEXT_INPUT_TYPE_SEARCH); | 166 search_box_->SetTextInputType(ui::TEXT_INPUT_TYPE_SEARCH); | 
| 154 search_box_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF); | 167 search_box_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF); | 
| 155 content_container_->AddChildView(search_box_); | 168 content_container_->AddChildView(search_box_); | 
| 156 layout->SetFlexForView(search_box_, 1); | 169 layout->SetFlexForView(search_box_, 1); | 
| 157 | 170 | 
| 158 view_delegate_->GetSpeechUI()->AddObserver(this); | 171 view_delegate_->GetSpeechUI()->AddObserver(this); | 
| 159 ModelChanged(); | 172 ModelChanged(); | 
| 173 is_fullscreen_enabled_ = features::IsFullscreenAppListEnabled(); | |
| 
 
vadimt
2017/05/26 01:27:57
Does it compile? I don't see a declaration of is_f
 
newcomer
2017/05/26 17:11:28
Declared in header, line 127.
 
vadimt
2017/05/26 17:58:55
const then
 
newcomer
2017/05/26 23:20:21
Done.
 
 | |
| 160 } | 174 } | 
| 161 | 175 | 
| 162 SearchBoxView::~SearchBoxView() { | 176 SearchBoxView::~SearchBoxView() { | 
| 163 view_delegate_->GetSpeechUI()->RemoveObserver(this); | 177 view_delegate_->GetSpeechUI()->RemoveObserver(this); | 
| 164 model_->search_box()->RemoveObserver(this); | 178 model_->search_box()->RemoveObserver(this); | 
| 165 } | 179 } | 
| 166 | 180 | 
| 167 void SearchBoxView::ModelChanged() { | 181 void SearchBoxView::ModelChanged() { | 
| 168 if (model_) | 182 if (model_) | 
| 169 model_->search_box()->RemoveObserver(this); | 183 model_->search_box()->RemoveObserver(this); | 
| (...skipping 11 matching lines...) Expand all Loading... | |
| 181 | 195 | 
| 182 void SearchBoxView::ClearSearch() { | 196 void SearchBoxView::ClearSearch() { | 
| 183 search_box_->SetText(base::string16()); | 197 search_box_->SetText(base::string16()); | 
| 184 view_delegate_->AutoLaunchCanceled(); | 198 view_delegate_->AutoLaunchCanceled(); | 
| 185 // Updates model and fires query changed manually because SetText() above | 199 // Updates model and fires query changed manually because SetText() above | 
| 186 // does not generate ContentsChanged() notification. | 200 // does not generate ContentsChanged() notification. | 
| 187 UpdateModel(); | 201 UpdateModel(); | 
| 188 NotifyQueryChanged(); | 202 NotifyQueryChanged(); | 
| 189 } | 203 } | 
| 190 | 204 | 
| 205 void SearchBoxView::SetAppListView(AppListView* app_list_view) { | |
| 206 app_list_view_ = app_list_view; | |
| 207 } | |
| 208 | |
| 191 void SearchBoxView::SetShadow(const gfx::ShadowValue& shadow) { | 209 void SearchBoxView::SetShadow(const gfx::ShadowValue& shadow) { | 
| 192 SetBorder(base::MakeUnique<views::ShadowBorder>(shadow)); | 210 SetBorder(base::MakeUnique<views::ShadowBorder>(shadow)); | 
| 193 Layout(); | 211 Layout(); | 
| 194 } | 212 } | 
| 195 | 213 | 
| 196 gfx::Rect SearchBoxView::GetViewBoundsForSearchBoxContentsBounds( | 214 gfx::Rect SearchBoxView::GetViewBoundsForSearchBoxContentsBounds( | 
| 197 const gfx::Rect& rect) const { | 215 const gfx::Rect& rect) const { | 
| 198 gfx::Rect view_bounds = rect; | 216 gfx::Rect view_bounds = rect; | 
| 199 view_bounds.Inset(-GetInsets()); | 217 view_bounds.Inset(-GetInsets()); | 
| 200 return view_bounds; | 218 return view_bounds; | 
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 return; | 298 return; | 
| 281 | 299 | 
| 282 base::string16 back_button_label(l10n_util::GetStringUTF16( | 300 base::string16 back_button_label(l10n_util::GetStringUTF16( | 
| 283 folder ? IDS_APP_LIST_FOLDER_CLOSE_FOLDER_ACCESSIBILE_NAME | 301 folder ? IDS_APP_LIST_FOLDER_CLOSE_FOLDER_ACCESSIBILE_NAME | 
| 284 : IDS_APP_LIST_BACK)); | 302 : IDS_APP_LIST_BACK)); | 
| 285 back_button_->SetAccessibleName(back_button_label); | 303 back_button_->SetAccessibleName(back_button_label); | 
| 286 back_button_->SetTooltipText(back_button_label); | 304 back_button_->SetTooltipText(back_button_label); | 
| 287 } | 305 } | 
| 288 | 306 | 
| 289 gfx::Size SearchBoxView::GetPreferredSize() const { | 307 gfx::Size SearchBoxView::GetPreferredSize() const { | 
| 290 return gfx::Size(kPreferredWidth, kPreferredHeight); | 308 return gfx::Size( | 
| 309 is_fullscreen_enabled_ ? kPreferredWidthFullscreen : kPreferredWidth, | |
| 310 kPreferredHeight); | |
| 291 } | 311 } | 
| 292 | 312 | 
| 293 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) { | 313 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) { | 
| 294 if (contents_view_) | 314 if (contents_view_) | 
| 295 return contents_view_->OnMouseWheel(event); | 315 return contents_view_->OnMouseWheel(event); | 
| 296 | 316 | 
| 297 return false; | 317 return false; | 
| 298 } | 318 } | 
| 299 | 319 | 
| 300 void SearchBoxView::OnEnabledChanged() { | 320 void SearchBoxView::OnEnabledChanged() { | 
| (...skipping 17 matching lines...) Expand all Loading... | |
| 318 void SearchBoxView::NotifyQueryChanged() { | 338 void SearchBoxView::NotifyQueryChanged() { | 
| 319 DCHECK(delegate_); | 339 DCHECK(delegate_); | 
| 320 delegate_->QueryChanged(this); | 340 delegate_->QueryChanged(this); | 
| 321 } | 341 } | 
| 322 | 342 | 
| 323 void SearchBoxView::ContentsChanged(views::Textfield* sender, | 343 void SearchBoxView::ContentsChanged(views::Textfield* sender, | 
| 324 const base::string16& new_contents) { | 344 const base::string16& new_contents) { | 
| 325 UpdateModel(); | 345 UpdateModel(); | 
| 326 view_delegate_->AutoLaunchCanceled(); | 346 view_delegate_->AutoLaunchCanceled(); | 
| 327 NotifyQueryChanged(); | 347 NotifyQueryChanged(); | 
| 348 | |
| 349 if (is_fullscreen_enabled_ && !app_list_view_->IsFullscreen()) { | |
| 350 // If the app list is in the peeking state, switch it to fullscreen. | |
| 351 app_list_view_->ToFullscreen(); | |
| 352 } | |
| 328 } | 353 } | 
| 329 | 354 | 
| 330 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, | 355 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, | 
| 331 const ui::KeyEvent& key_event) { | 356 const ui::KeyEvent& key_event) { | 
| 332 if (key_event.type() == ui::ET_KEY_PRESSED) { | 357 if (key_event.type() == ui::ET_KEY_PRESSED) { | 
| 333 if (key_event.key_code() == ui::VKEY_TAB && | 358 if (key_event.key_code() == ui::VKEY_TAB && | 
| 334 focused_view_ != FOCUS_CONTENTS_VIEW && | 359 focused_view_ != FOCUS_CONTENTS_VIEW && | 
| 335 MoveTabFocus(key_event.IsShiftDown())) | 360 MoveTabFocus(key_event.IsShiftDown())) | 
| 336 return true; | 361 return true; | 
| 337 | 362 | 
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 433 NotifyQueryChanged(); | 458 NotifyQueryChanged(); | 
| 434 } | 459 } | 
| 435 | 460 | 
| 436 void SearchBoxView::OnSpeechRecognitionStateChanged( | 461 void SearchBoxView::OnSpeechRecognitionStateChanged( | 
| 437 SpeechRecognitionState new_state) { | 462 SpeechRecognitionState new_state) { | 
| 438 SpeechRecognitionButtonPropChanged(); | 463 SpeechRecognitionButtonPropChanged(); | 
| 439 SchedulePaint(); | 464 SchedulePaint(); | 
| 440 } | 465 } | 
| 441 | 466 | 
| 442 } // namespace app_list | 467 } // namespace app_list | 
| OLD | NEW |