OLD | NEW |
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" |
11 #include "ui/app_list/app_list_view_delegate.h" | 11 #include "ui/app_list/app_list_view_delegate.h" |
12 #include "ui/app_list/search_box_model.h" | 12 #include "ui/app_list/search_box_model.h" |
| 13 #include "ui/app_list/speech_ui_model.h" |
13 #include "ui/app_list/views/app_list_menu_views.h" | 14 #include "ui/app_list/views/app_list_menu_views.h" |
14 #include "ui/app_list/views/contents_view.h" | 15 #include "ui/app_list/views/contents_view.h" |
15 #include "ui/app_list/views/search_box_view_delegate.h" | 16 #include "ui/app_list/views/search_box_view_delegate.h" |
16 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
17 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
18 #include "ui/events/event.h" | 19 #include "ui/events/event.h" |
19 #include "ui/views/controls/button/image_button.h" | 20 #include "ui/views/controls/button/image_button.h" |
20 #include "ui/views/controls/button/menu_button.h" | 21 #include "ui/views/controls/button/menu_button.h" |
21 #include "ui/views/controls/image_view.h" | 22 #include "ui/views/controls/image_view.h" |
22 #include "ui/views/controls/textfield/textfield.h" | 23 #include "ui/views/controls/textfield/textfield.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 IDR_APP_LIST_TOOLS_PRESSED)); | 64 IDR_APP_LIST_TOOLS_PRESSED)); |
64 AddChildView(menu_button_); | 65 AddChildView(menu_button_); |
65 #endif | 66 #endif |
66 | 67 |
67 search_box_->SetBorder(views::Border::NullBorder()); | 68 search_box_->SetBorder(views::Border::NullBorder()); |
68 search_box_->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont)); | 69 search_box_->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont)); |
69 search_box_->set_placeholder_text_color(kHintTextColor); | 70 search_box_->set_placeholder_text_color(kHintTextColor); |
70 search_box_->set_controller(this); | 71 search_box_->set_controller(this); |
71 AddChildView(search_box_); | 72 AddChildView(search_box_); |
72 | 73 |
| 74 view_delegate_->GetSpeechUI()->AddObserver(this); |
73 ModelChanged(); | 75 ModelChanged(); |
74 } | 76 } |
75 | 77 |
76 SearchBoxView::~SearchBoxView() { | 78 SearchBoxView::~SearchBoxView() { |
| 79 view_delegate_->GetSpeechUI()->RemoveObserver(this); |
77 model_->search_box()->RemoveObserver(this); | 80 model_->search_box()->RemoveObserver(this); |
78 } | 81 } |
79 | 82 |
80 void SearchBoxView::ModelChanged() { | 83 void SearchBoxView::ModelChanged() { |
81 if (model_) | 84 if (model_) |
82 model_->search_box()->RemoveObserver(this); | 85 model_->search_box()->RemoveObserver(this); |
83 | 86 |
84 model_ = view_delegate_->GetModel(); | 87 model_ = view_delegate_->GetModel(); |
85 DCHECK(model_); | 88 DCHECK(model_); |
86 model_->search_box()->AddObserver(this); | 89 model_->search_box()->AddObserver(this); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 menu_button_->GetBoundsInScreen().bottom_right() + | 206 menu_button_->GetBoundsInScreen().bottom_right() + |
204 gfx::Vector2d(kMenuXOffsetFromButton, kMenuYOffsetFromButton); | 207 gfx::Vector2d(kMenuXOffsetFromButton, kMenuYOffsetFromButton); |
205 menu_->RunMenuAt(menu_button_, menu_location); | 208 menu_->RunMenuAt(menu_button_, menu_location); |
206 } | 209 } |
207 | 210 |
208 void SearchBoxView::IconChanged() { | 211 void SearchBoxView::IconChanged() { |
209 icon_view_->SetImage(model_->search_box()->icon()); | 212 icon_view_->SetImage(model_->search_box()->icon()); |
210 } | 213 } |
211 | 214 |
212 void SearchBoxView::SpeechRecognitionButtonPropChanged() { | 215 void SearchBoxView::SpeechRecognitionButtonPropChanged() { |
213 const SearchBoxModel::ButtonProperty* speech_button_prop = | 216 const SearchBoxModel::SpeechButtonProperty* speech_button_prop = |
214 model_->search_box()->speech_button(); | 217 model_->search_box()->speech_button(); |
215 if (speech_button_prop) { | 218 if (speech_button_prop) { |
216 if (!speech_button_) { | 219 if (!speech_button_) { |
217 speech_button_ = new views::ImageButton(this); | 220 speech_button_ = new views::ImageButton(this); |
218 AddChildView(speech_button_); | 221 AddChildView(speech_button_); |
219 } | 222 } |
220 speech_button_->SetImage(views::Button::STATE_NORMAL, | 223 |
221 &speech_button_prop->icon); | 224 if (view_delegate_->GetSpeechUI()->state() == |
222 speech_button_->SetTooltipText(speech_button_prop->tooltip); | 225 SPEECH_RECOGNITION_HOTWORD_LISTENING) { |
| 226 speech_button_->SetImage( |
| 227 views::Button::STATE_NORMAL, &speech_button_prop->on_icon); |
| 228 speech_button_->SetTooltipText(speech_button_prop->on_tooltip); |
| 229 } else { |
| 230 speech_button_->SetImage( |
| 231 views::Button::STATE_NORMAL, &speech_button_prop->off_icon); |
| 232 speech_button_->SetTooltipText(speech_button_prop->off_tooltip); |
| 233 } |
223 } else { | 234 } else { |
224 if (speech_button_) { | 235 if (speech_button_) { |
225 // Deleting a view will detach it from its parent. | 236 // Deleting a view will detach it from its parent. |
226 delete speech_button_; | 237 delete speech_button_; |
227 speech_button_ = NULL; | 238 speech_button_ = NULL; |
228 } | 239 } |
229 } | 240 } |
230 } | 241 } |
231 | 242 |
232 void SearchBoxView::HintTextChanged() { | 243 void SearchBoxView::HintTextChanged() { |
233 search_box_->set_placeholder_text(model_->search_box()->hint_text()); | 244 search_box_->set_placeholder_text(model_->search_box()->hint_text()); |
234 } | 245 } |
235 | 246 |
236 void SearchBoxView::SelectionModelChanged() { | 247 void SearchBoxView::SelectionModelChanged() { |
237 search_box_->SelectSelectionModel(model_->search_box()->selection_model()); | 248 search_box_->SelectSelectionModel(model_->search_box()->selection_model()); |
238 } | 249 } |
239 | 250 |
240 void SearchBoxView::TextChanged() { | 251 void SearchBoxView::TextChanged() { |
241 search_box_->SetText(model_->search_box()->text()); | 252 search_box_->SetText(model_->search_box()->text()); |
242 NotifyQueryChanged(); | 253 NotifyQueryChanged(); |
243 } | 254 } |
244 | 255 |
| 256 void SearchBoxView::OnSpeechRecognitionStateChanged( |
| 257 SpeechRecognitionState new_state) { |
| 258 SpeechRecognitionButtonPropChanged(); |
| 259 SchedulePaint(); |
| 260 } |
| 261 |
245 } // namespace app_list | 262 } // namespace app_list |
OLD | NEW |