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

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

Issue 2941573002: cros: add google/mic icons to searchbox (Closed)
Patch Set: feedback 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;
xiyuan 2017/06/13 21:09:27 nit: Can you update those const -> constexpr since
Qiang(Joe) Xu 2017/06/13 21:31:21 Done.
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 SkColorSetARGBMacro(0xDE, 0x00, 0x00, 0x00);
65
56 // A background that paints a solid white rounded rect with a thin grey border. 66 // A background that paints a solid white rounded rect with a thin grey border.
57 class SearchBoxBackground : public views::Background { 67 class SearchBoxBackground : public views::Background {
58 public: 68 public:
59 SearchBoxBackground() 69 SearchBoxBackground()
60 : background_border_corner_radius_( 70 : background_border_corner_radius_(
61 features::IsFullscreenAppListEnabled() 71 features::IsFullscreenAppListEnabled()
62 ? kBackgroundBorderCornerRadiusFullscreen 72 ? kBackgroundBorderCornerRadiusFullscreen
63 : kBackgroundBorderCornerRadius) {} 73 : kBackgroundBorderCornerRadius) {}
64 ~SearchBoxBackground() override {} 74 ~SearchBoxBackground() override {}
65 75
66 private: 76 private:
67 // views::Background overrides: 77 // views::Background overrides:
68 void Paint(gfx::Canvas* canvas, views::View* view) const override { 78 void Paint(gfx::Canvas* canvas, views::View* view) const override {
69 gfx::Rect bounds = view->GetContentsBounds(); 79 gfx::Rect bounds = view->GetContentsBounds();
70 80
71 cc::PaintFlags flags; 81 cc::PaintFlags flags;
72 flags.setAntiAlias(true); 82 flags.setAntiAlias(true);
73 flags.setColor(kSearchBoxBackground); 83 flags.setColor(kSearchBoxBackgroundDefault);
74 canvas->DrawRoundRect(bounds, background_border_corner_radius_, flags); 84 canvas->DrawRoundRect(bounds, background_border_corner_radius_, flags);
75 } 85 }
76 86
77 const int background_border_corner_radius_; 87 const int background_border_corner_radius_;
78 88
79 DISALLOW_COPY_AND_ASSIGN(SearchBoxBackground); 89 DISALLOW_COPY_AND_ASSIGN(SearchBoxBackground);
80 }; 90 };
81 91
82 } // namespace 92 } // namespace
83 93
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 bool selected_; 132 bool selected_;
123 133
124 DISALLOW_COPY_AND_ASSIGN(SearchBoxImageButton); 134 DISALLOW_COPY_AND_ASSIGN(SearchBoxImageButton);
125 }; 135 };
126 136
127 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate, 137 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate,
128 AppListViewDelegate* view_delegate, 138 AppListViewDelegate* view_delegate,
129 AppListView* app_list_view) 139 AppListView* app_list_view)
130 : delegate_(delegate), 140 : delegate_(delegate),
131 view_delegate_(view_delegate), 141 view_delegate_(view_delegate),
132 model_(NULL), 142 model_(nullptr),
133 content_container_(new views::View), 143 content_container_(new views::View),
134 back_button_(NULL), 144 google_icon_(nullptr),
135 speech_button_(NULL), 145 back_button_(nullptr),
146 speech_button_(nullptr),
136 search_box_(new views::Textfield), 147 search_box_(new views::Textfield),
137 contents_view_(NULL), 148 contents_view_(nullptr),
138 app_list_view_(app_list_view), 149 app_list_view_(app_list_view),
139 focused_view_(FOCUS_SEARCH_BOX), 150 focused_view_(FOCUS_SEARCH_BOX),
140 is_fullscreen_app_list_enabled_(features::IsFullscreenAppListEnabled()) { 151 is_fullscreen_app_list_enabled_(features::IsFullscreenAppListEnabled()) {
141 SetLayoutManager(new views::FillLayout); 152 SetLayoutManager(new views::FillLayout);
142 SetPreferredSize(gfx::Size(is_fullscreen_app_list_enabled_ 153 SetPreferredSize(gfx::Size(is_fullscreen_app_list_enabled_
143 ? kPreferredWidthFullscreen 154 ? kPreferredWidthFullscreen
144 : kPreferredWidth, 155 : kPreferredWidth,
145 kPreferredHeight)); 156 kPreferredHeight));
146 AddChildView(content_container_); 157 AddChildView(content_container_);
147 158
148 SetShadow(GetShadowForZHeight(2)); 159 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>()); 160 content_container_->SetBackground(base::MakeUnique<SearchBoxBackground>());
158 161
159 views::BoxLayout* layout = new views::BoxLayout( 162 views::BoxLayout* layout = new views::BoxLayout(
160 views::BoxLayout::kHorizontal, gfx::Insets(0, kPadding), 163 views::BoxLayout::kHorizontal, gfx::Insets(0, kPadding),
161 kInnerPadding - views::Textfield::kTextPadding); 164 kInnerPadding - views::Textfield::kTextPadding);
162 content_container_->SetLayoutManager(layout); 165 content_container_->SetLayoutManager(layout);
163 layout->set_cross_axis_alignment( 166 layout->set_cross_axis_alignment(
164 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); 167 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
165 layout->set_minimum_cross_axis_size(kPreferredHeight); 168 layout->set_minimum_cross_axis_size(kPreferredHeight);
166 169
167 search_box_->SetBorder(views::NullBorder()); 170 search_box_->SetBorder(views::NullBorder());
168 search_box_->SetTextColor(kSearchTextColor); 171 search_box_->SetTextColor(kSearchTextColor);
169 search_box_->SetBackgroundColor(kSearchBoxBackground); 172 search_box_->SetBackgroundColor(kSearchBoxBackgroundDefault);
170 search_box_->set_placeholder_text_color(kHintTextColor);
171 search_box_->set_controller(this); 173 search_box_->set_controller(this);
172 search_box_->SetTextInputType(ui::TEXT_INPUT_TYPE_SEARCH); 174 search_box_->SetTextInputType(ui::TEXT_INPUT_TYPE_SEARCH);
173 search_box_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF); 175 search_box_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF);
176 if (is_fullscreen_app_list_enabled_) {
177 google_icon_ = new views::ImageView();
178 google_icon_->SetImage(gfx::CreateVectorIcon(
179 kIcGoogleBlackIcon, kGoogleIconSize, kDefaultSearchboxColor));
180 content_container_->AddChildView(google_icon_);
181
182 search_box_->set_placeholder_text_color(kDefaultSearchboxColor);
183 } else {
184 back_button_ = new SearchBoxImageButton(this);
185 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
186 back_button_->SetImage(
187 views::ImageButton::STATE_NORMAL,
188 rb.GetImageSkiaNamed(IDR_APP_LIST_FOLDER_BACK_NORMAL));
189 back_button_->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
190 views::ImageButton::ALIGN_MIDDLE);
191 SetBackButtonLabel(false);
192 content_container_->AddChildView(back_button_);
193
194 search_box_->set_placeholder_text_color(kHintTextColor);
195 }
174 content_container_->AddChildView(search_box_); 196 content_container_->AddChildView(search_box_);
175 layout->SetFlexForView(search_box_, 1); 197 layout->SetFlexForView(search_box_, 1);
176 198
177 view_delegate_->GetSpeechUI()->AddObserver(this); 199 view_delegate_->GetSpeechUI()->AddObserver(this);
178 ModelChanged(); 200 ModelChanged();
179 } 201 }
180 202
181 SearchBoxView::~SearchBoxView() { 203 SearchBoxView::~SearchBoxView() {
182 view_delegate_->GetSpeechUI()->RemoveObserver(this); 204 view_delegate_->GetSpeechUI()->RemoveObserver(this);
183 model_->search_box()->RemoveObserver(this); 205 model_->search_box()->RemoveObserver(this);
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 void SearchBoxView::SpeechRecognitionButtonPropChanged() { 433 void SearchBoxView::SpeechRecognitionButtonPropChanged() {
412 const SearchBoxModel::SpeechButtonProperty* speech_button_prop = 434 const SearchBoxModel::SpeechButtonProperty* speech_button_prop =
413 model_->search_box()->speech_button(); 435 model_->search_box()->speech_button();
414 if (speech_button_prop) { 436 if (speech_button_prop) {
415 if (!speech_button_) { 437 if (!speech_button_) {
416 speech_button_ = new SearchBoxImageButton(this); 438 speech_button_ = new SearchBoxImageButton(this);
417 content_container_->AddChildView(speech_button_); 439 content_container_->AddChildView(speech_button_);
418 } 440 }
419 441
420 speech_button_->SetAccessibleName(speech_button_prop->accessible_name); 442 speech_button_->SetAccessibleName(speech_button_prop->accessible_name);
443 if (is_fullscreen_app_list_enabled_) {
444 speech_button_->SetImage(
445 views::Button::STATE_NORMAL,
446 gfx::CreateVectorIcon(kIcMicBlackIcon, kMicIconSize,
447 kDefaultSearchboxColor));
448 }
449 // TODO(warx): consider removing on_tooltip as it is not accessible due to
450 // the overlap of speech UI.
421 if (view_delegate_->GetSpeechUI()->state() == 451 if (view_delegate_->GetSpeechUI()->state() ==
422 SPEECH_RECOGNITION_HOTWORD_LISTENING) { 452 SPEECH_RECOGNITION_HOTWORD_LISTENING) {
423 speech_button_->SetImage( 453 if (!is_fullscreen_app_list_enabled_) {
424 views::Button::STATE_NORMAL, &speech_button_prop->on_icon); 454 speech_button_->SetImage(views::Button::STATE_NORMAL,
455 &speech_button_prop->on_icon);
456 }
425 speech_button_->SetTooltipText(speech_button_prop->on_tooltip); 457 speech_button_->SetTooltipText(speech_button_prop->on_tooltip);
426 } else { 458 } else {
427 speech_button_->SetImage( 459 if (!is_fullscreen_app_list_enabled_) {
428 views::Button::STATE_NORMAL, &speech_button_prop->off_icon); 460 speech_button_->SetImage(views::Button::STATE_NORMAL,
461 &speech_button_prop->off_icon);
462 }
429 speech_button_->SetTooltipText(speech_button_prop->off_tooltip); 463 speech_button_->SetTooltipText(speech_button_prop->off_tooltip);
430 } 464 }
431 } else { 465 } else {
432 if (speech_button_) { 466 if (speech_button_) {
433 // Deleting a view will detach it from its parent. 467 // Deleting a view will detach it from its parent.
434 delete speech_button_; 468 delete speech_button_;
435 speech_button_ = NULL; 469 speech_button_ = NULL;
436 } 470 }
437 } 471 }
438 Layout(); 472 Layout();
(...skipping 14 matching lines...) Expand all
453 NotifyQueryChanged(); 487 NotifyQueryChanged();
454 } 488 }
455 489
456 void SearchBoxView::OnSpeechRecognitionStateChanged( 490 void SearchBoxView::OnSpeechRecognitionStateChanged(
457 SpeechRecognitionState new_state) { 491 SpeechRecognitionState new_state) {
458 SpeechRecognitionButtonPropChanged(); 492 SpeechRecognitionButtonPropChanged();
459 SchedulePaint(); 493 SchedulePaint();
460 } 494 }
461 495
462 } // namespace app_list 496 } // 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