1 // Copyright 2014 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_CONTROLLER_ANDROID_H_
6 #define CONTENT_BROWSER_ANDROID_OVERSCROLL_CONTROLLER_ANDROID_H_
8 #include "base/time/time.h"
9 #include "content/browser/android/overscroll_glow.h"
10 #include "content/browser/android/overscroll_refresh.h"
11 #include "content/common/input/input_event_ack_state.h"
12 #include "content/public/browser/web_contents_observer.h"
13 #include "ui/gfx/geometry/vector2d_f.h"
16 class WebGestureEvent
;
20 class CompositorFrameMetadata
;
25 class WindowAndroidCompositor
;
30 struct DidOverscrollParams
;
32 // Glue class for handling all inputs into Android-specific overscroll effects,
33 // both the passive overscroll glow and the active overscroll pull-to-refresh.
34 // Note that all input coordinates (both for events and overscroll) are in DIPs.
35 class OverscrollControllerAndroid
: public OverscrollGlowClient
,
36 public OverscrollRefreshClient
,
37 public WebContentsObserver
{
39 OverscrollControllerAndroid(WebContents
* web_contents
,
40 ui::WindowAndroidCompositor
* compositor
,
42 ~OverscrollControllerAndroid() override
;
44 // Returns true if |event| is consumed by an overscroll effect, in which
45 // case it should cease propagation.
46 bool WillHandleGestureEvent(const blink::WebGestureEvent
& event
);
48 // To be called upon receipt of a gesture event ack.
49 void OnGestureEventAck(const blink::WebGestureEvent
& event
,
50 InputEventAckState ack_result
);
52 // To be called upon receipt of an overscroll event.
53 void OnOverscrolled(const DidOverscrollParams
& overscroll_params
);
55 // Returns true if the effect still needs animation ticks.
56 // Note: The effect will detach itself when no further animation is required.
57 bool Animate(base::TimeTicks current_time
, cc::Layer
* parent_layer
);
59 // To be called whenever the content frame has been updated.
60 void OnFrameMetadataUpdated(const cc::CompositorFrameMetadata
& metadata
);
62 // Toggle activity of any overscroll effects. When disabled, events will be
63 // ignored until the controller is re-enabled.
68 // WebContentsObserver implementation.
69 void DidNavigateMainFrame(const LoadCommittedDetails
& details
,
70 const FrameNavigateParams
& params
) override
;
71 void DidToggleFullscreenModeForTab(bool entered_fullscreen
) override
;
73 // OverscrollRefreshClient implementation.
74 void TriggerRefresh() override
;
75 bool IsStillRefreshing() const override
;
77 // OverscrollGlowClient implementation.
78 scoped_ptr
<EdgeEffectBase
> CreateEdgeEffect() override
;
80 void SetNeedsAnimate();
82 ui::WindowAndroidCompositor
* compositor_
;
83 const float dpi_scale_
;
87 // TODO(jdduke): Factor out a common API from the two overscroll effects.
88 scoped_ptr
<OverscrollGlow
> glow_effect_
;
89 scoped_ptr
<OverscrollRefresh
> refresh_effect_
;
90 bool triggered_refresh_active_
;
93 DISALLOW_COPY_AND_ASSIGN(OverscrollControllerAndroid
);
96 } // namespace content
98 #endif // CONTENT_BROWSER_ANDROID_OVERSCROLL_CONTROLLER_ANDROID_H_