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

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

Issue 22268009: Move signin status and current user information into AppListModel. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 4 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
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 "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),
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_->search_box()->AddObserver(this);
65 IconChanged();
66 HintTextChanged();
60 } 67 }
61 68
62 SearchBoxView::~SearchBoxView() { 69 SearchBoxView::~SearchBoxView() {
63 if (model_) 70 model_->search_box()->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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 121
131 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) { 122 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) {
132 if (contents_view_) 123 if (contents_view_)
133 return contents_view_->OnMouseWheel(event); 124 return contents_view_->OnMouseWheel(event);
134 125
135 return false; 126 return false;
136 } 127 }
137 128
138 void SearchBoxView::UpdateModel() { 129 void SearchBoxView::UpdateModel() {
139 // Temporarily remove from observer to ignore notifications caused by us. 130 // Temporarily remove from observer to ignore notifications caused by us.
140 model_->RemoveObserver(this); 131 model_->search_box()->RemoveObserver(this);
141 model_->SetText(search_box_->text()); 132 model_->search_box()->SetText(search_box_->text());
142 model_->SetSelectionModel(search_box_->GetSelectionModel()); 133 model_->search_box()->SetSelectionModel(search_box_->GetSelectionModel());
143 model_->AddObserver(this); 134 model_->search_box()->AddObserver(this);
144 } 135 }
145 136
146 void SearchBoxView::NotifyQueryChanged() { 137 void SearchBoxView::NotifyQueryChanged() {
147 DCHECK(delegate_); 138 DCHECK(delegate_);
148 delegate_->QueryChanged(this); 139 delegate_->QueryChanged(this);
149 } 140 }
150 141
151 void SearchBoxView::ContentsChanged(views::Textfield* sender, 142 void SearchBoxView::ContentsChanged(views::Textfield* sender,
152 const base::string16& new_contents) { 143 const base::string16& new_contents) {
153 UpdateModel(); 144 UpdateModel();
154 NotifyQueryChanged(); 145 NotifyQueryChanged();
155 } 146 }
156 147
157 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, 148 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender,
158 const ui::KeyEvent& key_event) { 149 const ui::KeyEvent& key_event) {
159 bool handled = false; 150 bool handled = false;
160 if (contents_view_ && contents_view_->visible()) 151 if (contents_view_ && contents_view_->visible())
161 handled = contents_view_->OnKeyPressed(key_event); 152 handled = contents_view_->OnKeyPressed(key_event);
162 153
163 return handled; 154 return handled;
164 } 155 }
165 156
166 void SearchBoxView::OnMenuButtonClicked(View* source, const gfx::Point& point) { 157 void SearchBoxView::OnMenuButtonClicked(View* source, const gfx::Point& point) {
167 if (!menu_) 158 if (!menu_)
168 menu_.reset(new AppListMenuViews(view_delegate_)); 159 menu_.reset(new AppListMenuViews(view_delegate_, model_));
169 160
170 menu_->RunMenuAt(menu_button_, 161 menu_->RunMenuAt(menu_button_,
171 menu_button_->GetBoundsInScreen().bottom_right()); 162 menu_button_->GetBoundsInScreen().bottom_right());
172 } 163 }
173 164
174 void SearchBoxView::IconChanged() { 165 void SearchBoxView::IconChanged() {
175 icon_view_->SetImage(model_->icon()); 166 icon_view_->SetImage(model_->search_box()->icon());
176 } 167 }
177 168
178 void SearchBoxView::HintTextChanged() { 169 void SearchBoxView::HintTextChanged() {
179 search_box_->set_placeholder_text(model_->hint_text()); 170 search_box_->set_placeholder_text(model_->search_box()->hint_text());
180 } 171 }
181 172
182 void SearchBoxView::SelectionModelChanged() { 173 void SearchBoxView::SelectionModelChanged() {
183 search_box_->SelectSelectionModel(model_->selection_model()); 174 search_box_->SelectSelectionModel(model_->search_box()->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_->search_box()->text());
188 } 179 }
189 180
190 } // namespace app_list 181 } // namespace app_list
OLDNEW
« ui/app_list/views/search_box_view.h ('K') | « 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