Chromium Code Reviews| 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, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 42 gfx::Rect Border(const gfx::Size& bounds, const gfx::InsetsF& scale); | 42 gfx::Rect Border(const gfx::Size& bounds, const gfx::InsetsF& scale); |
| 43 | 43 |
| 44 scoped_ptr<UIResourceAndroid> ui_resource; | 44 scoped_ptr<UIResourceAndroid> ui_resource; |
| 45 gfx::Size size; | 45 gfx::Size size; |
| 46 gfx::Rect padding; | 46 gfx::Rect padding; |
| 47 gfx::Rect aperture; | 47 gfx::Rect aperture; |
| 48 }; | 48 }; |
| 49 | 49 |
| 50 static ResourceManager* FromJavaObject(jobject jobj); | 50 static ResourceManager* FromJavaObject(jobject jobj); |
| 51 | 51 |
| 52 explicit ResourceManager(content::UIResourceProvider* ui_resource_provider); | 52 explicit ResourceManager(ui::UIResourceProvider* ui_resource_provider); |
| 53 virtual ~ResourceManager(); | 53 virtual ~ResourceManager(); |
| 54 | 54 |
| 55 base::android::ScopedJavaLocalRef<jobject> GetJavaObject(JNIEnv* env); | 55 base::android::ScopedJavaLocalRef<jobject> GetJavaObject(JNIEnv* env); |
| 56 | 56 |
| 57 virtual void PreloadResource(ui::SystemUIResourceType type); | |
|
jdduke (slow)
2014/12/10 01:46:41
Let's go ahead and remove these two methods, updat
Jaekyun Seok (inactive)
2014/12/10 02:25:41
I believe that GetUIResourceId is useful and so I
| |
| 58 virtual cc::UIResourceId GetUIResourceId(ui::SystemUIResourceType type); | |
| 59 | |
| 57 ResourceManager::Resource* GetResource(AndroidResourceType res_type, | 60 ResourceManager::Resource* GetResource(AndroidResourceType res_type, |
| 58 int res_id); | 61 int res_id); |
| 62 ResourceManager::Resource* GetResource(AndroidResourceType res_type, | |
|
jdduke (slow)
2014/12/10 01:46:41
I'm wary of adding these methods that take a strin
Jaekyun Seok (inactive)
2014/12/10 02:25:41
I agree. Let's do this later when it is needed.
| |
| 63 std::string res_name); | |
| 59 void PreloadResource(AndroidResourceType res_type, int res_id); | 64 void PreloadResource(AndroidResourceType res_type, int res_id); |
| 65 void PreloadResource(AndroidResourceType res_type, std::string res_name); | |
| 60 | 66 |
| 61 // Called from Java ---------------------------------------------------------- | 67 // Called from Java ---------------------------------------------------------- |
| 62 void OnResourceReady(JNIEnv* env, | 68 void OnResourceReady(JNIEnv* env, |
| 63 jobject jobj, | 69 jobject jobj, |
| 64 jint res_type, | 70 jint res_type, |
| 65 jint res_id, | 71 jint res_id, |
| 66 jobject bitmap, | 72 jobject bitmap, |
| 67 jint padding_left, | 73 jint padding_left, |
| 68 jint padding_top, | 74 jint padding_top, |
| 69 jint padding_right, | 75 jint padding_right, |
| 70 jint padding_bottom, | 76 jint padding_bottom, |
| 71 jint aperture_left, | 77 jint aperture_left, |
| 72 jint aperture_top, | 78 jint aperture_top, |
| 73 jint aperture_right, | 79 jint aperture_right, |
| 74 jint aperture_bottom); | 80 jint aperture_bottom); |
| 75 | 81 |
| 76 static bool RegisterResourceManager(JNIEnv* env); | 82 static bool RegisterResourceManager(JNIEnv* env); |
| 77 | 83 |
| 78 private: | 84 private: |
| 85 friend class TestResourceManager; | |
| 86 | |
| 87 int GetAndroidResourceIdFromString(std::string res_name); | |
| 88 | |
| 89 // Start loading the resource. virtual for testing. | |
| 90 virtual void PreloadResourceFromJava(AndroidResourceType res_type, | |
| 91 int res_id); | |
| 92 virtual void RequestResourceFromJava(AndroidResourceType res_type, | |
| 93 int res_id); | |
| 94 | |
| 79 typedef IDMap<Resource, IDMapOwnPointer> ResourceMap; | 95 typedef IDMap<Resource, IDMapOwnPointer> ResourceMap; |
| 80 | 96 |
| 81 content::UIResourceProvider* ui_resource_provider_; | 97 ui::UIResourceProvider* ui_resource_provider_; |
| 82 ResourceMap resources_[ANDROID_RESOURCE_TYPE_COUNT]; | 98 ResourceMap resources_[ANDROID_RESOURCE_TYPE_COUNT]; |
| 83 | 99 |
| 84 base::android::ScopedJavaGlobalRef<jobject> java_obj_; | 100 base::android::ScopedJavaGlobalRef<jobject> java_obj_; |
| 101 base::hash_map<std::string, int> android_res_name_to_res_id_map_; | |
| 85 | 102 |
| 86 DISALLOW_COPY_AND_ASSIGN(ResourceManager); | 103 DISALLOW_COPY_AND_ASSIGN(ResourceManager); |
| 87 }; | 104 }; |
| 88 | 105 |
| 89 } // namespace ui | 106 } // namespace ui |
| 90 | 107 |
| 91 #endif // UI_ANDROID_RESOURCES_RESOURCE_MANAGER_H_ | 108 #endif // UI_ANDROID_RESOURCES_RESOURCE_MANAGER_H_ |
| OLD | NEW |