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, | |
Yusuf
2016/07/08 16:35:05
I feel like we need a comment paragraph somewhere
no sievers
2016/07/08 18:29:04
I'm guessing it needs to evolve a bit but I can pu
no sievers
2016/07/08 19:22:10
Done.
| |
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) { | |
Yusuf
2016/07/08 16:35:05
these(parent_ being accessible this much) worry me
no sievers
2016/07/08 18:29:04
Good point. We could check that a child being adde
no sievers
2016/07/08 19:22:10
Done.
Yusuf
2016/07/08 23:06:00
I would say yes it would make sense for WindowAndr
| |
36 DCHECK(child); | |
37 DCHECK(std::find(children_.begin(), children_.end(), child) == | |
38 children_.end()); | |
39 | |
40 children_.push_back(child); | |
41 if (child->parent_) | |
42 parent_->RemoveChild(child); | |
43 child->parent_ = this; | |
44 } | |
45 | |
46 void ViewAndroid::RemoveChild(ViewAndroid* child) { | |
47 DCHECK(child); | |
48 DCHECK_EQ(child->parent_, this); | |
49 | |
50 std::list<ViewAndroid*>::iterator it = | |
51 std::find(children_.begin(), children_.end(), child); | |
52 DCHECK(it != children_.end()); | |
53 children_.erase(it); | |
54 child->parent_ = nullptr; | |
55 } | |
56 | |
57 WindowAndroid* ViewAndroid::GetWindowAndroid() const { | |
58 if (window_) | |
59 return window_; | |
60 | |
61 return parent_ ? parent_->GetWindowAndroid() : nullptr; | |
62 } | |
63 | |
64 void ViewAndroid::SetWindowAndroid(WindowAndroid* root_window) { | |
65 window_ = root_window; | |
66 } | |
67 | |
68 const JavaRef<jobject>& ViewAndroid::GetViewAndroidDelegate() | |
69 const { | |
70 if (!delegate_.is_null()) | |
71 return delegate_; | |
72 | |
73 return parent_ ? parent_->GetViewAndroidDelegate() : delegate_; | |
74 } | |
75 | |
76 cc::Layer* ViewAndroid::GetLayer() const { | |
77 return layer_.get(); | |
78 } | |
79 | |
80 void ViewAndroid::SetLayer(scoped_refptr<cc::Layer> layer) { | |
81 layer_ = layer; | |
82 } | |
83 | |
84 } // namespace ui | |
OLD | NEW |