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 2ecf3cda6bc0b182cb5364872211b1fd3dbe8bfc..648ff0994645090ebd35584cfe52001170423dd9 100644 |
| --- a/ui/views/controls/slide_out_view.cc |
| +++ b/ui/views/controls/slide_out_view.cc |
| @@ -12,8 +12,11 @@ namespace views { |
| SlideOutView::SlideOutView() |
| : gesture_scroll_amount_(0.f) { |
| - SetPaintToLayer(true); |
| - SetFillsBoundsOpaquely(false); |
| + // Only use accelerated compositing when it is available on the platform. |
|
msw
2013/01/17 22:45:39
nit: this comment seems redundant, but it's okay i
dewittj
2013/01/18 18:30:48
Changed it to be more helpful.
|
| + if (get_use_acceleration_when_possible()) { |
| + SetPaintToLayer(true); |
| + SetFillsBoundsOpaquely(false); |
| + } |
| } |
| SlideOutView::~SlideOutView() { |
| @@ -43,11 +46,14 @@ void SlideOutView::OnGestureEvent(ui::GestureEvent* event) { |
| // The scroll-update events include the incremental scroll amount. |
| gesture_scroll_amount_ += event->details().scroll_x(); |
| - gfx::Transform transform; |
| - transform.Translate(gesture_scroll_amount_, 0.0); |
| - layer()->SetTransform(transform); |
| - layer()->SetOpacity( |
| - 1.f - std::min(fabsf(gesture_scroll_amount_) / width(), 1.f)); |
| + if (get_use_acceleration_when_possible()) { |
| + gfx::Transform transform; |
| + transform.Translate(gesture_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(); |
| @@ -64,26 +70,33 @@ void SlideOutView::OnGestureEvent(ui::GestureEvent* event) { |
| void SlideOutView::RestoreVisualState() { |
| // Restore the layer state. |
|
sadrul
2013/01/18 17:53:11
Move the comment inside the if.
You could also ea
dewittj
2013/01/18 18:30:48
Done.
|
| - const int kSwipeRestoreDurationMS = 150; |
| - ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator()); |
| - settings.SetTransitionDuration( |
| - base::TimeDelta::FromMilliseconds(kSwipeRestoreDurationMS)); |
| - layer()->SetTransform(gfx::Transform()); |
| - layer()->SetOpacity(1.f); |
| + if (get_use_acceleration_when_possible()) { |
| + const int kSwipeRestoreDurationMS = 150; |
| + ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator()); |
| + settings.SetTransitionDuration( |
| + base::TimeDelta::FromMilliseconds(kSwipeRestoreDurationMS)); |
| + layer()->SetTransform(gfx::Transform()); |
| + layer()->SetOpacity(1.f); |
| + } |
| } |
| 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); |
| - |
| - gfx::Transform transform; |
| - transform.Translate(direction == SLIDE_LEFT ? -width() : width(), 0.0); |
| - layer()->SetTransform(transform); |
| - layer()->SetOpacity(0.f); |
| + if (get_use_acceleration_when_possible()) { |
| + 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); |
| + |
| + gfx::Transform transform; |
| + transform.Translate(direction == SLIDE_LEFT ? -width() : width(), 0.0); |
| + layer()->SetTransform(transform); |
| + layer()->SetOpacity(0.f); |
| + } else { |
| + // No animations, so don't wait to fire the OnSlideOut event. |
| + OnSlideOut(); |
| + } |
| } |
| void SlideOutView::OnImplicitAnimationsCompleted() { |