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

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

Issue 2136373002: Make WindowAndroid a ViewAndroid (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@view3
Patch Set: 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
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 11
12 namespace ui { 12 namespace ui {
13 13
14 using base::android::AttachCurrentThread; 14 using base::android::AttachCurrentThread;
15 using base::android::JavaRef; 15 using base::android::JavaRef;
16 using base::android::ScopedJavaLocalRef; 16 using base::android::ScopedJavaLocalRef;
17 17
18 ViewAndroid::ViewAndroid(const JavaRef<jobject>& delegate, 18 ViewAndroid::ViewAndroid(const JavaRef<jobject>& delegate)
19 WindowAndroid* root_window) 19 : parent_(nullptr), delegate_(delegate) {}
20 : parent_(nullptr), window_(root_window), delegate_(delegate) {}
21 20
22 ViewAndroid::ViewAndroid() : parent_(nullptr), window_(nullptr) {} 21 ViewAndroid::ViewAndroid() : parent_(nullptr) {}
23 22
24 ViewAndroid::~ViewAndroid() { 23 ViewAndroid::~ViewAndroid() {
25 if (parent_) 24 RemoveFromParent();
26 parent_->RemoveChild(this);
27 25
28 for (std::list<ViewAndroid*>::iterator it = children_.begin(); 26 for (std::list<ViewAndroid*>::iterator it = children_.begin();
29 it != children_.end(); it++) { 27 it != children_.end(); it++) {
30 DCHECK_EQ((*it)->parent_, this); 28 DCHECK_EQ((*it)->parent_, this);
31 (*it)->parent_ = nullptr; 29 (*it)->parent_ = nullptr;
32 } 30 }
33 } 31 }
34 32
35 void ViewAndroid::AddChild(ViewAndroid* child) { 33 void ViewAndroid::AddChild(ViewAndroid* child) {
36 DCHECK(child); 34 DCHECK(child);
37 DCHECK(child->window_ == nullptr) << "Children shouldn't have a root window";
38 DCHECK(std::find(children_.begin(), children_.end(), child) == 35 DCHECK(std::find(children_.begin(), children_.end(), child) ==
39 children_.end()); 36 children_.end());
40 37
41 children_.push_back(child); 38 children_.push_back(child);
42 if (child->parent_) 39 if (child->parent_)
43 parent_->RemoveChild(child); 40 child->RemoveFromParent();
44 child->parent_ = this; 41 child->parent_ = this;
45 } 42 }
46 43
44 void ViewAndroid::RemoveFromParent() {
45 if (parent_)
46 parent_->RemoveChild(this);
47 }
48
47 void ViewAndroid::RemoveChild(ViewAndroid* child) { 49 void ViewAndroid::RemoveChild(ViewAndroid* child) {
48 DCHECK(child); 50 DCHECK(child);
49 DCHECK_EQ(child->parent_, this); 51 DCHECK_EQ(child->parent_, this);
50 52
51 std::list<ViewAndroid*>::iterator it = 53 std::list<ViewAndroid*>::iterator it =
52 std::find(children_.begin(), children_.end(), child); 54 std::find(children_.begin(), children_.end(), child);
53 DCHECK(it != children_.end()); 55 DCHECK(it != children_.end());
54 children_.erase(it); 56 children_.erase(it);
55 child->parent_ = nullptr; 57 child->parent_ = nullptr;
56 } 58 }
57 59
58 WindowAndroid* ViewAndroid::GetWindowAndroid() const { 60 WindowAndroid* ViewAndroid::GetWindowAndroid() {
Yusuf 2016/07/13 19:54:36 GetWindowAndroid will always return null if this i
no sievers 2016/07/13 23:32:12 It will return only non-null if the tree actually
59 if (window_)
60 return window_;
61
62 return parent_ ? parent_->GetWindowAndroid() : nullptr; 61 return parent_ ? parent_->GetWindowAndroid() : nullptr;
63 } 62 }
64 63
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() 64 const JavaRef<jobject>& ViewAndroid::GetViewAndroidDelegate()
71 const { 65 const {
72 if (!delegate_.is_null()) 66 if (!delegate_.is_null())
73 return delegate_; 67 return delegate_;
74 68
75 return parent_ ? parent_->GetViewAndroidDelegate() : delegate_; 69 return parent_ ? parent_->GetViewAndroidDelegate() : delegate_;
76 } 70 }
77 71
78 cc::Layer* ViewAndroid::GetLayer() const { 72 cc::Layer* ViewAndroid::GetLayer() const {
79 return layer_.get(); 73 return layer_.get();
80 } 74 }
81 75
82 void ViewAndroid::SetLayer(scoped_refptr<cc::Layer> layer) { 76 void ViewAndroid::SetLayer(scoped_refptr<cc::Layer> layer) {
83 layer_ = layer; 77 layer_ = layer;
84 } 78 }
85 79
86 } // namespace ui 80 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698