OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_RESOURCES_RESOURCE_MANAGER_H_ | 5 #ifndef UI_ANDROID_RESOURCES_RESOURCE_MANAGER_H_ |
6 #define UI_ANDROID_RESOURCES_RESOURCE_MANAGER_H_ | 6 #define UI_ANDROID_RESOURCES_RESOURCE_MANAGER_H_ |
7 | 7 |
| 8 #include <string> |
| 9 |
8 #include "base/android/jni_android.h" | 10 #include "base/android/jni_android.h" |
9 #include "base/id_map.h" | 11 #include "base/id_map.h" |
10 #include "cc/resources/ui_resource_client.h" | 12 #include "cc/resources/ui_resource_client.h" |
11 #include "ui/android/ui_android_export.h" | 13 #include "ui/android/ui_android_export.h" |
| 14 #include "ui/base/android/system_ui_resource_type.h" |
12 #include "ui/gfx/geometry/rect.h" | 15 #include "ui/gfx/geometry/rect.h" |
13 | 16 |
14 namespace content { | |
15 class UIResourceProvider; | |
16 } | |
17 | |
18 namespace ui { | 17 namespace ui { |
19 | 18 |
20 class UIResourceAndroid; | 19 class UIResourceAndroid; |
| 20 class UIResourceProvider; |
21 | 21 |
22 // A Java counterpart will be generated for this enum. | 22 // A Java counterpart will be generated for this enum. |
23 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.ui.resources | 23 // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.ui.resources |
24 enum AndroidResourceType { | 24 enum AndroidResourceType { |
25 ANDROID_RESOURCE_TYPE_STATIC = 0, | 25 ANDROID_RESOURCE_TYPE_STATIC = 0, |
26 ANDROID_RESOURCE_TYPE_DYNAMIC, | 26 ANDROID_RESOURCE_TYPE_DYNAMIC, |
27 ANDROID_RESOURCE_TYPE_DYNAMIC_BITMAP, | 27 ANDROID_RESOURCE_TYPE_DYNAMIC_BITMAP, |
28 ANDROID_RESOURCE_TYPE_SYSTEM, | 28 ANDROID_RESOURCE_TYPE_SYSTEM, |
29 | 29 |
30 ANDROID_RESOURCE_TYPE_COUNT, | 30 ANDROID_RESOURCE_TYPE_COUNT, |
31 ANDROID_RESOURCE_TYPE_FIRST = ANDROID_RESOURCE_TYPE_STATIC, | 31 ANDROID_RESOURCE_TYPE_FIRST = ANDROID_RESOURCE_TYPE_STATIC, |
32 ANDROID_RESOURCE_TYPE_LAST = ANDROID_RESOURCE_TYPE_SYSTEM, | 32 ANDROID_RESOURCE_TYPE_LAST = ANDROID_RESOURCE_TYPE_SYSTEM, |
33 }; | 33 }; |
34 | 34 |
| 35 // TODO(jdduke): Make ResourceManager a pure interface, crbug/426939. |
35 class UI_ANDROID_EXPORT ResourceManager { | 36 class UI_ANDROID_EXPORT ResourceManager { |
36 public: | 37 public: |
37 struct Resource { | 38 struct Resource { |
38 public: | 39 public: |
39 Resource(); | 40 Resource(); |
40 ~Resource(); | 41 ~Resource(); |
41 gfx::Rect Border(const gfx::Size& bounds); | 42 gfx::Rect Border(const gfx::Size& bounds); |
42 gfx::Rect Border(const gfx::Size& bounds, const gfx::InsetsF& scale); | 43 gfx::Rect Border(const gfx::Size& bounds, const gfx::InsetsF& scale); |
43 | 44 |
44 scoped_ptr<UIResourceAndroid> ui_resource; | 45 scoped_ptr<UIResourceAndroid> ui_resource; |
45 gfx::Size size; | 46 gfx::Size size; |
46 gfx::Rect padding; | 47 gfx::Rect padding; |
47 gfx::Rect aperture; | 48 gfx::Rect aperture; |
48 }; | 49 }; |
49 | 50 |
50 static ResourceManager* FromJavaObject(jobject jobj); | 51 static ResourceManager* FromJavaObject(jobject jobj); |
51 | 52 |
52 explicit ResourceManager(content::UIResourceProvider* ui_resource_provider); | 53 explicit ResourceManager(ui::UIResourceProvider* ui_resource_provider); |
53 virtual ~ResourceManager(); | 54 virtual ~ResourceManager(); |
54 | 55 |
55 base::android::ScopedJavaLocalRef<jobject> GetJavaObject(JNIEnv* env); | 56 base::android::ScopedJavaLocalRef<jobject> GetJavaObject(JNIEnv* env); |
56 | 57 |
| 58 virtual cc::UIResourceId GetUIResourceId(AndroidResourceType res_type, |
| 59 int res_id); |
57 ResourceManager::Resource* GetResource(AndroidResourceType res_type, | 60 ResourceManager::Resource* GetResource(AndroidResourceType res_type, |
58 int res_id); | 61 int res_id); |
59 void PreloadResource(AndroidResourceType res_type, int res_id); | 62 virtual void PreloadResource(AndroidResourceType res_type, int res_id); |
60 | 63 |
61 // Called from Java ---------------------------------------------------------- | 64 // Called from Java ---------------------------------------------------------- |
62 void OnResourceReady(JNIEnv* env, | 65 void OnResourceReady(JNIEnv* env, |
63 jobject jobj, | 66 jobject jobj, |
64 jint res_type, | 67 jint res_type, |
65 jint res_id, | 68 jint res_id, |
66 jobject bitmap, | 69 jobject bitmap, |
67 jint padding_left, | 70 jint padding_left, |
68 jint padding_top, | 71 jint padding_top, |
69 jint padding_right, | 72 jint padding_right, |
70 jint padding_bottom, | 73 jint padding_bottom, |
71 jint aperture_left, | 74 jint aperture_left, |
72 jint aperture_top, | 75 jint aperture_top, |
73 jint aperture_right, | 76 jint aperture_right, |
74 jint aperture_bottom); | 77 jint aperture_bottom); |
75 | 78 |
76 static bool RegisterResourceManager(JNIEnv* env); | 79 static bool RegisterResourceManager(JNIEnv* env); |
77 | 80 |
78 private: | 81 private: |
| 82 friend class TestResourceManager; |
| 83 |
| 84 // Start loading the resource. virtual for testing. |
| 85 virtual void PreloadResourceFromJava(AndroidResourceType res_type, |
| 86 int res_id); |
| 87 virtual void RequestResourceFromJava(AndroidResourceType res_type, |
| 88 int res_id); |
| 89 |
79 typedef IDMap<Resource, IDMapOwnPointer> ResourceMap; | 90 typedef IDMap<Resource, IDMapOwnPointer> ResourceMap; |
80 | 91 |
81 content::UIResourceProvider* ui_resource_provider_; | 92 ui::UIResourceProvider* ui_resource_provider_; |
82 ResourceMap resources_[ANDROID_RESOURCE_TYPE_COUNT]; | 93 ResourceMap resources_[ANDROID_RESOURCE_TYPE_COUNT]; |
83 | 94 |
84 base::android::ScopedJavaGlobalRef<jobject> java_obj_; | 95 base::android::ScopedJavaGlobalRef<jobject> java_obj_; |
85 | 96 |
86 DISALLOW_COPY_AND_ASSIGN(ResourceManager); | 97 DISALLOW_COPY_AND_ASSIGN(ResourceManager); |
87 }; | 98 }; |
88 | 99 |
89 } // namespace ui | 100 } // namespace ui |
90 | 101 |
91 #endif // UI_ANDROID_RESOURCES_RESOURCE_MANAGER_H_ | 102 #endif // UI_ANDROID_RESOURCES_RESOURCE_MANAGER_H_ |
OLD | NEW |