ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / content / browser / android / overscroll_glow.h
blob8685c9c788609ee43a2afdc02f2df2b9882a706c
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_ANDROID_OVERSCROLL_GLOW_H_
6 #define CONTENT_BROWSER_ANDROID_OVERSCROLL_GLOW_H_
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/time/time.h"
11 #include "ui/gfx/geometry/size_f.h"
12 #include "ui/gfx/geometry/vector2d_f.h"
14 namespace cc {
15 class Layer;
18 namespace content {
20 class EdgeEffectBase;
22 // Provides lazy, customized EdgeEffect creation.
23 class OverscrollGlowClient {
24 public:
25 virtual ~OverscrollGlowClient() {}
27 // Called lazily, after the initial overscrolling event.
28 virtual scoped_ptr<EdgeEffectBase> CreateEdgeEffect() = 0;
31 /* |OverscrollGlow| mirrors its Android counterpart, OverscrollGlow.java.
32 * Conscious tradeoffs were made to align this as closely as possible with the
33 * original Android Java version.
35 class OverscrollGlow {
36 public:
37 enum Edge { EDGE_TOP = 0, EDGE_LEFT, EDGE_BOTTOM, EDGE_RIGHT, EDGE_COUNT };
39 // |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);
43 ~OverscrollGlow();
45 // Called when the root content layer overscrolls.
46 // |accumulated_overscroll| and |overscroll_delta| are in device pixels, while
47 // |velocity| is in device pixels / second.
48 // Returns true if the effect still needs animation ticks.
49 bool OnOverscrolled(base::TimeTicks current_time,
50 gfx::Vector2dF accumulated_overscroll,
51 gfx::Vector2dF overscroll_delta,
52 gfx::Vector2dF velocity,
53 gfx::Vector2dF overscroll_location);
55 // Returns true if the effect still needs animation ticks, with effect layers
56 // attached to |parent_layer| if necessary.
57 // Note: The effect will detach itself when no further animation is required.
58 bool Animate(base::TimeTicks current_time, cc::Layer* parent_layer);
60 // Update the effect according to the most recent display parameters,
61 // Note: All dimensions are in device pixels.
62 void UpdateDisplay(const gfx::SizeF& viewport_size,
63 const gfx::SizeF& content_size,
64 const gfx::Vector2dF& content_scroll_offset);
66 // Reset the effect to its inactive state, clearing any active effects.
67 void Reset();
69 // Whether the effect is active, either being pulled or receding.
70 bool IsActive() const;
72 private:
73 enum Axis { AXIS_X, AXIS_Y };
75 // Returns whether the effect has been properly initialized.
76 bool InitializeIfNecessary();
77 bool CheckNeedsAnimate();
78 void UpdateLayerAttachment(cc::Layer* parent);
79 void Detach();
80 void Pull(base::TimeTicks current_time,
81 const gfx::Vector2dF& overscroll_delta,
82 const gfx::Vector2dF& overscroll_location);
83 void Absorb(base::TimeTicks current_time,
84 const gfx::Vector2dF& velocity,
85 bool x_overscroll_started,
86 bool y_overscroll_started);
87 void Release(base::TimeTicks current_time);
89 EdgeEffectBase* GetOppositeEdge(int edge_index);
91 OverscrollGlowClient* const client_;
92 scoped_ptr<EdgeEffectBase> edge_effects_[EDGE_COUNT];
94 gfx::SizeF viewport_size_;
95 float edge_offsets_[EDGE_COUNT];
96 bool initialized_;
98 scoped_refptr<cc::Layer> root_layer_;
100 DISALLOW_COPY_AND_ASSIGN(OverscrollGlow);
103 } // namespace content
105 #endif // CONTENT_BROWSER_ANDROID_OVERSCROLL_GLOW_H_