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_manager.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 class UI_ANDROID_EXPORT ResourceManager { | 35 class UI_ANDROID_EXPORT ResourceManager : public ui::SystemUIResourceManager { |
| 36 public: | 36 public: |
| 37 struct Resource { | 37 struct Resource { |
| 38 public: | 38 public: |
| 39 Resource(); | 39 Resource(); |
| 40 ~Resource(); | 40 ~Resource(); |
| 41 gfx::Rect Border(const gfx::Size& bounds); | 41 gfx::Rect Border(const gfx::Size& bounds); |
| 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 ~ResourceManager() override; |
| 54 | |
| 55 // ui::SystemUIResourceManager implementation. | |
| 56 void PreloadResource(ui::SystemUIResourceType type) override; | |
|
jdduke (slow)
2014/12/08 16:23:13
Can we just get rid of the SystemUIResourceManager
Jaekyun Seok (inactive)
2014/12/09 11:42:35
I want to keep the SystemUIResourceManager interfa
| |
| 57 cc::UIResourceId GetUIResourceId(ui::SystemUIResourceType type) override; | |
| 54 | 58 |
| 55 base::android::ScopedJavaLocalRef<jobject> GetJavaObject(JNIEnv* env); | 59 base::android::ScopedJavaLocalRef<jobject> GetJavaObject(JNIEnv* env); |
| 56 | 60 |
| 57 ResourceManager::Resource* GetResource(AndroidResourceType res_type, | 61 ResourceManager::Resource* GetResource(AndroidResourceType res_type, |
| 58 int res_id); | 62 int res_id); |
| 63 ResourceManager::Resource* GetResource(AndroidResourceType res_type, | |
|
jdduke (slow)
2014/12/08 16:23:13
Where are these methods that take a string used? I
Jaekyun Seok (inactive)
2014/12/09 11:42:35
This was requested from David.
David, could you p
| |
| 64 std::string res_name); | |
| 59 void PreloadResource(AndroidResourceType res_type, int res_id); | 65 void PreloadResource(AndroidResourceType res_type, int res_id); |
| 66 void PreloadResource(AndroidResourceType res_type, std::string res_name); | |
| 60 | 67 |
| 61 // Called from Java ---------------------------------------------------------- | 68 // Called from Java ---------------------------------------------------------- |
| 62 void OnResourceReady(JNIEnv* env, | 69 void OnResourceReady(JNIEnv* env, |
| 63 jobject jobj, | 70 jobject jobj, |
| 64 jint res_type, | 71 jint res_type, |
| 65 jint res_id, | 72 jint res_id, |
| 66 jobject bitmap, | 73 jobject bitmap, |
| 67 jint padding_left, | 74 jint padding_left, |
| 68 jint padding_top, | 75 jint padding_top, |
| 69 jint padding_right, | 76 jint padding_right, |
| 70 jint padding_bottom, | 77 jint padding_bottom, |
| 71 jint aperture_left, | 78 jint aperture_left, |
| 72 jint aperture_top, | 79 jint aperture_top, |
| 73 jint aperture_right, | 80 jint aperture_right, |
| 74 jint aperture_bottom); | 81 jint aperture_bottom); |
| 75 | 82 |
| 76 static bool RegisterResourceManager(JNIEnv* env); | 83 static bool RegisterResourceManager(JNIEnv* env); |
| 77 | 84 |
| 78 private: | 85 private: |
| 86 int GetAndroidResourceIdFromString(std::string res_name); | |
| 87 | |
| 79 typedef IDMap<Resource, IDMapOwnPointer> ResourceMap; | 88 typedef IDMap<Resource, IDMapOwnPointer> ResourceMap; |
| 80 | 89 |
| 81 content::UIResourceProvider* ui_resource_provider_; | 90 ui::UIResourceProvider* ui_resource_provider_; |
| 82 ResourceMap resources_[ANDROID_RESOURCE_TYPE_COUNT]; | 91 ResourceMap resources_[ANDROID_RESOURCE_TYPE_COUNT]; |
| 83 | 92 |
| 84 base::android::ScopedJavaGlobalRef<jobject> java_obj_; | 93 base::android::ScopedJavaGlobalRef<jobject> java_obj_; |
| 94 base::hash_map<std::string, int> android_res_name_to_res_id_map_; | |
| 85 | 95 |
| 86 DISALLOW_COPY_AND_ASSIGN(ResourceManager); | 96 DISALLOW_COPY_AND_ASSIGN(ResourceManager); |
| 87 }; | 97 }; |
| 88 | 98 |
| 89 } // namespace ui | 99 } // namespace ui |
| 90 | 100 |
| 91 #endif // UI_ANDROID_RESOURCES_RESOURCE_MANAGER_H_ | 101 #endif // UI_ANDROID_RESOURCES_RESOURCE_MANAGER_H_ |
| OLD | NEW |