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

Side by Side Diff: ui/android/view_android.cc

Issue 2103243002: Factor out ContentViewAndroidDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 years, 5 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
« ui/android/view_android.h ('K') | « ui/android/view_android.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "ui/android/view_android.h" 5 #include "ui/android/view_android.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "cc/layers/layer.h" 10 #include "cc/layers/layer.h"
11 #include "jni/ViewAndroid_jni.h"
12 #include "ui/android/window_android.h"
13 #include "ui/gfx/android/device_display_info.h"
11 14
12 namespace ui { 15 namespace ui {
13 16
14 using base::android::AttachCurrentThread; 17 using base::android::AttachCurrentThread;
15 using base::android::JavaRef; 18 using base::android::JavaRef;
16 using base::android::ScopedJavaLocalRef; 19 using base::android::ScopedJavaLocalRef;
17 20
18 ViewAndroid::ViewAndroid(const JavaRef<jobject>& delegate, 21 ViewAndroid::ViewAndroid(const JavaRef<jobject>& context,
22 const JavaRef<jobject>& delegate,
19 WindowAndroid* root_window) 23 WindowAndroid* root_window)
20 : parent_(nullptr), window_(root_window), delegate_(delegate) {} 24 : parent_(nullptr)
25 , window_(root_window)
26 , java_ref_(Java_ViewAndroid_create(base::android::AttachCurrentThread(),
27 context.obj(),
28 delegate.obj()))
29 , delegate_(delegate) {}
21 30
22 ViewAndroid::ViewAndroid() : parent_(nullptr), window_(nullptr) {} 31 ViewAndroid::ViewAndroid() : parent_(nullptr), window_(nullptr) {}
23 32
33 bool ViewAndroid::RegisterWindowAndroid(JNIEnv* env) {
34 return RegisterNativesImpl(env);
35 }
36
24 ViewAndroid::~ViewAndroid() { 37 ViewAndroid::~ViewAndroid() {
25 if (parent_) 38 if (parent_)
26 parent_->RemoveChild(this); 39 parent_->RemoveChild(this);
27 40
28 for (std::list<ViewAndroid*>::iterator it = children_.begin(); 41 for (std::list<ViewAndroid*>::iterator it = children_.begin();
29 it != children_.end(); it++) { 42 it != children_.end(); it++) {
30 DCHECK_EQ((*it)->parent_, this); 43 DCHECK_EQ((*it)->parent_, this);
31 (*it)->parent_ = nullptr; 44 (*it)->parent_ = nullptr;
32 } 45 }
33 } 46 }
(...skipping 14 matching lines...) Expand all
48 DCHECK(child); 61 DCHECK(child);
49 DCHECK_EQ(child->parent_, this); 62 DCHECK_EQ(child->parent_, this);
50 63
51 std::list<ViewAndroid*>::iterator it = 64 std::list<ViewAndroid*>::iterator it =
52 std::find(children_.begin(), children_.end(), child); 65 std::find(children_.begin(), children_.end(), child);
53 DCHECK(it != children_.end()); 66 DCHECK(it != children_.end());
54 children_.erase(it); 67 children_.erase(it);
55 child->parent_ = nullptr; 68 child->parent_ = nullptr;
56 } 69 }
57 70
71 ScopedJavaLocalRef<jobject>
72 ViewAndroid::AcquireAnchorView() {
73 if (delegate_.is_null())
no sievers 2016/07/14 23:14:32 Doesn't it need to go to the parent's delegate if
Jinsuk Kim 2016/07/15 05:46:27 Makes sense. In fact other methods |SetAnchorRect|
74 return base::android::ScopedJavaLocalRef<jobject>();
75
76 JNIEnv* env = base::android::AttachCurrentThread();
77 return ScopedJavaLocalRef<jobject>(
78 Java_ViewAndroid_acquireAnchorView(env,
79 java_ref_.obj()));
80 }
81
82 void ViewAndroid::SetAnchorRect(const jobject& anchor,
83 const gfx::RectF& bounds) {
84 JNIEnv* env = base::android::AttachCurrentThread();
85 gfx::DeviceDisplayInfo device_info;
86 float scale = device_info.GetDIPScale();
87 int left_margin = std::round(bounds.x() * scale);
88 float content_offset_y_pix = GetWindowAndroid()->content_offset().y();
no sievers 2016/07/14 23:14:32 nit: can you put a TODO? content_offset() should b
Jinsuk Kim 2016/07/15 05:46:27 Meant to do it in this CL but it involved changes
89 int top_margin = std::round(content_offset_y_pix + bounds.y() * scale);
90 Java_ViewAndroid_setAnchorViewPosition(env,
91 java_ref_.obj(),
92 anchor,
93 bounds.x(),
94 bounds.y(),
95 bounds.width(),
96 bounds.height(),
97 scale,
98 left_margin,
99 top_margin);
100 }
101
102 void ViewAndroid::RemoveAnchorView(const jobject& anchor) {
103 JNIEnv* env = base::android::AttachCurrentThread();
104 Java_ViewAndroid_removeAnchorView(env, java_ref_.obj(), anchor);
105 }
106
58 WindowAndroid* ViewAndroid::GetWindowAndroid() const { 107 WindowAndroid* ViewAndroid::GetWindowAndroid() const {
59 if (window_) 108 if (window_)
60 return window_; 109 return window_;
61 110
62 return parent_ ? parent_->GetWindowAndroid() : nullptr; 111 return parent_ ? parent_->GetWindowAndroid() : nullptr;
63 } 112 }
64 113
65 void ViewAndroid::SetWindowAndroid(WindowAndroid* root_window) { 114 void ViewAndroid::SetWindowAndroid(WindowAndroid* root_window) {
66 window_ = root_window; 115 window_ = root_window;
67 DCHECK(parent_ == nullptr) << "Children shouldn't have a root window"; 116 DCHECK(parent_ == nullptr) << "Children shouldn't have a root window";
68 } 117 }
69 118
70 const JavaRef<jobject>& ViewAndroid::GetViewAndroidDelegate()
71 const {
72 if (!delegate_.is_null())
73 return delegate_;
74
75 return parent_ ? parent_->GetViewAndroidDelegate() : delegate_;
no sievers 2016/07/14 23:14:32 see above, I think you want to keep the recursion
Jinsuk Kim 2016/07/15 05:46:27 Done.
76 }
77
78 cc::Layer* ViewAndroid::GetLayer() const { 119 cc::Layer* ViewAndroid::GetLayer() const {
79 return layer_.get(); 120 return layer_.get();
80 } 121 }
81 122
82 void ViewAndroid::SetLayer(scoped_refptr<cc::Layer> layer) { 123 void ViewAndroid::SetLayer(scoped_refptr<cc::Layer> layer) {
83 layer_ = layer; 124 layer_ = layer;
84 } 125 }
85 126
86 } // namespace ui 127 } // namespace ui
OLDNEW
« ui/android/view_android.h ('K') | « ui/android/view_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698