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

Side by Side Diff: chrome/browser/ui/views/frame/scroll_end_effect_controller_ash.cc

Issue 22265009: Implement initial version of scroll end effect Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Responded to outstanding comments from sadrul@ Created 7 years, 1 month 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
OLDNEW
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();
54
55 int capped_delta_y = delta_y;
56 // Limiting the delta size being a proportion of the frame bounds size.
57 if (capped_delta_y > 0) {
58 capped_delta_y = std::min(gfx::ToRoundedInt((frame_bounds_.height() *
59 kScrollEndEffectFactor)),
60 capped_delta_y);
61 } else if (capped_delta_y < 0) {
62 capped_delta_y = -std::min(gfx::ToRoundedInt((frame_bounds_.height() *
63 kScrollEndEffectFactor)),
64 -capped_delta_y);
65 }
66
67 start_delta_y_ = current_delta_y_;
68 end_delta_y_ = capped_delta_y;
69 if (end_delta_y_ == 0) {
70 animation_->Reset();
71 animation_->Show();
72 if (animation_->GetSlideDuration() == 0) {
73 AnimationProgressed(animation_.get());
74 AnimationEnded(animation_.get());
75 }
76 } else {
77 animation_->Reset();
78 ApplyDelta(end_delta_y_);
79 }
19 } 80 }
81
82 void ScrollEndEffectControllerAsh::AnimationEnded(
83 const gfx::Animation* animation) {
84 if (current_delta_y_ == 0)
85 DeactivateEffect();
86 }
87
88 void ScrollEndEffectControllerAsh::AnimationProgressed(
89 const gfx::Animation* animation) {
90 ApplyDelta(gfx::Tween::IntValueBetween(animation_->GetCurrentValue(),
91 start_delta_y_,
92 end_delta_y_));
93 }
94
95 void ScrollEndEffectControllerAsh::ActivateEffect() {
96 is_effect_active_ = true;
97 frame_bounds_ = delegate_->GetFrameBounds();
98 delegate_->GetContentsContainer()->ActivateScrollEndEffect();
99 }
100
101 void ScrollEndEffectControllerAsh::DeactivateEffect() {
102 is_effect_active_ = false;
103 delegate_->SetFrameBounds(frame_bounds_);
104 delegate_->GetContentsContainer()->DeactivateScrollEndEffect();
105 }
106
107 void ScrollEndEffectControllerAsh::ApplyDelta(int delta_y) {
108 current_delta_y_ = delta_y;
109 gfx::Rect bounds = frame_bounds_;
110
111 float scale_factor = 1.0f - static_cast<float>(std::abs(current_delta_y_)) /
112 static_cast<float>(bounds.height());
113
114 bounds.set_height(gfx::ToRoundedInt(bounds.height() * scale_factor));
115 bool scrolling_down = current_delta_y_ > 0;
116 if (scrolling_down) {
117 gfx::Point bounds_orig = bounds.origin();
118 bounds_orig.set_y(bounds_orig.y() + current_delta_y_);
119 bounds.set_origin(bounds_orig);
120 }
121 delegate_->SetFrameBounds(bounds);
122 delegate_->GetContentsContainer()->
123 UpdateScrollEndEffectHeightDelta(frame_bounds_.height() - bounds.height(),
124 scrolling_down);
125 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698