Chromium Code Reviews| 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 "base/android/jni_string.h" | 10 #include "base/android/jni_string.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 DCHECK(std::find(children_.begin(), children_.end(), child) == | 116 DCHECK(std::find(children_.begin(), children_.end(), child) == |
| 117 children_.end()); | 117 children_.end()); |
| 118 DCHECK(!SubtreeHasEventForwarder(child) || !ViewTreeHasEventForwarder(this)) | 118 DCHECK(!SubtreeHasEventForwarder(child) || !ViewTreeHasEventForwarder(this)) |
| 119 << "Only one event handler is allowed."; | 119 << "Only one event handler is allowed."; |
| 120 | 120 |
| 121 // The new child goes to the top, which is the end of the list. | 121 // The new child goes to the top, which is the end of the list. |
| 122 children_.push_back(child); | 122 children_.push_back(child); |
| 123 if (child->parent_) | 123 if (child->parent_) |
| 124 child->RemoveFromParent(); | 124 child->RemoveFromParent(); |
| 125 child->parent_ = this; | 125 child->parent_ = this; |
| 126 child->OnPhysicalBackingSizeChanged(physical_size_); | |
| 126 } | 127 } |
| 127 | 128 |
| 128 // static | 129 // static |
| 129 bool ViewAndroid::ViewTreeHasEventForwarder(ViewAndroid* view) { | 130 bool ViewAndroid::ViewTreeHasEventForwarder(ViewAndroid* view) { |
| 130 ViewAndroid* v = view; | 131 ViewAndroid* v = view; |
| 131 do { | 132 do { |
| 132 if (v->has_event_forwarder()) | 133 if (v->has_event_forwarder()) |
| 133 return true; | 134 return true; |
| 134 v = v->parent_; | 135 v = v->parent_; |
| 135 } while (v); | 136 } while (v); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 } | 223 } |
| 223 | 224 |
| 224 cc::Layer* ViewAndroid::GetLayer() const { | 225 cc::Layer* ViewAndroid::GetLayer() const { |
| 225 return layer_.get(); | 226 return layer_.get(); |
| 226 } | 227 } |
| 227 | 228 |
| 228 void ViewAndroid::SetLayer(scoped_refptr<cc::Layer> layer) { | 229 void ViewAndroid::SetLayer(scoped_refptr<cc::Layer> layer) { |
| 229 layer_ = layer; | 230 layer_ = layer; |
| 230 } | 231 } |
| 231 | 232 |
| 233 void ViewAndroid::UpdateLayerBounds() { | |
| 234 if (layer_) | |
| 235 layer_->SetBounds(physical_size_); | |
| 236 } | |
| 237 | |
| 232 void ViewAndroid::SetLayout(ViewAndroid::LayoutParams params) { | 238 void ViewAndroid::SetLayout(ViewAndroid::LayoutParams params) { |
| 233 layout_params_ = params; | 239 layout_params_ = params; |
| 234 } | 240 } |
| 235 | 241 |
| 236 bool ViewAndroid::StartDragAndDrop(const JavaRef<jstring>& jtext, | 242 bool ViewAndroid::StartDragAndDrop(const JavaRef<jstring>& jtext, |
| 237 const JavaRef<jobject>& jimage) { | 243 const JavaRef<jobject>& jimage) { |
| 238 ScopedJavaLocalRef<jobject> delegate(GetViewAndroidDelegate()); | 244 ScopedJavaLocalRef<jobject> delegate(GetViewAndroidDelegate()); |
| 239 if (delegate.is_null()) | 245 if (delegate.is_null()) |
| 240 return false; | 246 return false; |
| 241 JNIEnv* env = base::android::AttachCurrentThread(); | 247 JNIEnv* env = base::android::AttachCurrentThread(); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 272 } | 278 } |
| 273 | 279 |
| 274 int ViewAndroid::GetSystemWindowInsetBottom() { | 280 int ViewAndroid::GetSystemWindowInsetBottom() { |
| 275 ScopedJavaLocalRef<jobject> delegate(GetViewAndroidDelegate()); | 281 ScopedJavaLocalRef<jobject> delegate(GetViewAndroidDelegate()); |
| 276 if (delegate.is_null()) | 282 if (delegate.is_null()) |
| 277 return 0; | 283 return 0; |
| 278 JNIEnv* env = base::android::AttachCurrentThread(); | 284 JNIEnv* env = base::android::AttachCurrentThread(); |
| 279 return Java_ViewAndroidDelegate_getSystemWindowInsetBottom(env, delegate); | 285 return Java_ViewAndroidDelegate_getSystemWindowInsetBottom(env, delegate); |
| 280 } | 286 } |
| 281 | 287 |
| 288 void ViewAndroid::OnPhysicalBackingSizeChanged(const gfx::Size& size) { | |
| 289 if (physical_size_ == size) | |
| 290 return; | |
| 291 physical_size_ = size; | |
| 292 UpdateLayerBounds(); | |
| 293 if (client_ && client_->OnPhysicalBackingSizeChanged()) | |
|
boliu
2017/04/29 00:18:40
this makes no sense, why would client ever want to
Jinsuk Kim
2017/04/30 00:23:50
Can do without bool return type. Changed to void.
| |
| 294 return; | |
| 295 | |
| 296 for (auto* child : children_) | |
| 297 child->OnPhysicalBackingSizeChanged(size); | |
| 298 } | |
| 299 | |
| 300 gfx::Size ViewAndroid::GetPhysicalBackingSize() { | |
| 301 return physical_size_; | |
| 302 } | |
| 303 | |
| 282 bool ViewAndroid::OnTouchEvent(const MotionEventAndroid& event, | 304 bool ViewAndroid::OnTouchEvent(const MotionEventAndroid& event, |
| 283 bool for_touch_handle) { | 305 bool for_touch_handle) { |
| 284 return HitTest( | 306 return HitTest( |
| 285 base::Bind(&ViewAndroid::SendTouchEventToClient, for_touch_handle), | 307 base::Bind(&ViewAndroid::SendTouchEventToClient, for_touch_handle), |
| 286 event); | 308 event); |
| 287 } | 309 } |
| 288 | 310 |
| 289 bool ViewAndroid::SendTouchEventToClient(bool for_touch_handle, | 311 bool ViewAndroid::SendTouchEventToClient(bool for_touch_handle, |
| 290 ViewClient* client, | 312 ViewClient* client, |
| 291 const MotionEventAndroid& event) { | 313 const MotionEventAndroid& event) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 matched = bound.Contains(e->GetX(0), e->GetY(0)); | 354 matched = bound.Contains(e->GetX(0), e->GetY(0)); |
| 333 } | 355 } |
| 334 if (matched && child->HitTest(send_to_client, *e)) | 356 if (matched && child->HitTest(send_to_client, *e)) |
| 335 return true; | 357 return true; |
| 336 } | 358 } |
| 337 } | 359 } |
| 338 return false; | 360 return false; |
| 339 } | 361 } |
| 340 | 362 |
| 341 } // namespace ui | 363 } // namespace ui |
| OLD | NEW |