| 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 ViewClient; |
| 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 explicit ViewAndroid(ViewClient* client); |
| 58 // use the next available parent's delegate. | |
| 59 ViewAndroid(const base::android::JavaRef<jobject>& delegate); | |
| 60 | 59 |
| 61 ViewAndroid(); | 60 ViewAndroid(); |
| 61 |
| 62 virtual ~ViewAndroid(); | 62 virtual ~ViewAndroid(); |
| 63 | 63 |
| 64 // Returns the window at the root of this hierarchy, or |null| | 64 // Returns the window at the root of this hierarchy, or |null| |
| 65 // if disconnected. | 65 // if disconnected. |
| 66 virtual WindowAndroid* GetWindowAndroid() const; | 66 virtual WindowAndroid* GetWindowAndroid() const; |
| 67 | 67 |
| 68 // Returns |EventHandler| associated with the current ViewAndroid. |
| 69 // Create one if not present. |
| 70 base::android::ScopedJavaLocalRef<jobject> GetEventHandler(); |
| 71 |
| 68 // Used to return and set the layer for this view. May be |null|. | 72 // Used to return and set the layer for this view. May be |null|. |
| 69 cc::Layer* GetLayer() const; | 73 cc::Layer* GetLayer() const; |
| 70 void SetLayer(scoped_refptr<cc::Layer> layer); | 74 void SetLayer(scoped_refptr<cc::Layer> layer); |
| 71 | 75 |
| 72 void SetDelegate(const base::android::JavaRef<jobject>& delegate); | 76 void SetDelegate(const base::android::JavaRef<jobject>& delegate); |
| 73 | 77 |
| 74 // Adds this view as a child of another view. | 78 // Adds this view as a child of another view. |
| 75 void AddChild(ViewAndroid* child); | 79 void AddChild(ViewAndroid* child); |
| 76 | 80 |
| 77 // Detaches this view from its parent. | 81 // Detaches this view from its parent. |
| 78 void RemoveFromParent(); | 82 void RemoveFromParent(); |
| 79 | 83 |
| 80 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, | 84 bool StartDragAndDrop(const base::android::JavaRef<jstring>& jtext, |
| 81 const base::android::JavaRef<jobject>& jimage); | 85 const base::android::JavaRef<jobject>& jimage); |
| 82 | 86 |
| 83 ScopedAnchorView AcquireAnchorView(); | 87 ScopedAnchorView AcquireAnchorView(); |
| 84 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, | 88 void SetAnchorRect(const base::android::JavaRef<jobject>& anchor, |
| 85 const gfx::RectF& bounds); | 89 const gfx::RectF& bounds); |
| 86 | 90 |
| 91 gfx::Size GetPhysicalBackingSize(); |
| 92 void UpdateLayerBounds(); |
| 93 |
| 94 // Internal implementation of ViewClient forwarding calls to the interface. |
| 95 void OnPhysicalBackingSizeChanged(int width, int height); |
| 96 |
| 87 protected: | 97 protected: |
| 88 ViewAndroid* parent_; | 98 ViewAndroid* parent_; |
| 89 | 99 |
| 90 private: | 100 private: |
| 91 void RemoveChild(ViewAndroid* child); | 101 void RemoveChild(ViewAndroid* child); |
| 92 | 102 |
| 103 // Checks if any ViewAndroid instance in the tree hierarchy (including |
| 104 // all the parents and the children) has |EventHandler| already. |
| 105 bool HasEventHandlerInTreeHierarchy(); |
| 106 |
| 107 // Checks if any children (plus this ViewAndroid itself) has |EventHandler|. |
| 108 bool HasEventHandlerInSubtree(); |
| 109 |
| 93 // Returns the Java delegate for this view. This is used to delegate work | 110 // 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 | 111 // up to the embedding view (or the embedder that can deal with the |
| 95 // implementation details). | 112 // implementation details). |
| 96 const base::android::ScopedJavaLocalRef<jobject> | 113 const base::android::ScopedJavaLocalRef<jobject> |
| 97 GetViewAndroidDelegate() const; | 114 GetViewAndroidDelegate() const; |
| 98 | 115 |
| 116 // Creates a new |EventHandler| for this ViewAndroid. No parent or child |
| 117 // should have |EventHandler| for this ViewAndroid to have one. |
| 118 base::android::ScopedJavaLocalRef<jobject> CreateEventHandler(); |
| 119 |
| 120 bool HasEventHandler(); |
| 121 |
| 99 std::list<ViewAndroid*> children_; | 122 std::list<ViewAndroid*> children_; |
| 100 scoped_refptr<cc::Layer> layer_; | 123 scoped_refptr<cc::Layer> layer_; |
| 101 JavaObjectWeakGlobalRef delegate_; | 124 JavaObjectWeakGlobalRef delegate_; |
| 125 JavaObjectWeakGlobalRef event_handler_; |
| 126 ViewClient* const client_; |
| 127 |
| 128 int physical_width_pix_; |
| 129 int physical_height_pix_; |
| 102 | 130 |
| 103 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); | 131 DISALLOW_COPY_AND_ASSIGN(ViewAndroid); |
| 104 }; | 132 }; |
| 105 | 133 |
| 134 bool RegisterEventHandler(JNIEnv* env); |
| 135 |
| 106 } // namespace ui | 136 } // namespace ui |
| 107 | 137 |
| 108 #endif // UI_ANDROID_VIEW_ANDROID_H_ | 138 #endif // UI_ANDROID_VIEW_ANDROID_H_ |
| OLD | NEW |