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

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: Remove ifdefs. 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
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 #include "ui/views/controls/slide_out_view_impl.h"
10 11
11 namespace views { 12 namespace views {
12 13
13 SlideOutView::SlideOutView() 14 SlideOutView::SlideOutView()
14 : gesture_scroll_amount_(0.f) { 15 : gesture_scroll_amount_(0.f) {
15 SetPaintToLayer(true); 16 if (get_use_acceleration_when_possible()) {
msw 2013/01/17 02:28:30 nit: remove unnecessary braces.
dewittj 2013/01/17 21:25:18 Gone.
16 SetFillsBoundsOpaquely(false); 17 impl_.reset(new SlideOutViewImpl(this));
18 }
17 } 19 }
18 20
19 SlideOutView::~SlideOutView() { 21 SlideOutView::~SlideOutView() {
20 } 22 }
21 23
22 void SlideOutView::OnGestureEvent(ui::GestureEvent* event) { 24 void SlideOutView::OnGestureEvent(ui::GestureEvent* event) {
23 if (event->type() == ui::ET_SCROLL_FLING_START) { 25 if (event->type() == ui::ET_SCROLL_FLING_START) {
24 // The threshold for the fling velocity is computed empirically. 26 // The threshold for the fling velocity is computed empirically.
25 // The unit is in pixels/second. 27 // The unit is in pixels/second.
26 const float kFlingThresholdForClose = 800.f; 28 const float kFlingThresholdForClose = 800.f;
27 if (fabsf(event->details().velocity_x()) > kFlingThresholdForClose) { 29 if (fabsf(event->details().velocity_x()) > kFlingThresholdForClose) {
28 SlideOutAndClose(event->details().velocity_x() < 0 ? SLIDE_LEFT : 30 SlideOutAndClose(event->details().velocity_x() < 0 ? SLIDE_LEFT :
29 SLIDE_RIGHT); 31 SLIDE_RIGHT);
30 event->StopPropagation(); 32 event->StopPropagation();
31 return; 33 return;
32 } 34 }
33 RestoreVisualState(); 35 RestoreVisualState();
34 return; 36 return;
35 } 37 }
36 38
37 if (!event->IsScrollGestureEvent()) 39 if (!event->IsScrollGestureEvent())
38 return; 40 return;
39 41
40 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN) { 42 if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN) {
41 gesture_scroll_amount_ = 0.f; 43 gesture_scroll_amount_ = 0.f;
42 } else if (event->type() == ui::ET_GESTURE_SCROLL_UPDATE) { 44 } else if (event->type() == ui::ET_GESTURE_SCROLL_UPDATE) {
43 // The scroll-update events include the incremental scroll amount. 45 // The scroll-update events include the incremental scroll amount.
44 gesture_scroll_amount_ += event->details().scroll_x(); 46 gesture_scroll_amount_ += event->details().scroll_x();
45 47
46 gfx::Transform transform; 48 if (impl_)
47 transform.Translate(gesture_scroll_amount_, 0.0); 49 impl_->TransformView(gesture_scroll_amount_);
48 layer()->SetTransform(transform);
49 layer()->SetOpacity(
50 1.f - std::min(fabsf(gesture_scroll_amount_) / width(), 1.f));
51 } else if (event->type() == ui::ET_GESTURE_SCROLL_END) { 50 } else if (event->type() == ui::ET_GESTURE_SCROLL_END) {
52 const float kScrollRatioForClosingNotification = 0.5f; 51 const float kScrollRatioForClosingNotification = 0.5f;
53 float scrolled_ratio = fabsf(gesture_scroll_amount_) / width(); 52 float scrolled_ratio = fabsf(gesture_scroll_amount_) / width();
54 if (scrolled_ratio >= kScrollRatioForClosingNotification) { 53 if (scrolled_ratio >= kScrollRatioForClosingNotification) {
55 SlideOutAndClose(gesture_scroll_amount_ < 0 ? SLIDE_LEFT : SLIDE_RIGHT); 54 SlideOutAndClose(gesture_scroll_amount_ < 0 ? SLIDE_LEFT : SLIDE_RIGHT);
56 event->StopPropagation(); 55 event->StopPropagation();
57 return; 56 return;
58 } 57 }
59 RestoreVisualState(); 58 RestoreVisualState();
60 } 59 }
61 60
62 event->SetHandled(); 61 event->SetHandled();
63 } 62 }
64 63
65 void SlideOutView::RestoreVisualState() { 64 void SlideOutView::RestoreVisualState() {
66 // Restore the layer state. 65 // Restore the layer state.
67 const int kSwipeRestoreDurationMS = 150; 66 if (impl_)
68 ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator()); 67 impl_->RestoreView();
69 settings.SetTransitionDuration(
70 base::TimeDelta::FromMilliseconds(kSwipeRestoreDurationMS));
71 layer()->SetTransform(gfx::Transform());
72 layer()->SetOpacity(1.f);
73 } 68 }
74 69
75 void SlideOutView::SlideOutAndClose(SlideDirection direction) { 70 void SlideOutView::SlideOutAndClose(SlideDirection direction) {
76 const int kSwipeOutTotalDurationMS = 150; 71 if (impl_)
77 int swipe_out_duration = kSwipeOutTotalDurationMS * layer()->opacity(); 72 impl_->HideView(direction);
78 ui::ScopedLayerAnimationSettings settings(layer()->GetAnimator());
79 settings.SetTransitionDuration(
80 base::TimeDelta::FromMilliseconds(swipe_out_duration));
81 settings.AddObserver(this);
82
83 gfx::Transform transform;
84 transform.Translate(direction == SLIDE_LEFT ? -width() : width(), 0.0);
85 layer()->SetTransform(transform);
86 layer()->SetOpacity(0.f);
87 } 73 }
88 74
89 void SlideOutView::OnImplicitAnimationsCompleted() { 75 void SlideOutView::OnImplicitAnimationsCompleted() {
90 OnSlideOut(); 76 OnSlideOut();
91 } 77 }
92 78
93 } // namespace views 79 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698