Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: ui/app_list/views/search_box_view.cc

Issue 2941573002: cros: add google/mic icons to searchbox (Closed)
Patch Set: rebase Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/app_list/views/search_box_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_features.h"
14 #include "ui/app_list/app_list_model.h" 14 #include "ui/app_list/app_list_model.h"
15 #include "ui/app_list/app_list_switches.h" 15 #include "ui/app_list/app_list_switches.h"
16 #include "ui/app_list/app_list_view_delegate.h" 16 #include "ui/app_list/app_list_view_delegate.h"
17 #include "ui/app_list/resources/grit/app_list_resources.h" 17 #include "ui/app_list/resources/grit/app_list_resources.h"
18 #include "ui/app_list/search_box_model.h" 18 #include "ui/app_list/search_box_model.h"
19 #include "ui/app_list/speech_ui_model.h" 19 #include "ui/app_list/speech_ui_model.h"
20 #include "ui/app_list/vector_icons.h"
20 #include "ui/app_list/views/app_list_view.h" 21 #include "ui/app_list/views/app_list_view.h"
21 #include "ui/app_list/views/contents_view.h" 22 #include "ui/app_list/views/contents_view.h"
22 #include "ui/app_list/views/search_box_view_delegate.h" 23 #include "ui/app_list/views/search_box_view_delegate.h"
23 #include "ui/base/ime/text_input_flags.h" 24 #include "ui/base/ime/text_input_flags.h"
24 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/resource/resource_bundle.h" 26 #include "ui/base/resource/resource_bundle.h"
26 #include "ui/events/event.h" 27 #include "ui/events/event.h"
27 #include "ui/gfx/canvas.h" 28 #include "ui/gfx/canvas.h"
28 #include "ui/gfx/geometry/insets.h" 29 #include "ui/gfx/geometry/insets.h"
30 #include "ui/gfx/paint_vector_icon.h"
29 #include "ui/gfx/shadow_value.h" 31 #include "ui/gfx/shadow_value.h"
30 #include "ui/strings/grit/ui_strings.h" 32 #include "ui/strings/grit/ui_strings.h"
31 #include "ui/views/background.h" 33 #include "ui/views/background.h"
32 #include "ui/views/border.h" 34 #include "ui/views/border.h"
33 #include "ui/views/controls/button/image_button.h" 35 #include "ui/views/controls/button/image_button.h"
34 #include "ui/views/controls/image_view.h" 36 #include "ui/views/controls/image_view.h"
35 #include "ui/views/controls/textfield/textfield.h" 37 #include "ui/views/controls/textfield/textfield.h"
36 #include "ui/views/layout/box_layout.h" 38 #include "ui/views/layout/box_layout.h"
37 #include "ui/views/layout/fill_layout.h" 39 #include "ui/views/layout/fill_layout.h"
38 #include "ui/views/shadow_border.h" 40 #include "ui/views/shadow_border.h"
39 #include "ui/views/widget/widget.h" 41 #include "ui/views/widget/widget.h"
40 42
41 namespace app_list { 43 namespace app_list {
42 44
43 namespace { 45 namespace {
44 46
45 const int kPadding = 16; 47 const int kPadding = 16;
46 const int kInnerPadding = 24; 48 const int kInnerPadding = 24;
47 const int kPreferredWidth = 360; 49 const int kPreferredWidth = 360;
48 const int kPreferredWidthFullscreen = 544; 50 const int kPreferredWidthFullscreen = 544;
49 const int kPreferredHeight = 48; 51 const int kPreferredHeight = 48;
50 52
51 const SkColor kHintTextColor = SkColorSetRGB(0xA0, 0xA0, 0xA0); 53 const SkColor kHintTextColor = SkColorSetRGB(0xA0, 0xA0, 0xA0);
52 54
53 const int kBackgroundBorderCornerRadius = 2; 55 const int kBackgroundBorderCornerRadius = 2;
54 const int kBackgroundBorderCornerRadiusFullscreen = 20; 56 const int kBackgroundBorderCornerRadiusFullscreen = 20;
55 57
58 constexpr int kGoogleIconSize = 24;
59 constexpr int kMicIconSize = 24;
60
61 // Default color used when wallpaper customized color is not available for
62 // searchbox, #000 at 87% opacity.
63 constexpr SkColor kDefaultSearchboxColor =
64 SkColorSetA(SK_ColorTRANSPARENT, 0xDE);
xiyuan 2017/06/13 20:10:41 nit: SK_ColorTRANSPARENT -> SK_ColorBLACK. Techniq
xiyuan 2017/06/13 20:10:41 Prefer to use SkColorSetARGBMacro instead of SkCol
Qiang(Joe) Xu 2017/06/13 20:50:53 Done.
65
66 bool IsFullscreenAppListEnabled() {
xiyuan 2017/06/13 20:10:41 Get rid of this. Alex has a CL (https://codereview
Qiang(Joe) Xu 2017/06/13 20:50:53 Done.
67 // Cache this value to avoid repeated lookup.
68 static bool cached_value = features::IsFullscreenAppListEnabled();
69 return cached_value;
70 }
71
56 // A background that paints a solid white rounded rect with a thin grey border. 72 // A background that paints a solid white rounded rect with a thin grey border.
57 class SearchBoxBackground : public views::Background { 73 class SearchBoxBackground : public views::Background {
58 public: 74 public:
59 SearchBoxBackground() 75 SearchBoxBackground()
60 : background_border_corner_radius_( 76 : background_border_corner_radius_(
61 features::IsFullscreenAppListEnabled() 77 features::IsFullscreenAppListEnabled()
62 ? kBackgroundBorderCornerRadiusFullscreen 78 ? kBackgroundBorderCornerRadiusFullscreen
63 : kBackgroundBorderCornerRadius) {} 79 : kBackgroundBorderCornerRadius) {}
64 ~SearchBoxBackground() override {} 80 ~SearchBoxBackground() override {}
65 81
66 private: 82 private:
67 // views::Background overrides: 83 // views::Background overrides:
68 void Paint(gfx::Canvas* canvas, views::View* view) const override { 84 void Paint(gfx::Canvas* canvas, views::View* view) const override {
69 gfx::Rect bounds = view->GetContentsBounds(); 85 gfx::Rect bounds = view->GetContentsBounds();
70 86
71 cc::PaintFlags flags; 87 cc::PaintFlags flags;
72 flags.setAntiAlias(true); 88 flags.setAntiAlias(true);
73 flags.setColor(kSearchBoxBackground); 89 flags.setColor(kSearchBoxBackgroundDefault);
74 canvas->DrawRoundRect(bounds, background_border_corner_radius_, flags); 90 canvas->DrawRoundRect(bounds, background_border_corner_radius_, flags);
75 } 91 }
76 92
77 const int background_border_corner_radius_; 93 const int background_border_corner_radius_;
78 94
79 DISALLOW_COPY_AND_ASSIGN(SearchBoxBackground); 95 DISALLOW_COPY_AND_ASSIGN(SearchBoxBackground);
80 }; 96 };
81 97
82 } // namespace 98 } // namespace
83 99
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 DISALLOW_COPY_AND_ASSIGN(SearchBoxImageButton); 140 DISALLOW_COPY_AND_ASSIGN(SearchBoxImageButton);
125 }; 141 };
126 142
127 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate, 143 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate,
128 AppListViewDelegate* view_delegate, 144 AppListViewDelegate* view_delegate,
129 AppListView* app_list_view) 145 AppListView* app_list_view)
130 : delegate_(delegate), 146 : delegate_(delegate),
131 view_delegate_(view_delegate), 147 view_delegate_(view_delegate),
132 model_(NULL), 148 model_(NULL),
133 content_container_(new views::View), 149 content_container_(new views::View),
150 google_icon_(new views::ImageView),
xiyuan 2017/06/13 20:10:41 This leaks for the old behavior since |google_icon
Qiang(Joe) Xu 2017/06/13 20:50:53 Done.
134 back_button_(NULL), 151 back_button_(NULL),
135 speech_button_(NULL), 152 speech_button_(NULL),
136 search_box_(new views::Textfield), 153 search_box_(new views::Textfield),
137 contents_view_(NULL), 154 contents_view_(NULL),
138 app_list_view_(app_list_view), 155 app_list_view_(app_list_view),
139 focused_view_(FOCUS_SEARCH_BOX), 156 focused_view_(FOCUS_SEARCH_BOX),
140 is_fullscreen_app_list_enabled_(features::IsFullscreenAppListEnabled()) { 157 is_fullscreen_app_list_enabled_(features::IsFullscreenAppListEnabled()) {
141 SetLayoutManager(new views::FillLayout); 158 SetLayoutManager(new views::FillLayout);
142 SetPreferredSize(gfx::Size(is_fullscreen_app_list_enabled_ 159 SetPreferredSize(gfx::Size(is_fullscreen_app_list_enabled_
143 ? kPreferredWidthFullscreen 160 ? kPreferredWidthFullscreen
144 : kPreferredWidth, 161 : kPreferredWidth,
145 kPreferredHeight)); 162 kPreferredHeight));
146 AddChildView(content_container_); 163 AddChildView(content_container_);
147 164
148 SetShadow(GetShadowForZHeight(2)); 165 SetShadow(GetShadowForZHeight(2));
149 back_button_ = new SearchBoxImageButton(this);
150 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
151 back_button_->SetImage(views::ImageButton::STATE_NORMAL,
152 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL));
153 back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
154 views::ImageButton::ALIGN_MIDDLE);
155 SetBackButtonLabel(false);
156 content_container_->AddChildView(back_button_);
157 content_container_->SetBackground(base::MakeUnique<SearchBoxBackground>()); 166 content_container_->SetBackground(base::MakeUnique<SearchBoxBackground>());
158 167
159 views::BoxLayout* layout = new views::BoxLayout( 168 views::BoxLayout* layout = new views::BoxLayout(
160 views::BoxLayout::kHorizontal, gfx::Insets(0, kPadding), 169 views::BoxLayout::kHorizontal, gfx::Insets(0, kPadding),
161 kInnerPadding - views::Textfield::kTextPadding); 170 kInnerPadding - views::Textfield::kTextPadding);
162 content_container_->SetLayoutManager(layout); 171 content_container_->SetLayoutManager(layout);
163 layout->set_cross_axis_alignment( 172 layout->set_cross_axis_alignment(
164 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); 173 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
165 layout->set_minimum_cross_axis_size(kPreferredHeight); 174 layout->set_minimum_cross_axis_size(kPreferredHeight);
166 175
167 search_box_->SetBorder(views::NullBorder()); 176 search_box_->SetBorder(views::NullBorder());
168 search_box_->SetTextColor(kSearchTextColor); 177 search_box_->SetTextColor(kSearchTextColor);
169 search_box_->SetBackgroundColor(kSearchBoxBackground); 178 search_box_->SetBackgroundColor(kSearchBoxBackgroundDefault);
170 search_box_->set_placeholder_text_color(kHintTextColor);
171 search_box_->set_controller(this); 179 search_box_->set_controller(this);
172 search_box_->SetTextInputType(ui::TEXT_INPUT_TYPE_SEARCH); 180 search_box_->SetTextInputType(ui::TEXT_INPUT_TYPE_SEARCH);
173 search_box_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF); 181 search_box_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF);
182 if (features::IsFullscreenAppListEnabled()) {
183 google_icon_->SetImage(gfx::CreateVectorIcon(
184 kIcGoogleBlackIcon, kGoogleIconSize, kDefaultSearchboxColor));
185 content_container_->AddChildView(google_icon_);
186
187 search_box_->set_placeholder_text_color(kDefaultSearchboxColor);
188 } else {
189 back_button_ = new SearchBoxImageButton(this);
190 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
191 back_button_->SetImage(
192 views::ImageButton::STATE_NORMAL,
193 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL));
194 back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
195 views::ImageButton::ALIGN_MIDDLE);
196 SetBackButtonLabel(false);
197 content_container_->AddChildView(back_button_);
198
199 search_box_->set_placeholder_text_color(kHintTextColor);
200 }
174 content_container_->AddChildView(search_box_); 201 content_container_->AddChildView(search_box_);
175 layout->SetFlexForView(search_box_, 1); 202 layout->SetFlexForView(search_box_, 1);
176 203
177 view_delegate_->GetSpeechUI()->AddObserver(this); 204 view_delegate_->GetSpeechUI()->AddObserver(this);
178 ModelChanged(); 205 ModelChanged();
179 } 206 }
180 207
181 SearchBoxView::~SearchBoxView() { 208 SearchBoxView::~SearchBoxView() {
182 view_delegate_->GetSpeechUI()->RemoveObserver(this); 209 view_delegate_->GetSpeechUI()->RemoveObserver(this);
183 model_->search_box()->RemoveObserver(this); 210 model_->search_box()->RemoveObserver(this);
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 void SearchBoxView::SpeechRecognitionButtonPropChanged() { 438 void SearchBoxView::SpeechRecognitionButtonPropChanged() {
412 const SearchBoxModel::SpeechButtonProperty* speech_button_prop = 439 const SearchBoxModel::SpeechButtonProperty* speech_button_prop =
413 model_->search_box()->speech_button(); 440 model_->search_box()->speech_button();
414 if (speech_button_prop) { 441 if (speech_button_prop) {
415 if (!speech_button_) { 442 if (!speech_button_) {
416 speech_button_ = new SearchBoxImageButton(this); 443 speech_button_ = new SearchBoxImageButton(this);
417 content_container_->AddChildView(speech_button_); 444 content_container_->AddChildView(speech_button_);
418 } 445 }
419 446
420 speech_button_->SetAccessibleName(speech_button_prop->accessible_name); 447 speech_button_->SetAccessibleName(speech_button_prop->accessible_name);
448 if (IsFullscreenAppListEnabled()) {
449 speech_button_->SetImage(
450 views::Button::STATE_NORMAL,
451 gfx::CreateVectorIcon(kIcMicBlackIcon, kMicIconSize,
452 kDefaultSearchboxColor));
xiyuan 2017/06/13 20:10:41 So we will show the mic icon regardless of the spe
Qiang(Joe) Xu 2017/06/13 20:50:53 Specification doesn't mention this. I think we can
xiyuan 2017/06/13 21:09:27 Acknowledged.
453 }
421 if (view_delegate_->GetSpeechUI()->state() == 454 if (view_delegate_->GetSpeechUI()->state() ==
422 SPEECH_RECOGNITION_HOTWORD_LISTENING) { 455 SPEECH_RECOGNITION_HOTWORD_LISTENING) {
423 speech_button_->SetImage( 456 if (!IsFullscreenAppListEnabled()) {
424 views::Button::STATE_NORMAL, &speech_button_prop->on_icon); 457 speech_button_->SetImage(views::Button::STATE_NORMAL,
458 &speech_button_prop->on_icon);
459 }
425 speech_button_->SetTooltipText(speech_button_prop->on_tooltip); 460 speech_button_->SetTooltipText(speech_button_prop->on_tooltip);
xiyuan 2017/06/13 20:10:41 It is a bit strange that we change the image optio
Qiang(Joe) Xu 2017/06/13 20:50:53 The tooltip is changed based on whether OK google
xiyuan 2017/06/13 21:09:27 Thanks for the clarification.
426 } else { 461 } else {
427 speech_button_->SetImage( 462 if (!IsFullscreenAppListEnabled()) {
428 views::Button::STATE_NORMAL, &speech_button_prop->off_icon); 463 speech_button_->SetImage(views::Button::STATE_NORMAL,
464 &speech_button_prop->off_icon);
465 }
429 speech_button_->SetTooltipText(speech_button_prop->off_tooltip); 466 speech_button_->SetTooltipText(speech_button_prop->off_tooltip);
430 } 467 }
431 } else { 468 } else {
432 if (speech_button_) { 469 if (speech_button_) {
433 // Deleting a view will detach it from its parent. 470 // Deleting a view will detach it from its parent.
434 delete speech_button_; 471 delete speech_button_;
435 speech_button_ = NULL; 472 speech_button_ = NULL;
436 } 473 }
437 } 474 }
438 Layout(); 475 Layout();
(...skipping 14 matching lines...) Expand all
453 NotifyQueryChanged(); 490 NotifyQueryChanged();
454 } 491 }
455 492
456 void SearchBoxView::OnSpeechRecognitionStateChanged( 493 void SearchBoxView::OnSpeechRecognitionStateChanged(
457 SpeechRecognitionState new_state) { 494 SpeechRecognitionState new_state) {
458 SpeechRecognitionButtonPropChanged(); 495 SpeechRecognitionButtonPropChanged();
459 SchedulePaint(); 496 SchedulePaint();
460 } 497 }
461 498
462 } // namespace app_list 499 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/views/search_box_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698