Skip to content

Commit

Permalink
Pass TouchMajor to HitTestResult
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
hush authored and Commit bot committed Nov 13, 2014
1 parent 958f5e4 commit 1d93adc
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions android_webview/common/render_view_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2383,13 +2383,12 @@ public boolean onTouchEvent(MotionEvent event) {
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) {
Expand Down Expand Up @@ -2603,7 +2602,8 @@ private native boolean nativeOnDraw(long nativeAwContents, Canvas canvas,
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);
Expand Down
12 changes: 9 additions & 3 deletions android_webview/native/aw_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion android_webview/native/aw_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 5 additions & 3 deletions android_webview/renderer/aw_render_view_ext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
5 changes: 4 additions & 1 deletion android_webview/renderer/aw_render_view_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 1d93adc

Please sign in to comment.