OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/android/content_view_core_impl.h" | 5 #include "content/browser/android/content_view_core_impl.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
11 #include "content/browser/android/content_view_client.h" | 11 #include "content/browser/android/content_view_client.h" |
12 #include "content/browser/android/touch_point.h" | |
12 #include "content/browser/renderer_host/render_view_host_impl.h" | 13 #include "content/browser/renderer_host/render_view_host_impl.h" |
14 #include "content/browser/renderer_host/render_widget_host_impl.h" | |
15 #include "content/browser/renderer_host/render_widget_host_view_android.h" | |
13 #include "content/browser/web_contents/navigation_controller_impl.h" | 16 #include "content/browser/web_contents/navigation_controller_impl.h" |
14 #include "content/public/browser/browser_context.h" | 17 #include "content/public/browser/browser_context.h" |
18 #include "content/public/browser/interstitial_page.h" | |
15 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
16 #include "jni/content_view_core_jni.h" | 20 #include "jni/content_view_core_jni.h" |
17 #include "webkit/glue/webmenuitem.h" | 21 #include "webkit/glue/webmenuitem.h" |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | |
23 #include "third_party/WebKit/Source/WebKit/chromium/public/android/WebInputEvent Factory.h" | |
18 | 24 |
19 using base::android::AttachCurrentThread; | 25 using base::android::AttachCurrentThread; |
20 using base::android::ConvertUTF16ToJavaString; | 26 using base::android::ConvertUTF16ToJavaString; |
21 using base::android::ConvertUTF8ToJavaString; | 27 using base::android::ConvertUTF8ToJavaString; |
22 using base::android::GetClass; | 28 using base::android::GetClass; |
23 using base::android::HasField; | 29 using base::android::HasField; |
24 using base::android::ScopedJavaGlobalRef; | 30 using base::android::ScopedJavaGlobalRef; |
25 using base::android::ScopedJavaLocalRef; | 31 using base::android::ScopedJavaLocalRef; |
32 using WebKit::WebInputEvent; | |
33 using WebKit::WebInputEventFactory; | |
26 | 34 |
27 // Describes the type and enabled state of a select popup item. | 35 // Describes the type and enabled state of a select popup item. |
28 // Keep in sync with the value defined in SelectPopupDialog.java | 36 // Keep in sync with the value defined in SelectPopupDialog.java |
29 enum PopupItemType { | 37 enum PopupItemType { |
30 POPUP_ITEM_TYPE_GROUP = 0, | 38 POPUP_ITEM_TYPE_GROUP = 0, |
31 POPUP_ITEM_TYPE_DISABLED, | 39 POPUP_ITEM_TYPE_DISABLED, |
32 POPUP_ITEM_TYPE_ENABLED | 40 POPUP_ITEM_TYPE_ENABLED |
33 }; | 41 }; |
34 | 42 |
35 namespace { | 43 namespace { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 const NotificationSource& source, | 97 const NotificationSource& source, |
90 const NotificationDetails& details) { | 98 const NotificationDetails& details) { |
91 // TODO(jrg) | 99 // TODO(jrg) |
92 } | 100 } |
93 | 101 |
94 void ContentViewCoreImpl::InitJNI(JNIEnv* env, jobject obj) { | 102 void ContentViewCoreImpl::InitJNI(JNIEnv* env, jobject obj) { |
95 java_object_ = new JavaObject; | 103 java_object_ = new JavaObject; |
96 java_object_->obj = env->NewWeakGlobalRef(obj); | 104 java_object_->obj = env->NewWeakGlobalRef(obj); |
97 } | 105 } |
98 | 106 |
107 RenderWidgetHostViewAndroid* ContentViewCoreImpl:: | |
108 GetRenderWidgetHostViewAndroid() { | |
109 RenderWidgetHostView* rwhv = NULL; | |
110 if (!web_contents_) { | |
111 return NULL; | |
112 } else if (web_contents_->ShowingInterstitialPage()) { | |
113 rwhv = web_contents_->GetInterstitialPage()-> | |
114 GetRenderViewHostForTesting()->GetView(); | |
115 // An interstitial page must have had Show() called immediately after | |
116 // construction in order for the render widget to exist. Currently Desktop | |
117 // Chrome does not enforce this is the case, however we do here to keep the | |
118 // state consistent with the WebContents. | |
119 CHECK(rwhv); | |
120 } else { | |
121 rwhv = web_contents_->GetRenderWidgetHostView(); | |
122 } | |
123 return static_cast<RenderWidgetHostViewAndroid*>(rwhv); | |
124 } | |
125 | |
99 // ---------------------------------------------------------------------------- | 126 // ---------------------------------------------------------------------------- |
100 // Methods called from Java via JNI | 127 // Methods called from Java via JNI |
101 // ---------------------------------------------------------------------------- | 128 // ---------------------------------------------------------------------------- |
102 | 129 |
103 void ContentViewCoreImpl::LoadUrlWithoutUrlSanitization(JNIEnv* env, | 130 void ContentViewCoreImpl::LoadUrlWithoutUrlSanitization(JNIEnv* env, |
104 jobject, | 131 jobject, |
105 jstring jurl, | 132 jstring jurl, |
106 int page_transition) { | 133 int page_transition) { |
107 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); | 134 GURL url(base::android::ConvertJavaStringToUTF8(env, jurl)); |
108 | 135 |
(...skipping 29 matching lines...) Expand all Loading... | |
138 // We report 1 in that case so the UI does not assume the page is loading. | 165 // We report 1 in that case so the UI does not assume the page is loading. |
139 if (web_contents()->GetURL().is_empty() || !content_view_client_.get()) | 166 if (web_contents()->GetURL().is_empty() || !content_view_client_.get()) |
140 return static_cast<jdouble>(1.0); | 167 return static_cast<jdouble>(1.0); |
141 return static_cast<jdouble>(content_view_client_->GetLoadProgress()); | 168 return static_cast<jdouble>(content_view_client_->GetLoadProgress()); |
142 } | 169 } |
143 | 170 |
144 jboolean ContentViewCoreImpl::IsIncognito(JNIEnv* env, jobject obj) { | 171 jboolean ContentViewCoreImpl::IsIncognito(JNIEnv* env, jobject obj) { |
145 return web_contents()->GetBrowserContext()->IsOffTheRecord(); | 172 return web_contents()->GetBrowserContext()->IsOffTheRecord(); |
146 } | 173 } |
147 | 174 |
175 jboolean ContentViewCoreImpl::TouchEvent(JNIEnv* env, jobject obj, | |
176 jlong time_ms, | |
177 jint type, jobjectArray pts) { | |
178 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | |
179 if (rwhv) { | |
180 // 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.
| |
181 // by the Javascript. Without this, scroll/pinch is unreliable on any page | |
182 // capturing onTouchEvent as soon as the renderer stops responding (e.g. | |
183 // while refreshing tiles). | |
184 // TODO(aelias): http://b/5255553 -- Find a way to allow the case where | |
185 // JavaScript can choose to handle some of touch events during one touch | |
186 // sequence, without compromising performance. For example, renderer | |
187 // handling horizontal move while leaving vertical move to the browser to | |
188 // handle. | |
189 using WebKit::WebTouchEvent; | |
190 WebKit::WebTouchEvent event; | |
191 TouchPoint::BuildWebTouchEvent(env, type, time_ms, pts, event); | |
192 rwhv->TouchEvent(event); | |
193 return true; | |
194 } | |
195 return false; | |
196 } | |
197 | |
198 void ContentViewCoreImpl::SendGestureEvent(WebInputEvent::Type type, | |
199 long time_ms, int x, int y, | |
200 float dx, float dy, | |
201 bool link_preview_tap) { | |
202 WebKit::WebGestureEvent event = WebInputEventFactory::gestureEvent( | |
203 type, time_ms / 1000.0, x, y, dx, dy, | |
204 0); | |
205 if (GetRenderWidgetHostViewAndroid()) | |
206 GetRenderWidgetHostViewAndroid()->GestureEvent(event); | |
207 } | |
208 | |
209 void ContentViewCoreImpl::ScrollBegin(JNIEnv* env, jobject obj, jlong time_ms, | |
210 jint x, jint y) { | |
211 SendGestureEvent(WebInputEvent::GestureScrollBegin, time_ms, x, y, 0, 0, | |
212 false); | |
213 } | |
214 | |
215 void ContentViewCoreImpl::ScrollEnd(JNIEnv* env, jobject obj, jlong time_ms) { | |
216 SendGestureEvent(WebInputEvent::GestureScrollEnd, time_ms, 0, 0, 0, 0, false); | |
217 } | |
218 | |
219 void ContentViewCoreImpl::ScrollBy(JNIEnv* env, jobject obj, jlong time_ms, | |
220 jint dx, jint dy) { | |
221 SendGestureEvent(WebInputEvent::GestureScrollUpdate, time_ms, 0, 0, -dx, -dy, | |
222 false); | |
223 } | |
224 | |
225 void ContentViewCoreImpl::FlingStart(JNIEnv* env, jobject obj, jlong time_ms, | |
226 jint x, jint y, jint vx, jint vy) { | |
227 SendGestureEvent(WebInputEvent::GestureFlingStart, time_ms, x, y, vx, vy, | |
228 false); | |
229 } | |
230 | |
231 void ContentViewCoreImpl::FlingCancel(JNIEnv* env, jobject obj, jlong time_ms) { | |
232 SendGestureEvent(WebInputEvent::GestureFlingCancel, time_ms, 0, 0, 0, 0, | |
233 false); | |
234 } | |
235 | |
236 void ContentViewCoreImpl::SingleTap(JNIEnv* env, jobject obj, jlong time_ms, | |
237 jint x, jint y, jboolean link_preview_tap) { | |
238 SendGestureEvent(WebInputEvent::GestureTap, time_ms, x, y, 0, 0, | |
239 link_preview_tap); | |
240 } | |
241 | |
242 void ContentViewCoreImpl::ShowPressState(JNIEnv* env, jobject obj, | |
243 jlong time_ms, | |
244 jint x, jint y) { | |
245 SendGestureEvent(WebInputEvent::GestureTapDown, time_ms, x, y, 0, 0, false); | |
246 } | |
247 | |
248 void ContentViewCoreImpl::DoubleTap(JNIEnv* env, jobject obj, jlong time_ms, | |
249 jint x, jint y) { | |
250 SendGestureEvent(WebInputEvent::GestureDoubleTap, time_ms, x, y, 0, 0, false); | |
251 } | |
252 | |
253 void ContentViewCoreImpl::LongPress(JNIEnv* env, jobject obj, jlong time_ms, | |
254 jint x, jint y, jboolean link_preview_tap) { | |
255 SendGestureEvent(WebInputEvent::GestureLongPress, time_ms, x, y, 0, 0, | |
256 link_preview_tap); | |
257 } | |
258 | |
259 void ContentViewCoreImpl::PinchBegin(JNIEnv* env, jobject obj, jlong time_ms, | |
260 jint x, jint y) { | |
261 SendGestureEvent(WebInputEvent::GesturePinchBegin, time_ms, x, y, 0, 0, | |
262 false); | |
263 } | |
264 | |
265 void ContentViewCoreImpl::PinchEnd(JNIEnv* env, jobject obj, jlong time_ms) { | |
266 SendGestureEvent(WebInputEvent::GesturePinchEnd, time_ms, 0, 0, 0, 0, false); | |
267 } | |
268 | |
269 void ContentViewCoreImpl::PinchBy(JNIEnv* env, jobject obj, jlong time_ms, | |
270 jint anchor_x, jint anchor_y, jfloat delta) { | |
271 SendGestureEvent(WebInputEvent::GesturePinchUpdate, time_ms, | |
272 anchor_x, anchor_y, delta, delta, false); | |
273 } | |
274 | |
148 jboolean ContentViewCoreImpl::CanGoBack(JNIEnv* env, jobject obj) { | 275 jboolean ContentViewCoreImpl::CanGoBack(JNIEnv* env, jobject obj) { |
149 return web_contents_->GetController().CanGoBack(); | 276 return web_contents_->GetController().CanGoBack(); |
150 } | 277 } |
151 | 278 |
152 jboolean ContentViewCoreImpl::CanGoForward(JNIEnv* env, jobject obj) { | 279 jboolean ContentViewCoreImpl::CanGoForward(JNIEnv* env, jobject obj) { |
153 return web_contents_->GetController().CanGoForward(); | 280 return web_contents_->GetController().CanGoForward(); |
154 } | 281 } |
155 | 282 |
156 jboolean ContentViewCoreImpl::CanGoToOffset(JNIEnv* env, jobject obj, | 283 jboolean ContentViewCoreImpl::CanGoToOffset(JNIEnv* env, jobject obj, |
157 jint offset) { | 284 jint offset) { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 POPUP_ITEM_TYPE_DISABLED)); | 418 POPUP_ITEM_TYPE_DISABLED)); |
292 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); | 419 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); |
293 } | 420 } |
294 ScopedJavaLocalRef<jobjectArray> items_array( | 421 ScopedJavaLocalRef<jobjectArray> items_array( |
295 base::android::ToJavaArrayOfStrings(env, labels)); | 422 base::android::ToJavaArrayOfStrings(env, labels)); |
296 Java_ContentViewCore_showSelectPopup(env, java_object_->View(env).obj(), | 423 Java_ContentViewCore_showSelectPopup(env, java_object_->View(env).obj(), |
297 items_array.obj(), enabled_array.obj(), | 424 items_array.obj(), enabled_array.obj(), |
298 multiple, selected_array.obj()); | 425 multiple, selected_array.obj()); |
299 } | 426 } |
300 | 427 |
428 void ContentViewCoreImpl::ConfirmTouchEvent(bool handled) { | |
429 JNIEnv* env = AttachCurrentThread(); | |
430 Java_ContentViewCore_confirmTouchEvent(env, java_object_->View(env).obj(), | |
431 handled); | |
432 } | |
433 | |
434 void ContentViewCoreImpl::DidSetNeedTouchEvents(bool need_touch_events) { | |
435 JNIEnv* env = AttachCurrentThread(); | |
436 Java_ContentViewCore_didSetNeedTouchEvents(env, | |
437 java_object_->View(env).obj(), | |
438 need_touch_events); | |
439 } | |
440 | |
301 bool ContentViewCoreImpl::HasFocus() { | 441 bool ContentViewCoreImpl::HasFocus() { |
302 NOTIMPLEMENTED() << "not upstreamed yet"; | 442 NOTIMPLEMENTED() << "not upstreamed yet"; |
303 return false; | 443 return false; |
304 } | 444 } |
305 | 445 |
306 void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) { | 446 void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) { |
307 NOTIMPLEMENTED() << "not upstreamed yet"; | 447 NOTIMPLEMENTED() << "not upstreamed yet"; |
308 } | 448 } |
309 | 449 |
310 void ContentViewCoreImpl::OnSelectionBoundsChanged( | 450 void ContentViewCoreImpl::OnSelectionBoundsChanged( |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
379 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { | 519 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { |
380 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; | 520 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; |
381 return false; | 521 return false; |
382 } | 522 } |
383 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); | 523 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); |
384 | 524 |
385 return RegisterNativesImpl(env) >= 0; | 525 return RegisterNativesImpl(env) >= 0; |
386 } | 526 } |
387 | 527 |
388 } // namespace content | 528 } // namespace content |
OLD | NEW |