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

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