diff options
author | hush <hush@chromium.org> | 2014-11-13 12:11:16 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-13 20:11:35 +0000 |
commit | 1d93adc3addd7b336d541f77eb272c2aa43a7053 (patch) | |
tree | 665eb42859facdf88c8e0469b622a334741b68bb | |
parent | 958f5e401524d8a31c5cf9228b3c9adace3d30ff (diff) | |
download | chromium_src-1d93adc3addd7b336d541f77eb272c2aa43a7053.zip chromium_src-1d93adc3addd7b336d541f77eb272c2aa43a7053.tar.gz chromium_src-1d93adc3addd7b336d541f77eb272c2aa43a7053.tar.bz2 |
Pass TouchMajor to HitTestResult
Blink side change to do hit-test that mimics GestureTap:
https://codereview.chromium.org/470833002
Without the touch major information, HitTestResult may not
match how touch events are handled in content view core. As
a result, it is possible that the user touches a link while
the hitTestResult returns unknown type.
BUG=403865
Review URL: https://codereview.chromium.org/475633002
Cr-Commit-Position: refs/heads/master@{#304067}
8 files changed, 43 insertions, 22 deletions
diff --git a/android_webview/browser/renderer_host/aw_render_view_host_ext.cc b/android_webview/browser/renderer_host/aw_render_view_host_ext.cc index 8428990..bee4ece 100644 --- a/android_webview/browser/renderer_host/aw_render_view_host_ext.cc +++ b/android_webview/browser/renderer_host/aw_render_view_host_ext.cc @@ -57,11 +57,12 @@ void AwRenderViewHostExt::MarkHitTestDataRead() { has_new_hit_test_data_ = false; } -void AwRenderViewHostExt::RequestNewHitTestDataAt(int view_x, int view_y) { +void AwRenderViewHostExt::RequestNewHitTestDataAt( + const gfx::PointF& touch_center, + const gfx::SizeF& touch_area) { DCHECK(CalledOnValidThread()); - Send(new AwViewMsg_DoHitTest(web_contents()->GetRoutingID(), - view_x, - view_y)); + Send(new AwViewMsg_DoHitTest(web_contents()->GetRoutingID(), touch_center, + touch_area)); } const AwHitTestData& AwRenderViewHostExt::GetLastHitTestData() const { diff --git a/android_webview/browser/renderer_host/aw_render_view_host_ext.h b/android_webview/browser/renderer_host/aw_render_view_host_ext.h index 4b6c7eb..0f9d3ce 100644 --- a/android_webview/browser/renderer_host/aw_render_view_host_ext.h +++ b/android_webview/browser/renderer_host/aw_render_view_host_ext.h @@ -11,6 +11,8 @@ #include "base/callback_forward.h" #include "base/threading/non_thread_safe.h" #include "third_party/skia/include/core/SkColor.h" +#include "ui/gfx/geometry/point_f.h" +#include "ui/gfx/geometry/size_f.h" #include "ui/gfx/size.h" class GURL; @@ -53,9 +55,10 @@ class AwRenderViewHostExt : public content::WebContentsObserver, void ClearCache(); // Do a hit test at the view port coordinates and asynchronously update - // |last_hit_test_data_|. |view_x| and |view_y| are in density independent - // pixels used by blink::WebView. - void RequestNewHitTestDataAt(int view_x, int view_y); + // |last_hit_test_data_|. Width and height in |touch_area| are in density + // independent pixels used by blink::WebView. + void RequestNewHitTestDataAt(const gfx::PointF& touch_center, + const gfx::SizeF& touch_area); // Optimization to avoid unnecessary Java object creation on hit test. bool HasNewHitTestData() const; diff --git a/android_webview/common/render_view_messages.h b/android_webview/common/render_view_messages.h index 9354db5..4a2ab59 100644 --- a/android_webview/common/render_view_messages.h +++ b/android_webview/common/render_view_messages.h @@ -9,6 +9,8 @@ #include "ipc/ipc_message_macros.h" #include "ipc/ipc_platform_file.h" #include "third_party/skia/include/core/SkColor.h" +#include "ui/gfx/geometry/point_f.h" +#include "ui/gfx/geometry/size_f.h" // Singly-included section for enums and custom IPC traits. #ifndef ANDROID_WEBVIEW_COMMON_RENDER_VIEW_MESSAGES_H_ @@ -49,8 +51,8 @@ IPC_MESSAGE_ROUTED1(AwViewMsg_DocumentHasImages, // physical pixel values with the 0,0 at the top left of the current displayed // view (ie 0,0 is not the top left of the page if the page is scrolled). IPC_MESSAGE_ROUTED2(AwViewMsg_DoHitTest, - int /* view_x */, - int /* view_y */) + gfx::PointF /* touch_center */, + gfx::SizeF /* touch_area */) // Sets the zoom factor for text only. Used in layout modes other than // Text Autosizing. diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java index 60b976e..854865b 100644 --- a/android_webview/java/src/org/chromium/android_webview/AwContents.java +++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java @@ -2383,13 +2383,12 @@ public class AwContents implements SmartClipProvider { mScrollOffsetManager.setProcessingTouchEvent(false); if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { - int actionIndex = event.getActionIndex(); - // Note this will trigger IPC back to browser even if nothing is // hit. nativeRequestNewHitTestDataAt(mNativeAwContents, - (int) Math.round(event.getX(actionIndex) / mDIPScale), - (int) Math.round(event.getY(actionIndex) / mDIPScale)); + event.getX() / (float) mDIPScale, + event.getY() / (float) mDIPScale, + event.getTouchMajor() / (float) mDIPScale); } if (mOverScrollGlow != null) { @@ -2603,7 +2602,8 @@ public class AwContents implements SmartClipProvider { private native byte[] nativeGetCertificate(long nativeAwContents); // Coordinates in desity independent pixels. - private native void nativeRequestNewHitTestDataAt(long nativeAwContents, int x, int y); + private native void nativeRequestNewHitTestDataAt(long nativeAwContents, float x, float y, + float touchMajor); private native void nativeUpdateLastHitTestData(long nativeAwContents); private native void nativeOnSizeChanged(long nativeAwContents, int w, int h, int ow, int oh); diff --git a/android_webview/native/aw_contents.cc b/android_webview/native/aw_contents.cc index 3d48f9c..159ccc0 100644 --- a/android_webview/native/aw_contents.cc +++ b/android_webview/native/aw_contents.cc @@ -66,6 +66,7 @@ #include "net/cert/x509_certificate.h" #include "third_party/skia/include/core/SkPicture.h" #include "ui/gfx/android/java_bitmap.h" +#include "ui/gfx/geometry/rect_f.h" #include "ui/gfx/image/image.h" #include "ui/gfx/size.h" @@ -724,10 +725,15 @@ base::android::ScopedJavaLocalRef<jbyteArray> reinterpret_cast<const uint8*>(der_string.data()), der_string.length()); } -void AwContents::RequestNewHitTestDataAt(JNIEnv* env, jobject obj, - jint x, jint y) { +void AwContents::RequestNewHitTestDataAt(JNIEnv* env, + jobject obj, + jfloat x, + jfloat y, + jfloat touch_major) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - render_view_host_ext_->RequestNewHitTestDataAt(x, y); + gfx::PointF touch_center(x, y); + gfx::SizeF touch_area(touch_major, touch_major); + render_view_host_ext_->RequestNewHitTestDataAt(touch_center, touch_area); } void AwContents::UpdateLastHitTestData(JNIEnv* env, jobject obj) { diff --git a/android_webview/native/aw_contents.h b/android_webview/native/aw_contents.h index ed4b0ec4..a415287 100644 --- a/android_webview/native/aw_contents.h +++ b/android_webview/native/aw_contents.h @@ -97,7 +97,11 @@ class AwContents : public FindHelper::Listener, void AddVisitedLinks(JNIEnv* env, jobject obj, jobjectArray jvisited_links); base::android::ScopedJavaLocalRef<jbyteArray> GetCertificate( JNIEnv* env, jobject obj); - void RequestNewHitTestDataAt(JNIEnv* env, jobject obj, jint x, jint y); + void RequestNewHitTestDataAt(JNIEnv* env, + jobject obj, + jfloat x, + jfloat y, + jfloat touch_major); void UpdateLastHitTestData(JNIEnv* env, jobject obj); void OnSizeChanged(JNIEnv* env, jobject obj, int w, int h, int ow, int oh); void SetViewVisibility(JNIEnv* env, jobject obj, bool visible); diff --git a/android_webview/renderer/aw_render_view_ext.cc b/android_webview/renderer/aw_render_view_ext.cc index dc4264e..6bef962 100644 --- a/android_webview/renderer/aw_render_view_ext.cc +++ b/android_webview/renderer/aw_render_view_ext.cc @@ -265,13 +265,15 @@ void AwRenderViewExt::FocusedNodeChanged(const blink::WebNode& node) { Send(new AwViewHostMsg_UpdateHitTestData(routing_id(), data)); } -void AwRenderViewExt::OnDoHitTest(int view_x, int view_y) { +void AwRenderViewExt::OnDoHitTest(const gfx::PointF& touch_center, + const gfx::SizeF& touch_area) { if (!render_view() || !render_view()->GetWebView()) return; const blink::WebHitTestResult result = - render_view()->GetWebView()->hitTestResultAt( - blink::WebPoint(view_x, view_y)); + render_view()->GetWebView()->hitTestResultForTap( + blink::WebPoint(touch_center.x(), touch_center.y()), + blink::WebSize(touch_area.width(), touch_area.height())); AwHitTestData data; if (!result.urlElement().isNull()) { diff --git a/android_webview/renderer/aw_render_view_ext.h b/android_webview/renderer/aw_render_view_ext.h index 57ce7c7..509fc08 100644 --- a/android_webview/renderer/aw_render_view_ext.h +++ b/android_webview/renderer/aw_render_view_ext.h @@ -10,6 +10,8 @@ #include "base/timer/timer.h" #include "content/public/renderer/render_view_observer.h" #include "third_party/skia/include/core/SkColor.h" +#include "ui/gfx/geometry/point_f.h" +#include "ui/gfx/geometry/size_f.h" #include "ui/gfx/size.h" namespace blink { @@ -41,7 +43,8 @@ class AwRenderViewExt : public content::RenderViewObserver { void OnDocumentHasImagesRequest(int id); - void OnDoHitTest(int view_x, int view_y); + void OnDoHitTest(const gfx::PointF& touch_center, + const gfx::SizeF& touch_area); void OnSetTextZoomFactor(float zoom_factor); |