| 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 "base/time/time.h" | 8 #include "base/time/time.h" |
| 9 #include "content/browser/android/overscroll_glow.h" | 9 #include "content/browser/android/overscroll_glow.h" |
| 10 #include "content/browser/android/overscroll_refresh.h" | 10 #include "content/browser/android/overscroll_refresh.h" |
| 11 #include "content/common/input/input_event_ack_state.h" | 11 #include "content/common/input/input_event_ack_state.h" |
| 12 #include "content/public/browser/web_contents_observer.h" | 12 #include "content/public/browser/web_contents_observer.h" |
| 13 #include "ui/gfx/geometry/vector2d_f.h" | 13 #include "ui/gfx/geometry/vector2d_f.h" |
| 14 | 14 |
| 15 namespace blink { | 15 namespace blink { |
| 16 class WebGestureEvent; | 16 class WebGestureEvent; |
| 17 } | 17 } |
| 18 | 18 |
| 19 namespace cc { | 19 namespace cc { |
| 20 class CompositorFrameMetadata; | 20 class CompositorFrameMetadata; |
| 21 class Layer; | 21 class Layer; |
| 22 } | 22 } |
| 23 | 23 |
| 24 namespace ui { | 24 namespace ui { |
| 25 class WindowAndroidCompositor; | 25 class WindowAndroidCompositor; |
| 26 } | 26 } |
| 27 | 27 |
| 28 namespace content { | 28 namespace content { |
| 29 | 29 |
| 30 class ContentViewCoreImpl; |
| 30 struct DidOverscrollParams; | 31 struct DidOverscrollParams; |
| 31 | 32 |
| 32 // Glue class for handling all inputs into Android-specific overscroll effects, | 33 // 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 // 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 // Note that all input coordinates (both for events and overscroll) are in DIPs. |
| 35 class OverscrollControllerAndroid : public OverscrollGlowClient, | 36 class OverscrollControllerAndroid : public OverscrollGlowClient, |
| 36 public OverscrollRefreshClient, | |
| 37 public WebContentsObserver { | 37 public WebContentsObserver { |
| 38 public: | 38 public: |
| 39 OverscrollControllerAndroid(WebContents* web_contents, | 39 explicit OverscrollControllerAndroid(ContentViewCoreImpl* content_view_core); |
| 40 ui::WindowAndroidCompositor* compositor, | |
| 41 float dpi_scale); | |
| 42 ~OverscrollControllerAndroid() override; | 40 ~OverscrollControllerAndroid() override; |
| 43 | 41 |
| 44 // Returns true if |event| is consumed by an overscroll effect, in which | 42 // Returns true if |event| is consumed by an overscroll effect, in which |
| 45 // case it should cease propagation. | 43 // case it should cease propagation. |
| 46 bool WillHandleGestureEvent(const blink::WebGestureEvent& event); | 44 bool WillHandleGestureEvent(const blink::WebGestureEvent& event); |
| 47 | 45 |
| 48 // To be called upon receipt of a gesture event ack. | 46 // To be called upon receipt of a gesture event ack. |
| 49 void OnGestureEventAck(const blink::WebGestureEvent& event, | 47 void OnGestureEventAck(const blink::WebGestureEvent& event, |
| 50 InputEventAckState ack_result); | 48 InputEventAckState ack_result); |
| 51 | 49 |
| 52 // To be called upon receipt of an overscroll event. | 50 // To be called upon receipt of an overscroll event. |
| 53 void OnOverscrolled(const DidOverscrollParams& overscroll_params); | 51 void OnOverscrolled(const DidOverscrollParams& overscroll_params); |
| 54 | 52 |
| 55 // Returns true if the effect still needs animation ticks. | 53 // Returns true if the effect still needs animation ticks. |
| 56 // Note: The effect will detach itself when no further animation is required. | 54 // Note: The effect will detach itself when no further animation is required. |
| 57 bool Animate(base::TimeTicks current_time, cc::Layer* parent_layer); | 55 bool Animate(base::TimeTicks current_time, cc::Layer* parent_layer); |
| 58 | 56 |
| 59 // To be called whenever the content frame has been updated. | 57 // To be called whenever the content frame has been updated. |
| 60 void OnFrameMetadataUpdated(const cc::CompositorFrameMetadata& metadata); | 58 void OnFrameMetadataUpdated(const cc::CompositorFrameMetadata& metadata); |
| 61 | 59 |
| 62 // Toggle activity of any overscroll effects. When disabled, events will be | 60 // Toggle activity of any overscroll effects. When disabled, events will be |
| 63 // ignored until the controller is re-enabled. | 61 // ignored until the controller is re-enabled. |
| 64 void Enable(); | 62 void Enable(); |
| 65 void Disable(); | 63 void Disable(); |
| 66 | 64 |
| 67 private: | 65 private: |
| 68 // WebContentsObserver implementation. | 66 // WebContentsObserver implementation. |
| 69 void DidNavigateMainFrame(const LoadCommittedDetails& details, | |
| 70 const FrameNavigateParams& params) override; | |
| 71 void DidToggleFullscreenModeForTab(bool entered_fullscreen) override; | 67 void DidToggleFullscreenModeForTab(bool entered_fullscreen) override; |
| 72 | 68 |
| 73 // OverscrollRefreshClient implementation. | |
| 74 void TriggerRefresh() override; | |
| 75 bool IsStillRefreshing() const override; | |
| 76 | |
| 77 // OverscrollGlowClient implementation. | 69 // OverscrollGlowClient implementation. |
| 78 scoped_ptr<EdgeEffectBase> CreateEdgeEffect() override; | 70 scoped_ptr<EdgeEffectBase> CreateEdgeEffect() override; |
| 79 | 71 |
| 80 void SetNeedsAnimate(); | 72 void SetNeedsAnimate(); |
| 81 | 73 |
| 82 ui::WindowAndroidCompositor* compositor_; | 74 ui::WindowAndroidCompositor* const compositor_; |
| 83 const float dpi_scale_; | 75 const float dpi_scale_; |
| 84 | 76 |
| 85 bool enabled_; | 77 bool enabled_; |
| 86 | 78 |
| 87 // TODO(jdduke): Factor out a common API from the two overscroll effects. | 79 // TODO(jdduke): Factor out a common API from the two overscroll effects. |
| 88 scoped_ptr<OverscrollGlow> glow_effect_; | 80 scoped_ptr<OverscrollGlow> glow_effect_; |
| 89 scoped_ptr<OverscrollRefresh> refresh_effect_; | 81 scoped_ptr<OverscrollRefresh> refresh_effect_; |
| 90 bool triggered_refresh_active_; | 82 bool has_initialized_refresh_effect_; |
| 91 bool is_fullscreen_; | 83 bool is_fullscreen_; |
| 92 | 84 |
| 93 DISALLOW_COPY_AND_ASSIGN(OverscrollControllerAndroid); | 85 DISALLOW_COPY_AND_ASSIGN(OverscrollControllerAndroid); |
| 94 }; | 86 }; |
| 95 | 87 |
| 96 } // namespace content | 88 } // namespace content |
| 97 | 89 |
| 98 #endif // CONTENT_BROWSER_ANDROID_OVERSCROLL_CONTROLLER_ANDROID_H_ | 90 #endif // CONTENT_BROWSER_ANDROID_OVERSCROLL_CONTROLLER_ANDROID_H_ |
| OLD | NEW |