Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/views/controls/slide_out_view_impl.h" | |
| 6 | |
| 7 #include "ui/compositor/layer.h" | |
| 8 #include "ui/compositor/scoped_layer_animation_settings.h" | |
| 9 #include "ui/gfx/transform.h" | |
| 10 #include "ui/views/controls/slide_out_view.h" | |
| 11 | |
| 12 namespace views { | |
| 13 | |
| 14 SlideOutViewImpl::SlideOutViewImpl(SlideOutView* view) | |
| 15 : view_(view) { | |
| 16 view->SetPaintToLayer(true); | |
| 17 view->SetFillsBoundsOpaquely(false); | |
| 18 } | |
| 19 | |
| 20 SlideOutViewImpl::~SlideOutViewImpl() { | |
| 21 } | |
| 22 | |
| 23 void SlideOutViewImpl::TransformView(float scroll_amount) { | |
| 24 gfx::Transform transform; | |
|
msw
2013/01/17 02:28:30
Perhaps it's just me, but I'd rather see these imp
sadrul
2013/01/17 03:27:22
I agree. That would be simpler.
dewittj
2013/01/17 21:25:18
Done.
| |
| 25 transform.Translate(scroll_amount, 0.0); | |
| 26 view_->layer()->SetTransform(transform); | |
| 27 view_->layer()->SetOpacity( | |
| 28 1.f - std::min(fabsf(scroll_amount) / view_->width(), 1.f)); | |
| 29 } | |
| 30 | |
| 31 void SlideOutViewImpl::RestoreView() { | |
| 32 const int kSwipeRestoreDurationMS = 150; | |
| 33 ui::ScopedLayerAnimationSettings settings(view_->layer()->GetAnimator()); | |
| 34 settings.SetTransitionDuration( | |
| 35 base::TimeDelta::FromMilliseconds(kSwipeRestoreDurationMS)); | |
| 36 view_->layer()->SetTransform(gfx::Transform()); | |
| 37 view_->layer()->SetOpacity(1.f); | |
| 38 } | |
| 39 | |
| 40 void SlideOutViewImpl::HideView(SlideOutView::SlideDirection direction) { | |
| 41 const int kSwipeOutTotalDurationMS = 150; | |
| 42 int swipe_out_duration = kSwipeOutTotalDurationMS * view_->layer()->opacity(); | |
| 43 ui::ScopedLayerAnimationSettings settings(view_->layer()->GetAnimator()); | |
| 44 settings.SetTransitionDuration( | |
| 45 base::TimeDelta::FromMilliseconds(swipe_out_duration)); | |
| 46 settings.AddObserver(view_); | |
| 47 | |
| 48 gfx::Transform transform; | |
| 49 if (direction == SlideOutView::SLIDE_LEFT) | |
| 50 transform.Translate(-view_->width(), 0.0); | |
| 51 else | |
| 52 transform.Translate(view_->width(), 0.0); | |
| 53 view_->layer()->SetTransform(transform); | |
| 54 view_->layer()->SetOpacity(0.f); | |
| 55 } | |
| 56 | |
| 57 } // namespace views | |
| OLD | NEW |