OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/views/frame/scroll_end_effect_controller_ash.h" | 5 #include "chrome/browser/ui/views/frame/scroll_end_effect_controller_ash.h" |
6 | 6 |
7 ScrollEndEffectController* ScrollEndEffectController::Create() { | 7 #include "chrome/browser/ui/views/download/download_shelf_view.h" |
8 return new ScrollEndEffectControllerAsh(); | 8 #include "chrome/browser/ui/views/frame/browser_frame.h" |
9 #include "chrome/browser/ui/views/frame/browser_view.h" | |
10 #include "chrome/browser/ui/views/frame/contents_container.h" | |
11 #include "content/public/browser/web_contents.h" | |
12 #include "content/public/browser/web_contents_view.h" | |
13 #include "ui/aura/window.h" | |
14 #include "ui/compositor/layer_type.h" | |
15 #include "ui/gfx/animation/tween.h" | |
16 #include "ui/gfx/rect_conversions.h" | |
17 #include "ui/gfx/safe_integer_conversions.h" | |
18 #include "ui/views/controls/single_split_view.h" | |
19 #include "ui/views/controls/webview/webview.h" | |
20 | |
21 namespace { | |
22 // This factor is used to control how much translation is applied relative to | |
23 // the size of the window. Specifically translation is limited to a max of | |
24 // window_size * factor. | |
25 const float kScrollEndEffectFactor = 0.05f; | |
26 } // namespace | |
27 | |
28 ScrollEndEffectController* ScrollEndEffectController::Create( | |
29 ScrollEndEffectControllerDelegate* delegate) { | |
30 return new ScrollEndEffectControllerAsh(delegate); | |
9 } | 31 } |
10 | 32 |
11 ScrollEndEffectControllerAsh::ScrollEndEffectControllerAsh() { | 33 ScrollEndEffectControllerAsh::ScrollEndEffectControllerAsh( |
34 ScrollEndEffectControllerDelegate* delegate) | |
35 : delegate_(delegate), | |
36 is_effect_active_(false), | |
37 start_delta_y_(0), | |
38 current_delta_y_(0), | |
39 end_delta_y_(0) { | |
40 animation_.reset(new gfx::SlideAnimation(this)); | |
41 animation_->SetSlideDuration(100); | |
42 animation_->SetTweenType(gfx::Tween::EASE_OUT); | |
12 } | 43 } |
13 | 44 |
14 ScrollEndEffectControllerAsh::~ScrollEndEffectControllerAsh() { | 45 ScrollEndEffectControllerAsh::~ScrollEndEffectControllerAsh() { |
15 } | 46 } |
16 | 47 |
17 void ScrollEndEffectControllerAsh::OverscrollUpdate(int delta_y) { | 48 void ScrollEndEffectControllerAsh::OverscrollUpdate(int delta_y) { |
18 // TODO(rharrison): Implement initial version of scroll end effect | 49 if (!is_effect_active_ && delta_y == 0) |
50 return; | |
51 | |
52 if (!is_effect_active_) { | |
53 ActivateEffect(); | |
sadrul
2013/10/25 18:28:25
no {}
rharrison
2013/11/18 21:52:26
Done.
| |
54 } | |
55 | |
56 int capped_delta_y = delta_y; | |
57 // Limiting the delta size being a proportion of the frame bounds size. | |
58 if (capped_delta_y > 0) { | |
59 capped_delta_y = std::min(gfx::ToRoundedInt((frame_bounds_.height() * | |
60 kScrollEndEffectFactor)), | |
61 capped_delta_y); | |
62 } else if (capped_delta_y < 0) { | |
63 capped_delta_y = -std::min(gfx::ToRoundedInt((frame_bounds_.height() * | |
64 kScrollEndEffectFactor)), | |
65 -capped_delta_y); | |
66 } | |
67 | |
68 start_delta_y_ = current_delta_y_; | |
69 end_delta_y_ = capped_delta_y; | |
70 if (end_delta_y_ == 0) { | |
71 animation_->Reset(); | |
72 animation_->Show(); | |
73 if (animation_->GetSlideDuration() == 0) { | |
74 AnimationProgressed(animation_.get()); | |
75 AnimationEnded(animation_.get()); | |
76 } | |
77 } else { | |
78 animation_->Reset(); | |
79 ApplyDelta(end_delta_y_); | |
80 } | |
19 } | 81 } |
82 | |
83 void ScrollEndEffectControllerAsh::AnimationEnded( | |
84 const gfx::Animation* animation) { | |
85 if (current_delta_y_ == 0) | |
86 DeactivateEffect(); | |
87 } | |
88 | |
89 void ScrollEndEffectControllerAsh::AnimationProgressed( | |
90 const gfx::Animation* animation) { | |
91 ApplyDelta(gfx::Tween::IntValueBetween(animation_->GetCurrentValue(), | |
92 start_delta_y_, | |
93 end_delta_y_)); | |
94 } | |
95 | |
96 void ScrollEndEffectControllerAsh::ActivateEffect() { | |
97 is_effect_active_ = true; | |
98 frame_bounds_ = delegate_->GetFrameBounds(); | |
99 delegate_->GetContentsContainer()->ActivateScrollEndEffect(); | |
100 } | |
101 | |
102 void ScrollEndEffectControllerAsh::DeactivateEffect() { | |
103 is_effect_active_ = false; | |
104 delegate_->SetFrameBounds(frame_bounds_); | |
105 delegate_->GetContentsContainer()->DeactivateScrollEndEffect(); | |
106 } | |
107 | |
108 void ScrollEndEffectControllerAsh::ApplyDelta(int delta_y) { | |
109 current_delta_y_ = delta_y; | |
110 gfx::Rect bounds = frame_bounds_; | |
111 | |
112 float scale_factor = std::abs(current_delta_y_); | |
113 scale_factor /= bounds.height(); | |
114 scale_factor = 1 - scale_factor; | |
sadrul
2013/10/25 18:28:25
float scale_factor = 1 - std::abs(current_delta_y_
rharrison
2013/11/18 21:52:26
Done.
| |
115 | |
116 bounds.set_height(gfx::ToRoundedInt(bounds.height() * scale_factor)); | |
117 bool scrolling_down = current_delta_y_ > 0; | |
118 if (scrolling_down) { | |
119 gfx::Point bounds_orig = bounds.origin(); | |
120 bounds_orig.set_y(bounds_orig.y() + current_delta_y_); | |
121 bounds.set_origin(bounds_orig); | |
122 } | |
123 delegate_->SetFrameBounds(bounds); | |
124 delegate_->GetContentsContainer()-> | |
125 UpdateScrollEndEffectHeightDelta(frame_bounds_.height() - bounds.height(), | |
126 scrolling_down); | |
127 } | |
OLD | NEW |