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 "ash/shelf/app_list_button.h" | 5 #include "ash/shelf/app_list_button.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "ash/public/cpp/shelf_types.h" | 10 #include "ash/public/cpp/shelf_types.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 #include "ui/gfx/paint_vector_icon.h" | 38 #include "ui/gfx/paint_vector_icon.h" |
39 #include "ui/gfx/scoped_canvas.h" | 39 #include "ui/gfx/scoped_canvas.h" |
40 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" | 40 #include "ui/views/animation/flood_fill_ink_drop_ripple.h" |
41 #include "ui/views/animation/ink_drop_impl.h" | 41 #include "ui/views/animation/ink_drop_impl.h" |
42 #include "ui/views/animation/ink_drop_mask.h" | 42 #include "ui/views/animation/ink_drop_mask.h" |
43 #include "ui/views/painter.h" | 43 #include "ui/views/painter.h" |
44 | 44 |
45 namespace ash { | 45 namespace ash { |
46 namespace { | 46 namespace { |
47 constexpr int kVoiceInteractionAnimationDelayMs = 200; | 47 constexpr int kVoiceInteractionAnimationDelayMs = 200; |
| 48 constexpr int kVoiceInteractionAnimationHideDelayMs = 500; |
48 } // namespace | 49 } // namespace |
49 | 50 |
50 constexpr uint8_t kVoiceInteractionRunningAlpha = 255; // 100% alpha | 51 constexpr uint8_t kVoiceInteractionRunningAlpha = 255; // 100% alpha |
51 constexpr uint8_t kVoiceInteractionNotRunningAlpha = 138; // 54% alpha | 52 constexpr uint8_t kVoiceInteractionNotRunningAlpha = 138; // 54% alpha |
52 | 53 |
53 AppListButton::AppListButton(InkDropButtonListener* listener, | 54 AppListButton::AppListButton(InkDropButtonListener* listener, |
54 ShelfView* shelf_view, | 55 ShelfView* shelf_view, |
55 Shelf* shelf) | 56 Shelf* shelf) |
56 : views::ImageButton(nullptr), | 57 : views::ImageButton(nullptr), |
57 is_showing_app_list_(false), | 58 is_showing_app_list_(false), |
(...skipping 12 matching lines...) Expand all Loading... |
70 l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE)); | 71 l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE)); |
71 SetSize(gfx::Size(kShelfSize, kShelfSize)); | 72 SetSize(gfx::Size(kShelfSize, kShelfSize)); |
72 SetFocusPainter(TrayPopupUtils::CreateFocusPainter()); | 73 SetFocusPainter(TrayPopupUtils::CreateFocusPainter()); |
73 set_notify_action(CustomButton::NOTIFY_ON_PRESS); | 74 set_notify_action(CustomButton::NOTIFY_ON_PRESS); |
74 | 75 |
75 if (chromeos::switches::IsVoiceInteractionEnabled()) { | 76 if (chromeos::switches::IsVoiceInteractionEnabled()) { |
76 voice_interaction_overlay_ = new VoiceInteractionOverlay(this); | 77 voice_interaction_overlay_ = new VoiceInteractionOverlay(this); |
77 AddChildView(voice_interaction_overlay_); | 78 AddChildView(voice_interaction_overlay_); |
78 voice_interaction_overlay_->SetVisible(false); | 79 voice_interaction_overlay_->SetVisible(false); |
79 voice_interaction_animation_delay_timer_.reset(new base::OneShotTimer()); | 80 voice_interaction_animation_delay_timer_.reset(new base::OneShotTimer()); |
| 81 voice_interaction_animation_hide_delay_timer_.reset( |
| 82 new base::OneShotTimer()); |
80 } else { | 83 } else { |
81 voice_interaction_overlay_ = nullptr; | 84 voice_interaction_overlay_ = nullptr; |
82 } | 85 } |
83 } | 86 } |
84 | 87 |
85 AppListButton::~AppListButton() { | 88 AppListButton::~AppListButton() { |
86 Shell::Get()->RemoveShellObserver(this); | 89 Shell::Get()->RemoveShellObserver(this); |
87 if (voice_interaction_animation_delay_timer_) | |
88 voice_interaction_animation_delay_timer_->Stop(); | |
89 } | 90 } |
90 | 91 |
91 void AppListButton::OnAppListShown() { | 92 void AppListButton::OnAppListShown() { |
92 AnimateInkDrop(views::InkDropState::ACTIVATED, nullptr); | 93 AnimateInkDrop(views::InkDropState::ACTIVATED, nullptr); |
93 is_showing_app_list_ = true; | 94 is_showing_app_list_ = true; |
94 shelf_->UpdateAutoHideState(); | 95 shelf_->UpdateAutoHideState(); |
95 } | 96 } |
96 | 97 |
97 void AppListButton::OnAppListDismissed() { | 98 void AppListButton::OnAppListDismissed() { |
98 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr); | 99 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr); |
(...skipping 29 matching lines...) Expand all Loading... |
128 voice_interaction_animation_delay_timer_->Stop(); | 129 voice_interaction_animation_delay_timer_->Stop(); |
129 } | 130 } |
130 ImageButton::OnGestureEvent(event); | 131 ImageButton::OnGestureEvent(event); |
131 return; | 132 return; |
132 case ui::ET_GESTURE_TAP_DOWN: | 133 case ui::ET_GESTURE_TAP_DOWN: |
133 if (voice_interaction_overlay_) { | 134 if (voice_interaction_overlay_) { |
134 voice_interaction_animation_delay_timer_->Start( | 135 voice_interaction_animation_delay_timer_->Start( |
135 FROM_HERE, | 136 FROM_HERE, |
136 base::TimeDelta::FromMilliseconds( | 137 base::TimeDelta::FromMilliseconds( |
137 kVoiceInteractionAnimationDelayMs), | 138 kVoiceInteractionAnimationDelayMs), |
138 base::Bind(&VoiceInteractionOverlay::StartAnimation, | 139 base::Bind(&AppListButton::StartVoiceInteractionAnimation, |
139 base::Unretained(voice_interaction_overlay_))); | 140 base::Unretained(this))); |
140 } | 141 } |
141 if (!Shell::Get()->IsAppListVisible()) | 142 if (!Shell::Get()->IsAppListVisible()) |
142 AnimateInkDrop(views::InkDropState::ACTION_PENDING, event); | 143 AnimateInkDrop(views::InkDropState::ACTION_PENDING, event); |
143 ImageButton::OnGestureEvent(event); | 144 ImageButton::OnGestureEvent(event); |
144 return; | 145 return; |
145 case ui::ET_GESTURE_LONG_PRESS: | 146 case ui::ET_GESTURE_LONG_PRESS: |
146 if (chromeos::switches::IsVoiceInteractionEnabled()) { | 147 if (chromeos::switches::IsVoiceInteractionEnabled()) { |
147 base::RecordAction(base::UserMetricsAction( | 148 base::RecordAction(base::UserMetricsAction( |
148 "VoiceInteraction.Started.AppListButtonLongPress")); | 149 "VoiceInteraction.Started.AppListButtonLongPress")); |
149 Shell::Get()->app_list()->StartVoiceInteractionSession(); | 150 Shell::Get()->app_list()->StartVoiceInteractionSession(); |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
313 | 314 |
314 if (shown) | 315 if (shown) |
315 OnAppListShown(); | 316 OnAppListShown(); |
316 else | 317 else |
317 OnAppListDismissed(); | 318 OnAppListDismissed(); |
318 } | 319 } |
319 | 320 |
320 void AppListButton::OnVoiceInteractionStatusChanged(bool running) { | 321 void AppListButton::OnVoiceInteractionStatusChanged(bool running) { |
321 voice_interaction_running_ = running; | 322 voice_interaction_running_ = running; |
322 SchedulePaint(); | 323 SchedulePaint(); |
| 324 |
| 325 // Voice interaction window shows up, we start hiding the animation if it is |
| 326 // running. |
| 327 if (running && voice_interaction_overlay_->IsBursting()) { |
| 328 voice_interaction_animation_hide_delay_timer_->Start( |
| 329 FROM_HERE, |
| 330 base::TimeDelta::FromMilliseconds( |
| 331 kVoiceInteractionAnimationHideDelayMs), |
| 332 base::Bind(&VoiceInteractionOverlay::HideAnimation, |
| 333 base::Unretained(voice_interaction_overlay_))); |
| 334 } |
| 335 } |
| 336 |
| 337 void AppListButton::StartVoiceInteractionAnimation() { |
| 338 // We only show the voice interaction icon and related animation when the |
| 339 // shelf is at the bottom position and voice interaction is not running. |
| 340 ShelfAlignment alignment = shelf_->alignment(); |
| 341 bool show_icon = (alignment == SHELF_ALIGNMENT_BOTTOM || |
| 342 alignment == SHELF_ALIGNMENT_BOTTOM_LOCKED) && |
| 343 !voice_interaction_running_; |
| 344 voice_interaction_overlay_->StartAnimation(show_icon); |
323 } | 345 } |
324 | 346 |
325 } // namespace ash | 347 } // namespace ash |
OLD | NEW |