From 9fb96d289ea3511cb4e058050dad066934d453f7 Mon Sep 17 00:00:00 2001 From: "Yan, Shaobo" Date: Fri, 11 Mar 2016 22:07:53 +0800 Subject: [PATCH] [Android] Port OverScrolled Event to ContentViewClient for Crosswalk. OverScrolled Event could be catch by WebView through Android View System. But XWalkView is not a true view, so XWalkView need this patch to port OverScrolled Event to it. BUG=XWALK-4871 BUG=XWALK-4894 --- content/browser/android/content_view_core_impl.cc | 8 ++++++++ content/browser/android/content_view_core_impl.h | 2 ++ .../renderer_host/render_widget_host_view_android.cc | 4 ++++ .../org/chromium/content/browser/ContentViewClient.java | 6 ++++++ .../src/org/chromium/content/browser/ContentViewCore.java | 8 ++++++++ 5 files changed, 28 insertions(+) diff --git a/content/browser/android/content_view_core_impl.cc b/content/browser/android/content_view_core_impl.cc index 650285d2fb8d1..6dd1b71468513 100644 --- a/content/browser/android/content_view_core_impl.cc +++ b/content/browser/android/content_view_core_impl.cc @@ -694,6 +694,14 @@ bool ContentViewCoreImpl::ShouldBlockMediaRequest(const GURL& url) { j_url.obj()); } +void ContentViewCoreImpl::DidOverscroll(bool clampedX, bool clampedY) { + JNIEnv* env = base::android::AttachCurrentThread(); + ScopedJavaLocalRef j_obj = java_ref_.get(env); + if (!j_obj.is_null()) { + Java_ContentViewCore_didOverscroll(env, j_obj.obj(), clampedX, clampedY); + } +} + void ContentViewCoreImpl::DidStopFlinging() { JNIEnv* env = AttachCurrentThread(); diff --git a/content/browser/android/content_view_core_impl.h b/content/browser/android/content_view_core_impl.h index 55157a15e752a..e4abf23a828ee 100644 --- a/content/browser/android/content_view_core_impl.h +++ b/content/browser/android/content_view_core_impl.h @@ -284,6 +284,8 @@ class ContentViewCoreImpl : public ContentViewCore, void DidStopFlinging(); + void DidOverscroll(bool clampedX, bool clampedY); + // Returns the context with which the ContentViewCore was created, typically // the Activity context. base::android::ScopedJavaLocalRef GetContext() const; diff --git a/content/browser/renderer_host/render_widget_host_view_android.cc b/content/browser/renderer_host/render_widget_host_view_android.cc index 8cd423e698e55..0f68821dc992c 100644 --- a/content/browser/renderer_host/render_widget_host_view_android.cc +++ b/content/browser/renderer_host/render_widget_host_view_android.cc @@ -1768,6 +1768,10 @@ void RenderWidgetHostViewAndroid::DidOverscroll( if (overscroll_controller_) overscroll_controller_->OnOverscrolled(params); + + bool clampedX = params.latest_overscroll_delta.x() != 0 ? true : false; + bool clampedY = params.latest_overscroll_delta.y() != 0 ? true : false; + content_view_core_->DidOverscroll(clampedX, clampedY); } void RenderWidgetHostViewAndroid::DidStopFlinging() { diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewClient.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewClient.java index 6daa9e8015ca5..97d8b873260b6 100644 --- a/content/public/android/java/src/org/chromium/content/browser/ContentViewClient.java +++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewClient.java @@ -224,4 +224,10 @@ public int getDesiredWidthMeasureSpec() { public int getDesiredHeightMeasureSpec() { return UNSPECIFIED_MEASURE_SPEC; } + + /** + * Called when overscroll event has been fired + **/ + public void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) { + } } diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java index f9b447c86ba02..13c5703556f4e 100644 --- a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java +++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java @@ -3363,6 +3363,14 @@ public void setContextualSearchClient(ContextualSearchClient contextualSearchCli mContextualSearchClient = contextualSearchClient; } + @CalledByNative + public void didOverscroll(boolean clampedX, boolean clampedY) { + mContentViewClient.onOverScrolled(mRenderCoordinates.getScrollXPixInt(), + mRenderCoordinates.getScrollYPixInt(), + clampedX, + clampedY); + } + private native long nativeInit(WebContents webContents, ViewAndroidDelegate viewAndroidDelegate, long windowAndroidPtr, HashSet retainedObjectSet); private static native ContentViewCore nativeFromWebContentsAndroid(WebContents webContents);