OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/android/compositor/layer_title_cache.h" | |
6 | |
7 #include <android/bitmap.h> | |
8 | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "cc/layers/layer.h" | |
11 #include "cc/layers/ui_resource_layer.h" | |
12 #include "chrome/browser/android/compositor/decoration_title.h" | |
13 #include "content/public/browser/android/ui_resource_provider.h" | |
Jaekyun Seok (inactive)
2014/12/11 01:31:04
This isn't used. Please remove it.
Changwan Ryu
2014/12/11 04:12:33
Done.
| |
14 #include "jni/LayerTitleCache_jni.h" | |
15 #include "ui/android/resources/resource_manager.h" | |
16 #include "ui/gfx/android/java_bitmap.h" | |
17 #include "ui/gfx/point_f.h" | |
18 #include "ui/gfx/rect_f.h" | |
19 #include "ui/gfx/size.h" | |
20 | |
21 namespace chrome { | |
22 namespace android { | |
23 | |
24 // static | |
25 LayerTitleCache* LayerTitleCache::FromJavaObject(jobject jobj) { | |
26 if (!jobj) | |
27 return NULL; | |
28 return reinterpret_cast<LayerTitleCache*>(Java_LayerTitleCache_getNativePtr( | |
29 base::android::AttachCurrentThread(), jobj)); | |
30 } | |
31 | |
32 LayerTitleCache::LayerTitleCache(JNIEnv* env, | |
33 jobject obj, | |
34 jint fade_width, | |
35 jint favicon_start_padding, | |
36 jint favicon_end_padding, | |
37 jint spinner_resource_id, | |
38 jint spinner_incognito_resource_id) | |
39 : weak_java_title_cache_(env, obj), | |
40 fade_width_(fade_width), | |
41 favicon_start_padding_(favicon_start_padding), | |
42 favicon_end_padding_(favicon_end_padding), | |
43 spinner_resource_id_(spinner_resource_id), | |
44 spinner_incognito_resource_id_(spinner_incognito_resource_id), | |
45 resource_manager_(nullptr) { | |
46 } | |
47 | |
48 void LayerTitleCache::Destroy(JNIEnv* env, jobject obj) { | |
49 delete this; | |
50 } | |
51 | |
52 void LayerTitleCache::UpdateLayer(JNIEnv* env, | |
53 jobject obj, | |
54 jint tab_id, | |
55 jint title_resource_id, | |
56 jint favicon_resource_id, | |
57 bool is_incognito, | |
58 bool is_rtl) { | |
59 DecorationTitle* title_layer = layer_cache_.Lookup(tab_id); | |
60 if (title_layer == NULL) { | |
61 layer_cache_.AddWithID( | |
62 new DecorationTitle( | |
63 this, resource_manager_, title_resource_id, favicon_resource_id, | |
64 spinner_resource_id_, spinner_incognito_resource_id_, fade_width_, | |
65 favicon_start_padding_, favicon_end_padding_, is_incognito, is_rtl), | |
66 tab_id); | |
67 } else { | |
68 if (title_resource_id != -1 && favicon_resource_id != -1) { | |
69 title_layer->Update(title_resource_id, favicon_resource_id, fade_width_, | |
70 favicon_start_padding_, favicon_end_padding_, | |
71 is_incognito, is_rtl); | |
72 } else { | |
73 layer_cache_.Remove(tab_id); | |
74 } | |
75 } | |
76 } | |
77 | |
78 void LayerTitleCache::ClearExcept(JNIEnv* env, jobject obj, jint except_id) { | |
79 IDMap<DecorationTitle, IDMapOwnPointer>::iterator iter(&layer_cache_); | |
80 for (; !iter.IsAtEnd(); iter.Advance()) { | |
81 const int id = iter.GetCurrentKey(); | |
82 if (id != except_id) | |
83 layer_cache_.Remove(id); | |
84 } | |
85 } | |
86 | |
87 DecorationTitle* LayerTitleCache::GetTitleLayer(int tab_id) { | |
88 return layer_cache_.Lookup(tab_id); | |
89 } | |
90 | |
91 void LayerTitleCache::SetResourceManager( | |
92 ui::ResourceManager* resource_manager) { | |
93 resource_manager_ = resource_manager; | |
94 | |
95 IDMap<DecorationTitle, IDMapOwnPointer>::iterator iter(&layer_cache_); | |
96 for (; !iter.IsAtEnd(); iter.Advance()) { | |
97 iter.GetCurrentValue()->SetResourceManager(resource_manager_); | |
98 } | |
99 } | |
100 | |
101 LayerTitleCache::~LayerTitleCache() { | |
102 } | |
103 | |
104 bool RegisterLayerTitleCache(JNIEnv* env) { | |
105 return RegisterNativesImpl(env); | |
106 } | |
107 | |
108 // ---------------------------------------------------------------------------- | |
109 // Native JNI methods | |
110 // ---------------------------------------------------------------------------- | |
111 | |
112 jlong Init(JNIEnv* env, | |
113 jobject obj, | |
114 jint fade_width, | |
115 jint favicon_start_padding, | |
116 jint favicon_end_padding, | |
117 jint spinner_resource_id, | |
118 jint spinner_incognito_resource_id) { | |
119 LayerTitleCache* cache = new LayerTitleCache( | |
120 env, obj, fade_width, favicon_start_padding, favicon_end_padding, | |
121 spinner_resource_id, spinner_incognito_resource_id); | |
122 return reinterpret_cast<intptr_t>(cache); | |
123 } | |
124 | |
125 } // namespace android | |
126 } // namespace chrome | |
OLD | NEW |