Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
[Android] Port OverScrolled Event to ContentViewClient for Crosswalk.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
shaoboyan committed Mar 24, 2016
1 parent 5c3da74 commit 9fb96d2
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions content/browser/android/content_view_core_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<jobject> 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();

Expand Down
2 changes: 2 additions & 0 deletions content/browser/android/content_view_core_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<jobject> GetContext() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object> retainedObjectSet);
private static native ContentViewCore nativeFromWebContentsAndroid(WebContents webContents);
Expand Down

0 comments on commit 9fb96d2

Please sign in to comment.