Chromium Code Reviews| Index: ui/views/controls/slide_out_view.cc |
| diff --git a/ui/views/controls/slide_out_view.cc b/ui/views/controls/slide_out_view.cc |
| index d3cafecf7eb42a40ce1f9b1bdf69c7927da9c1f2..b47b700acc46e6f8bc3d3c0182f35225ab708538 100644 |
| --- a/ui/views/controls/slide_out_view.cc |
| +++ b/ui/views/controls/slide_out_view.cc |
| @@ -10,8 +10,13 @@ |
| namespace views { |
| -SlideOutView::SlideOutView() |
| - : gesture_scroll_amount_(0.f) { |
| +bool SlideOutView::disable_animations_ = false; |
|
sky
2016/02/16 16:13:06
// static
|
| + |
| +void SlideOutView::DisableAnimationsForTesting() { |
| + disable_animations_ = true; |
| +} |
| + |
| +SlideOutView::SlideOutView() { |
| // If accelerated compositing is not available, this widget tracks the |
| // OnSlideOut event but does not render any visible changes. |
| SetPaintToLayer(true); |
| @@ -22,11 +27,14 @@ SlideOutView::~SlideOutView() { |
| } |
| void SlideOutView::OnGestureEvent(ui::GestureEvent* event) { |
| + const float kScrollRatioForClosingNotification = 0.5f; |
| + |
| if (event->type() == ui::ET_SCROLL_FLING_START) { |
| // The threshold for the fling velocity is computed empirically. |
| // The unit is in pixels/second. |
| const float kFlingThresholdForClose = 800.f; |
| - if (fabsf(event->details().velocity_x()) > kFlingThresholdForClose) { |
| + if (slide_out_enabled_ && |
| + fabsf(event->details().velocity_x()) > kFlingThresholdForClose) { |
| SlideOutAndClose(event->details().velocity_x() < 0 ? SLIDE_LEFT : |
| SLIDE_RIGHT); |
| event->StopPropagation(); |
| @@ -40,22 +48,36 @@ void SlideOutView::OnGestureEvent(ui::GestureEvent* event) { |
| return; |
| if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN) { |
| - gesture_scroll_amount_ = 0.f; |
| + gesture_amount_ = 0.f; |
| } else if (event->type() == ui::ET_GESTURE_SCROLL_UPDATE) { |
| // The scroll-update events include the incremental scroll amount. |
| - gesture_scroll_amount_ += event->details().scroll_x(); |
| + gesture_amount_ += event->details().scroll_x(); |
| + |
| + float scroll_amount; |
| + if (slide_out_enabled_) { |
| + scroll_amount = gesture_amount_; |
| + layer()->SetOpacity(1.f - std::min(fabsf(scroll_amount) / width(), 1.f)); |
| + } else { |
|
sadrul
2016/02/17 17:29:26
Define kScrollRatioForClosingNotification here.
yoshiki
2016/02/22 13:39:27
We can't. kScrollRatioForClosingNotification is us
|
| + if (gesture_amount_ >= 0) { |
| + scroll_amount = std::min(0.5f * gesture_amount_, |
| + width() * kScrollRatioForClosingNotification); |
| + } else { |
| + scroll_amount = |
| + std::max(0.5f * gesture_amount_, |
| + -1.f * width() * kScrollRatioForClosingNotification); |
| + } |
| + layer()->SetOpacity(1.f); |
|
sadrul
2016/02/17 17:29:26
Do you need to SetOpacity() here at all?
yoshiki
2016/02/22 13:39:27
Removed
|
| + } |
| gfx::Transform transform; |
| - transform.Translate(gesture_scroll_amount_, 0.0); |
| + transform.Translate(scroll_amount, 0.0); |
| layer()->SetTransform(transform); |
| - layer()->SetOpacity( |
| - 1.f - std::min(fabsf(gesture_scroll_amount_) / width(), 1.f)); |
| } else if (event->type() == ui::ET_GESTURE_SCROLL_END) { |
| - const float kScrollRatioForClosingNotification = 0.5f; |
| - float scrolled_ratio = fabsf(gesture_scroll_amount_) / width(); |
| - if (scrolled_ratio >= kScrollRatioForClosingNotification) { |
| - SlideOutAndClose(gesture_scroll_amount_ < 0 ? SLIDE_LEFT : SLIDE_RIGHT); |
| + float scrolled_ratio = fabsf(gesture_amount_) / width(); |
| + if (slide_out_enabled_ && |
| + scrolled_ratio >= kScrollRatioForClosingNotification) { |
| + SlideOutAndClose(gesture_amount_ < 0 ? SLIDE_LEFT : SLIDE_RIGHT); |
| event->StopPropagation(); |
| return; |
| } |
| @@ -77,16 +99,21 @@ void SlideOutView::RestoreVisualState() { |
| void SlideOutView::SlideOutAndClose(SlideDirection direction) { |
| const int kSwipeOutTotalDurationMS = 150; |
| - int swipe_out_duration = kSwipeOutTotalDurationMS * layer()->opacity(); |
| - ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator()); |
| - settings.SetTransitionDuration( |
| - base::TimeDelta::FromMilliseconds(swipe_out_duration)); |
| - settings.AddObserver(this); |
| + if (!disable_animations_) { |
| + int swipe_out_duration = kSwipeOutTotalDurationMS * layer()->opacity(); |
| + ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator()); |
| + settings.SetTransitionDuration( |
| + base::TimeDelta::FromMilliseconds(swipe_out_duration)); |
| + settings.AddObserver(this); |
| + } |
| gfx::Transform transform; |
| transform.Translate(direction == SLIDE_LEFT ? -width() : width(), 0.0); |
| layer()->SetTransform(transform); |
| layer()->SetOpacity(0.f); |
| + |
| + if (disable_animations_) |
| + OnImplicitAnimationsCompleted(); |
|
sadrul
2016/02/17 17:29:26
Can you use ScopedAnimationDurationScaleMode with
yoshiki
2016/02/22 13:39:27
I didn't know that. I can remove the flag with Sco
|
| } |
| void SlideOutView::OnImplicitAnimationsCompleted() { |