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 <stdint.h> |
| 8 |
| 9 #include <limits> |
| 10 |
7 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
8 #include "third_party/skia/include/core/SkPath.h" | 12 #include "third_party/skia/include/core/SkPath.h" |
9 #include "ui/app_list/app_list_constants.h" | 13 #include "ui/app_list/app_list_constants.h" |
10 #include "ui/app_list/app_list_model.h" | 14 #include "ui/app_list/app_list_model.h" |
11 #include "ui/app_list/app_list_view_delegate.h" | 15 #include "ui/app_list/app_list_view_delegate.h" |
12 #include "ui/app_list/resources/grit/app_list_resources.h" | 16 #include "ui/app_list/resources/grit/app_list_resources.h" |
13 #include "ui/app_list/speech_ui_model.h" | 17 #include "ui/app_list/speech_ui_model.h" |
14 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
15 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
16 #include "ui/gfx/canvas.h" | 20 #include "ui/gfx/canvas.h" |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 } | 160 } |
157 | 161 |
158 SpeechView::~SpeechView() { | 162 SpeechView::~SpeechView() { |
159 delegate_->GetSpeechUI()->RemoveObserver(this); | 163 delegate_->GetSpeechUI()->RemoveObserver(this); |
160 } | 164 } |
161 | 165 |
162 void SpeechView::Reset() { | 166 void SpeechView::Reset() { |
163 OnSpeechRecognitionStateChanged(delegate_->GetSpeechUI()->state()); | 167 OnSpeechRecognitionStateChanged(delegate_->GetSpeechUI()->state()); |
164 } | 168 } |
165 | 169 |
166 int SpeechView::GetIndicatorRadius(uint8 level) { | 170 int SpeechView::GetIndicatorRadius(uint8_t level) { |
167 int radius_min = mic_button_->width() / 2 + kIndicatorRadiusMinOffset; | 171 int radius_min = mic_button_->width() / 2 + kIndicatorRadiusMinOffset; |
168 int range = kIndicatorRadiusMax - radius_min; | 172 int range = kIndicatorRadiusMax - radius_min; |
169 return level * range / kuint8max + radius_min; | 173 return level * range / std::numeric_limits<uint8_t>::max() + radius_min; |
170 } | 174 } |
171 | 175 |
172 void SpeechView::Layout() { | 176 void SpeechView::Layout() { |
173 views::View* container = child_at(0); | 177 views::View* container = child_at(0); |
174 container->SetBoundsRect(GetContentsBounds()); | 178 container->SetBoundsRect(GetContentsBounds()); |
175 | 179 |
176 // Because container is a pure View, this class should layout its children. | 180 // Because container is a pure View, this class should layout its children. |
177 const gfx::Rect contents_bounds = container->GetContentsBounds(); | 181 const gfx::Rect contents_bounds = container->GetContentsBounds(); |
178 if (logo_) | 182 if (logo_) |
179 logo_->SetBounds(kLogoMarginLeft, kLogoMarginTop, kLogoWidth, kLogoHeight); | 183 logo_->SetBounds(kLogoMarginLeft, kLogoMarginTop, kLogoWidth, kLogoHeight); |
(...skipping 13 matching lines...) Expand all Loading... |
193 } | 197 } |
194 | 198 |
195 gfx::Size SpeechView::GetPreferredSize() const { | 199 gfx::Size SpeechView::GetPreferredSize() const { |
196 return gfx::Size(0, kSpeechViewMaxHeight); | 200 return gfx::Size(0, kSpeechViewMaxHeight); |
197 } | 201 } |
198 | 202 |
199 void SpeechView::ButtonPressed(views::Button* sender, const ui::Event& event) { | 203 void SpeechView::ButtonPressed(views::Button* sender, const ui::Event& event) { |
200 delegate_->StopSpeechRecognition(); | 204 delegate_->StopSpeechRecognition(); |
201 } | 205 } |
202 | 206 |
203 void SpeechView::OnSpeechSoundLevelChanged(uint8 level) { | 207 void SpeechView::OnSpeechSoundLevelChanged(uint8_t level) { |
204 if (!visible() || | 208 if (!visible() || |
205 delegate_->GetSpeechUI()->state() == SPEECH_RECOGNITION_NETWORK_ERROR) | 209 delegate_->GetSpeechUI()->state() == SPEECH_RECOGNITION_NETWORK_ERROR) |
206 return; | 210 return; |
207 | 211 |
208 gfx::Point origin = mic_button_->bounds().CenterPoint(); | 212 gfx::Point origin = mic_button_->bounds().CenterPoint(); |
209 int radius = GetIndicatorRadius(level); | 213 int radius = GetIndicatorRadius(level); |
210 origin.Offset(-radius, -radius + kIndicatorCenterOffsetY); | 214 origin.Offset(-radius, -radius + kIndicatorCenterOffsetY); |
211 gfx::Rect indicator_bounds = | 215 gfx::Rect indicator_bounds = |
212 gfx::Rect(origin, gfx::Size(radius * 2, radius * 2)); | 216 gfx::Rect(origin, gfx::Size(radius * 2, radius * 2)); |
213 if (indicator_->visible()) { | 217 if (indicator_->visible()) { |
(...skipping 27 matching lines...) Expand all Loading... |
241 } | 245 } |
242 speech_result_->SetText(l10n_util::GetStringUTF16(text_resource_id)); | 246 speech_result_->SetText(l10n_util::GetStringUTF16(text_resource_id)); |
243 speech_result_->SetEnabledColor(kHintTextColor); | 247 speech_result_->SetEnabledColor(kHintTextColor); |
244 | 248 |
245 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 249 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
246 mic_button_->SetImage(views::Button::STATE_NORMAL, | 250 mic_button_->SetImage(views::Button::STATE_NORMAL, |
247 bundle.GetImageSkiaNamed(resource_id)); | 251 bundle.GetImageSkiaNamed(resource_id)); |
248 } | 252 } |
249 | 253 |
250 } // namespace app_list | 254 } // namespace app_list |
OLD | NEW |