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" | |
jochen (gone - plz use gerrit)
2012/07/19 14:50:06
alphabetical ordering
| |
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() { | |
jochen (gone - plz use gerrit)
2012/07/19 14:50:06
please keep the class and method name together on
| |
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, | |
jochen (gone - plz use gerrit)
2012/07/19 14:50:06
one parameter per line
| |
176 jlong time_ms, | |
177 jint type, jobjectArray pts) { | |
178 RenderWidgetHostViewAndroid* rwhv = GetRenderWidgetHostViewAndroid(); | |
179 if (rwhv) { | |
180 using WebKit::WebTouchEvent; | |
181 WebKit::WebTouchEvent event; | |
182 TouchPoint::BuildWebTouchEvent(env, type, time_ms, pts, event); | |
183 rwhv->TouchEvent(event); | |
184 return true; | |
185 } | |
186 return false; | |
187 } | |
188 | |
189 void ContentViewCoreImpl::SendGestureEvent(WebInputEvent::Type type, | |
190 long time_ms, int x, int y, | |
191 float dx, float dy, | |
192 bool link_preview_tap) { | |
193 WebKit::WebGestureEvent event = WebInputEventFactory::gestureEvent( | |
194 type, time_ms / 1000.0, x, y, dx, dy, | |
195 0); | |
jochen (gone - plz use gerrit)
2012/07/19 14:50:06
the 0); fits on the previous line
| |
196 if (GetRenderWidgetHostViewAndroid()) | |
197 GetRenderWidgetHostViewAndroid()->GestureEvent(event); | |
198 } | |
199 | |
200 void ContentViewCoreImpl::ScrollBegin(JNIEnv* env, jobject obj, jlong time_ms, | |
201 jint x, jint y) { | |
202 SendGestureEvent(WebInputEvent::GestureScrollBegin, time_ms, x, y, 0, 0, | |
jochen (gone - plz use gerrit)
2012/07/19 14:50:06
I would format this as
SendGestureEvent(
WebI
| |
203 false); | |
204 } | |
205 | |
206 void ContentViewCoreImpl::ScrollEnd(JNIEnv* env, jobject obj, jlong time_ms) { | |
207 SendGestureEvent(WebInputEvent::GestureScrollEnd, time_ms, 0, 0, 0, 0, false); | |
208 } | |
209 | |
210 void ContentViewCoreImpl::ScrollBy(JNIEnv* env, jobject obj, jlong time_ms, | |
211 jint dx, jint dy) { | |
212 SendGestureEvent(WebInputEvent::GestureScrollUpdate, time_ms, 0, 0, -dx, -dy, | |
213 false); | |
214 } | |
215 | |
216 void ContentViewCoreImpl::FlingStart(JNIEnv* env, jobject obj, jlong time_ms, | |
217 jint x, jint y, jint vx, jint vy) { | |
218 SendGestureEvent(WebInputEvent::GestureFlingStart, time_ms, x, y, vx, vy, | |
219 false); | |
220 } | |
221 | |
222 void ContentViewCoreImpl::FlingCancel(JNIEnv* env, jobject obj, jlong time_ms) { | |
223 SendGestureEvent(WebInputEvent::GestureFlingCancel, time_ms, 0, 0, 0, 0, | |
224 false); | |
225 } | |
226 | |
227 void ContentViewCoreImpl::SingleTap(JNIEnv* env, jobject obj, jlong time_ms, | |
228 jint x, jint y, jboolean link_preview_tap) { | |
229 SendGestureEvent(WebInputEvent::GestureTap, time_ms, x, y, 0, 0, | |
230 link_preview_tap); | |
231 } | |
232 | |
233 void ContentViewCoreImpl::ShowPressState(JNIEnv* env, jobject obj, | |
234 jlong time_ms, | |
235 jint x, jint y) { | |
236 SendGestureEvent(WebInputEvent::GestureTapDown, time_ms, x, y, 0, 0, false); | |
237 } | |
238 | |
239 void ContentViewCoreImpl::DoubleTap(JNIEnv* env, jobject obj, jlong time_ms, | |
240 jint x, jint y) { | |
241 SendGestureEvent(WebInputEvent::GestureDoubleTap, time_ms, x, y, 0, 0, false); | |
242 } | |
243 | |
244 void ContentViewCoreImpl::LongPress(JNIEnv* env, jobject obj, jlong time_ms, | |
245 jint x, jint y, jboolean link_preview_tap) { | |
246 SendGestureEvent(WebInputEvent::GestureLongPress, time_ms, x, y, 0, 0, | |
247 link_preview_tap); | |
248 } | |
249 | |
250 void ContentViewCoreImpl::PinchBegin(JNIEnv* env, jobject obj, jlong time_ms, | |
251 jint x, jint y) { | |
252 SendGestureEvent(WebInputEvent::GesturePinchBegin, time_ms, x, y, 0, 0, | |
253 false); | |
254 } | |
255 | |
256 void ContentViewCoreImpl::PinchEnd(JNIEnv* env, jobject obj, jlong time_ms) { | |
257 SendGestureEvent(WebInputEvent::GesturePinchEnd, time_ms, 0, 0, 0, 0, false); | |
258 } | |
259 | |
260 void ContentViewCoreImpl::PinchBy(JNIEnv* env, jobject obj, jlong time_ms, | |
261 jint anchor_x, jint anchor_y, jfloat delta) { | |
262 SendGestureEvent(WebInputEvent::GesturePinchUpdate, time_ms, | |
263 anchor_x, anchor_y, delta, delta, false); | |
264 } | |
265 | |
148 jboolean ContentViewCoreImpl::CanGoBack(JNIEnv* env, jobject obj) { | 266 jboolean ContentViewCoreImpl::CanGoBack(JNIEnv* env, jobject obj) { |
149 return web_contents_->GetController().CanGoBack(); | 267 return web_contents_->GetController().CanGoBack(); |
150 } | 268 } |
151 | 269 |
152 jboolean ContentViewCoreImpl::CanGoForward(JNIEnv* env, jobject obj) { | 270 jboolean ContentViewCoreImpl::CanGoForward(JNIEnv* env, jobject obj) { |
153 return web_contents_->GetController().CanGoForward(); | 271 return web_contents_->GetController().CanGoForward(); |
154 } | 272 } |
155 | 273 |
156 jboolean ContentViewCoreImpl::CanGoToOffset(JNIEnv* env, jobject obj, | 274 jboolean ContentViewCoreImpl::CanGoToOffset(JNIEnv* env, jobject obj, |
157 jint offset) { | 275 jint offset) { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 POPUP_ITEM_TYPE_DISABLED)); | 409 POPUP_ITEM_TYPE_DISABLED)); |
292 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); | 410 env->SetIntArrayRegion(enabled_array.obj(), i, 1, &enabled); |
293 } | 411 } |
294 ScopedJavaLocalRef<jobjectArray> items_array( | 412 ScopedJavaLocalRef<jobjectArray> items_array( |
295 base::android::ToJavaArrayOfStrings(env, labels)); | 413 base::android::ToJavaArrayOfStrings(env, labels)); |
296 Java_ContentViewCore_showSelectPopup(env, java_object_->View(env).obj(), | 414 Java_ContentViewCore_showSelectPopup(env, java_object_->View(env).obj(), |
297 items_array.obj(), enabled_array.obj(), | 415 items_array.obj(), enabled_array.obj(), |
298 multiple, selected_array.obj()); | 416 multiple, selected_array.obj()); |
299 } | 417 } |
300 | 418 |
419 void ContentViewCoreImpl::ConfirmTouchEvent(bool handled) { | |
420 JNIEnv* env = AttachCurrentThread(); | |
421 Java_ContentViewCore_confirmTouchEvent(env, java_object_->View(env).obj(), | |
422 handled); | |
jochen (gone - plz use gerrit)
2012/07/19 14:50:06
indenting off. also only one parameter per line
| |
423 } | |
424 | |
425 void ContentViewCoreImpl::DidSetNeedTouchEvents(bool need_touch_events) { | |
426 JNIEnv* env = AttachCurrentThread(); | |
427 Java_ContentViewCore_didSetNeedTouchEvents(env, | |
428 java_object_->View(env).obj(), | |
429 need_touch_events); | |
430 } | |
431 | |
301 bool ContentViewCoreImpl::HasFocus() { | 432 bool ContentViewCoreImpl::HasFocus() { |
302 NOTIMPLEMENTED() << "not upstreamed yet"; | 433 NOTIMPLEMENTED() << "not upstreamed yet"; |
303 return false; | 434 return false; |
304 } | 435 } |
305 | 436 |
306 void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) { | 437 void ContentViewCoreImpl::OnSelectionChanged(const std::string& text) { |
307 NOTIMPLEMENTED() << "not upstreamed yet"; | 438 NOTIMPLEMENTED() << "not upstreamed yet"; |
308 } | 439 } |
309 | 440 |
310 void ContentViewCoreImpl::OnSelectionBoundsChanged( | 441 void ContentViewCoreImpl::OnSelectionBoundsChanged( |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
379 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { | 510 if (!HasField(env, clazz, "mNativeContentViewCore", "I")) { |
380 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; | 511 DLOG(ERROR) << "Unable to find ContentView.mNativeContentViewCore!"; |
381 return false; | 512 return false; |
382 } | 513 } |
383 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); | 514 g_native_content_view = GetFieldID(env, clazz, "mNativeContentViewCore", "I"); |
384 | 515 |
385 return RegisterNativesImpl(env) >= 0; | 516 return RegisterNativesImpl(env) >= 0; |
386 } | 517 } |
387 | 518 |
388 } // namespace content | 519 } // namespace content |
OLD | NEW |