OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CONTENT_BROWSER_ANDROID_OVERSCROLL_CONTROLLER_ANDROID_H_ | 5 #ifndef CONTENT_BROWSER_ANDROID_OVERSCROLL_CONTROLLER_ANDROID_H_ |
6 #define CONTENT_BROWSER_ANDROID_OVERSCROLL_CONTROLLER_ANDROID_H_ | 6 #define CONTENT_BROWSER_ANDROID_OVERSCROLL_CONTROLLER_ANDROID_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "content/common/content_export.h" | |
13 #include "content/common/input/input_event_ack_state.h" | 14 #include "content/common/input/input_event_ack_state.h" |
14 #include "ui/android/overscroll_glow.h" | 15 #include "ui/android/overscroll_glow.h" |
15 #include "ui/android/overscroll_refresh.h" | 16 #include "ui/android/overscroll_refresh.h" |
16 #include "ui/gfx/geometry/vector2d_f.h" | 17 #include "ui/gfx/geometry/vector2d_f.h" |
17 | 18 |
18 namespace blink { | 19 namespace blink { |
19 class WebGestureEvent; | 20 class WebGestureEvent; |
20 } | 21 } |
21 | 22 |
22 namespace cc { | 23 namespace cc { |
23 class CompositorFrameMetadata; | 24 class CompositorFrameMetadata; |
24 class Layer; | 25 class Layer; |
25 } | 26 } |
26 | 27 |
27 namespace ui { | 28 namespace ui { |
28 class WindowAndroidCompositor; | 29 class WindowAndroidCompositor; |
29 struct DidOverscrollParams; | 30 struct DidOverscrollParams; |
30 } | 31 } |
31 | 32 |
32 namespace content { | 33 namespace content { |
33 | 34 |
34 // Glue class for handling all inputs into Android-specific overscroll effects, | 35 // Glue class for handling all inputs into Android-specific overscroll effects, |
35 // both the passive overscroll glow and the active overscroll pull-to-refresh. | 36 // both the passive overscroll glow and the active overscroll pull-to-refresh. |
36 // Note that all input coordinates (both for events and overscroll) are in DIPs. | 37 // Note that all input coordinates (both for events and overscroll) are in DIPs. |
37 class OverscrollControllerAndroid : public ui::OverscrollGlowClient { | 38 class CONTENT_EXPORT OverscrollControllerAndroid |
39 : public ui::OverscrollGlowClient { | |
38 public: | 40 public: |
39 OverscrollControllerAndroid( | 41 OverscrollControllerAndroid( |
40 ui::OverscrollRefreshHandler* overscroll_refresh_handler, | 42 ui::OverscrollRefreshHandler* overscroll_refresh_handler, |
41 ui::WindowAndroidCompositor* compositor, | 43 ui::WindowAndroidCompositor* compositor, |
42 float dpi_scale); | 44 float dpi_scale); |
45 | |
46 static OverscrollControllerAndroid* CreateForTests( | |
47 ui::WindowAndroidCompositor* compositor, | |
48 float dpi_scale, | |
49 std::unique_ptr<ui::OverscrollGlow> glow_effect, | |
50 std::unique_ptr<ui::OverscrollRefresh> refresh_effect); | |
51 | |
43 ~OverscrollControllerAndroid() override; | 52 ~OverscrollControllerAndroid() override; |
44 | 53 |
45 // Returns true if |event| is consumed by an overscroll effect, in which | 54 // Returns true if |event| is consumed by an overscroll effect, in which |
46 // case it should cease propagation. | 55 // case it should cease propagation. |
47 bool WillHandleGestureEvent(const blink::WebGestureEvent& event); | 56 bool WillHandleGestureEvent(const blink::WebGestureEvent& event); |
48 | 57 |
49 // To be called upon receipt of a gesture event ack. | 58 // To be called upon receipt of a gesture event ack. |
50 void OnGestureEventAck(const blink::WebGestureEvent& event, | 59 void OnGestureEventAck(const blink::WebGestureEvent& event, |
51 InputEventAckState ack_result); | 60 InputEventAckState ack_result); |
52 | 61 |
53 // To be called upon receipt of an overscroll event. | 62 // To be called upon receipt of an overscroll event. |
54 void OnOverscrolled(const ui::DidOverscrollParams& overscroll_params); | 63 void OnOverscrolled(const ui::DidOverscrollParams& overscroll_params); |
55 | 64 |
56 // Returns true if the effect still needs animation ticks. | 65 // Returns true if the effect still needs animation ticks. |
57 // Note: The effect will detach itself when no further animation is required. | 66 // Note: The effect will detach itself when no further animation is required. |
58 bool Animate(base::TimeTicks current_time, cc::Layer* parent_layer); | 67 bool Animate(base::TimeTicks current_time, cc::Layer* parent_layer); |
59 | 68 |
60 // To be called whenever the content frame has been updated. | 69 // To be called whenever the content frame has been updated. |
61 void OnFrameMetadataUpdated(const cc::CompositorFrameMetadata& metadata); | 70 void OnFrameMetadataUpdated(const cc::CompositorFrameMetadata& metadata); |
62 | 71 |
63 // Toggle activity of any overscroll effects. When disabled, events will be | 72 // Toggle activity of any overscroll effects. When disabled, events will be |
64 // ignored until the controller is re-enabled. | 73 // ignored until the controller is re-enabled. |
65 void Enable(); | 74 void Enable(); |
66 void Disable(); | 75 void Disable(); |
67 | 76 |
68 private: | 77 private: |
78 // This method should only be called from CreateForTest. | |
Ted C
2017/08/28 18:58:48
CreateForTest[s]
sunyunjia
2017/08/29 17:32:30
Done.
| |
79 OverscrollControllerAndroid( | |
80 ui::WindowAndroidCompositor* compositor, | |
81 float dpi_scale, | |
82 std::unique_ptr<ui::OverscrollGlow> glow_effect, | |
83 std::unique_ptr<ui::OverscrollRefresh> refresh_effect); | |
69 // OverscrollGlowClient implementation. | 84 // OverscrollGlowClient implementation. |
Avi (use Gerrit)
2017/08/24 21:12:43
extra blank line before this one.
sunyunjia
2017/08/29 17:32:30
Done.
| |
70 std::unique_ptr<ui::EdgeEffectBase> CreateEdgeEffect() override; | 85 std::unique_ptr<ui::EdgeEffectBase> CreateEdgeEffect() override; |
71 | 86 |
72 void SetNeedsAnimate(); | 87 void SetNeedsAnimate(); |
73 | 88 |
74 ui::WindowAndroidCompositor* const compositor_; | 89 ui::WindowAndroidCompositor* const compositor_; |
75 const float dpi_scale_; | 90 const float dpi_scale_; |
76 | 91 |
77 bool enabled_; | 92 bool enabled_; |
78 | 93 |
79 // TODO(jdduke): Factor out a common API from the two overscroll effects. | 94 // TODO(jdduke): Factor out a common API from the two overscroll effects. |
80 std::unique_ptr<ui::OverscrollGlow> glow_effect_; | 95 std::unique_ptr<ui::OverscrollGlow> glow_effect_; |
81 std::unique_ptr<ui::OverscrollRefresh> refresh_effect_; | 96 std::unique_ptr<ui::OverscrollRefresh> refresh_effect_; |
82 | 97 |
83 DISALLOW_COPY_AND_ASSIGN(OverscrollControllerAndroid); | 98 DISALLOW_COPY_AND_ASSIGN(OverscrollControllerAndroid); |
84 }; | 99 }; |
85 | 100 |
86 } // namespace content | 101 } // namespace content |
87 | 102 |
88 #endif // CONTENT_BROWSER_ANDROID_OVERSCROLL_CONTROLLER_ANDROID_H_ | 103 #endif // CONTENT_BROWSER_ANDROID_OVERSCROLL_CONTROLLER_ANDROID_H_ |
OLD | NEW |