Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/android/jni_android.h" | 9 #include "base/android/jni_android.h" |
| 10 #include "base/android/jni_array.h" | 10 #include "base/android/jni_array.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 48 #include "content/public/browser/web_contents.h" | 48 #include "content/public/browser/web_contents.h" |
| 49 #include "content/public/common/content_client.h" | 49 #include "content/public/common/content_client.h" |
| 50 #include "content/public/common/content_switches.h" | 50 #include "content/public/common/content_switches.h" |
| 51 #include "content/public/common/menu_item.h" | 51 #include "content/public/common/menu_item.h" |
| 52 #include "content/public/common/user_agent.h" | 52 #include "content/public/common/user_agent.h" |
| 53 #include "device/geolocation/geolocation_service_context.h" | 53 #include "device/geolocation/geolocation_service_context.h" |
| 54 #include "jni/ContentViewCore_jni.h" | 54 #include "jni/ContentViewCore_jni.h" |
| 55 #include "jni/DragEvent_jni.h" | 55 #include "jni/DragEvent_jni.h" |
| 56 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 56 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 57 #include "ui/android/view_android.h" | 57 #include "ui/android/view_android.h" |
| 58 #include "ui/android/view_root.h" | |
| 58 #include "ui/android/window_android.h" | 59 #include "ui/android/window_android.h" |
| 59 #include "ui/base/clipboard/clipboard.h" | 60 #include "ui/base/clipboard/clipboard.h" |
| 60 #include "ui/base/ui_base_switches_util.h" | 61 #include "ui/base/ui_base_switches_util.h" |
| 61 #include "ui/events/android/motion_event_android.h" | 62 #include "ui/events/android/motion_event_android.h" |
| 62 #include "ui/events/blink/blink_event_util.h" | 63 #include "ui/events/blink/blink_event_util.h" |
| 63 #include "ui/events/blink/web_input_event_traits.h" | 64 #include "ui/events/blink/web_input_event_traits.h" |
| 64 #include "ui/events/event_utils.h" | 65 #include "ui/events/event_utils.h" |
| 65 #include "ui/events/gesture_detection/motion_event.h" | 66 #include "ui/events/gesture_detection/motion_event.h" |
| 66 #include "ui/gfx/android/java_bitmap.h" | 67 #include "ui/gfx/android/java_bitmap.h" |
| 67 #include "ui/gfx/geometry/point_conversions.h" | 68 #include "ui/gfx/geometry/point_conversions.h" |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 java_ref_.reset(); | 268 java_ref_.reset(); |
| 268 if (!j_obj.is_null()) { | 269 if (!j_obj.is_null()) { |
| 269 Java_ContentViewCore_onNativeContentViewCoreDestroyed( | 270 Java_ContentViewCore_onNativeContentViewCoreDestroyed( |
| 270 env, j_obj, reinterpret_cast<intptr_t>(this)); | 271 env, j_obj, reinterpret_cast<intptr_t>(this)); |
| 271 } | 272 } |
| 272 } | 273 } |
| 273 | 274 |
| 274 void ContentViewCoreImpl::UpdateWindowAndroid( | 275 void ContentViewCoreImpl::UpdateWindowAndroid( |
| 275 JNIEnv* env, | 276 JNIEnv* env, |
| 276 const base::android::JavaParamRef<jobject>& obj, | 277 const base::android::JavaParamRef<jobject>& obj, |
| 278 const base::android::JavaParamRef<jobject>& jview_root, | |
| 277 jlong window_android) { | 279 jlong window_android) { |
| 278 ui::ViewAndroid* view = GetViewAndroid(); | |
| 279 ui::WindowAndroid* window = | 280 ui::WindowAndroid* window = |
|
boliu
2017/01/04 18:58:06
should DCHECK that window and view root are either
Jinsuk Kim
2017/01/05 11:03:12
Renamed to UpdateViewRoot.
| |
| 280 reinterpret_cast<ui::WindowAndroid*>(window_android); | 281 reinterpret_cast<ui::WindowAndroid*>(window_android); |
| 281 if (window == GetWindowAndroid()) | 282 if (window == GetWindowAndroid()) |
|
boliu
2017/01/04 18:58:05
this is not enough, what if view_root is different
Jinsuk Kim
2017/01/05 11:03:12
Used view_root instead. ViewRoot and WA always com
| |
| 282 return; | 283 return; |
| 284 ui::ViewAndroid* view = GetViewAndroid(); | |
| 285 view->RemoveFromParent(); | |
|
boliu
2017/01/04 18:58:06
Remove/AddChild should stay where they used to be
Jinsuk Kim
2017/01/05 11:03:12
Done.
| |
| 286 ui::ViewRoot::FromJavaObject(env, jview_root)->AddChild(view); | |
|
boliu
2017/01/04 18:58:05
probably should match WindowAndroid pattern here t
Jinsuk Kim
2017/01/05 11:03:12
Done.
| |
| 283 if (GetWindowAndroid()) { | 287 if (GetWindowAndroid()) { |
| 284 for (auto& observer : observer_list_) | 288 for (auto& observer : observer_list_) |
| 285 observer.OnDetachedFromWindow(); | 289 observer.OnDetachedFromWindow(); |
| 286 view->RemoveFromParent(); | |
| 287 } | 290 } |
| 288 if (window) { | 291 if (window) { |
| 289 window->AddChild(view); | |
| 290 for (auto& observer : observer_list_) | 292 for (auto& observer : observer_list_) |
| 291 observer.OnAttachedToWindow(); | 293 observer.OnAttachedToWindow(); |
| 292 } | 294 } |
| 293 } | 295 } |
| 294 | 296 |
| 295 base::android::ScopedJavaLocalRef<jobject> | 297 base::android::ScopedJavaLocalRef<jobject> |
| 296 ContentViewCoreImpl::GetWebContentsAndroid(JNIEnv* env, | 298 ContentViewCoreImpl::GetWebContentsAndroid(JNIEnv* env, |
| 297 const JavaParamRef<jobject>& obj) { | 299 const JavaParamRef<jobject>& obj) { |
| 298 return web_contents_->GetJavaWebContents(); | 300 return web_contents_->GetJavaWebContents(); |
| 299 } | 301 } |
| (...skipping 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1525 static_cast<WebContentsImpl*>(web_contents())->GetView()); | 1527 static_cast<WebContentsImpl*>(web_contents())->GetView()); |
| 1526 DCHECK(wcva); | 1528 DCHECK(wcva); |
| 1527 wcva->SetContentViewCore(NULL); | 1529 wcva->SetContentViewCore(NULL); |
| 1528 } | 1530 } |
| 1529 | 1531 |
| 1530 // This is called for each ContentView. | 1532 // This is called for each ContentView. |
| 1531 jlong Init(JNIEnv* env, | 1533 jlong Init(JNIEnv* env, |
| 1532 const JavaParamRef<jobject>& obj, | 1534 const JavaParamRef<jobject>& obj, |
| 1533 const JavaParamRef<jobject>& jweb_contents, | 1535 const JavaParamRef<jobject>& jweb_contents, |
| 1534 const JavaParamRef<jobject>& jview_android_delegate, | 1536 const JavaParamRef<jobject>& jview_android_delegate, |
| 1535 jlong jwindow_android, | 1537 const JavaParamRef<jobject>& jview_root, |
| 1536 jfloat dipScale, | 1538 jfloat dipScale, |
| 1537 const JavaParamRef<jobject>& retained_objects_set) { | 1539 const JavaParamRef<jobject>& retained_objects_set) { |
| 1538 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | 1540 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
| 1539 WebContents::FromJavaWebContents(jweb_contents)); | 1541 WebContents::FromJavaWebContents(jweb_contents)); |
| 1540 CHECK(web_contents) << | 1542 CHECK(web_contents) << |
| 1541 "A ContentViewCoreImpl should be created with a valid WebContents."; | 1543 "A ContentViewCoreImpl should be created with a valid WebContents."; |
| 1542 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView(); | 1544 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView(); |
| 1543 view_android->SetDelegate(jview_android_delegate); | 1545 view_android->SetDelegate(jview_android_delegate); |
| 1544 view_android->SetLayer(cc::Layer::Create()); | 1546 view_android->SetLayer(cc::Layer::Create()); |
| 1545 | 1547 ui::ViewRoot::FromJavaObject(env, jview_root)->AddChild(view_android); |
| 1546 ui::WindowAndroid* window_android = | |
| 1547 reinterpret_cast<ui::WindowAndroid*>(jwindow_android); | |
| 1548 DCHECK(window_android); | |
| 1549 window_android->AddChild(view_android); | |
| 1550 | 1548 |
| 1551 // TODO: pass dipScale. | 1549 // TODO: pass dipScale. |
| 1552 ContentViewCoreImpl* view = new ContentViewCoreImpl( | 1550 ContentViewCoreImpl* view = new ContentViewCoreImpl( |
| 1553 env, obj, web_contents, dipScale, retained_objects_set); | 1551 env, obj, web_contents, dipScale, retained_objects_set); |
| 1554 return reinterpret_cast<intptr_t>(view); | 1552 return reinterpret_cast<intptr_t>(view); |
| 1555 } | 1553 } |
| 1556 | 1554 |
| 1557 static ScopedJavaLocalRef<jobject> FromWebContentsAndroid( | 1555 static ScopedJavaLocalRef<jobject> FromWebContentsAndroid( |
| 1558 JNIEnv* env, | 1556 JNIEnv* env, |
| 1559 const JavaParamRef<jclass>& clazz, | 1557 const JavaParamRef<jclass>& clazz, |
| 1560 const JavaParamRef<jobject>& jweb_contents) { | 1558 const JavaParamRef<jobject>& jweb_contents) { |
| 1561 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents); | 1559 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents); |
| 1562 if (!web_contents) | 1560 if (!web_contents) |
| 1563 return ScopedJavaLocalRef<jobject>(); | 1561 return ScopedJavaLocalRef<jobject>(); |
| 1564 | 1562 |
| 1565 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents); | 1563 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents); |
| 1566 if (!view) | 1564 if (!view) |
| 1567 return ScopedJavaLocalRef<jobject>(); | 1565 return ScopedJavaLocalRef<jobject>(); |
| 1568 | 1566 |
| 1569 return view->GetJavaObject(); | 1567 return view->GetJavaObject(); |
| 1570 } | 1568 } |
| 1571 | 1569 |
| 1572 bool RegisterContentViewCore(JNIEnv* env) { | 1570 bool RegisterContentViewCore(JNIEnv* env) { |
| 1573 return RegisterNativesImpl(env); | 1571 return RegisterNativesImpl(env); |
| 1574 } | 1572 } |
| 1575 | 1573 |
| 1576 } // namespace content | 1574 } // namespace content |
| OLD | NEW |