Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(785)

Side by Side Diff: content/browser/android/content_view_core_impl.cc

Issue 2595263002: Introduce ViewRoot forwarding input/view events to native (Closed)
Patch Set: tests Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 if (!j_obj.is_null()) { 268 if (!j_obj.is_null()) {
269 Java_ContentViewCore_onNativeContentViewCoreDestroyed( 269 Java_ContentViewCore_onNativeContentViewCoreDestroyed(
270 env, j_obj, reinterpret_cast<intptr_t>(this)); 270 env, j_obj, reinterpret_cast<intptr_t>(this));
271 } 271 }
272 } 272 }
273 273
274 void ContentViewCoreImpl::UpdateWindowAndroid( 274 void ContentViewCoreImpl::UpdateWindowAndroid(
275 JNIEnv* env, 275 JNIEnv* env,
276 const base::android::JavaParamRef<jobject>& obj, 276 const base::android::JavaParamRef<jobject>& obj,
277 jlong window_android) { 277 jlong window_android) {
278 ui::ViewAndroid* view = GetViewAndroid();
279 ui::WindowAndroid* window = 278 ui::WindowAndroid* window =
280 reinterpret_cast<ui::WindowAndroid*>(window_android); 279 reinterpret_cast<ui::WindowAndroid*>(window_android);
281 if (window == GetWindowAndroid()) 280 if (window == GetWindowAndroid())
282 return; 281 return;
282 ui::ViewAndroid* view = GetViewAndroid();
283 if (GetWindowAndroid()) { 283 if (GetWindowAndroid()) {
284 for (auto& observer : observer_list_) 284 for (auto& observer : observer_list_)
285 observer.OnDetachedFromWindow(); 285 observer.OnDetachedFromWindow();
286 view->RemoveFromParent(); 286 view->SetWindowAndroid(nullptr);
287 } 287 }
288 if (window) { 288 if (window) {
289 window->AddChild(view); 289 view->SetWindowAndroid(window);
290 for (auto& observer : observer_list_) 290 for (auto& observer : observer_list_)
291 observer.OnAttachedToWindow(); 291 observer.OnAttachedToWindow();
292 } 292 }
293 } 293 }
294 294
295 base::android::ScopedJavaLocalRef<jobject> 295 base::android::ScopedJavaLocalRef<jobject>
296 ContentViewCoreImpl::GetWebContentsAndroid(JNIEnv* env, 296 ContentViewCoreImpl::GetWebContentsAndroid(JNIEnv* env,
297 const JavaParamRef<jobject>& obj) { 297 const JavaParamRef<jobject>& obj) {
298 return web_contents_->GetJavaWebContents(); 298 return web_contents_->GetJavaWebContents();
299 } 299 }
(...skipping 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1525 static_cast<WebContentsImpl*>(web_contents())->GetView()); 1525 static_cast<WebContentsImpl*>(web_contents())->GetView());
1526 DCHECK(wcva); 1526 DCHECK(wcva);
1527 wcva->SetContentViewCore(NULL); 1527 wcva->SetContentViewCore(NULL);
1528 } 1528 }
1529 1529
1530 // This is called for each ContentView. 1530 // This is called for each ContentView.
1531 jlong Init(JNIEnv* env, 1531 jlong Init(JNIEnv* env,
1532 const JavaParamRef<jobject>& obj, 1532 const JavaParamRef<jobject>& obj,
1533 const JavaParamRef<jobject>& jweb_contents, 1533 const JavaParamRef<jobject>& jweb_contents,
1534 const JavaParamRef<jobject>& jview_android_delegate, 1534 const JavaParamRef<jobject>& jview_android_delegate,
1535 jlong jwindow_android,
1536 jfloat dipScale, 1535 jfloat dipScale,
1537 const JavaParamRef<jobject>& retained_objects_set) { 1536 const JavaParamRef<jobject>& retained_objects_set) {
1538 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( 1537 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>(
1539 WebContents::FromJavaWebContents(jweb_contents)); 1538 WebContents::FromJavaWebContents(jweb_contents));
1540 CHECK(web_contents) << 1539 CHECK(web_contents) <<
1541 "A ContentViewCoreImpl should be created with a valid WebContents."; 1540 "A ContentViewCoreImpl should be created with a valid WebContents.";
1542 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView(); 1541 ui::ViewAndroid* view_android = web_contents->GetView()->GetNativeView();
1543 view_android->SetDelegate(jview_android_delegate); 1542 view_android->SetDelegate(jview_android_delegate);
1544 view_android->SetLayer(cc::Layer::Create()); 1543 view_android->SetLayer(cc::Layer::Create());
1545 1544
1546 ui::WindowAndroid* window_android =
1547 reinterpret_cast<ui::WindowAndroid*>(jwindow_android);
1548 DCHECK(window_android);
1549 window_android->AddChild(view_android);
1550
1551 // TODO: pass dipScale. 1545 // TODO: pass dipScale.
1552 ContentViewCoreImpl* view = new ContentViewCoreImpl( 1546 ContentViewCoreImpl* view = new ContentViewCoreImpl(
1553 env, obj, web_contents, dipScale, retained_objects_set); 1547 env, obj, web_contents, dipScale, retained_objects_set);
1554 return reinterpret_cast<intptr_t>(view); 1548 return reinterpret_cast<intptr_t>(view);
1555 } 1549 }
1556 1550
1557 static ScopedJavaLocalRef<jobject> FromWebContentsAndroid( 1551 static ScopedJavaLocalRef<jobject> FromWebContentsAndroid(
1558 JNIEnv* env, 1552 JNIEnv* env,
1559 const JavaParamRef<jclass>& clazz, 1553 const JavaParamRef<jclass>& clazz,
1560 const JavaParamRef<jobject>& jweb_contents) { 1554 const JavaParamRef<jobject>& jweb_contents) {
1561 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents); 1555 WebContents* web_contents = WebContents::FromJavaWebContents(jweb_contents);
1562 if (!web_contents) 1556 if (!web_contents)
1563 return ScopedJavaLocalRef<jobject>(); 1557 return ScopedJavaLocalRef<jobject>();
1564 1558
1565 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents); 1559 ContentViewCore* view = ContentViewCore::FromWebContents(web_contents);
1566 if (!view) 1560 if (!view)
1567 return ScopedJavaLocalRef<jobject>(); 1561 return ScopedJavaLocalRef<jobject>();
1568 1562
1569 return view->GetJavaObject(); 1563 return view->GetJavaObject();
1570 } 1564 }
1571 1565
1572 bool RegisterContentViewCore(JNIEnv* env) { 1566 bool RegisterContentViewCore(JNIEnv* env) {
1573 return RegisterNativesImpl(env); 1567 return RegisterNativesImpl(env);
1574 } 1568 }
1575 1569
1576 } // namespace content 1570 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698