forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview_android.h
108 lines (79 loc) · 3.2 KB
/
view_android.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_ANDROID_VIEW_ANDROID_H_
#define UI_ANDROID_VIEW_ANDROID_H_
#include <list>
#include "base/android/jni_weak_ref.h"
#include "base/memory/ref_counted.h"
#include "ui/android/ui_android_export.h"
#include "ui/gfx/geometry/rect_f.h"
namespace cc {
class Layer;
}
namespace ui {
class WindowAndroid;
// A simple container for a UI layer.
// At the root of the hierarchy is a WindowAndroid, when attached.
class UI_ANDROID_EXPORT ViewAndroid {
public:
// Stores an anchored view to delete itself at the end of its lifetime
// automatically. This helps manage the lifecyle without the dependency
// on |ViewAndroid|.
class ScopedAnchorView {
public:
ScopedAnchorView(JNIEnv* env,
const base::android::JavaRef<jobject>& jview,
const base::android::JavaRef<jobject>& jdelegate);
ScopedAnchorView();
ScopedAnchorView(ScopedAnchorView&& other);
ScopedAnchorView& operator=(ScopedAnchorView&& other);
// Calls JNI removeView() on the delegate for cleanup.
~ScopedAnchorView();
void Reset();
const base::android::ScopedJavaLocalRef<jobject> view() const;
private:
// TODO(jinsukkim): Following weak refs can be cast to strong refs which
// cannot be garbage-collected and leak memory. Rewrite not to use them.
// see comments in crrev.com/2103243002.
JavaObjectWeakGlobalRef view_;
JavaObjectWeakGlobalRef delegate_;
// Default copy/assign disabled by move constructor.
};
// A ViewAndroid may have its own delegate or otherwise will
// use the next available parent's delegate.
ViewAndroid(const base::android::JavaRef<jobject>& delegate);
ViewAndroid();
virtual ~ViewAndroid();
// Returns the window at the root of this hierarchy, or |null|
// if disconnected.
virtual WindowAndroid* GetWindowAndroid() const;
// Used to return and set the layer for this view. May be |null|.
cc::Layer* GetLayer() const;
void SetLayer(scoped_refptr<cc::Layer> layer);
void SetDelegate(const base::android::JavaRef<jobject>& delegate);
// Adds this view as a child of another view.
void AddChild(ViewAndroid* child);
// Detaches this view from its parent.
void RemoveFromParent();
bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext,
const base::android::JavaRef<jobject>& jimage);
ScopedAnchorView AcquireAnchorView();
void SetAnchorRect(const base::android::JavaRef<jobject>& anchor,
const gfx::RectF& bounds);
protected:
ViewAndroid* parent_;
private:
void RemoveChild(ViewAndroid* child);
// Returns the Java delegate for this view. This is used to delegate work
// up to the embedding view (or the embedder that can deal with the
// implementation details).
const base::android::ScopedJavaLocalRef<jobject>
GetViewAndroidDelegate() const;
std::list<ViewAndroid*> children_;
scoped_refptr<cc::Layer> layer_;
JavaObjectWeakGlobalRef delegate_;
DISALLOW_COPY_AND_ASSIGN(ViewAndroid);
};
} // namespace ui
#endif // UI_ANDROID_VIEW_ANDROID_H_