Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/ui/app_list/search/search_resource_manager.h" | 5 #include "chrome/browser/ui/app_list/search/search_resource_manager.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/app_list/start_page_service.h" | 7 #include "chrome/browser/ui/app_list/start_page_service.h" |
| 8 #include "grit/components_scaled_resources.h" | 8 #include "grit/components_scaled_resources.h" |
| 9 #include "grit/generated_resources.h" | 9 #include "grit/generated_resources.h" |
| 10 #include "grit/theme_resources.h" | 10 #include "grit/theme_resources.h" |
| 11 #include "ui/app_list/search_box_model.h" | 11 #include "ui/app_list/search_box_model.h" |
| 12 #include "ui/app_list/speech_ui_model.h" | 12 #include "ui/app_list/speech_ui_model.h" |
| 13 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
| 14 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
| 15 | 15 |
| 16 namespace app_list { | 16 namespace app_list { |
| 17 | 17 |
| 18 namespace { | |
| 19 | |
| 20 scoped_ptr<SearchBoxModel::SpeechButtonProperty> CreateNewProperty( | |
| 21 SpeechRecognitionState state) { | |
| 22 if (state == SPEECH_RECOGNITION_OFF) | |
| 23 return nullptr; | |
| 24 | |
| 25 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
| 26 return make_scoped_ptr(new SearchBoxModel::SpeechButtonProperty( | |
| 27 *bundle.GetImageSkiaNamed(IDR_OMNIBOX_MIC_SEARCH), | |
| 28 l10n_util::GetStringUTF16(IDS_APP_LIST_HOTWORD_LISTENING), | |
| 29 *bundle.GetImageSkiaNamed(IDR_APP_LIST_MIC_HOTWORD_OFF), | |
| 30 l10n_util::GetStringUTF16(IDS_APP_LIST_START_SPEECH_RECOGNITION))); | |
| 31 } | |
| 32 | |
| 33 } // namespace | |
| 34 | |
| 18 SearchResourceManager::SearchResourceManager(Profile* profile, | 35 SearchResourceManager::SearchResourceManager(Profile* profile, |
| 19 SearchBoxModel* search_box, | 36 SearchBoxModel* search_box, |
| 20 SpeechUIModel* speech_ui) | 37 SpeechUIModel* speech_ui) |
| 21 : search_box_(search_box), | 38 : search_box_(search_box), |
| 22 speech_ui_(speech_ui) { | 39 speech_ui_(speech_ui) { |
| 23 speech_ui_->AddObserver(this); | 40 speech_ui_->AddObserver(this); |
| 24 | 41 |
| 25 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 42 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 26 search_box_->SetIcon(*bundle.GetImageSkiaNamed(IDR_OMNIBOX_SEARCH)); | 43 search_box_->SetIcon(*bundle.GetImageSkiaNamed(IDR_OMNIBOX_SEARCH)); |
| 27 StartPageService* service = StartPageService::Get(profile); | 44 StartPageService* service = StartPageService::Get(profile); |
| 28 if (service && service->GetSpeechRecognitionContents()) { | 45 if (service && service->GetSpeechRecognitionContents()) { |
| 29 search_box_->SetSpeechRecognitionButton( | 46 search_box_->SetSpeechRecognitionButton( |
| 30 scoped_ptr<SearchBoxModel::SpeechButtonProperty>( | 47 CreateNewProperty(service->state())); |
| 31 new SearchBoxModel::SpeechButtonProperty( | |
| 32 *bundle.GetImageSkiaNamed(IDR_OMNIBOX_MIC_SEARCH), | |
| 33 l10n_util::GetStringUTF16( | |
| 34 IDS_APP_LIST_HOTWORD_LISTENING), | |
| 35 *bundle.GetImageSkiaNamed(IDR_APP_LIST_MIC_HOTWORD_OFF), | |
| 36 l10n_util::GetStringUTF16( | |
| 37 IDS_APP_LIST_START_SPEECH_RECOGNITION)))); | |
| 38 } | 48 } |
|
tapted
2014/11/26 02:05:59
it looks like the whole if block above is redundan
Jun Mukai
2014/11/26 23:29:51
Done.
| |
| 39 OnSpeechRecognitionStateChanged(speech_ui_->state()); | 49 OnSpeechRecognitionStateChanged(speech_ui_->state()); |
| 40 } | 50 } |
| 41 | 51 |
| 42 SearchResourceManager::~SearchResourceManager() { | 52 SearchResourceManager::~SearchResourceManager() { |
| 43 speech_ui_->RemoveObserver(this); | 53 speech_ui_->RemoveObserver(this); |
| 44 } | 54 } |
| 45 | 55 |
| 46 void SearchResourceManager::OnSpeechRecognitionStateChanged( | 56 void SearchResourceManager::OnSpeechRecognitionStateChanged( |
| 47 SpeechRecognitionState new_state) { | 57 SpeechRecognitionState new_state) { |
| 48 search_box_->SetHintText(l10n_util::GetStringUTF16( | 58 search_box_->SetHintText(l10n_util::GetStringUTF16( |
| 49 (new_state == SPEECH_RECOGNITION_HOTWORD_LISTENING) ? | 59 (new_state == SPEECH_RECOGNITION_HOTWORD_LISTENING) ? |
| 50 IDS_SEARCH_BOX_HOTWORD_HINT : IDS_SEARCH_BOX_HINT)); | 60 IDS_SEARCH_BOX_HOTWORD_HINT : IDS_SEARCH_BOX_HINT)); |
| 61 search_box_->SetSpeechRecognitionButton(CreateNewProperty(new_state)); | |
| 51 } | 62 } |
| 52 | 63 |
| 53 } // namespace app_list | 64 } // namespace app_list |
| OLD | NEW |