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

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

Issue 11836003: Allow message center and related bubbles to render on Windows. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Take out Impl, address nits. Created 7 years, 11 months 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
« no previous file with comments | « ui/views/controls/slide_out_view.h ('k') | no next file » | 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
11 namespace views { 11 namespace views {
12 12
13 SlideOutView::SlideOutView() 13 SlideOutView::SlideOutView()
14 : gesture_scroll_amount_(0.f) { 14 : gesture_scroll_amount_(0.f) {
15 SetPaintToLayer(true); 15 // 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.
16 SetFillsBoundsOpaquely(false); 16 if (get_use_acceleration_when_possible()) {
17 SetPaintToLayer(true);
18 SetFillsBoundsOpaquely(false);
19 }
17 } 20 }
18 21
19 SlideOutView::~SlideOutView() { 22 SlideOutView::~SlideOutView() {
20 } 23 }
21 24
22 void SlideOutView::OnGestureEvent(ui::GestureEvent* event) { 25 void SlideOutView::OnGestureEvent(ui::GestureEvent* event) {
23 if (event->type() == ui::ET_SCROLL_FLING_START) { 26 if (event->type() == ui::ET_SCROLL_FLING_START) {
24 // The threshold for the fling velocity is computed empirically. 27 // The threshold for the fling velocity is computed empirically.
25 // The unit is in pixels/second. 28 // The unit is in pixels/second.
26 const float kFlingThresholdForClose = 800.f; 29 const float kFlingThresholdForClose = 800.f;
27 if (fabsf(event->details().velocity_x()) > kFlingThresholdForClose) { 30 if (fabsf(event->details().velocity_x()) > kFlingThresholdForClose) {
28 SlideOutAndClose(event->details().velocity_x() < 0 ? SLIDE_LEFT : 31 SlideOutAndClose(event->details().velocity_x() < 0 ? SLIDE_LEFT :
29 SLIDE_RIGHT); 32 SLIDE_RIGHT);
30 event->StopPropagation(); 33 event->StopPropagation();
31 return; 34 return;
32 } 35 }
33 RestoreVisualState(); 36 RestoreVisualState();
34 return; 37 return;
35 } 38 }
36 39
37 if (!event->IsScrollGestureEvent()) 40 if (!event->IsScrollGestureEvent())
38 return; 41 return;
39 42
40 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN) { 43 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN) {
41 gesture_scroll_amount_ = 0.f; 44 gesture_scroll_amount_ = 0.f;
42 } else if (event->type() == ui::ET_GESTURE_SCROLL_UPDATE) { 45 } else if (event->type() == ui::ET_GESTURE_SCROLL_UPDATE) {
43 // The scroll-update events include the incremental scroll amount. 46 // The scroll-update events include the incremental scroll amount.
44 gesture_scroll_amount_ += event->details().scroll_x(); 47 gesture_scroll_amount_ += event->details().scroll_x();
45 48
46 gfx::Transform transform; 49 if (get_use_acceleration_when_possible()) {
47 transform.Translate(gesture_scroll_amount_, 0.0); 50 gfx::Transform transform;
48 layer()->SetTransform(transform); 51 transform.Translate(gesture_scroll_amount_, 0.0);
49 layer()->SetOpacity( 52 layer()->SetTransform(transform);
50 1.f - std::min(fabsf(gesture_scroll_amount_) / width(), 1.f)); 53 layer()->SetOpacity(
54 1.f - std::min(fabsf(gesture_scroll_amount_) / width(), 1.f));
55 }
56
51 } else if (event->type() == ui::ET_GESTURE_SCROLL_END) { 57 } else if (event->type() == ui::ET_GESTURE_SCROLL_END) {
52 const float kScrollRatioForClosingNotification = 0.5f; 58 const float kScrollRatioForClosingNotification = 0.5f;
53 float scrolled_ratio = fabsf(gesture_scroll_amount_) / width(); 59 float scrolled_ratio = fabsf(gesture_scroll_amount_) / width();
54 if (scrolled_ratio >= kScrollRatioForClosingNotification) { 60 if (scrolled_ratio >= kScrollRatioForClosingNotification) {
55 SlideOutAndClose(gesture_scroll_amount_ < 0 ? SLIDE_LEFT : SLIDE_RIGHT); 61 SlideOutAndClose(gesture_scroll_amount_ < 0 ? SLIDE_LEFT : SLIDE_RIGHT);
56 event->StopPropagation(); 62 event->StopPropagation();
57 return; 63 return;
58 } 64 }
59 RestoreVisualState(); 65 RestoreVisualState();
60 } 66 }
61 67
62 event->SetHandled(); 68 event->SetHandled();
63 } 69 }
64 70
65 void SlideOutView::RestoreVisualState() { 71 void SlideOutView::RestoreVisualState() {
66 // Restore the layer state. 72 // 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.
67 const int kSwipeRestoreDurationMS = 150; 73 if (get_use_acceleration_when_possible()) {
68 ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator()); 74 const int kSwipeRestoreDurationMS = 150;
69 settings.SetTransitionDuration( 75 ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator());
70 base::TimeDelta::FromMilliseconds(kSwipeRestoreDurationMS)); 76 settings.SetTransitionDuration(
71 layer()->SetTransform(gfx::Transform()); 77 base::TimeDelta::FromMilliseconds(kSwipeRestoreDurationMS));
72 layer()->SetOpacity(1.f); 78 layer()->SetTransform(gfx::Transform());
79 layer()->SetOpacity(1.f);
80 }
73 } 81 }
74 82
75 void SlideOutView::SlideOutAndClose(SlideDirection direction) { 83 void SlideOutView::SlideOutAndClose(SlideDirection direction) {
76 const int kSwipeOutTotalDurationMS = 150; 84 if (get_use_acceleration_when_possible()) {
77 int swipe_out_duration = kSwipeOutTotalDurationMS * layer()->opacity(); 85 const int kSwipeOutTotalDurationMS = 150;
78 ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator()); 86 int swipe_out_duration = kSwipeOutTotalDurationMS * layer()->opacity();
79 settings.SetTransitionDuration( 87 ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator());
80 base::TimeDelta::FromMilliseconds(swipe_out_duration)); 88 settings.SetTransitionDuration(
81 settings.AddObserver(this); 89 base::TimeDelta::FromMilliseconds(swipe_out_duration));
90 settings.AddObserver(this);
82 91
83 gfx::Transform transform; 92 gfx::Transform transform;
84 transform.Translate(direction == SLIDE_LEFT ? -width() : width(), 0.0); 93 transform.Translate(direction == SLIDE_LEFT ? -width() : width(), 0.0);
85 layer()->SetTransform(transform); 94 layer()->SetTransform(transform);
86 layer()->SetOpacity(0.f); 95 layer()->SetOpacity(0.f);
96 } else {
97 // No animations, so don't wait to fire the OnSlideOut event.
98 OnSlideOut();
99 }
87 } 100 }
88 101
89 void SlideOutView::OnImplicitAnimationsCompleted() { 102 void SlideOutView::OnImplicitAnimationsCompleted() {
90 OnSlideOut(); 103 OnSlideOut();
91 } 104 }
92 105
93 } // namespace views 106 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/slide_out_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698