OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/android/view_android.h" |
| 6 |
| 7 #include <algorithm> |
| 8 |
| 9 #include "base/android/jni_android.h" |
| 10 #include "cc/layers/layer.h" |
| 11 |
| 12 namespace ui { |
| 13 |
| 14 using base::android::AttachCurrentThread; |
| 15 using base::android::JavaRef; |
| 16 using base::android::ScopedJavaLocalRef; |
| 17 |
| 18 ViewAndroid::ViewAndroid(const JavaRef<jobject>& delegate, |
| 19 WindowAndroid* root_window) |
| 20 : parent_(nullptr), window_(root_window), delegate_(delegate) {} |
| 21 |
| 22 ViewAndroid::ViewAndroid() : parent_(nullptr), window_(nullptr) {} |
| 23 |
| 24 ViewAndroid::~ViewAndroid() { |
| 25 if (parent_) |
| 26 parent_->RemoveChild(this); |
| 27 |
| 28 for (std::list<ViewAndroid*>::iterator it = children_.begin(); |
| 29 it != children_.end(); it++) { |
| 30 DCHECK_EQ((*it)->parent_, this); |
| 31 (*it)->parent_ = nullptr; |
| 32 } |
| 33 } |
| 34 |
| 35 void ViewAndroid::AddChild(ViewAndroid* child) { |
| 36 DCHECK(child); |
| 37 DCHECK(child->window_ == nullptr) << "Children shouldn't have a root window"; |
| 38 DCHECK(std::find(children_.begin(), children_.end(), child) == |
| 39 children_.end()); |
| 40 |
| 41 children_.push_back(child); |
| 42 if (child->parent_) |
| 43 parent_->RemoveChild(child); |
| 44 child->parent_ = this; |
| 45 } |
| 46 |
| 47 void ViewAndroid::RemoveChild(ViewAndroid* child) { |
| 48 DCHECK(child); |
| 49 DCHECK_EQ(child->parent_, this); |
| 50 |
| 51 std::list<ViewAndroid*>::iterator it = |
| 52 std::find(children_.begin(), children_.end(), child); |
| 53 DCHECK(it != children_.end()); |
| 54 children_.erase(it); |
| 55 child->parent_ = nullptr; |
| 56 } |
| 57 |
| 58 WindowAndroid* ViewAndroid::GetWindowAndroid() const { |
| 59 if (window_) |
| 60 return window_; |
| 61 |
| 62 return parent_ ? parent_->GetWindowAndroid() : nullptr; |
| 63 } |
| 64 |
| 65 void ViewAndroid::SetWindowAndroid(WindowAndroid* root_window) { |
| 66 window_ = root_window; |
| 67 DCHECK(parent_ == nullptr) << "Children shouldn't have a root window"; |
| 68 } |
| 69 |
| 70 const JavaRef<jobject>& ViewAndroid::GetViewAndroidDelegate() |
| 71 const { |
| 72 if (!delegate_.is_null()) |
| 73 return delegate_; |
| 74 |
| 75 return parent_ ? parent_->GetViewAndroidDelegate() : delegate_; |
| 76 } |
| 77 |
| 78 cc::Layer* ViewAndroid::GetLayer() const { |
| 79 return layer_.get(); |
| 80 } |
| 81 |
| 82 void ViewAndroid::SetLayer(scoped_refptr<cc::Layer> layer) { |
| 83 layer_ = layer; |
| 84 } |
| 85 |
| 86 } // namespace ui |
OLD | NEW |