| 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" | |
| 14 #include "ui/app_list/app_list_model.h" | 13 #include "ui/app_list/app_list_model.h" |
| 15 #include "ui/app_list/app_list_switches.h" | 14 #include "ui/app_list/app_list_switches.h" |
| 16 #include "ui/app_list/app_list_view_delegate.h" | 15 #include "ui/app_list/app_list_view_delegate.h" |
| 17 #include "ui/app_list/resources/grit/app_list_resources.h" | 16 #include "ui/app_list/resources/grit/app_list_resources.h" |
| 18 #include "ui/app_list/search_box_model.h" | 17 #include "ui/app_list/search_box_model.h" |
| 19 #include "ui/app_list/speech_ui_model.h" | 18 #include "ui/app_list/speech_ui_model.h" |
| 20 #include "ui/app_list/views/app_list_view.h" | |
| 21 #include "ui/app_list/views/contents_view.h" | 19 #include "ui/app_list/views/contents_view.h" |
| 22 #include "ui/app_list/views/search_box_view_delegate.h" | 20 #include "ui/app_list/views/search_box_view_delegate.h" |
| 23 #include "ui/base/ime/text_input_flags.h" | 21 #include "ui/base/ime/text_input_flags.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 25 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
| 26 #include "ui/events/event.h" | 24 #include "ui/events/event.h" |
| 27 #include "ui/gfx/canvas.h" | 25 #include "ui/gfx/canvas.h" |
| 28 #include "ui/gfx/geometry/insets.h" | 26 #include "ui/gfx/geometry/insets.h" |
| 29 #include "ui/gfx/shadow_value.h" | 27 #include "ui/gfx/shadow_value.h" |
| 30 #include "ui/strings/grit/ui_strings.h" | 28 #include "ui/strings/grit/ui_strings.h" |
| 31 #include "ui/views/background.h" | 29 #include "ui/views/background.h" |
| 32 #include "ui/views/border.h" | 30 #include "ui/views/border.h" |
| 33 #include "ui/views/controls/button/image_button.h" | 31 #include "ui/views/controls/button/image_button.h" |
| 34 #include "ui/views/controls/image_view.h" | 32 #include "ui/views/controls/image_view.h" |
| 35 #include "ui/views/controls/textfield/textfield.h" | 33 #include "ui/views/controls/textfield/textfield.h" |
| 36 #include "ui/views/layout/box_layout.h" | 34 #include "ui/views/layout/box_layout.h" |
| 37 #include "ui/views/layout/fill_layout.h" | 35 #include "ui/views/layout/fill_layout.h" |
| 38 #include "ui/views/shadow_border.h" | 36 #include "ui/views/shadow_border.h" |
| 39 #include "ui/views/widget/widget.h" | |
| 40 | 37 |
| 41 namespace app_list { | 38 namespace app_list { |
| 42 | 39 |
| 43 namespace { | 40 namespace { |
| 44 | 41 |
| 45 const int kPadding = 16; | 42 const int kPadding = 16; |
| 46 const int kInnerPadding = 24; | 43 const int kInnerPadding = 24; |
| 47 const int kPreferredWidth = 360; | 44 const int kPreferredWidth = 360; |
| 48 const int kPreferredWidthFullscreen = 544; | |
| 49 const int kPreferredHeight = 48; | 45 const int kPreferredHeight = 48; |
| 50 | 46 |
| 51 const SkColor kHintTextColor = SkColorSetRGB(0xA0, 0xA0, 0xA0); | 47 const SkColor kHintTextColor = SkColorSetRGB(0xA0, 0xA0, 0xA0); |
| 52 | 48 |
| 53 const int kBackgroundBorderCornerRadius = 2; | 49 const int kBackgroundBorderCornerRadius = 2; |
| 54 const int kBackgroundBorderCornerRadiusFullscreen = 20; | |
| 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 | 50 |
| 62 // A background that paints a solid white rounded rect with a thin grey border. | 51 // A background that paints a solid white rounded rect with a thin grey border. |
| 63 class SearchBoxBackground : public views::Background { | 52 class SearchBoxBackground : public views::Background { |
| 64 public: | 53 public: |
| 65 SearchBoxBackground() | 54 SearchBoxBackground() {} |
| 66 : background_border_corner_radius_( | |
| 67 IsFullscreenAppListEnabled() | |
| 68 ? kBackgroundBorderCornerRadiusFullscreen | |
| 69 : kBackgroundBorderCornerRadius) {} | |
| 70 ~SearchBoxBackground() override {} | 55 ~SearchBoxBackground() override {} |
| 71 | 56 |
| 72 private: | 57 private: |
| 73 // views::Background overrides: | 58 // views::Background overrides: |
| 74 void Paint(gfx::Canvas* canvas, views::View* view) const override { | 59 void Paint(gfx::Canvas* canvas, views::View* view) const override { |
| 75 gfx::Rect bounds = view->GetContentsBounds(); | 60 gfx::Rect bounds = view->GetContentsBounds(); |
| 76 | 61 |
| 77 cc::PaintFlags flags; | 62 cc::PaintFlags flags; |
| 78 flags.setAntiAlias(true); | 63 flags.setAntiAlias(true); |
| 79 flags.setColor(kSearchBoxBackground); | 64 flags.setColor(kSearchBoxBackground); |
| 80 canvas->DrawRoundRect(bounds, background_border_corner_radius_, flags); | 65 canvas->DrawRoundRect(bounds, kBackgroundBorderCornerRadius, flags); |
| 81 } | 66 } |
| 82 | 67 |
| 83 const int background_border_corner_radius_; | |
| 84 | |
| 85 DISALLOW_COPY_AND_ASSIGN(SearchBoxBackground); | 68 DISALLOW_COPY_AND_ASSIGN(SearchBoxBackground); |
| 86 }; | 69 }; |
| 87 | 70 |
| 88 } // namespace | 71 } // namespace |
| 89 | 72 |
| 90 // To paint grey background on mic and back buttons | 73 // To paint grey background on mic and back buttons |
| 91 class SearchBoxImageButton : public views::ImageButton { | 74 class SearchBoxImageButton : public views::ImageButton { |
| 92 public: | 75 public: |
| 93 explicit SearchBoxImageButton(views::ButtonListener* listener) | 76 explicit SearchBoxImageButton(views::ButtonListener* listener) |
| 94 : ImageButton(listener), selected_(false) {} | 77 : ImageButton(listener), selected_(false) {} |
| (...skipping 29 matching lines...) Expand all Loading... |
| 124 } | 107 } |
| 125 | 108 |
| 126 const char* GetClassName() const override { return "SearchBoxImageButton"; } | 109 const char* GetClassName() const override { return "SearchBoxImageButton"; } |
| 127 | 110 |
| 128 bool selected_; | 111 bool selected_; |
| 129 | 112 |
| 130 DISALLOW_COPY_AND_ASSIGN(SearchBoxImageButton); | 113 DISALLOW_COPY_AND_ASSIGN(SearchBoxImageButton); |
| 131 }; | 114 }; |
| 132 | 115 |
| 133 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate, | 116 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate, |
| 134 AppListViewDelegate* view_delegate, | 117 AppListViewDelegate* view_delegate) |
| 135 AppListView* app_list_view) | |
| 136 : delegate_(delegate), | 118 : delegate_(delegate), |
| 137 view_delegate_(view_delegate), | 119 view_delegate_(view_delegate), |
| 138 model_(NULL), | 120 model_(NULL), |
| 139 content_container_(new views::View), | 121 content_container_(new views::View), |
| 140 back_button_(NULL), | 122 back_button_(NULL), |
| 141 speech_button_(NULL), | 123 speech_button_(NULL), |
| 142 search_box_(new views::Textfield), | 124 search_box_(new views::Textfield), |
| 143 contents_view_(NULL), | 125 contents_view_(NULL), |
| 144 app_list_view_(app_list_view), | |
| 145 focused_view_(FOCUS_SEARCH_BOX) { | 126 focused_view_(FOCUS_SEARCH_BOX) { |
| 146 SetLayoutManager(new views::FillLayout); | 127 SetLayoutManager(new views::FillLayout); |
| 147 SetPreferredSize(gfx::Size(IsFullscreenAppListEnabled() | 128 SetPreferredSize(gfx::Size(kPreferredWidth, kPreferredHeight)); |
| 148 ? kPreferredWidthFullscreen | |
| 149 : kPreferredWidth, | |
| 150 kPreferredHeight)); | |
| 151 AddChildView(content_container_); | 129 AddChildView(content_container_); |
| 152 | 130 |
| 153 SetShadow(GetShadowForZHeight(2)); | 131 SetShadow(GetShadowForZHeight(2)); |
| 154 back_button_ = new SearchBoxImageButton(this); | 132 back_button_ = new SearchBoxImageButton(this); |
| 155 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 133 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 156 back_button_->SetImage(views::ImageButton::STATE_NORMAL, | 134 back_button_->SetImage(views::ImageButton::STATE_NORMAL, |
| 157 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL)); | 135 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL)); |
| 158 back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, | 136 back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER, |
| 159 views::ImageButton::ALIGN_MIDDLE); | 137 views::ImageButton::ALIGN_MIDDLE); |
| 160 SetBackButtonLabel(false); | 138 SetBackButtonLabel(false); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 void SearchBoxView::NotifyQueryChanged() { | 316 void SearchBoxView::NotifyQueryChanged() { |
| 339 DCHECK(delegate_); | 317 DCHECK(delegate_); |
| 340 delegate_->QueryChanged(this); | 318 delegate_->QueryChanged(this); |
| 341 } | 319 } |
| 342 | 320 |
| 343 void SearchBoxView::ContentsChanged(views::Textfield* sender, | 321 void SearchBoxView::ContentsChanged(views::Textfield* sender, |
| 344 const base::string16& new_contents) { | 322 const base::string16& new_contents) { |
| 345 UpdateModel(); | 323 UpdateModel(); |
| 346 view_delegate_->AutoLaunchCanceled(); | 324 view_delegate_->AutoLaunchCanceled(); |
| 347 NotifyQueryChanged(); | 325 NotifyQueryChanged(); |
| 348 | |
| 349 if (IsFullscreenAppListEnabled() && !app_list_view_->is_fullscreen()) { | |
| 350 // If the app list is in the peeking state, switch it to fullscreen. | |
| 351 app_list_view_->SetState(AppListView::FULLSCREEN); | |
| 352 } | |
| 353 } | 326 } |
| 354 | 327 |
| 355 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, | 328 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, |
| 356 const ui::KeyEvent& key_event) { | 329 const ui::KeyEvent& key_event) { |
| 357 if (key_event.type() == ui::ET_KEY_PRESSED) { | 330 if (key_event.type() == ui::ET_KEY_PRESSED) { |
| 358 if (key_event.key_code() == ui::VKEY_TAB && | 331 if (key_event.key_code() == ui::VKEY_TAB && |
| 359 focused_view_ != FOCUS_CONTENTS_VIEW && | 332 focused_view_ != FOCUS_CONTENTS_VIEW && |
| 360 MoveTabFocus(key_event.IsShiftDown())) | 333 MoveTabFocus(key_event.IsShiftDown())) |
| 361 return true; | 334 return true; |
| 362 | 335 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 NotifyQueryChanged(); | 431 NotifyQueryChanged(); |
| 459 } | 432 } |
| 460 | 433 |
| 461 void SearchBoxView::OnSpeechRecognitionStateChanged( | 434 void SearchBoxView::OnSpeechRecognitionStateChanged( |
| 462 SpeechRecognitionState new_state) { | 435 SpeechRecognitionState new_state) { |
| 463 SpeechRecognitionButtonPropChanged(); | 436 SpeechRecognitionButtonPropChanged(); |
| 464 SchedulePaint(); | 437 SchedulePaint(); |
| 465 } | 438 } |
| 466 | 439 |
| 467 } // namespace app_list | 440 } // namespace app_list |
| OLD | NEW |