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 "grit/ui_resources.h" | 9 #include "grit/ui_resources.h" |
| 10 #include "ui/app_list/app_list_model.h" |
10 #include "ui/app_list/search_box_model.h" | 11 #include "ui/app_list/search_box_model.h" |
11 #include "ui/app_list/search_box_view_delegate.h" | 12 #include "ui/app_list/search_box_view_delegate.h" |
12 #include "ui/app_list/views/app_list_menu_views.h" | 13 #include "ui/app_list/views/app_list_menu_views.h" |
13 #include "ui/base/events/event.h" | 14 #include "ui/base/events/event.h" |
14 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
15 #include "ui/views/controls/button/menu_button.h" | 16 #include "ui/views/controls/button/menu_button.h" |
16 #include "ui/views/controls/image_view.h" | 17 #include "ui/views/controls/image_view.h" |
17 #include "ui/views/controls/textfield/textfield.h" | 18 #include "ui/views/controls/textfield/textfield.h" |
18 | 19 |
19 namespace app_list { | 20 namespace app_list { |
20 | 21 |
21 namespace { | 22 namespace { |
22 | 23 |
23 const int kPadding = 14; | 24 const int kPadding = 14; |
24 const int kIconDimension = 32; | 25 const int kIconDimension = 32; |
25 const int kPreferredWidth = 360; | 26 const int kPreferredWidth = 360; |
26 const int kPreferredHeight = 48; | 27 const int kPreferredHeight = 48; |
27 const int kMenuButtonDimension = 29; | 28 const int kMenuButtonDimension = 29; |
28 | 29 |
29 const SkColor kHintTextColor = SkColorSetRGB(0xA0, 0xA0, 0xA0); | 30 const SkColor kHintTextColor = SkColorSetRGB(0xA0, 0xA0, 0xA0); |
30 | 31 |
31 } // namespace | 32 } // namespace |
32 | 33 |
33 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate, | 34 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate, |
34 AppListViewDelegate* view_delegate) | 35 AppListViewDelegate* view_delegate, |
| 36 AppListModel* model) |
35 : delegate_(delegate), | 37 : delegate_(delegate), |
36 view_delegate_(view_delegate), | 38 view_delegate_(view_delegate), |
37 model_(NULL), | 39 model_(model->search_box()), |
38 icon_view_(new views::ImageView), | 40 icon_view_(new views::ImageView), |
39 search_box_(new views::Textfield), | 41 search_box_(new views::Textfield), |
40 contents_view_(NULL) { | 42 contents_view_(NULL) { |
| 43 DCHECK(model_); |
41 AddChildView(icon_view_); | 44 AddChildView(icon_view_); |
42 | 45 |
43 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 46 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
44 | 47 |
45 #if !defined(OS_CHROMEOS) | 48 #if !defined(OS_CHROMEOS) |
46 menu_button_ = new views::MenuButton(NULL, base::string16(), this, false); | 49 menu_button_ = new views::MenuButton(NULL, base::string16(), this, false); |
47 menu_button_->set_border(NULL); | 50 menu_button_->set_border(NULL); |
48 menu_button_->SetIcon(*rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_NORMAL)); | 51 menu_button_->SetIcon(*rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_NORMAL)); |
49 menu_button_->SetHoverIcon(*rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_HOVER)); | 52 menu_button_->SetHoverIcon(*rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_HOVER)); |
50 menu_button_->SetPushedIcon(*rb.GetImageSkiaNamed( | 53 menu_button_->SetPushedIcon(*rb.GetImageSkiaNamed( |
51 IDR_APP_LIST_TOOLS_PRESSED)); | 54 IDR_APP_LIST_TOOLS_PRESSED)); |
52 AddChildView(menu_button_); | 55 AddChildView(menu_button_); |
53 #endif | 56 #endif |
54 | 57 |
55 search_box_->RemoveBorder(); | 58 search_box_->RemoveBorder(); |
56 search_box_->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); | 59 search_box_->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); |
57 search_box_->set_placeholder_text_color(kHintTextColor); | 60 search_box_->set_placeholder_text_color(kHintTextColor); |
58 search_box_->SetController(this); | 61 search_box_->SetController(this); |
59 AddChildView(search_box_); | 62 AddChildView(search_box_); |
| 63 |
| 64 model_->AddObserver(this); |
| 65 IconChanged(); |
| 66 HintTextChanged(); |
60 } | 67 } |
61 | 68 |
62 SearchBoxView::~SearchBoxView() { | 69 SearchBoxView::~SearchBoxView() { |
63 if (model_) | 70 model_->RemoveObserver(this); |
64 model_->RemoveObserver(this); | |
65 } | |
66 | |
67 void SearchBoxView::SetModel(SearchBoxModel* model) { | |
68 if (model_ == model) | |
69 return; | |
70 | |
71 if (model_) | |
72 model_->RemoveObserver(this); | |
73 | |
74 model_ = model; | |
75 if (model_) { | |
76 model_->AddObserver(this); | |
77 IconChanged(); | |
78 HintTextChanged(); | |
79 } | |
80 } | 71 } |
81 | 72 |
82 bool SearchBoxView::HasSearch() const { | 73 bool SearchBoxView::HasSearch() const { |
83 return !search_box_->text().empty(); | 74 return !search_box_->text().empty(); |
84 } | 75 } |
85 | 76 |
86 void SearchBoxView::ClearSearch() { | 77 void SearchBoxView::ClearSearch() { |
87 search_box_->SetText(base::string16()); | 78 search_box_->SetText(base::string16()); |
88 // Updates model and fires query changed manually because SetText() above | 79 // Updates model and fires query changed manually because SetText() above |
89 // does not generate ContentsChanged() notification. | 80 // does not generate ContentsChanged() notification. |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 | 172 |
182 void SearchBoxView::SelectionModelChanged() { | 173 void SearchBoxView::SelectionModelChanged() { |
183 search_box_->SelectSelectionModel(model_->selection_model()); | 174 search_box_->SelectSelectionModel(model_->selection_model()); |
184 } | 175 } |
185 | 176 |
186 void SearchBoxView::TextChanged() { | 177 void SearchBoxView::TextChanged() { |
187 search_box_->SetText(model_->text()); | 178 search_box_->SetText(model_->text()); |
188 } | 179 } |
189 | 180 |
190 } // namespace app_list | 181 } // namespace app_list |
OLD | NEW |