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

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

Issue 2348183002: App list: Remove search box menu (dead code). (Closed)
Patch Set: Rebase. Created 4 years, 3 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_model.h" 13 #include "ui/app_list/app_list_model.h"
14 #include "ui/app_list/app_list_switches.h" 14 #include "ui/app_list/app_list_switches.h"
15 #include "ui/app_list/app_list_view_delegate.h" 15 #include "ui/app_list/app_list_view_delegate.h"
16 #include "ui/app_list/resources/grit/app_list_resources.h" 16 #include "ui/app_list/resources/grit/app_list_resources.h"
17 #include "ui/app_list/search_box_model.h" 17 #include "ui/app_list/search_box_model.h"
18 #include "ui/app_list/speech_ui_model.h" 18 #include "ui/app_list/speech_ui_model.h"
19 #include "ui/app_list/views/app_list_menu_views.h"
20 #include "ui/app_list/views/contents_view.h" 19 #include "ui/app_list/views/contents_view.h"
21 #include "ui/app_list/views/search_box_view_delegate.h" 20 #include "ui/app_list/views/search_box_view_delegate.h"
22 #include "ui/base/ime/text_input_flags.h" 21 #include "ui/base/ime/text_input_flags.h"
23 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/base/resource/resource_bundle.h" 23 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/events/event.h" 24 #include "ui/events/event.h"
26 #include "ui/gfx/canvas.h" 25 #include "ui/gfx/canvas.h"
27 #include "ui/gfx/shadow_value.h" 26 #include "ui/gfx/shadow_value.h"
28 #include "ui/strings/grit/ui_strings.h" 27 #include "ui/strings/grit/ui_strings.h"
28 #include "ui/views/background.h"
29 #include "ui/views/border.h" 29 #include "ui/views/border.h"
30 #include "ui/views/controls/button/image_button.h" 30 #include "ui/views/controls/button/image_button.h"
31 #include "ui/views/controls/button/menu_button.h"
32 #include "ui/views/controls/image_view.h" 31 #include "ui/views/controls/image_view.h"
33 #include "ui/views/controls/textfield/textfield.h" 32 #include "ui/views/controls/textfield/textfield.h"
34 #include "ui/views/layout/box_layout.h" 33 #include "ui/views/layout/box_layout.h"
35 #include "ui/views/layout/fill_layout.h" 34 #include "ui/views/layout/fill_layout.h"
36 #include "ui/views/shadow_border.h" 35 #include "ui/views/shadow_border.h"
37 36
38 namespace app_list { 37 namespace app_list {
39 38
40 namespace { 39 namespace {
41 40
42 const int kPadding = 16; 41 const int kPadding = 16;
43 const int kInnerPadding = 24; 42 const int kInnerPadding = 24;
44 const int kPreferredWidth = 360; 43 const int kPreferredWidth = 360;
45 const int kPreferredHeight = 48; 44 const int kPreferredHeight = 48;
46 45
47 const SkColor kHintTextColor = SkColorSetRGB(0xA0, 0xA0, 0xA0); 46 const SkColor kHintTextColor = SkColorSetRGB(0xA0, 0xA0, 0xA0);
48 47
49 // Menu offset relative to the bottom-right corner of the menu button.
50 const int kMenuYOffsetFromButton = -4;
51 const int kMenuXOffsetFromButton = -7;
52
53 const int kBackgroundBorderCornerRadius = 2; 48 const int kBackgroundBorderCornerRadius = 2;
54 49
55 // A background that paints a solid white rounded rect with a thin grey border. 50 // A background that paints a solid white rounded rect with a thin grey border.
56 class SearchBoxBackground : public views::Background { 51 class SearchBoxBackground : public views::Background {
57 public: 52 public:
58 SearchBoxBackground() {} 53 SearchBoxBackground() {}
59 ~SearchBoxBackground() override {} 54 ~SearchBoxBackground() override {}
60 55
61 private: 56 private:
62 // views::Background overrides: 57 // views::Background overrides:
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 }; 111 };
117 112
118 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate, 113 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate,
119 AppListViewDelegate* view_delegate) 114 AppListViewDelegate* view_delegate)
120 : delegate_(delegate), 115 : delegate_(delegate),
121 view_delegate_(view_delegate), 116 view_delegate_(view_delegate),
122 model_(NULL), 117 model_(NULL),
123 content_container_(new views::View), 118 content_container_(new views::View),
124 back_button_(NULL), 119 back_button_(NULL),
125 speech_button_(NULL), 120 speech_button_(NULL),
126 menu_button_(NULL),
127 search_box_(new views::Textfield), 121 search_box_(new views::Textfield),
128 contents_view_(NULL), 122 contents_view_(NULL),
129 focused_view_(FOCUS_SEARCH_BOX) { 123 focused_view_(FOCUS_SEARCH_BOX) {
130 SetLayoutManager(new views::FillLayout); 124 SetLayoutManager(new views::FillLayout);
131 AddChildView(content_container_); 125 AddChildView(content_container_);
132 126
133 SetShadow(GetShadowForZHeight(2)); 127 SetShadow(GetShadowForZHeight(2));
134 back_button_ = new SearchBoxImageButton(this); 128 back_button_ = new SearchBoxImageButton(this);
135 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 129 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
136 back_button_->SetImage(views::ImageButton::STATE_NORMAL, 130 back_button_->SetImage(views::ImageButton::STATE_NORMAL,
(...skipping 15 matching lines...) Expand all
152 search_box_->SetBorder(views::Border::NullBorder()); 146 search_box_->SetBorder(views::Border::NullBorder());
153 search_box_->SetTextColor(kSearchTextColor); 147 search_box_->SetTextColor(kSearchTextColor);
154 search_box_->SetBackgroundColor(kSearchBoxBackground); 148 search_box_->SetBackgroundColor(kSearchBoxBackground);
155 search_box_->set_placeholder_text_color(kHintTextColor); 149 search_box_->set_placeholder_text_color(kHintTextColor);
156 search_box_->set_controller(this); 150 search_box_->set_controller(this);
157 search_box_->SetTextInputType(ui::TEXT_INPUT_TYPE_SEARCH); 151 search_box_->SetTextInputType(ui::TEXT_INPUT_TYPE_SEARCH);
158 search_box_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF); 152 search_box_->SetTextInputFlags(ui::TEXT_INPUT_FLAG_AUTOCORRECT_OFF);
159 content_container_->AddChildView(search_box_); 153 content_container_->AddChildView(search_box_);
160 layout->SetFlexForView(search_box_, 1); 154 layout->SetFlexForView(search_box_, 1);
161 155
162 #if !defined(OS_CHROMEOS)
163 // TODO(mgiuca): Remove the menu (this code doesn't run on non-Chrome-OS so
164 // the menu will never be created). https://crbug.com/600915.
165 menu_button_ = new views::MenuButton(base::string16(), this, false);
166 menu_button_->SetBorder(views::Border::NullBorder());
167 menu_button_->SetImage(views::Button::STATE_NORMAL,
168 *rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_NORMAL));
169 menu_button_->SetImage(views::Button::STATE_HOVERED,
170 *rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_HOVER));
171 menu_button_->SetImage(views::Button::STATE_PRESSED,
172 *rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_PRESSED));
173 content_container_->AddChildView(menu_button_);
174 #endif
175
176 view_delegate_->GetSpeechUI()->AddObserver(this); 156 view_delegate_->GetSpeechUI()->AddObserver(this);
177 ModelChanged(); 157 ModelChanged();
178 } 158 }
179 159
180 SearchBoxView::~SearchBoxView() { 160 SearchBoxView::~SearchBoxView() {
181 view_delegate_->GetSpeechUI()->RemoveObserver(this); 161 view_delegate_->GetSpeechUI()->RemoveObserver(this);
182 model_->search_box()->RemoveObserver(this); 162 model_->search_box()->RemoveObserver(this);
183 } 163 }
184 164
185 void SearchBoxView::ModelChanged() { 165 void SearchBoxView::ModelChanged() {
(...skipping 13 matching lines...) Expand all
199 179
200 void SearchBoxView::ClearSearch() { 180 void SearchBoxView::ClearSearch() {
201 search_box_->SetText(base::string16()); 181 search_box_->SetText(base::string16());
202 view_delegate_->AutoLaunchCanceled(); 182 view_delegate_->AutoLaunchCanceled();
203 // Updates model and fires query changed manually because SetText() above 183 // Updates model and fires query changed manually because SetText() above
204 // does not generate ContentsChanged() notification. 184 // does not generate ContentsChanged() notification.
205 UpdateModel(); 185 UpdateModel();
206 NotifyQueryChanged(); 186 NotifyQueryChanged();
207 } 187 }
208 188
209 void SearchBoxView::InvalidateMenu() {
210 menu_.reset();
211 }
212
213 void SearchBoxView::SetShadow(const gfx::ShadowValue& shadow) { 189 void SearchBoxView::SetShadow(const gfx::ShadowValue& shadow) {
214 SetBorder(base::MakeUnique<views::ShadowBorder>(shadow)); 190 SetBorder(base::MakeUnique<views::ShadowBorder>(shadow));
215 Layout(); 191 Layout();
216 } 192 }
217 193
218 gfx::Rect SearchBoxView::GetViewBoundsForSearchBoxContentsBounds( 194 gfx::Rect SearchBoxView::GetViewBoundsForSearchBoxContentsBounds(
219 const gfx::Rect& rect) const { 195 const gfx::Rect& rect) const {
220 gfx::Rect view_bounds = rect; 196 gfx::Rect view_bounds = rect;
221 view_bounds.Inset(-GetInsets()); 197 view_bounds.Inset(-GetInsets());
222 return view_bounds; 198 return view_bounds;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
314 290
315 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) { 291 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) {
316 if (contents_view_) 292 if (contents_view_)
317 return contents_view_->OnMouseWheel(event); 293 return contents_view_->OnMouseWheel(event);
318 294
319 return false; 295 return false;
320 } 296 }
321 297
322 void SearchBoxView::OnEnabledChanged() { 298 void SearchBoxView::OnEnabledChanged() {
323 search_box_->SetEnabled(enabled()); 299 search_box_->SetEnabled(enabled());
324 if (menu_button_)
325 menu_button_->SetEnabled(enabled());
326 if (speech_button_) 300 if (speech_button_)
327 speech_button_->SetEnabled(enabled()); 301 speech_button_->SetEnabled(enabled());
328 } 302 }
329 303
330 void SearchBoxView::UpdateModel() { 304 void SearchBoxView::UpdateModel() {
331 // Temporarily remove from observer to ignore notifications caused by us. 305 // Temporarily remove from observer to ignore notifications caused by us.
332 model_->search_box()->RemoveObserver(this); 306 model_->search_box()->RemoveObserver(this);
333 model_->search_box()->SetText(search_box_->text()); 307 model_->search_box()->SetText(search_box_->text());
334 model_->search_box()->SetSelectionModel(search_box_->GetSelectionModel()); 308 model_->search_box()->SetSelectionModel(search_box_->GetSelectionModel());
335 model_->search_box()->AddObserver(this); 309 model_->search_box()->AddObserver(this);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 void SearchBoxView::ButtonPressed(views::Button* sender, 375 void SearchBoxView::ButtonPressed(views::Button* sender,
402 const ui::Event& event) { 376 const ui::Event& event) {
403 if (back_button_ && sender == back_button_) 377 if (back_button_ && sender == back_button_)
404 delegate_->BackButtonPressed(); 378 delegate_->BackButtonPressed();
405 else if (speech_button_ && sender == speech_button_) 379 else if (speech_button_ && sender == speech_button_)
406 view_delegate_->StartSpeechRecognition(); 380 view_delegate_->StartSpeechRecognition();
407 else 381 else
408 NOTREACHED(); 382 NOTREACHED();
409 } 383 }
410 384
411 void SearchBoxView::OnMenuButtonClicked(views::MenuButton* source,
412 const gfx::Point& point,
413 const ui::Event* event) {
414 if (!menu_)
415 menu_.reset(new AppListMenuViews(view_delegate_));
416
417 const gfx::Point menu_location =
418 menu_button_->GetBoundsInScreen().bottom_right() +
419 gfx::Vector2d(kMenuXOffsetFromButton, kMenuYOffsetFromButton);
420 menu_->RunMenuAt(menu_button_, menu_location);
421 }
422
423 void SearchBoxView::SpeechRecognitionButtonPropChanged() { 385 void SearchBoxView::SpeechRecognitionButtonPropChanged() {
424 const SearchBoxModel::SpeechButtonProperty* speech_button_prop = 386 const SearchBoxModel::SpeechButtonProperty* speech_button_prop =
425 model_->search_box()->speech_button(); 387 model_->search_box()->speech_button();
426 if (speech_button_prop) { 388 if (speech_button_prop) {
427 if (!speech_button_) { 389 if (!speech_button_) {
428 speech_button_ = new SearchBoxImageButton(this); 390 speech_button_ = new SearchBoxImageButton(this);
429 content_container_->AddChildView(speech_button_); 391 content_container_->AddChildView(speech_button_);
430 } 392 }
431 393
432 speech_button_->SetAccessibleName(speech_button_prop->accessible_name); 394 speech_button_->SetAccessibleName(speech_button_prop->accessible_name);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 NotifyQueryChanged(); 427 NotifyQueryChanged();
466 } 428 }
467 429
468 void SearchBoxView::OnSpeechRecognitionStateChanged( 430 void SearchBoxView::OnSpeechRecognitionStateChanged(
469 SpeechRecognitionState new_state) { 431 SpeechRecognitionState new_state) {
470 SpeechRecognitionButtonPropChanged(); 432 SpeechRecognitionButtonPropChanged();
471 SchedulePaint(); 433 SchedulePaint();
472 } 434 }
473 435
474 } // namespace app_list 436 } // 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