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

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: rebase 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
« 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 "grit/ui_resources.h" 9 #include "grit/ui_resources.h"
10 #include "ui/app_list/app_list_model.h" 10 #include "ui/app_list/app_list_model.h"
(...skipping 22 matching lines...) Expand all
33 const int kMenuYOffsetFromButton = -4; 33 const int kMenuYOffsetFromButton = -4;
34 const int kMenuXOffsetFromButton = -7; 34 const int kMenuXOffsetFromButton = -7;
35 35
36 } // namespace 36 } // namespace
37 37
38 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate, 38 SearchBoxView::SearchBoxView(SearchBoxViewDelegate* delegate,
39 AppListViewDelegate* view_delegate, 39 AppListViewDelegate* view_delegate,
40 AppListModel* model) 40 AppListModel* model)
41 : delegate_(delegate), 41 : delegate_(delegate),
42 view_delegate_(view_delegate), 42 view_delegate_(view_delegate),
43 model_(model->search_box()), 43 model_(model),
44 icon_view_(new views::ImageView), 44 icon_view_(new views::ImageView),
45 search_box_(new views::Textfield), 45 search_box_(new views::Textfield),
46 contents_view_(NULL) { 46 contents_view_(NULL) {
47 DCHECK(model_); 47 DCHECK(model_);
48 AddChildView(icon_view_); 48 AddChildView(icon_view_);
49 49
50 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 50 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
51 51
52 #if !defined(OS_CHROMEOS) 52 #if !defined(OS_CHROMEOS)
53 menu_button_ = new views::MenuButton(NULL, base::string16(), this, false); 53 menu_button_ = new views::MenuButton(NULL, base::string16(), this, false);
54 menu_button_->set_border(NULL); 54 menu_button_->set_border(NULL);
55 menu_button_->SetIcon(*rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_NORMAL)); 55 menu_button_->SetIcon(*rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_NORMAL));
56 menu_button_->SetHoverIcon(*rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_HOVER)); 56 menu_button_->SetHoverIcon(*rb.GetImageSkiaNamed(IDR_APP_LIST_TOOLS_HOVER));
57 menu_button_->SetPushedIcon(*rb.GetImageSkiaNamed( 57 menu_button_->SetPushedIcon(*rb.GetImageSkiaNamed(
58 IDR_APP_LIST_TOOLS_PRESSED)); 58 IDR_APP_LIST_TOOLS_PRESSED));
59 AddChildView(menu_button_); 59 AddChildView(menu_button_);
60 #endif 60 #endif
61 61
62 search_box_->RemoveBorder(); 62 search_box_->RemoveBorder();
63 search_box_->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont)); 63 search_box_->SetFont(rb.GetFont(ui::ResourceBundle::MediumFont));
64 search_box_->set_placeholder_text_color(kHintTextColor); 64 search_box_->set_placeholder_text_color(kHintTextColor);
65 search_box_->SetController(this); 65 search_box_->SetController(this);
66 AddChildView(search_box_); 66 AddChildView(search_box_);
67 67
68 model_->AddObserver(this); 68 model_->search_box()->AddObserver(this);
69 IconChanged(); 69 IconChanged();
70 HintTextChanged(); 70 HintTextChanged();
71 } 71 }
72 72
73 SearchBoxView::~SearchBoxView() { 73 SearchBoxView::~SearchBoxView() {
74 model_->RemoveObserver(this); 74 model_->search_box()->RemoveObserver(this);
75 } 75 }
76 76
77 bool SearchBoxView::HasSearch() const { 77 bool SearchBoxView::HasSearch() const {
78 return !search_box_->text().empty(); 78 return !search_box_->text().empty();
79 } 79 }
80 80
81 void SearchBoxView::ClearSearch() { 81 void SearchBoxView::ClearSearch() {
82 search_box_->SetText(base::string16()); 82 search_box_->SetText(base::string16());
83 // Updates model and fires query changed manually because SetText() above 83 // Updates model and fires query changed manually because SetText() above
84 // does not generate ContentsChanged() notification. 84 // does not generate ContentsChanged() notification.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 125
126 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) { 126 bool SearchBoxView::OnMouseWheel(const ui::MouseWheelEvent& event) {
127 if (contents_view_) 127 if (contents_view_)
128 return contents_view_->OnMouseWheel(event); 128 return contents_view_->OnMouseWheel(event);
129 129
130 return false; 130 return false;
131 } 131 }
132 132
133 void SearchBoxView::UpdateModel() { 133 void SearchBoxView::UpdateModel() {
134 // Temporarily remove from observer to ignore notifications caused by us. 134 // Temporarily remove from observer to ignore notifications caused by us.
135 model_->RemoveObserver(this); 135 model_->search_box()->RemoveObserver(this);
136 model_->SetText(search_box_->text()); 136 model_->search_box()->SetText(search_box_->text());
137 model_->SetSelectionModel(search_box_->GetSelectionModel()); 137 model_->search_box()->SetSelectionModel(search_box_->GetSelectionModel());
138 model_->AddObserver(this); 138 model_->search_box()->AddObserver(this);
139 } 139 }
140 140
141 void SearchBoxView::NotifyQueryChanged() { 141 void SearchBoxView::NotifyQueryChanged() {
142 DCHECK(delegate_); 142 DCHECK(delegate_);
143 delegate_->QueryChanged(this); 143 delegate_->QueryChanged(this);
144 } 144 }
145 145
146 void SearchBoxView::ContentsChanged(views::Textfield* sender, 146 void SearchBoxView::ContentsChanged(views::Textfield* sender,
147 const base::string16& new_contents) { 147 const base::string16& new_contents) {
148 UpdateModel(); 148 UpdateModel();
149 NotifyQueryChanged(); 149 NotifyQueryChanged();
150 } 150 }
151 151
152 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender, 152 bool SearchBoxView::HandleKeyEvent(views::Textfield* sender,
153 const ui::KeyEvent& key_event) { 153 const ui::KeyEvent& key_event) {
154 bool handled = false; 154 bool handled = false;
155 if (contents_view_ && contents_view_->visible()) 155 if (contents_view_ && contents_view_->visible())
156 handled = contents_view_->OnKeyPressed(key_event); 156 handled = contents_view_->OnKeyPressed(key_event);
157 157
158 return handled; 158 return handled;
159 } 159 }
160 160
161 void SearchBoxView::OnMenuButtonClicked(View* source, const gfx::Point& point) { 161 void SearchBoxView::OnMenuButtonClicked(View* source, const gfx::Point& point) {
162 if (!menu_) 162 if (!menu_)
163 menu_.reset(new AppListMenuViews(view_delegate_)); 163 menu_.reset(new AppListMenuViews(view_delegate_, model_));
164 164
165 const gfx::Point menu_location = 165 const gfx::Point menu_location =
166 menu_button_->GetBoundsInScreen().bottom_right() + 166 menu_button_->GetBoundsInScreen().bottom_right() +
167 gfx::Vector2d(kMenuXOffsetFromButton, kMenuYOffsetFromButton); 167 gfx::Vector2d(kMenuXOffsetFromButton, kMenuYOffsetFromButton);
168 menu_->RunMenuAt(menu_button_, menu_location); 168 menu_->RunMenuAt(menu_button_, menu_location);
169 } 169 }
170 170
171 void SearchBoxView::IconChanged() { 171 void SearchBoxView::IconChanged() {
172 icon_view_->SetImage(model_->icon()); 172 icon_view_->SetImage(model_->search_box()->icon());
173 } 173 }
174 174
175 void SearchBoxView::HintTextChanged() { 175 void SearchBoxView::HintTextChanged() {
176 search_box_->set_placeholder_text(model_->hint_text()); 176 search_box_->set_placeholder_text(model_->search_box()->hint_text());
177 } 177 }
178 178
179 void SearchBoxView::SelectionModelChanged() { 179 void SearchBoxView::SelectionModelChanged() {
180 search_box_->SelectSelectionModel(model_->selection_model()); 180 search_box_->SelectSelectionModel(model_->search_box()->selection_model());
181 } 181 }
182 182
183 void SearchBoxView::TextChanged() { 183 void SearchBoxView::TextChanged() {
184 search_box_->SetText(model_->text()); 184 search_box_->SetText(model_->search_box()->text());
185 } 185 }
186 186
187 } // namespace app_list 187 } // 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