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

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

Issue 20656002: Add profile selector menu to app list. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove junk from list_model.h 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 if (model_)
tapted 2013/08/05 03:01:39 This `if` should be redundant now -- model_ is alw
calamity 2013/08/08 04:52:12 Done.
64 model_->RemoveObserver(this); 71 model_->search_box()->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 } 72 }
81 73
82 bool SearchBoxView::HasSearch() const { 74 bool SearchBoxView::HasSearch() const {
83 return !search_box_->text().empty(); 75 return !search_box_->text().empty();
84 } 76 }
85 77
86 void SearchBoxView::ClearSearch() { 78 void SearchBoxView::ClearSearch() {
87 search_box_->SetText(base::string16()); 79 search_box_->SetText(base::string16());
88 // Updates model and fires query changed manually because SetText() above 80 // Updates model and fires query changed manually because SetText() above
89 // does not generate ContentsChanged() notification. 81 // does not generate ContentsChanged() notification.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 122
131 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) { 123 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) {
132 if (contents_view_) 124 if (contents_view_)
133 return contents_view_->OnMouseWheel(event); 125 return contents_view_->OnMouseWheel(event);
134 126
135 return false; 127 return false;
136 } 128 }
137 129
138 void SearchBoxView::UpdateModel() { 130 void SearchBoxView::UpdateModel() {
139 // Temporarily remove from observer to ignore notifications caused by us. 131 // Temporarily remove from observer to ignore notifications caused by us.
140 model_->RemoveObserver(this); 132 model_->search_box()->RemoveObserver(this);
141 model_->SetText(search_box_->text()); 133 model_->search_box()->SetText(search_box_->text());
142 model_->SetSelectionModel(search_box_->GetSelectionModel()); 134 model_->search_box()->SetSelectionModel(search_box_->GetSelectionModel());
143 model_->AddObserver(this); 135 model_->search_box()->AddObserver(this);
144 } 136 }
145 137
146 void SearchBoxView::NotifyQueryChanged() { 138 void SearchBoxView::NotifyQueryChanged() {
147 DCHECK(delegate_); 139 DCHECK(delegate_);
148 delegate_->QueryChanged(this); 140 delegate_->QueryChanged(this);
149 } 141 }
150 142
151 void SearchBoxView::ContentsChanged(views::Textfield* sender, 143 void SearchBoxView::ContentsChanged(views::Textfield* sender,
152 const base::string16& new_contents) { 144 const base::string16& new_contents) {
153 UpdateModel(); 145 UpdateModel();
154 NotifyQueryChanged(); 146 NotifyQueryChanged();
155 } 147 }
156 148
157 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, 149 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender,
158 const ui::KeyEvent& key_event) { 150 const ui::KeyEvent& key_event) {
159 bool handled = false; 151 bool handled = false;
160 if (contents_view_ && contents_view_->visible()) 152 if (contents_view_ && contents_view_->visible())
161 handled = contents_view_->OnKeyPressed(key_event); 153 handled = contents_view_->OnKeyPressed(key_event);
162 154
163 return handled; 155 return handled;
164 } 156 }
165 157
166 void SearchBoxView::OnMenuButtonClicked(View* source, const gfx::Point& point) { 158 void SearchBoxView::OnMenuButtonClicked(View* source, const gfx::Point& point) {
167 if (!menu_) 159 if (!menu_)
168 menu_.reset(new AppListMenuViews(view_delegate_)); 160 menu_.reset(new AppListMenuViews(view_delegate_, model_));
169 161
170 menu_->RunMenuAt(menu_button_, 162 menu_->RunMenuAt(menu_button_,
171 menu_button_->GetBoundsInScreen().bottom_right()); 163 menu_button_->GetBoundsInScreen().bottom_right());
172 } 164 }
173 165
174 void SearchBoxView::IconChanged() { 166 void SearchBoxView::IconChanged() {
175 icon_view_->SetImage(model_->icon()); 167 icon_view_->SetImage(model_->search_box()->icon());
176 } 168 }
177 169
178 void SearchBoxView::HintTextChanged() { 170 void SearchBoxView::HintTextChanged() {
179 search_box_->set_placeholder_text(model_->hint_text()); 171 search_box_->set_placeholder_text(model_->search_box()->hint_text());
180 } 172 }
181 173
182 void SearchBoxView::SelectionModelChanged() { 174 void SearchBoxView::SelectionModelChanged() {
183 search_box_->SelectSelectionModel(model_->selection_model()); 175 search_box_->SelectSelectionModel(model_->search_box()->selection_model());
184 } 176 }
185 177
186 void SearchBoxView::TextChanged() { 178 void SearchBoxView::TextChanged() {
187 search_box_->SetText(model_->text()); 179 search_box_->SetText(model_->search_box()->text());
188 } 180 }
189 181
190 } // namespace app_list 182 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698