Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/speech_view.h" | 5 #include "ui/app_list/views/speech_view.h" |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "grit/ui_resources.h" | 8 #include "grit/ui_resources.h" |
| 9 #include "grit/ui_strings.h" | 9 #include "grit/ui_strings.h" |
| 10 #include "third_party/skia/include/core/SkPath.h" | 10 #include "third_party/skia/include/core/SkPath.h" |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 views::Background::CreateSolidBackground(SK_ColorWHITE)); | 156 views::Background::CreateSolidBackground(SK_ColorWHITE)); |
| 157 | 157 |
| 158 const gfx::ImageSkia& logo_image = delegate_->GetSpeechUI()->logo(); | 158 const gfx::ImageSkia& logo_image = delegate_->GetSpeechUI()->logo(); |
| 159 if (!logo_image.isNull()) { | 159 if (!logo_image.isNull()) { |
| 160 logo_ = new views::ImageView(); | 160 logo_ = new views::ImageView(); |
| 161 logo_->SetImage(&logo_image); | 161 logo_->SetImage(&logo_image); |
| 162 container->AddChildView(logo_); | 162 container->AddChildView(logo_); |
| 163 } | 163 } |
| 164 | 164 |
| 165 indicator_ = new SoundLevelIndicator(); | 165 indicator_ = new SoundLevelIndicator(); |
| 166 indicator_->SetVisible(false); | |
| 167 container->AddChildView(indicator_); | |
| 168 | 166 |
| 169 mic_button_ = new MicButton(this); | 167 mic_button_ = new MicButton(this); |
| 170 container->AddChildView(mic_button_); | 168 container->AddChildView(mic_button_); |
| 171 mic_button_->SetEventTargeter( | 169 mic_button_->SetEventTargeter( |
| 172 scoped_ptr<ui::EventTargeter>(new MicButtonTargeter(mic_button_))); | 170 scoped_ptr<ui::EventTargeter>(new MicButtonTargeter(mic_button_))); |
| 173 | 171 |
| 174 // TODO(mukai): use BoundedLabel to cap 2 lines. | 172 // TODO(mukai): use BoundedLabel to cap 2 lines. |
| 175 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 173 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 176 speech_result_ = new views::Label( | 174 speech_result_ = new views::Label( |
| 177 base::string16(), bundle.GetFontList(ui::ResourceBundle::LargeFont)); | 175 base::string16(), bundle.GetFontList(ui::ResourceBundle::LargeFont)); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 239 void SpeechView::OnSpeechSoundLevelChanged(uint8 level) { | 237 void SpeechView::OnSpeechSoundLevelChanged(uint8 level) { |
| 240 if (!visible() || | 238 if (!visible() || |
| 241 delegate_->GetSpeechUI()->state() == SPEECH_RECOGNITION_NETWORK_ERROR) | 239 delegate_->GetSpeechUI()->state() == SPEECH_RECOGNITION_NETWORK_ERROR) |
| 242 return; | 240 return; |
| 243 | 241 |
| 244 gfx::Point origin = mic_button_->bounds().CenterPoint(); | 242 gfx::Point origin = mic_button_->bounds().CenterPoint(); |
| 245 int radius = GetIndicatorRadius(level); | 243 int radius = GetIndicatorRadius(level); |
| 246 origin.Offset(-radius, -radius + kIndicatorCenterOffsetY); | 244 origin.Offset(-radius, -radius + kIndicatorCenterOffsetY); |
| 247 gfx::Rect indicator_bounds = | 245 gfx::Rect indicator_bounds = |
| 248 gfx::Rect(origin, gfx::Size(radius * 2, radius * 2)); | 246 gfx::Rect(origin, gfx::Size(radius * 2, radius * 2)); |
| 249 if (indicator_->visible()) { | 247 if (indicator_->parent()) { |
| 250 indicator_animator_->AnimateViewTo(indicator_, indicator_bounds); | 248 indicator_animator_->AnimateViewTo(indicator_, indicator_bounds); |
| 251 } else { | 249 } else { |
| 252 indicator_->SetVisible(true); | 250 views::View* container = child_at(0); |
| 251 container->AddChildViewAt(indicator_, container->GetIndexOf(mic_button_)); | |
| 253 indicator_->SetBoundsRect(indicator_bounds); | 252 indicator_->SetBoundsRect(indicator_bounds); |
| 254 } | 253 } |
| 255 } | 254 } |
| 256 | 255 |
| 257 void SpeechView::OnSpeechResult(const base::string16& result, | 256 void SpeechView::OnSpeechResult(const base::string16& result, |
| 258 bool is_final) { | 257 bool is_final) { |
| 259 speech_result_->SetText(result); | 258 speech_result_->SetText(result); |
| 260 speech_result_->SetEnabledColor(kResultTextColor); | 259 speech_result_->SetEnabledColor(kResultTextColor); |
| 261 } | 260 } |
| 262 | 261 |
| 263 void SpeechView::OnSpeechRecognitionStateChanged( | 262 void SpeechView::OnSpeechRecognitionStateChanged( |
| 264 SpeechRecognitionState new_state) { | 263 SpeechRecognitionState new_state) { |
| 265 int resource_id = IDR_APP_LIST_SPEECH_MIC_OFF; | 264 int resource_id = IDR_APP_LIST_SPEECH_MIC_OFF; |
| 266 if (new_state == SPEECH_RECOGNITION_RECOGNIZING) | 265 if (new_state == SPEECH_RECOGNITION_RECOGNIZING) |
| 267 resource_id = IDR_APP_LIST_SPEECH_MIC_ON; | 266 resource_id = IDR_APP_LIST_SPEECH_MIC_ON; |
| 268 else if (new_state == SPEECH_RECOGNITION_IN_SPEECH) | 267 else if (new_state == SPEECH_RECOGNITION_IN_SPEECH) |
| 269 resource_id = IDR_APP_LIST_SPEECH_MIC_RECORDING; | 268 resource_id = IDR_APP_LIST_SPEECH_MIC_RECORDING; |
| 270 | 269 |
| 271 int text_resource_id = IDS_APP_LIST_SPEECH_HINT_TEXT; | 270 int text_resource_id = IDS_APP_LIST_SPEECH_HINT_TEXT; |
| 272 | 271 |
| 273 if (new_state == SPEECH_RECOGNITION_NETWORK_ERROR) { | 272 if (new_state == SPEECH_RECOGNITION_NETWORK_ERROR) { |
| 274 text_resource_id = IDS_APP_LIST_SPEECH_NETWORK_ERROR_HINT_TEXT; | 273 text_resource_id = IDS_APP_LIST_SPEECH_NETWORK_ERROR_HINT_TEXT; |
| 275 indicator_->SetVisible(false); | 274 child_at(0)->RemoveChildView(indicator_); |
|
xiyuan
2014/06/18 23:13:05
Would a "indicator_->SchedulePaint()" here help?
Jun Mukai
2014/06/18 23:13:51
I tried SchedulePaint but it didn't help.
xiyuan
2014/06/18 23:16:02
Try put it before "indicator_->SetVisible(false);"
Jun Mukai
2014/06/19 00:58:14
Tried all pattern of SchedulePaint(), child_at(0)-
Jun Mukai
2014/06/19 01:00:57
Ah, I think I've found why. indicator_animator_ m
Jun Mukai
2014/06/19 02:20:15
Turns out I was totally pointless :(
Everything wa
| |
| 276 } | 275 } |
| 277 speech_result_->SetText(l10n_util::GetStringUTF16(text_resource_id)); | 276 speech_result_->SetText(l10n_util::GetStringUTF16(text_resource_id)); |
| 278 speech_result_->SetEnabledColor(kHintTextColor); | 277 speech_result_->SetEnabledColor(kHintTextColor); |
| 279 | 278 |
| 280 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 279 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 281 mic_button_->SetImage(views::Button::STATE_NORMAL, | 280 mic_button_->SetImage(views::Button::STATE_NORMAL, |
| 282 bundle.GetImageSkiaNamed(resource_id)); | 281 bundle.GetImageSkiaNamed(resource_id)); |
| 283 } | 282 } |
| 284 | 283 |
| 285 } // namespace app_list | 284 } // namespace app_list |
| OLD | NEW |