Index: ui/app_list/views/app_list_view.cc |
diff --git a/ui/app_list/views/app_list_view.cc b/ui/app_list/views/app_list_view.cc |
index d4c9ac196941cd5e46ad96c538e2268de34297e6..d8daca1d1006142dfd5860b01fe7aa79436202f5 100644 |
--- a/ui/app_list/views/app_list_view.cc |
+++ b/ui/app_list/views/app_list_view.cc |
@@ -15,7 +15,10 @@ |
#include "ui/app_list/views/app_list_main_view.h" |
#include "ui/app_list/views/search_box_view.h" |
#include "ui/app_list/views/signin_view.h" |
+#include "ui/app_list/views/speech_view.h" |
#include "ui/base/ui_base_switches.h" |
+#include "ui/compositor/layer.h" |
+#include "ui/compositor/scoped_layer_animation_settings.h" |
#include "ui/gfx/image/image_skia.h" |
#include "ui/gfx/insets.h" |
#include "ui/gfx/path.h" |
@@ -42,6 +45,12 @@ namespace { |
void (*g_next_paint_callback)(); |
+// The margin from the edge to the speech UI. |
+const int kSpeechUIMargin = 12; |
+ |
+// The vertical position for the appearing animation of the speech UI. |
+const float kSpeechUIApearingPosition =12; |
+ |
// The distance between the arrow tip and edge of the anchor view. |
const int kArrowOffset = 10; |
@@ -74,12 +83,15 @@ bool SupportsShadow() { |
AppListView::AppListView(AppListViewDelegate* delegate) |
: delegate_(delegate), |
app_list_main_view_(NULL), |
- signin_view_(NULL) { |
+ signin_view_(NULL), |
+ speech_view_(NULL) { |
CHECK(delegate); |
delegate_->GetModel()->AddObserver(this); |
+ delegate_->GetModel()->speech_ui()->AddObserver(this); |
} |
AppListView::~AppListView() { |
+ delegate_->GetModel()->speech_ui()->RemoveObserver(this); |
delegate_->GetModel()->RemoveObserver(this); |
// Remove child views first to ensure no remaining dependencies on delegate_. |
RemoveAllChildViews(true); |
@@ -213,6 +225,17 @@ void AppListView::InitAsBubbleInternal(gfx::NativeView parent, |
app_list_main_view_->GetPreferredSize().width()); |
AddChildView(signin_view_); |
+ // Speech recognition is available only when the start page exists. |
+ if (delegate_ && delegate_->GetStartPageContents()) { |
+ speech_view_ = new SpeechView(delegate_.get()); |
+ speech_view_->SetVisible(false); |
+#if defined(USE_AURA) |
+ speech_view_->SetPaintToLayer(true); |
+ speech_view_->SetFillsBoundsOpaquely(false); |
+#endif |
+ AddChildView(speech_view_); |
+ } |
+ |
OnSigninStatusChanged(); |
set_color(kContentsBackgroundColor); |
set_margins(gfx::Insets()); |
@@ -304,6 +327,15 @@ void AppListView::Layout() { |
const gfx::Rect contents_bounds = GetContentsBounds(); |
app_list_main_view_->SetBoundsRect(contents_bounds); |
signin_view_->SetBoundsRect(contents_bounds); |
+ |
+ if (speech_view_) { |
+ gfx::Rect speech_bounds = contents_bounds; |
+ speech_bounds.Inset(kSpeechUIMargin, kSpeechUIMargin); |
+ speech_bounds.set_height(std::min(speech_bounds.height(), |
+ SpeechView::kMaxHeight)); |
+ speech_bounds.Inset(-speech_view_->GetInsets()); |
+ speech_view_->SetBoundsRect(speech_bounds); |
+ } |
} |
void AppListView::OnWidgetDestroying(views::Widget* widget) { |
@@ -342,4 +374,47 @@ void AppListView::OnAppListModelSigninStatusChanged() { |
OnSigninStatusChanged(); |
} |
+void AppListView::OnSpeechRecognitionStateChanged( |
+ SpeechRecognitionState new_state) { |
+ DCHECK(!signin_view_->visible()); |
+ |
+ bool recognizing = new_state != SPEECH_RECOGNITION_NOT_STARTED; |
+ // No change for this class. |
+ if (speech_view_->visible() == recognizing) |
+ return; |
+ |
+ if (recognizing) |
+ speech_view_->Reset(); |
+ |
+#if defined(USE_AURA) |
+ { |
+ ui::ScopedLayerAnimationSettings main_settings( |
+ app_list_main_view_->layer()->GetAnimator()); |
+ app_list_main_view_->layer()->SetOpacity(recognizing ? 0.0f : 1.0f); |
+ } |
+ |
+ gfx::Transform speech_transform; |
+ speech_transform.Translate( |
+ 0, SkFloatToMScalar(kSpeechUIApearingPosition)); |
+ if (recognizing) |
+ speech_view_->layer()->SetTransform(speech_transform); |
+ |
+ { |
+ ui::ScopedLayerAnimationSettings speech_settings( |
+ speech_view_->layer()->GetAnimator()); |
+ speech_view_->layer()->SetOpacity(recognizing ? 1.0f : 0.0f); |
+ if (recognizing) |
+ speech_view_->layer()->SetTransform(gfx::Transform()); |
+ else |
+ speech_view_->layer()->SetTransform(speech_transform); |
+ } |
+#endif |
+ |
+ speech_view_->SetVisible(recognizing); |
+ app_list_main_view_->SetVisible(!recognizing); |
xiyuan
2013/12/05 22:06:30
Think we should call SetVisible of both views when
Jun Mukai
2013/12/06 00:31:10
Didn't notice that, thanks for pointing. Introduce
|
+ |
+ // Needs to schedule paint of AppListView itself, to repaint the background. |
+ SchedulePaint(); |
+} |
+ |
} // namespace app_list |