| 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 : background_border_corner_radius_( |
| 60 features::IsFullscreenAppListEnabled() |
| 61 ? kBackgroundBorderCornerRadiusFullscreen |
| 62 : kBackgroundBorderCornerRadius) {} |
| 54 ~SearchBoxBackground() override {} | 63 ~SearchBoxBackground() override {} |
| 55 | 64 |
| 56 private: | 65 private: |
| 57 // views::Background overrides: | 66 // views::Background overrides: |
| 58 void Paint(gfx::Canvas* canvas, views::View* view) const override { | 67 void Paint(gfx::Canvas* canvas, views::View* view) const override { |
| 59 gfx::Rect bounds = view->GetContentsBounds(); | 68 gfx::Rect bounds = view->GetContentsBounds(); |
| 60 | 69 |
| 61 cc::PaintFlags flags; | 70 cc::PaintFlags flags; |
| 62 flags.setAntiAlias(true); | 71 flags.setAntiAlias(true); |
| 63 flags.setColor(kSearchBoxBackground); | 72 flags.setColor(kSearchBoxBackground); |
| 64 canvas->DrawRoundRect(bounds, kBackgroundBorderCornerRadius, flags); | 73 canvas->DrawRoundRect(bounds, background_border_corner_radius_, flags); |
| 65 } | 74 } |
| 66 | 75 |
| 76 const int background_border_corner_radius_; |
| 77 |
| 67 DISALLOW_COPY_AND_ASSIGN(SearchBoxBackground); | 78 DISALLOW_COPY_AND_ASSIGN(SearchBoxBackground); |
| 68 }; | 79 }; |
| 69 | 80 |
| 70 } // namespace | 81 } // namespace |
| 71 | 82 |
| 72 // To paint grey background on mic and back buttons | 83 // To paint grey background on mic and back buttons |
| 73 class SearchBoxImageButton : public views::ImageButton { | 84 class SearchBoxImageButton : public views::ImageButton { |
| 74 public: | 85 public: |
| 75 explicit SearchBoxImageButton(views::ButtonListener* listener) | 86 explicit SearchBoxImageButton(views::ButtonListener* listener) |
| 76 : ImageButton(listener), selected_(false) {} | 87 : ImageButton(listener), selected_(false) {} |
| (...skipping 29 matching lines...) Expand all Loading... |
| 106 } | 117 } |
| 107 | 118 |
| 108 const char* GetClassName() const override { return "SearchBoxImageButton"; } | 119 const char* GetClassName() const override { return "SearchBoxImageButton"; } |
| 109 | 120 |
| 110 bool selected_; | 121 bool selected_; |
| 111 | 122 |
| 112 DISALLOW_COPY_AND_ASSIGN(SearchBoxImageButton); | 123 DISALLOW_COPY_AND_ASSIGN(SearchBoxImageButton); |
| 113 }; | 124 }; |
| 114 | 125 |
| 115 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate, | 126 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate, |
| 116 AppListViewDelegate* view_delegate) | 127 AppListViewDelegate* view_delegate, |
| 128 AppListView* app_list_view) |
| 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_(app_list_view), |
| 138 is_fullscreen_enabled_(features::IsFullscreenAppListEnabled()), |
| 125 focused_view_(FOCUS_SEARCH_BOX) { | 139 focused_view_(FOCUS_SEARCH_BOX) { |
| 126 SetLayoutManager(new views::FillLayout); | 140 SetLayoutManager(new views::FillLayout); |
| 127 AddChildView(content_container_); | 141 AddChildView(content_container_); |
| 128 | 142 |
| 129 SetShadow(GetShadowForZHeight(2)); | 143 SetShadow(GetShadowForZHeight(2)); |
| 130 back_button_ = new SearchBoxImageButton(this); | 144 back_button_ = new SearchBoxImageButton(this); |
| 131 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 145 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 132 back_button_->SetImage(views::ImageButton::STATE_NORMAL, | 146 back_button_->SetImage(views::ImageButton::STATE_NORMAL, |
| 133 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL)); | 147 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL)); |
| 134 back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, | 148 back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, |
| (...skipping 145 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( |
| 305 is_fullscreen_enabled_ ? kPreferredWidthFullscreen : kPreferredWidth, |
| 306 kPreferredHeight); |
| 291 } | 307 } |
| 292 | 308 |
| 293 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) { | 309 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) { |
| 294 if (contents_view_) | 310 if (contents_view_) |
| 295 return contents_view_->OnMouseWheel(event); | 311 return contents_view_->OnMouseWheel(event); |
| 296 | 312 |
| 297 return false; | 313 return false; |
| 298 } | 314 } |
| 299 | 315 |
| 300 void SearchBoxView::OnEnabledChanged() { | 316 void SearchBoxView::OnEnabledChanged() { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 318 void SearchBoxView::NotifyQueryChanged() { | 334 void SearchBoxView::NotifyQueryChanged() { |
| 319 DCHECK(delegate_); | 335 DCHECK(delegate_); |
| 320 delegate_->QueryChanged(this); | 336 delegate_->QueryChanged(this); |
| 321 } | 337 } |
| 322 | 338 |
| 323 void SearchBoxView::ContentsChanged(views::Textfield* sender, | 339 void SearchBoxView::ContentsChanged(views::Textfield* sender, |
| 324 const base::string16& new_contents) { | 340 const base::string16& new_contents) { |
| 325 UpdateModel(); | 341 UpdateModel(); |
| 326 view_delegate_->AutoLaunchCanceled(); | 342 view_delegate_->AutoLaunchCanceled(); |
| 327 NotifyQueryChanged(); | 343 NotifyQueryChanged(); |
| 344 |
| 345 if (is_fullscreen_enabled_ && !app_list_view_->IsFullscreen()) { |
| 346 // If the app list is in the peeking state, switch it to fullscreen. |
| 347 app_list_view_->ToFullscreen(); |
| 348 } |
| 328 } | 349 } |
| 329 | 350 |
| 330 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, | 351 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, |
| 331 const ui::KeyEvent& key_event) { | 352 const ui::KeyEvent& key_event) { |
| 332 if (key_event.type() == ui::ET_KEY_PRESSED) { | 353 if (key_event.type() == ui::ET_KEY_PRESSED) { |
| 333 if (key_event.key_code() == ui::VKEY_TAB && | 354 if (key_event.key_code() == ui::VKEY_TAB && |
| 334 focused_view_ != FOCUS_CONTENTS_VIEW && | 355 focused_view_ != FOCUS_CONTENTS_VIEW && |
| 335 MoveTabFocus(key_event.IsShiftDown())) | 356 MoveTabFocus(key_event.IsShiftDown())) |
| 336 return true; | 357 return true; |
| 337 | 358 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 NotifyQueryChanged(); | 454 NotifyQueryChanged(); |
| 434 } | 455 } |
| 435 | 456 |
| 436 void SearchBoxView::OnSpeechRecognitionStateChanged( | 457 void SearchBoxView::OnSpeechRecognitionStateChanged( |
| 437 SpeechRecognitionState new_state) { | 458 SpeechRecognitionState new_state) { |
| 438 SpeechRecognitionButtonPropChanged(); | 459 SpeechRecognitionButtonPropChanged(); |
| 439 SchedulePaint(); | 460 SchedulePaint(); |
| 440 } | 461 } |
| 441 | 462 |
| 442 } // namespace app_list | 463 } // namespace app_list |
| OLD | NEW |