Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/message_center/views/slide_out_controller.h" | 5 #include "ui/message_center/views/slide_out_controller.h" |
| 6 | 6 |
| 7 #include "ui/compositor/layer.h" | 7 #include "ui/compositor/layer.h" |
| 8 #include "ui/compositor/scoped_layer_animation_settings.h" | 8 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 9 #include "ui/gfx/transform.h" | 9 #include "ui/gfx/transform.h" |
| 10 | 10 |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 65 } else if (event->type() == ui::ET_GESTURE_SCROLL_END) { | 65 } else if (event->type() == ui::ET_GESTURE_SCROLL_END) { |
| 66 float scrolled_ratio = fabsf(gesture_amount_) / width; | 66 float scrolled_ratio = fabsf(gesture_amount_) / width; |
| 67 if (enabled_ && scrolled_ratio >= kScrollRatioForClosingNotification) { | 67 if (enabled_ && scrolled_ratio >= kScrollRatioForClosingNotification) { |
| 68 SlideOutAndClose(gesture_amount_); | 68 SlideOutAndClose(gesture_amount_); |
| 69 event->StopPropagation(); | 69 event->StopPropagation(); |
| 70 return; | 70 return; |
| 71 } | 71 } |
| 72 RestoreVisualState(); | 72 RestoreVisualState(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 delegate_->OnSlideChanged(); | |
|
Evan Stade
2017/05/16 21:58:14
Can the interested party (ArcCustomNotificationVie
Eliot Courtney
2017/05/17 04:48:25
I tried this (by adding an override for OnLayerAni
| |
| 75 event->SetHandled(); | 76 event->SetHandled(); |
| 76 } | 77 } |
| 77 | 78 |
| 78 void SlideOutController::RestoreVisualState() { | 79 void SlideOutController::RestoreVisualState() { |
| 79 ui::Layer* layer = delegate_->GetSlideOutLayer(); | 80 ui::Layer* layer = delegate_->GetSlideOutLayer(); |
| 80 // Restore the layer state. | 81 // Restore the layer state. |
| 81 const int kSwipeRestoreDurationMS = 150; | 82 const int kSwipeRestoreDurationMS = 150; |
| 82 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); | 83 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); |
| 83 settings.SetTransitionDuration( | 84 settings.SetTransitionDuration( |
| 84 base::TimeDelta::FromMilliseconds(kSwipeRestoreDurationMS)); | 85 base::TimeDelta::FromMilliseconds(kSwipeRestoreDurationMS)); |
| 85 layer->SetTransform(gfx::Transform()); | 86 layer->SetTransform(gfx::Transform()); |
| 86 layer->SetOpacity(1.f); | 87 layer->SetOpacity(1.f); |
| 87 } | 88 } |
| 88 | 89 |
| 89 void SlideOutController::SlideOutAndClose(int direction) { | 90 void SlideOutController::SlideOutAndClose(int direction) { |
| 90 ui::Layer* layer = delegate_->GetSlideOutLayer(); | 91 ui::Layer* layer = delegate_->GetSlideOutLayer(); |
| 91 const int kSwipeOutTotalDurationMS = 150; | 92 const int kSwipeOutTotalDurationMS = 150; |
| 92 int swipe_out_duration = kSwipeOutTotalDurationMS * layer->opacity(); | 93 int swipe_out_duration = kSwipeOutTotalDurationMS * layer->opacity(); |
| 93 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); | 94 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); |
| 94 settings.SetTransitionDuration( | 95 settings.SetTransitionDuration( |
| 95 base::TimeDelta::FromMilliseconds(swipe_out_duration)); | 96 base::TimeDelta::FromMilliseconds(swipe_out_duration)); |
| 96 settings.AddObserver(this); | 97 settings.AddObserver(this); |
| 97 | 98 |
| 98 gfx::Transform transform; | 99 gfx::Transform transform; |
| 99 int width = layer->bounds().width(); | 100 int width = layer->bounds().width(); |
| 100 transform.Translate(direction < 0 ? -width : width, 0.0); | 101 transform.Translate(direction < 0 ? -width : width, 0.0); |
| 101 layer->SetTransform(transform); | 102 layer->SetTransform(transform); |
| 102 layer->SetOpacity(0.f); | 103 layer->SetOpacity(0.f); |
| 104 delegate_->OnSlideChanged(); | |
| 103 } | 105 } |
| 104 | 106 |
| 105 void SlideOutController::OnImplicitAnimationsCompleted() { | 107 void SlideOutController::OnImplicitAnimationsCompleted() { |
| 106 delegate_->OnSlideOut(); | 108 delegate_->OnSlideOut(); |
| 107 } | 109 } |
| 108 | 110 |
| 109 } // namespace views | 111 } // namespace views |
| OLD | NEW |