blob: 7ebb8171e8640ac640b57b54a56a80aabf4c6abf [file] [log] [blame]
[email protected]c6de4d8e2013-05-17 17:51:511// 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
3// found in the LICENSE file.
4
5#ifndef CONTENT_BROWSER_ANDROID_OVERSCROLL_GLOW_H_
6#define CONTENT_BROWSER_ANDROID_OVERSCROLL_GLOW_H_
7
8#include "base/memory/ref_counted.h"
9#include "base/memory/scoped_ptr.h"
[email protected]a43858f2013-06-28 15:18:3710#include "base/time/time.h"
tfarina93bfa912014-12-05 14:23:1511#include "ui/gfx/geometry/size_f.h"
12#include "ui/gfx/geometry/vector2d_f.h"
[email protected]c6de4d8e2013-05-17 17:51:5113
[email protected]cffc3282014-08-15 23:38:2414namespace cc {
15class Layer;
[email protected]c6de4d8e2013-05-17 17:51:5116}
17
18namespace content {
19
[email protected]cffc3282014-08-15 23:38:2420class EdgeEffectBase;
21
jdduke0fa512992014-11-21 03:18:4522// Provides lazy, customized EdgeEffect creation.
23class OverscrollGlowClient {
24 public:
25 virtual ~OverscrollGlowClient() {}
26
27 // Called lazily, after the initial overscrolling event.
28 virtual scoped_ptr<EdgeEffectBase> CreateEdgeEffect() = 0;
29};
30
[email protected]bb4b8b792013-07-26 10:54:5531/* |OverscrollGlow| mirrors its Android counterpart, OverscrollGlow.java.
[email protected]c6de4d8e2013-05-17 17:51:5132 * Conscious tradeoffs were made to align this as closely as possible with the
[email protected]afaaf902014-04-11 23:43:0933 * original Android Java version.
[email protected]c6de4d8e2013-05-17 17:51:5134 */
35class OverscrollGlow {
36 public:
[email protected]cffc3282014-08-15 23:38:2437 enum Edge { EDGE_TOP = 0, EDGE_LEFT, EDGE_BOTTOM, EDGE_RIGHT, EDGE_COUNT };
38
jdduke0fa512992014-11-21 03:18:4539 // |client| must be valid for the duration of the effect's lifetime.
40 // The effect is enabled by default, but will remain dormant until the first
41 // overscroll event.
42 explicit OverscrollGlow(OverscrollGlowClient* client);
[email protected]c6de4d8e2013-05-17 17:51:5143 ~OverscrollGlow();
44
jdduke9db1b9d2014-11-15 00:49:5245 // Called when the root content layer overscrolls.
[email protected]5b198332014-04-29 09:37:5746 // |accumulated_overscroll| and |overscroll_delta| are in device pixels, while
47 // |velocity| is in device pixels / second.
jdduke3367dde2015-07-25 01:23:4748 // |overscroll_location| is the coordinate of the causal overscrolling event.
[email protected]580d3362013-12-07 02:56:4349 // Returns true if the effect still needs animation ticks.
jdduke9db1b9d2014-11-15 00:49:5250 bool OnOverscrolled(base::TimeTicks current_time,
a.berwal29999902015-04-30 06:43:1051 const gfx::Vector2dF& accumulated_overscroll,
[email protected]5b198332014-04-29 09:37:5752 gfx::Vector2dF overscroll_delta,
[email protected]cffc3282014-08-15 23:38:2453 gfx::Vector2dF velocity,
a.berwal29999902015-04-30 06:43:1054 const gfx::Vector2dF& overscroll_location);
[email protected]c724a0a2013-06-22 00:23:4455
jdduke9db1b9d2014-11-15 00:49:5256 // Returns true if the effect still needs animation ticks, with effect layers
57 // attached to |parent_layer| if necessary.
[email protected]580d3362013-12-07 02:56:4358 // Note: The effect will detach itself when no further animation is required.
jdduke9db1b9d2014-11-15 00:49:5259 bool Animate(base::TimeTicks current_time, cc::Layer* parent_layer);
[email protected]c6de4d8e2013-05-17 17:51:5160
[email protected]afaaf902014-04-11 23:43:0961 // Update the effect according to the most recent display parameters,
62 // Note: All dimensions are in device pixels.
jddukeb00377552015-04-15 01:55:0863 void OnFrameUpdated(const gfx::SizeF& viewport_size,
64 const gfx::SizeF& content_size,
65 const gfx::Vector2dF& content_scroll_offset);
jdduke9db1b9d2014-11-15 00:49:5266
67 // Reset the effect to its inactive state, clearing any active effects.
68 void Reset();
[email protected]afaaf902014-04-11 23:43:0969
jdduke2dbb7e82015-02-11 20:58:2370 // Whether the effect is active, either being pulled or receding.
71 bool IsActive() const;
72
jdduke9349a45e2015-03-17 21:50:2373 // The maximum alpha value (in the range [0,1]) of any animated edge layers.
74 // If the effect is inactive, this will be 0.
75 float GetVisibleAlpha() const;
76
[email protected]c6de4d8e2013-05-17 17:51:5177 private:
78 enum Axis { AXIS_X, AXIS_Y };
79
jdduke9db1b9d2014-11-15 00:49:5280 // Returns whether the effect has been properly initialized.
[email protected]580d3362013-12-07 02:56:4381 bool InitializeIfNecessary();
jdduke9db1b9d2014-11-15 00:49:5282 bool CheckNeedsAnimate();
[email protected]580d3362013-12-07 02:56:4383 void UpdateLayerAttachment(cc::Layer* parent);
84 void Detach();
[email protected]cffc3282014-08-15 23:38:2485 void Pull(base::TimeTicks current_time,
86 const gfx::Vector2dF& overscroll_delta,
87 const gfx::Vector2dF& overscroll_location);
[email protected]c6de4d8e2013-05-17 17:51:5188 void Absorb(base::TimeTicks current_time,
[email protected]cffc3282014-08-15 23:38:2489 const gfx::Vector2dF& velocity,
[email protected]5b198332014-04-29 09:37:5790 bool x_overscroll_started,
91 bool y_overscroll_started);
[email protected]e5535032013-10-15 19:13:3392 void Release(base::TimeTicks current_time);
[email protected]c6de4d8e2013-05-17 17:51:5193
[email protected]cffc3282014-08-15 23:38:2494 EdgeEffectBase* GetOppositeEdge(int edge_index);
[email protected]c6de4d8e2013-05-17 17:51:5195
jdduke0fa512992014-11-21 03:18:4596 OverscrollGlowClient* const client_;
[email protected]cffc3282014-08-15 23:38:2497 scoped_ptr<EdgeEffectBase> edge_effects_[EDGE_COUNT];
[email protected]c6de4d8e2013-05-17 17:51:5198
jdduke9db1b9d2014-11-15 00:49:5299 gfx::SizeF viewport_size_;
100 float edge_offsets_[EDGE_COUNT];
[email protected]afaaf902014-04-11 23:43:09101 bool initialized_;
jdduke3367dde2015-07-25 01:23:47102 bool allow_horizontal_overscroll_;
103 bool allow_vertical_overscroll_;
[email protected]c6de4d8e2013-05-17 17:51:51104
105 scoped_refptr<cc::Layer> root_layer_;
[email protected]c6de4d8e2013-05-17 17:51:51106
107 DISALLOW_COPY_AND_ASSIGN(OverscrollGlow);
108};
109
110} // namespace content
111
tfarinabccc34c72015-02-27 21:32:15112#endif // CONTENT_BROWSER_ANDROID_OVERSCROLL_GLOW_H_