OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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/scene_layer/tab_list_scene_layer.h" |
| 6 |
| 7 #include "base/android/jni_android.h" |
| 8 #include "chrome/browser/android/compositor/layer/content_layer.h" |
| 9 #include "chrome/browser/android/compositor/layer/tab_layer.h" |
| 10 #include "chrome/browser/android/compositor/layer_title_cache.h" |
| 11 #include "chrome/browser/android/compositor/tab_content_manager.h" |
| 12 #include "jni/TabListSceneLayer_jni.h" |
| 13 #include "ui/android/resources/resource_manager_impl.h" |
| 14 |
| 15 namespace chrome { |
| 16 namespace android { |
| 17 |
| 18 TabListSceneLayer::TabListSceneLayer(JNIEnv* env, jobject jobj) |
| 19 : SceneLayer(env, jobj), |
| 20 content_obscures_self_(false), |
| 21 write_index_(0), |
| 22 resource_manager_(nullptr), |
| 23 layer_title_cache_(nullptr), |
| 24 tab_content_manager_(nullptr), |
| 25 background_color_(SK_ColorWHITE), |
| 26 own_tree_(cc::Layer::Create()) { |
| 27 layer()->AddChild(own_tree_); |
| 28 } |
| 29 |
| 30 TabListSceneLayer::~TabListSceneLayer() { |
| 31 } |
| 32 |
| 33 void TabListSceneLayer::SetContentTree(JNIEnv* env, |
| 34 jobject jobj, |
| 35 jobject jcontent_tree) { |
| 36 SceneLayer* content_tree = FromJavaObject(env, jcontent_tree); |
| 37 if (content_tree && content_tree->layer()) { |
| 38 content_tree_ = content_tree->layer(); |
| 39 } else { |
| 40 content_tree_->RemoveFromParent(); |
| 41 content_tree_ = nullptr; |
| 42 } |
| 43 |
| 44 if (content_tree_.get()) |
| 45 layer()->AddChild(content_tree_); |
| 46 } |
| 47 |
| 48 void TabListSceneLayer::BeginBuildingFrame(JNIEnv* env, jobject jobj) { |
| 49 write_index_ = 0; |
| 50 content_obscures_self_ = false; |
| 51 } |
| 52 |
| 53 void TabListSceneLayer::FinishBuildingFrame(JNIEnv* env, jobject jobj) { |
| 54 if (layers_.size() > write_index_) |
| 55 RemoveTabLayersInRange(write_index_, layers_.size()); |
| 56 } |
| 57 |
| 58 void TabListSceneLayer::PutLayer(JNIEnv* env, |
| 59 jobject jobj, |
| 60 jint id, |
| 61 jint toolbar_resource_id, |
| 62 jint close_button_resource_id, |
| 63 jint shadow_resource_id, |
| 64 jint contour_resource_id, |
| 65 jint back_logo_resource_id, |
| 66 jint border_resource_id, |
| 67 jboolean can_use_live_layer, |
| 68 jboolean can_use_ntp_fallback, |
| 69 jint tab_background_color, |
| 70 jint background_color, |
| 71 jint back_logo_color, |
| 72 jboolean incognito, |
| 73 jboolean is_portrait, |
| 74 jfloat x, |
| 75 jfloat y, |
| 76 jfloat width, |
| 77 jfloat height, |
| 78 jfloat content_width, |
| 79 jfloat content_height, |
| 80 jfloat visible_content_height, |
| 81 jfloat viewport_x, |
| 82 jfloat viewport_y, |
| 83 jfloat viewport_width, |
| 84 jfloat viewport_height, |
| 85 jfloat shadow_x, |
| 86 jfloat shadow_y, |
| 87 jfloat shadow_width, |
| 88 jfloat shadow_height, |
| 89 jfloat pivot_x, |
| 90 jfloat pivot_y, |
| 91 jfloat rotation_x, |
| 92 jfloat rotation_y, |
| 93 jfloat alpha, |
| 94 jfloat border_alpha, |
| 95 jfloat contour_alpha, |
| 96 jfloat shadow_alpha, |
| 97 jfloat close_alpha, |
| 98 jfloat close_btn_width, |
| 99 jfloat static_to_view_blend, |
| 100 jfloat border_scale, |
| 101 jfloat saturation, |
| 102 jfloat brightness, |
| 103 jboolean show_toolbar, |
| 104 jboolean anonymize_toolbar, |
| 105 jfloat toolbar_alpha, |
| 106 jfloat toolbar_y_offset, |
| 107 jfloat side_border_scale, |
| 108 jboolean attach_content, |
| 109 jboolean inset_border, |
| 110 jobject jlayer_title_cache, |
| 111 jobject jtab_content_manager, |
| 112 jobject jresource_manager) { |
| 113 // TODO(changwan): move these to constructor if possible |
| 114 if (resource_manager_ == nullptr) { |
| 115 resource_manager_ = |
| 116 ui::ResourceManagerImpl::FromJavaObject(jresource_manager); |
| 117 } |
| 118 if (layer_title_cache_ == nullptr) |
| 119 layer_title_cache_ = LayerTitleCache::FromJavaObject(jlayer_title_cache); |
| 120 if (tab_content_manager_ == nullptr) { |
| 121 tab_content_manager_ = |
| 122 TabContentManager::FromJavaObject(jtab_content_manager); |
| 123 } |
| 124 |
| 125 background_color_ = background_color; |
| 126 own_tree_->SetPosition(gfx::Point(viewport_x, viewport_y)); |
| 127 own_tree_->SetBounds(gfx::Size(viewport_width, viewport_height)); |
| 128 |
| 129 scoped_refptr<TabLayer> layer = GetNextLayer(incognito); |
| 130 layer->SetProperties( |
| 131 id, can_use_live_layer, can_use_ntp_fallback, toolbar_resource_id, |
| 132 close_button_resource_id, shadow_resource_id, contour_resource_id, |
| 133 back_logo_resource_id, border_resource_id, tab_background_color, |
| 134 back_logo_color, is_portrait, x, y, width, height, shadow_x, shadow_y, |
| 135 shadow_width, shadow_height, pivot_x, pivot_y, rotation_x, rotation_y, |
| 136 alpha, border_alpha, contour_alpha, shadow_alpha, close_alpha, |
| 137 border_scale, saturation, brightness, close_btn_width, |
| 138 static_to_view_blend, content_width, content_height, content_width, |
| 139 visible_content_height, show_toolbar, anonymize_toolbar, toolbar_alpha, |
| 140 toolbar_y_offset, side_border_scale, attach_content, inset_border); |
| 141 |
| 142 if (attach_content) { |
| 143 gfx::RectF self(own_tree_->position(), own_tree_->bounds()); |
| 144 gfx::RectF content(x, y, width, height); |
| 145 |
| 146 content_obscures_self_ |= content.Contains(self); |
| 147 } |
| 148 } |
| 149 |
| 150 base::android::ScopedJavaLocalRef<jobject> TabListSceneLayer::GetJavaObject( |
| 151 JNIEnv* env) { |
| 152 return base::android::ScopedJavaLocalRef<jobject>(java_obj_); |
| 153 } |
| 154 |
| 155 void TabListSceneLayer::OnDetach() { |
| 156 SceneLayer::OnDetach(); |
| 157 RemoveAllRemainingTabLayers(); |
| 158 } |
| 159 |
| 160 bool TabListSceneLayer::ShouldShowBackground() { |
| 161 return !content_obscures_self_; |
| 162 } |
| 163 |
| 164 SkColor TabListSceneLayer::GetBackgroundColor() { |
| 165 return background_color_; |
| 166 } |
| 167 |
| 168 void TabListSceneLayer::RemoveAllRemainingTabLayers() { |
| 169 if (layers_.size() > 0) |
| 170 RemoveTabLayersInRange(0, layers_.size()); |
| 171 } |
| 172 |
| 173 void TabListSceneLayer::RemoveTabLayersInRange(unsigned start, unsigned end) { |
| 174 DCHECK_LT(start, end); |
| 175 DCHECK_LE(end, layers_.size()); |
| 176 DCHECK_LE(0u, start); |
| 177 for (unsigned i = start; i < end; ++i) |
| 178 layers_[i]->layer()->RemoveFromParent(); |
| 179 layers_.erase(layers_.begin() + start, layers_.begin() + end); |
| 180 } |
| 181 |
| 182 scoped_refptr<TabLayer> TabListSceneLayer::GetNextLayer(bool incognito) { |
| 183 while (write_index_ < layers_.size()) { |
| 184 scoped_refptr<TabLayer> potential = layers_[write_index_]; |
| 185 if (potential->is_incognito() == incognito) |
| 186 break; |
| 187 potential->layer()->RemoveFromParent(); |
| 188 layers_.erase(layers_.begin() + write_index_); |
| 189 } |
| 190 |
| 191 if (write_index_ < layers_.size()) |
| 192 return layers_[write_index_++]; |
| 193 |
| 194 scoped_refptr<TabLayer> layer = TabLayer::Create( |
| 195 incognito, resource_manager_, layer_title_cache_, tab_content_manager_); |
| 196 layers_.push_back(layer); |
| 197 own_tree_->AddChild(layer->layer()); |
| 198 write_index_++; |
| 199 return layer; |
| 200 } |
| 201 |
| 202 static jlong Init(JNIEnv* env, jobject jobj) { |
| 203 // This will automatically bind to the Java object and pass ownership there. |
| 204 TabListSceneLayer* scene_layer = new TabListSceneLayer(env, jobj); |
| 205 return reinterpret_cast<intptr_t>(scene_layer); |
| 206 } |
| 207 |
| 208 bool RegisterTabListSceneLayer(JNIEnv* env) { |
| 209 return RegisterNativesImpl(env); |
| 210 } |
| 211 |
| 212 } // namespace android |
| 213 } // namespace chrome |
OLD | NEW |