| 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 bool IsFullscreenAppListEnabled() { | |
| 57 // Cache this value to avoid repeated lookup. | |
| 58 static bool cached_value = features::IsFullscreenAppListEnabled(); | |
| 59 return cached_value; | |
| 60 } | |
| 61 | |
| 62 // A background that paints a solid white rounded rect with a thin grey border. | 56 // A background that paints a solid white rounded rect with a thin grey border. |
| 63 class SearchBoxBackground : public views::Background { | 57 class SearchBoxBackground : public views::Background { |
| 64 public: | 58 public: |
| 65 SearchBoxBackground() | 59 SearchBoxBackground() |
| 66 : background_border_corner_radius_( | 60 : background_border_corner_radius_( |
| 67 IsFullscreenAppListEnabled() | 61 features::IsFullscreenAppListEnabled() |
| 68 ? kBackgroundBorderCornerRadiusFullscreen | 62 ? kBackgroundBorderCornerRadiusFullscreen |
| 69 : kBackgroundBorderCornerRadius) {} | 63 : kBackgroundBorderCornerRadius) {} |
| 70 ~SearchBoxBackground() override {} | 64 ~SearchBoxBackground() override {} |
| 71 | 65 |
| 72 private: | 66 private: |
| 73 // views::Background overrides: | 67 // views::Background overrides: |
| 74 void Paint(gfx::Canvas* canvas, views::View* view) const override { | 68 void Paint(gfx::Canvas* canvas, views::View* view) const override { |
| 75 gfx::Rect bounds = view->GetContentsBounds(); | 69 gfx::Rect bounds = view->GetContentsBounds(); |
| 76 | 70 |
| 77 cc::PaintFlags flags; | 71 cc::PaintFlags flags; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 AppListView* app_list_view) | 129 AppListView* app_list_view) |
| 136 : delegate_(delegate), | 130 : delegate_(delegate), |
| 137 view_delegate_(view_delegate), | 131 view_delegate_(view_delegate), |
| 138 model_(NULL), | 132 model_(NULL), |
| 139 content_container_(new views::View), | 133 content_container_(new views::View), |
| 140 back_button_(NULL), | 134 back_button_(NULL), |
| 141 speech_button_(NULL), | 135 speech_button_(NULL), |
| 142 search_box_(new views::Textfield), | 136 search_box_(new views::Textfield), |
| 143 contents_view_(NULL), | 137 contents_view_(NULL), |
| 144 app_list_view_(app_list_view), | 138 app_list_view_(app_list_view), |
| 145 focused_view_(FOCUS_SEARCH_BOX) { | 139 focused_view_(FOCUS_SEARCH_BOX), |
| 140 is_fullscreen_app_list_enabled_(features::IsFullscreenAppListEnabled()) { |
| 146 SetLayoutManager(new views::FillLayout); | 141 SetLayoutManager(new views::FillLayout); |
| 147 SetPreferredSize(gfx::Size(IsFullscreenAppListEnabled() | 142 SetPreferredSize(gfx::Size(is_fullscreen_app_list_enabled_ |
| 148 ? kPreferredWidthFullscreen | 143 ? kPreferredWidthFullscreen |
| 149 : kPreferredWidth, | 144 : kPreferredWidth, |
| 150 kPreferredHeight)); | 145 kPreferredHeight)); |
| 151 AddChildView(content_container_); | 146 AddChildView(content_container_); |
| 152 | 147 |
| 153 SetShadow(GetShadowForZHeight(2)); | 148 SetShadow(GetShadowForZHeight(2)); |
| 154 back_button_ = new SearchBoxImageButton(this); | 149 back_button_ = new SearchBoxImageButton(this); |
| 155 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 150 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 156 back_button_->SetImage(views::ImageButton::STATE_NORMAL, | 151 back_button_->SetImage(views::ImageButton::STATE_NORMAL, |
| 157 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL)); | 152 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL)); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 DCHECK(delegate_); | 334 DCHECK(delegate_); |
| 340 delegate_->QueryChanged(this); | 335 delegate_->QueryChanged(this); |
| 341 } | 336 } |
| 342 | 337 |
| 343 void SearchBoxView::ContentsChanged(views::Textfield* sender, | 338 void SearchBoxView::ContentsChanged(views::Textfield* sender, |
| 344 const base::string16& new_contents) { | 339 const base::string16& new_contents) { |
| 345 UpdateModel(); | 340 UpdateModel(); |
| 346 view_delegate_->AutoLaunchCanceled(); | 341 view_delegate_->AutoLaunchCanceled(); |
| 347 NotifyQueryChanged(); | 342 NotifyQueryChanged(); |
| 348 | 343 |
| 349 if (IsFullscreenAppListEnabled() && !app_list_view_->is_fullscreen()) { | 344 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. | 345 // If the app list is in the peeking state, switch it to fullscreen. |
| 351 app_list_view_->SetState(AppListView::FULLSCREEN); | 346 app_list_view_->SetState(AppListView::FULLSCREEN); |
| 352 } | 347 } |
| 353 } | 348 } |
| 354 | 349 |
| 355 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, | 350 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, |
| 356 const ui::KeyEvent& key_event) { | 351 const ui::KeyEvent& key_event) { |
| 357 if (key_event.type() == ui::ET_KEY_PRESSED) { | 352 if (key_event.type() == ui::ET_KEY_PRESSED) { |
| 358 if (key_event.key_code() == ui::VKEY_TAB && | 353 if (key_event.key_code() == ui::VKEY_TAB && |
| 359 focused_view_ != FOCUS_CONTENTS_VIEW && | 354 focused_view_ != FOCUS_CONTENTS_VIEW && |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 NotifyQueryChanged(); | 453 NotifyQueryChanged(); |
| 459 } | 454 } |
| 460 | 455 |
| 461 void SearchBoxView::OnSpeechRecognitionStateChanged( | 456 void SearchBoxView::OnSpeechRecognitionStateChanged( |
| 462 SpeechRecognitionState new_state) { | 457 SpeechRecognitionState new_state) { |
| 463 SpeechRecognitionButtonPropChanged(); | 458 SpeechRecognitionButtonPropChanged(); |
| 464 SchedulePaint(); | 459 SchedulePaint(); |
| 465 } | 460 } |
| 466 | 461 |
| 467 } // namespace app_list | 462 } // namespace app_list |
| OLD | NEW |