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