Chromium Code Reviews| Index: content/browser/android/content_view_core_impl.cc |
| diff --git a/content/browser/android/content_view_core_impl.cc b/content/browser/android/content_view_core_impl.cc |
| index 58494276b0ca5925fa2f50aa5a3007c2b7792002..53398509813da54efcc304ca27fbee6bdc5ee6ce 100644 |
| --- a/content/browser/android/content_view_core_impl.cc |
| +++ b/content/browser/android/content_view_core_impl.cc |
| @@ -9,12 +9,18 @@ |
| #include "base/android/jni_string.h" |
| #include "base/android/scoped_java_ref.h" |
| #include "content/browser/android/content_view_client.h" |
| +#include "content/browser/android/touch_point.h" |
| #include "content/browser/renderer_host/render_view_host_impl.h" |
| +#include "content/browser/renderer_host/render_widget_host_impl.h" |
| +#include "content/browser/renderer_host/render_widget_host_view_android.h" |
| #include "content/browser/web_contents/navigation_controller_impl.h" |
| #include "content/public/browser/browser_context.h" |
| +#include "content/public/browser/interstitial_page.h" |
| #include "content/public/browser/web_contents.h" |
| #include "jni/content_view_core_jni.h" |
| #include "webkit/glue/webmenuitem.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/android/WebInputEventFactory.h" |
| using base::android::AttachCurrentThread; |
| using base::android::ConvertUTF16ToJavaString; |
| @@ -23,6 +29,8 @@ using base::android::GetClass; |
| using base::android::HasField; |
| using base::android::ScopedJavaGlobalRef; |
| using base::android::ScopedJavaLocalRef; |
| +using WebKit::WebInputEvent; |
| +using WebKit::WebInputEventFactory; |
| // Describes the type and enabled state of a select popup item. |
| // Keep in sync with the value defined in SelectPopupDialog.java |
| @@ -96,6 +104,25 @@ void ContentViewCoreImpl::InitJNI(JNIEnv* env, jobject obj) { |
| java_object_->obj = env->NewWeakGlobalRef(obj); |
| } |
| +RenderWidgetHostViewAndroid* ContentViewCoreImpl:: |
| + GetRenderWidgetHostViewAndroid() { |
| + RenderWidgetHostView* rwhv = NULL; |
| + if (!web_contents_) { |
| + return NULL; |
| + } else if (web_contents_->ShowingInterstitialPage()) { |
| + rwhv = web_contents_->GetInterstitialPage()-> |
| + GetRenderViewHostForTesting()->GetView(); |
| + // An interstitial page must have had Show() called immediately after |
| + // construction in order for the render widget to exist. Currently Desktop |
| + // Chrome does not enforce this is the case, however we do here to keep the |
| + // state consistent with the WebContents. |
| + CHECK(rwhv); |
| + } else { |
| + rwhv = web_contents_->GetRenderWidgetHostView(); |
| + } |
| + return static_cast<RenderWidgetHostViewAndroid*>(rwhv); |
| +} |
| + |
| // ---------------------------------------------------------------------------- |
| // Methods called from Java via JNI |
| // ---------------------------------------------------------------------------- |
| @@ -145,6 +172,106 @@ jboolean ContentViewCoreImpl::IsIncognito(JNIEnv* env, jobject obj) { |
| return web_contents()->GetBrowserContext()->IsOffTheRecord(); |
| } |
| +jboolean ContentViewCoreImpl::TouchEvent(JNIEnv* env, jobject obj, |
| + jlong time_ms, |
| + jint type, jobjectArray pts) { |
| + RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); |
| + if (rwhv) { |
| + // This throws out scroll and pinch events if the initial touch is rejected |
|
aelias_OOO_until_Jul13
2012/07/19 03:43:51
This whole comment is no longer in its place here,
Yusuf
2012/07/19 05:01:52
Done.
|
| + // by the Javascript. Without this, scroll/pinch is unreliable on any page |
| + // capturing onTouchEvent as soon as the renderer stops responding (e.g. |
| + // while refreshing tiles). |
| + // TODO(aelias): http://b/5255553 -- Find a way to allow the case where |
| + // JavaScript can choose to handle some of touch events during one touch |
| + // sequence, without compromising performance. For example, renderer |
| + // handling horizontal move while leaving vertical move to the browser to |
| + // handle. |
| + using WebKit::WebTouchEvent; |
| + WebKit::WebTouchEvent event; |
| + TouchPoint::BuildWebTouchEvent(env, type, time_ms, pts, event); |
| + rwhv->TouchEvent(event); |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| +void ContentViewCoreImpl::SendGestureEvent(WebInputEvent::Type type, |
| + long time_ms, int x, int y, |
| + float dx, float dy, |
| + bool link_preview_tap) { |
| + WebKit::WebGestureEvent event = WebInputEventFactory::gestureEvent( |
| + type, time_ms / 1000.0, x, y, dx, dy, |
| + 0); |
| + if (GetRenderWidgetHostViewAndroid()) |
| + GetRenderWidgetHostViewAndroid()->GestureEvent(event); |
| +} |
| + |
| +void ContentViewCoreImpl::ScrollBegin(JNIEnv* env, jobject obj, jlong time_ms, |
| + jint x, jint y) { |
| + SendGestureEvent(WebInputEvent::GestureScrollBegin, time_ms, x, y, 0, 0, |
| + false); |
| +} |
| + |
| +void ContentViewCoreImpl::ScrollEnd(JNIEnv* env, jobject obj, jlong time_ms) { |
| + SendGestureEvent(WebInputEvent::GestureScrollEnd, time_ms, 0, 0, 0, 0, false); |
| +} |
| + |
| +void ContentViewCoreImpl::ScrollBy(JNIEnv* env, jobject obj, jlong time_ms, |
| + jint dx, jint dy) { |
| + SendGestureEvent(WebInputEvent::GestureScrollUpdate, time_ms, 0, 0, -dx, -dy, |
| + false); |
| +} |
| + |
| +void ContentViewCoreImpl::FlingStart(JNIEnv* env, jobject obj, jlong time_ms, |
| + jint x, jint y, jint vx, jint vy) { |
| + SendGestureEvent(WebInputEvent::GestureFlingStart, time_ms, x, y, vx, vy, |
| + false); |
| +} |
| + |
| +void ContentViewCoreImpl::FlingCancel(JNIEnv* env, jobject obj, jlong time_ms) { |
| + SendGestureEvent(WebInputEvent::GestureFlingCancel, time_ms, 0, 0, 0, 0, |
| + false); |
| +} |
| + |
| +void ContentViewCoreImpl::SingleTap(JNIEnv* env, jobject obj, jlong time_ms, |
| + jint x, jint y, jboolean link_preview_tap) { |
| + SendGestureEvent(WebInputEvent::GestureTap, time_ms, x, y, 0, 0, |
| + link_preview_tap); |
| +} |
| + |
| +void ContentViewCoreImpl::ShowPressState(JNIEnv* env, jobject obj, |
| + jlong time_ms, |
| + jint x, jint y) { |
| + SendGestureEvent(WebInputEvent::GestureTapDown, time_ms, x, y, 0, 0, false); |
| +} |
| + |
| +void ContentViewCoreImpl::DoubleTap(JNIEnv* env, jobject obj, jlong time_ms, |
| + jint x, jint y) { |
| + SendGestureEvent(WebInputEvent::GestureDoubleTap, time_ms, x, y, 0, 0, false); |
| +} |
| + |
| +void ContentViewCoreImpl::LongPress(JNIEnv* env, jobject obj, jlong time_ms, |
| + jint x, jint y, jboolean link_preview_tap) { |
| + SendGestureEvent(WebInputEvent::GestureLongPress, time_ms, x, y, 0, 0, |
| + link_preview_tap); |
| +} |
| + |
| +void ContentViewCoreImpl::PinchBegin(JNIEnv* env, jobject obj, jlong time_ms, |
| + jint x, jint y) { |
| + SendGestureEvent(WebInputEvent::GesturePinchBegin, time_ms, x, y, 0, 0, |
| + false); |
| +} |
| + |
| +void ContentViewCoreImpl::PinchEnd(JNIEnv* env, jobject obj, jlong time_ms) { |
| + SendGestureEvent(WebInputEvent::GesturePinchEnd, time_ms, 0, 0, 0, 0, false); |
| +} |
| + |
| +void ContentViewCoreImpl::PinchBy(JNIEnv* env, jobject obj, jlong time_ms, |
| + jint anchor_x, jint anchor_y, jfloat delta) { |
| + SendGestureEvent(WebInputEvent::GesturePinchUpdate, time_ms, |
| + anchor_x, anchor_y, delta, delta, false); |
| +} |
| + |
| jboolean ContentViewCoreImpl::CanGoBack(JNIEnv* env, jobject obj) { |
| return web_contents_->GetController().CanGoBack(); |
| } |
| @@ -298,6 +425,19 @@ void ContentViewCoreImpl::ShowSelectPopupMenu( |
| multiple, selected_array.obj()); |
| } |
| +void ContentViewCoreImpl::ConfirmTouchEvent(bool handled) { |
| + JNIEnv* env = AttachCurrentThread(); |
| + Java_ContentViewCore_confirmTouchEvent(env, java_object_->View(env).obj(), |
| + handled); |
| +} |
| + |
| +void ContentViewCoreImpl::DidSetNeedTouchEvents(bool need_touch_events) { |
| + JNIEnv* env = AttachCurrentThread(); |
| + Java_ContentViewCore_didSetNeedTouchEvents(env, |
| + java_object_->View(env).obj(), |
| + need_touch_events); |
| +} |
| + |
| bool ContentViewCoreImpl::HasFocus() { |
| NOTIMPLEMENTED() << "not upstreamed yet"; |
| return false; |