OLD | NEW |
---|---|
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/ViewAndroidDelegate_jni.h" | 11 #include "jni/ViewAndroidDelegate_jni.h" |
12 #include "ui/android/event_handler.h" | |
12 #include "ui/android/window_android.h" | 13 #include "ui/android/window_android.h" |
13 #include "ui/display/display.h" | 14 #include "ui/display/display.h" |
14 #include "ui/display/screen.h" | 15 #include "ui/display/screen.h" |
15 | 16 |
16 namespace ui { | 17 namespace ui { |
17 | 18 |
19 using base::android::JavaParamRef; | |
18 using base::android::JavaRef; | 20 using base::android::JavaRef; |
19 using base::android::ScopedJavaLocalRef; | 21 using base::android::ScopedJavaLocalRef; |
20 | 22 |
21 ViewAndroid::ScopedAnchorView::ScopedAnchorView( | 23 ViewAndroid::ScopedAnchorView::ScopedAnchorView( |
22 JNIEnv* env, | 24 JNIEnv* env, |
23 const JavaRef<jobject>& jview, | 25 const JavaRef<jobject>& jview, |
24 const JavaRef<jobject>& jdelegate) | 26 const JavaRef<jobject>& jdelegate) |
25 : view_(env, jview.obj()), delegate_(env, jdelegate.obj()) { | 27 : view_(env, jview.obj()), delegate_(env, jdelegate.obj()) { |
26 // If there's a view, then we need a delegate to remove it. | 28 // If there's a view, then we need a delegate to remove it. |
27 DCHECK(!jdelegate.is_null() || jview.is_null()); | 29 DCHECK(!jdelegate.is_null() || jview.is_null()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
61 view_.reset(); | 63 view_.reset(); |
62 delegate_.reset(); | 64 delegate_.reset(); |
63 } | 65 } |
64 | 66 |
65 const base::android::ScopedJavaLocalRef<jobject> | 67 const base::android::ScopedJavaLocalRef<jobject> |
66 ViewAndroid::ScopedAnchorView::view() const { | 68 ViewAndroid::ScopedAnchorView::view() const { |
67 JNIEnv* env = base::android::AttachCurrentThread(); | 69 JNIEnv* env = base::android::AttachCurrentThread(); |
68 return view_.get(env); | 70 return view_.get(env); |
69 } | 71 } |
70 | 72 |
71 ViewAndroid::ViewAndroid(const JavaRef<jobject>& delegate) | 73 ViewAndroid::ViewAndroid() : parent_(nullptr), |
72 : parent_(nullptr) | 74 client_(nullptr), |
73 , delegate_(base::android::AttachCurrentThread(), | 75 handler_(nullptr) {} |
74 delegate.obj()) {} | |
75 | |
76 ViewAndroid::ViewAndroid() : parent_(nullptr) {} | |
77 | 76 |
78 ViewAndroid::~ViewAndroid() { | 77 ViewAndroid::~ViewAndroid() { |
79 RemoveFromParent(); | 78 RemoveFromParent(); |
80 | 79 |
81 for (std::list<ViewAndroid*>::iterator it = children_.begin(); | 80 for (std::list<ViewAndroid*>::iterator it = children_.begin(); |
82 it != children_.end(); it++) { | 81 it != children_.end(); it++) { |
83 DCHECK_EQ((*it)->parent_, this); | 82 DCHECK_EQ((*it)->parent_, this); |
84 (*it)->parent_ = nullptr; | 83 (*it)->parent_ = nullptr; |
85 } | 84 } |
86 } | 85 } |
87 | 86 |
88 void ViewAndroid::SetDelegate(const JavaRef<jobject>& delegate) { | 87 void ViewAndroid::SetDelegate(const JavaRef<jobject>& delegate) { |
88 // A ViewAndroid may have its own delegate or otherwise will | |
89 // use the next available parent's delegate. | |
89 JNIEnv* env = base::android::AttachCurrentThread(); | 90 JNIEnv* env = base::android::AttachCurrentThread(); |
90 delegate_ = JavaObjectWeakGlobalRef(env, delegate); | 91 delegate_ = JavaObjectWeakGlobalRef(env, delegate); |
91 } | 92 } |
92 | 93 |
94 EventHandler* ViewAndroid::GetEventHandler() { | |
95 if (!parent_ || parent_ == GetWindowAndroid()) { | |
boliu
2016/12/02 23:53:22
what is the second half of this condition checking
Jinsuk Kim
2016/12/05 11:07:44
In the tree WindowAndroid - ViewAndroid(1) - ViewA
boliu
2016/12/06 00:10:17
Ahh I see..
But for chrome (and other non-webview
Jinsuk Kim
2016/12/06 07:35:07
Addressed in the new patch.
| |
96 if (!handler_) | |
97 handler_ = new EventHandler(this); | |
98 return handler_; | |
99 } | |
100 return parent_->GetEventHandler(); | |
101 } | |
102 | |
93 void ViewAndroid::AddChild(ViewAndroid* child) { | 103 void ViewAndroid::AddChild(ViewAndroid* child) { |
94 DCHECK(child); | 104 DCHECK(child); |
95 DCHECK(std::find(children_.begin(), children_.end(), child) == | 105 DCHECK(std::find(children_.begin(), children_.end(), child) == |
96 children_.end()); | 106 children_.end()); |
97 | 107 |
98 children_.push_back(child); | 108 children_.push_back(child); |
99 if (child->parent_) | 109 if (child->parent_) |
100 child->RemoveFromParent(); | 110 child->RemoveFromParent(); |
101 child->parent_ = this; | 111 child->parent_ = this; |
102 } | 112 } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 bool ViewAndroid::StartDragAndDrop(const JavaRef<jstring>& jtext, | 182 bool ViewAndroid::StartDragAndDrop(const JavaRef<jstring>& jtext, |
173 const JavaRef<jobject>& jimage) { | 183 const JavaRef<jobject>& jimage) { |
174 ScopedJavaLocalRef<jobject> delegate(GetViewAndroidDelegate()); | 184 ScopedJavaLocalRef<jobject> delegate(GetViewAndroidDelegate()); |
175 if (delegate.is_null()) | 185 if (delegate.is_null()) |
176 return false; | 186 return false; |
177 JNIEnv* env = base::android::AttachCurrentThread(); | 187 JNIEnv* env = base::android::AttachCurrentThread(); |
178 return Java_ViewAndroidDelegate_startDragAndDrop(env, delegate, jtext, | 188 return Java_ViewAndroidDelegate_startDragAndDrop(env, delegate, jtext, |
179 jimage); | 189 jimage); |
180 } | 190 } |
181 | 191 |
192 gfx::Size ViewAndroid::GetPhysicalBackingSize() { | |
193 EventHandler* handler = GetEventHandler(); | |
194 if (!handler) | |
195 return gfx::Size(); | |
196 return gfx::Size(handler->GetPhysicalBackingSizeWidthPix(), | |
197 handler->GetPhysicalBackingSizeHeightPix()); | |
198 } | |
199 | |
200 bool ViewAndroid::OnPhysicalBackingSizeChanged(int width, int height) { | |
201 if (client_ && client_->OnPhysicalBackingSizeChanged(width, height)) | |
202 return true; | |
203 for (auto it = children_.begin(); it != children_.end(); ++it) { | |
204 if ((*it)->OnPhysicalBackingSizeChanged(width, height)) | |
205 return true; | |
206 } | |
207 return false; | |
208 } | |
209 | |
182 } // namespace ui | 210 } // namespace ui |
OLD | NEW |