OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef UI_ANDROID_VIEW_ANDROID_H_ | 5 #ifndef UI_ANDROID_VIEW_ANDROID_H_ |
6 #define UI_ANDROID_VIEW_ANDROID_H_ | 6 #define UI_ANDROID_VIEW_ANDROID_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 | 9 |
10 #include "base/android/jni_weak_ref.h" | 10 #include "base/android/jni_weak_ref.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "ui/android/ui_android_export.h" | 12 #include "ui/android/ui_android_export.h" |
13 #include "ui/gfx/geometry/rect_f.h" | 13 #include "ui/gfx/geometry/rect_f.h" |
14 | 14 |
15 namespace cc { | 15 namespace cc { |
16 class Layer; | 16 class Layer; |
17 } | 17 } |
18 | 18 |
19 namespace ui { | 19 namespace ui { |
20 | 20 |
21 class EventHandler; | |
21 class WindowAndroid; | 22 class WindowAndroid; |
22 | 23 |
23 // A simple container for a UI layer. | 24 // A simple container for a UI layer. |
24 // At the root of the hierarchy is a WindowAndroid, when attached. | 25 // At the root of the hierarchy is a WindowAndroid, when attached. |
25 class UI_ANDROID_EXPORT ViewAndroid { | 26 class UI_ANDROID_EXPORT ViewAndroid { |
26 public: | 27 public: |
27 // Stores an anchored view to delete itself at the end of its lifetime | 28 // Stores an anchored view to delete itself at the end of its lifetime |
28 // automatically. This helps manage the lifecyle without the dependency | 29 // automatically. This helps manage the lifecyle without the dependency |
29 // on |ViewAndroid|. | 30 // on |ViewAndroid|. |
30 class ScopedAnchorView { | 31 class ScopedAnchorView { |
(...skipping 16 matching lines...) Expand all Loading... | |
47 private: | 48 private: |
48 // TODO(jinsukkim): Following weak refs can be cast to strong refs which | 49 // TODO(jinsukkim): Following weak refs can be cast to strong refs which |
49 // cannot be garbage-collected and leak memory. Rewrite not to use them. | 50 // cannot be garbage-collected and leak memory. Rewrite not to use them. |
50 // see comments in crrev.com/2103243002. | 51 // see comments in crrev.com/2103243002. |
51 JavaObjectWeakGlobalRef view_; | 52 JavaObjectWeakGlobalRef view_; |
52 JavaObjectWeakGlobalRef delegate_; | 53 JavaObjectWeakGlobalRef delegate_; |
53 | 54 |
54 // Default copy/assign disabled by move constructor. | 55 // Default copy/assign disabled by move constructor. |
55 }; | 56 }; |
56 | 57 |
57 // A ViewAndroid may have its own delegate or otherwise will | 58 // Client interface used to forward events from Java to native views. |
58 // use the next available parent's delegate. | 59 // Calls not handled by a client are dispatched to its children along |
59 ViewAndroid(const base::android::JavaRef<jobject>& delegate); | 60 // the hierarchy of ViewAndroid. Overriden method should return true |
61 // to indicate that the event was handled and stop the processing. | |
62 class ViewClient { | |
boliu
2016/12/02 23:53:22
put this in a separate file, presumably this will
Jinsuk Kim
2016/12/05 11:07:44
Done.
| |
63 public: | |
64 bool OnPhysicalBackingSizeChanged(int width, int height) { return false; } | |
boliu
2016/12/02 23:53:22
virtual? also I think inlining virtual method is n
Jinsuk Kim
2016/12/05 11:07:44
Done.
| |
65 }; | |
60 | 66 |
61 ViewAndroid(); | 67 ViewAndroid(); |
62 virtual ~ViewAndroid(); | 68 virtual ~ViewAndroid(); |
63 | 69 |
64 // Returns the window at the root of this hierarchy, or |null| | 70 // Returns the window at the root of this hierarchy, or |null| |
65 // if disconnected. | 71 // if disconnected. |
66 virtual WindowAndroid* GetWindowAndroid() const; | 72 virtual WindowAndroid* GetWindowAndroid() const; |
67 | 73 |
68 // Used to return and set the layer for this view. May be |null|. | 74 // Used to return and set the layer for this view. May be |null|. |
69 cc::Layer* GetLayer() const; | 75 cc::Layer* GetLayer() const; |
70 void SetLayer(scoped_refptr<cc::Layer> layer); | 76 void SetLayer(scoped_refptr<cc::Layer> layer); |
71 | 77 |
72 void SetDelegate(const base::android::JavaRef<jobject>& delegate); | 78 void SetDelegate(const base::android::JavaRef<jobject>& delegate); |
73 | 79 |
80 EventHandler* GetEventHandler(); | |
81 | |
74 // Adds this view as a child of another view. | 82 // Adds this view as a child of another view. |
75 void AddChild(ViewAndroid* child); | 83 void AddChild(ViewAndroid* child); |
76 | 84 |
77 // Detaches this view from its parent. | 85 // Detaches this view from its parent. |
78 void RemoveFromParent(); | 86 void RemoveFromParent(); |
79 | 87 |
88 void SetViewClient(ViewClient* client) { client_ = client; } | |
boliu
2016/12/02 23:53:22
can we pass this in on construction?
Jinsuk Kim
2016/12/05 11:07:44
Done.
| |
89 | |
80 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, | 90 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, |
81 const base::android::JavaRef<jobject>& jimage); | 91 const base::android::JavaRef<jobject>& jimage); |
82 | 92 |
93 gfx::Size GetPhysicalBackingSize(); | |
94 | |
83 ScopedAnchorView AcquireAnchorView(); | 95 ScopedAnchorView AcquireAnchorView(); |
84 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, | 96 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, |
85 const gfx::RectF& bounds); | 97 const gfx::RectF& bounds); |
86 | 98 |
99 // Internal implementation of ViewClient forwarding calls to the interface. | |
100 bool OnPhysicalBackingSizeChanged(int width, int height); | |
101 | |
87 protected: | 102 protected: |
88 ViewAndroid* parent_; | 103 ViewAndroid* parent_; |
89 | 104 |
90 private: | 105 private: |
91 void RemoveChild(ViewAndroid* child); | 106 void RemoveChild(ViewAndroid* child); |
92 | 107 |
93 // Returns the Java delegate for this view. This is used to delegate work | 108 // Returns the Java delegate for this view. This is used to delegate work |
94 // up to the embedding view (or the embedder that can deal with the | 109 // up to the embedding view (or the embedder that can deal with the |
95 // implementation details). | 110 // implementation details). |
96 const base::android::ScopedJavaLocalRef<jobject> | 111 const base::android::ScopedJavaLocalRef<jobject> |
97 GetViewAndroidDelegate() const; | 112 GetViewAndroidDelegate() const; |
98 | 113 |
99 std::list<ViewAndroid*> children_; | 114 std::list<ViewAndroid*> children_; |
100 scoped_refptr<cc::Layer> layer_; | 115 scoped_refptr<cc::Layer> layer_; |
101 JavaObjectWeakGlobalRef delegate_; | 116 JavaObjectWeakGlobalRef delegate_; |
117 ViewClient* client_; | |
118 EventHandler* handler_; | |
102 | 119 |
103 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); | 120 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); |
104 }; | 121 }; |
105 | 122 |
106 } // namespace ui | 123 } // namespace ui |
107 | 124 |
108 #endif // UI_ANDROID_VIEW_ANDROID_H_ | 125 #endif // UI_ANDROID_VIEW_ANDROID_H_ |
OLD | NEW |