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

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

Issue 2122403002: Android: Extend ViewAndroid (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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
(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
OLDNEW
« content/browser/android/content_view_core_impl.cc ('K') | « ui/android/view_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698