Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: ui/views/controls/slide_out_view.cc

Issue 11418040: gfx::Transform API clean-up (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/transform_util.cc ('k') | ui/views/corewm/image_grid.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/views/controls/slide_out_view.h" 5 #include "ui/views/controls/slide_out_view.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 25 matching lines...) Expand all
36 if (!event->IsScrollGestureEvent()) 36 if (!event->IsScrollGestureEvent())
37 return ui::ER_UNHANDLED; 37 return ui::ER_UNHANDLED;
38 38
39 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN) { 39 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN) {
40 gesture_scroll_amount_ = 0.f; 40 gesture_scroll_amount_ = 0.f;
41 } else if (event->type() == ui::ET_GESTURE_SCROLL_UPDATE) { 41 } else if (event->type() == ui::ET_GESTURE_SCROLL_UPDATE) {
42 // The scroll-update events include the incremental scroll amount. 42 // The scroll-update events include the incremental scroll amount.
43 gesture_scroll_amount_ += event->details().scroll_x(); 43 gesture_scroll_amount_ += event->details().scroll_x();
44 44
45 gfx::Transform transform; 45 gfx::Transform transform;
46 transform.SetTranslateX(gesture_scroll_amount_); 46 transform.Translate(gesture_scroll_amount_, 0.0);
47 layer()->SetTransform(transform); 47 layer()->SetTransform(transform);
48 layer()->SetOpacity( 48 layer()->SetOpacity(
49 1.f - std::min(fabsf(gesture_scroll_amount_) / width(), 1.f)); 49 1.f - std::min(fabsf(gesture_scroll_amount_) / width(), 1.f));
50 } else if (event->type() == ui::ET_GESTURE_SCROLL_END) { 50 } else if (event->type() == ui::ET_GESTURE_SCROLL_END) {
51 const float kScrollRatioForClosingNotification = 0.5f; 51 const float kScrollRatioForClosingNotification = 0.5f;
52 float scrolled_ratio = fabsf(gesture_scroll_amount_) / width(); 52 float scrolled_ratio = fabsf(gesture_scroll_amount_) / width();
53 if (scrolled_ratio >= kScrollRatioForClosingNotification) { 53 if (scrolled_ratio >= kScrollRatioForClosingNotification) {
54 SlideOutAndClose(gesture_scroll_amount_ < 0 ? SLIDE_LEFT : SLIDE_RIGHT); 54 SlideOutAndClose(gesture_scroll_amount_ < 0 ? SLIDE_LEFT : SLIDE_RIGHT);
55 return ui::ER_CONSUMED; 55 return ui::ER_CONSUMED;
56 } 56 }
(...skipping 15 matching lines...) Expand all
72 72
73 void SlideOutView::SlideOutAndClose(SlideDirection direction) { 73 void SlideOutView::SlideOutAndClose(SlideDirection direction) {
74 const int kSwipeOutTotalDurationMS = 150; 74 const int kSwipeOutTotalDurationMS = 150;
75 int swipe_out_duration = kSwipeOutTotalDurationMS * layer()->opacity(); 75 int swipe_out_duration = kSwipeOutTotalDurationMS * layer()->opacity();
76 ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator()); 76 ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator());
77 settings.SetTransitionDuration( 77 settings.SetTransitionDuration(
78 base::TimeDelta::FromMilliseconds(swipe_out_duration)); 78 base::TimeDelta::FromMilliseconds(swipe_out_duration));
79 settings.AddObserver(this); 79 settings.AddObserver(this);
80 80
81 gfx::Transform transform; 81 gfx::Transform transform;
82 transform.SetTranslateX(direction == SLIDE_LEFT ? -width() : width()); 82 transform.Translate(direction == SLIDE_LEFT ? -width() : width(), 0.0);
83 layer()->SetTransform(transform); 83 layer()->SetTransform(transform);
84 layer()->SetOpacity(0.f); 84 layer()->SetOpacity(0.f);
85 } 85 }
86 86
87 void SlideOutView::OnImplicitAnimationsCompleted() { 87 void SlideOutView::OnImplicitAnimationsCompleted() {
88 OnSlideOut(); 88 OnSlideOut();
89 } 89 }
90 90
91 } // namespace views 91 } // namespace views
OLDNEW
« no previous file with comments | « ui/gfx/transform_util.cc ('k') | ui/views/corewm/image_grid.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698