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

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: small fixups 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 {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 55
55 search_box_->RemoveBorder(); 56 search_box_->RemoveBorder();
56 search_box_->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); 57 search_box_->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont));
57 search_box_->set_placeholder_text_color(kHintTextColor); 58 search_box_->set_placeholder_text_color(kHintTextColor);
58 search_box_->SetController(this); 59 search_box_->SetController(this);
59 AddChildView(search_box_); 60 AddChildView(search_box_);
60 } 61 }
61 62
62 SearchBoxView::~SearchBoxView() { 63 SearchBoxView::~SearchBoxView() {
63 if (model_) 64 if (model_)
64 model_->RemoveObserver(this); 65 model_->search_box()->RemoveObserver(this);
65 } 66 }
66 67
67 void SearchBoxView::SetModel(SearchBoxModel* model) { 68 void SearchBoxView::SetModel(AppListModel* model) {
68 if (model_ == model) 69 if (model_ == model)
69 return; 70 return;
70 71
71 if (model_) 72 if (model_)
72 model_->RemoveObserver(this); 73 model_->search_box()->RemoveObserver(this);
73 74
74 model_ = model; 75 model_ = model;
75 if (model_) { 76 if (model_) {
76 model_->AddObserver(this); 77 model_->search_box()->AddObserver(this);
77 IconChanged(); 78 IconChanged();
78 HintTextChanged(); 79 HintTextChanged();
79 } 80 }
80 } 81 }
81 82
82 bool SearchBoxView::HasSearch() const { 83 bool SearchBoxView::HasSearch() const {
83 return !search_box_->text().empty(); 84 return !search_box_->text().empty();
84 } 85 }
85 86
86 void SearchBoxView::ClearSearch() { 87 void SearchBoxView::ClearSearch() {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 131
131 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) { 132 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) {
132 if (contents_view_) 133 if (contents_view_)
133 return contents_view_->OnMouseWheel(event); 134 return contents_view_->OnMouseWheel(event);
134 135
135 return false; 136 return false;
136 } 137 }
137 138
138 void SearchBoxView::UpdateModel() { 139 void SearchBoxView::UpdateModel() {
139 // Temporarily remove from observer to ignore notifications caused by us. 140 // Temporarily remove from observer to ignore notifications caused by us.
140 model_->RemoveObserver(this); 141 model_->search_box()->RemoveObserver(this);
141 model_->SetText(search_box_->text()); 142 model_->search_box()->SetText(search_box_->text());
142 model_->SetSelectionModel(search_box_->GetSelectionModel()); 143 model_->search_box()->SetSelectionModel(search_box_->GetSelectionModel());
143 model_->AddObserver(this); 144 model_->search_box()->AddObserver(this);
144 } 145 }
145 146
146 void SearchBoxView::NotifyQueryChanged() { 147 void SearchBoxView::NotifyQueryChanged() {
147 DCHECK(delegate_); 148 DCHECK(delegate_);
148 delegate_->QueryChanged(this); 149 delegate_->QueryChanged(this);
149 } 150 }
150 151
151 void SearchBoxView::ContentsChanged(views::Textfield* sender, 152 void SearchBoxView::ContentsChanged(views::Textfield* sender,
152 const base::string16& new_contents) { 153 const base::string16& new_contents) {
153 UpdateModel(); 154 UpdateModel();
154 NotifyQueryChanged(); 155 NotifyQueryChanged();
155 } 156 }
156 157
157 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, 158 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender,
158 const ui::KeyEvent& key_event) { 159 const ui::KeyEvent& key_event) {
159 bool handled = false; 160 bool handled = false;
160 if (contents_view_ && contents_view_->visible()) 161 if (contents_view_ && contents_view_->visible())
161 handled = contents_view_->OnKeyPressed(key_event); 162 handled = contents_view_->OnKeyPressed(key_event);
162 163
163 return handled; 164 return handled;
164 } 165 }
165 166
166 void SearchBoxView::OnMenuButtonClicked(View* source, const gfx::Point& point) { 167 void SearchBoxView::OnMenuButtonClicked(View* source, const gfx::Point& point) {
167 if (!menu_) 168 if (!menu_)
168 menu_.reset(new AppListMenuViews(view_delegate_)); 169 menu_.reset(new AppListMenuViews(view_delegate_, model_));
169 170
170 menu_->RunMenuAt(menu_button_, 171 menu_->RunMenuAt(menu_button_,
171 menu_button_->GetBoundsInScreen().bottom_right()); 172 menu_button_->GetBoundsInScreen().bottom_right());
172 } 173 }
173 174
174 void SearchBoxView::IconChanged() { 175 void SearchBoxView::IconChanged() {
175 icon_view_->SetImage(model_->icon()); 176 icon_view_->SetImage(model_->search_box()->icon());
176 } 177 }
177 178
178 void SearchBoxView::HintTextChanged() { 179 void SearchBoxView::HintTextChanged() {
179 search_box_->set_placeholder_text(model_->hint_text()); 180 search_box_->set_placeholder_text(model_->search_box()->hint_text());
180 } 181 }
181 182
182 void SearchBoxView::SelectionModelChanged() { 183 void SearchBoxView::SelectionModelChanged() {
183 search_box_->SelectSelectionModel(model_->selection_model()); 184 search_box_->SelectSelectionModel(model_->search_box()->selection_model());
184 } 185 }
185 186
186 void SearchBoxView::TextChanged() { 187 void SearchBoxView::TextChanged() {
187 search_box_->SetText(model_->text()); 188 search_box_->SetText(model_->search_box()->text());
188 } 189 }
189 190
190 } // namespace app_list 191 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698