| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 #include "chrome/browser/android/compositor/scene_layer/contextual_search_scene_
layer.h" | 5 #include "chrome/browser/android/compositor/scene_layer/contextual_search_scene_
layer.h" |
| 6 | 6 |
| 7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
| 8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
| 9 #include "cc/layers/solid_color_layer.h" |
| 9 #include "chrome/browser/android/compositor/layer/contextual_search_layer.h" | 10 #include "chrome/browser/android/compositor/layer/contextual_search_layer.h" |
| 11 #include "content/public/browser/android/compositor.h" |
| 10 #include "content/public/browser/android/content_view_core.h" | 12 #include "content/public/browser/android/content_view_core.h" |
| 11 #include "jni/ContextualSearchSceneLayer_jni.h" | 13 #include "jni/ContextualSearchSceneLayer_jni.h" |
| 12 #include "ui/android/resources/resource_manager_impl.h" | 14 #include "ui/android/resources/resource_manager_impl.h" |
| 13 #include "ui/gfx/android/java_bitmap.h" | 15 #include "ui/gfx/android/java_bitmap.h" |
| 14 | 16 |
| 15 namespace chrome { | 17 namespace chrome { |
| 16 namespace android { | 18 namespace android { |
| 17 | 19 |
| 18 ContextualSearchSceneLayer::ContextualSearchSceneLayer(JNIEnv* env, | 20 ContextualSearchSceneLayer::ContextualSearchSceneLayer(JNIEnv* env, |
| 19 jobject jobj) | 21 jobject jobj) |
| 20 : SceneLayer(env, jobj) { | 22 : SceneLayer(env, jobj), |
| 23 base_page_brightness_(1.0f), |
| 24 content_container_(cc::Layer::Create()) { |
| 25 // Responsible for moving the base page without modifying the layer itself. |
| 26 content_container_->SetIsDrawable(true); |
| 27 content_container_->SetPosition(gfx::PointF(0.0f, 0.0f)); |
| 28 } |
| 29 |
| 30 void ContextualSearchSceneLayer::CreateContextualSearchLayer( |
| 31 JNIEnv* env, |
| 32 const JavaParamRef<jobject>& object, |
| 33 const JavaParamRef<jobject>& jresource_manager) { |
| 34 ui::ResourceManager* resource_manager = |
| 35 ui::ResourceManagerImpl::FromJavaObject(jresource_manager); |
| 36 contextual_search_layer_ = ContextualSearchLayer::Create(resource_manager); |
| 37 |
| 38 // The Contextual Search layer is initially invisible. |
| 39 contextual_search_layer_->layer()->SetHideLayerAndSubtree(true); |
| 40 |
| 41 // Add all layers to the tree; this is order dependent. |
| 42 layer()->AddChild(content_container_); |
| 43 layer()->AddChild(contextual_search_layer_->layer()); |
| 21 } | 44 } |
| 22 | 45 |
| 23 ContextualSearchSceneLayer::~ContextualSearchSceneLayer() { | 46 ContextualSearchSceneLayer::~ContextualSearchSceneLayer() { |
| 24 } | 47 } |
| 25 | 48 |
| 26 void ContextualSearchSceneLayer::UpdateContextualSearchLayer( | 49 void ContextualSearchSceneLayer::UpdateContextualSearchLayer( |
| 27 JNIEnv* env, | 50 JNIEnv* env, |
| 28 const JavaParamRef<jobject>& object, | 51 const JavaParamRef<jobject>& object, |
| 29 jint search_bar_background_resource_id, | 52 jint search_bar_background_resource_id, |
| 30 jint search_context_resource_id, | 53 jint search_context_resource_id, |
| 31 jint search_term_resource_id, | 54 jint search_term_resource_id, |
| 32 jint search_caption_resource_id, | 55 jint search_caption_resource_id, |
| 33 jint search_bar_shadow_resource_id, | 56 jint search_bar_shadow_resource_id, |
| 34 jint panel_icon_resource_id, | 57 jint panel_icon_resource_id, |
| 35 jint search_provider_icon_sprite_metadata_resource_id, | 58 jint search_provider_icon_sprite_metadata_resource_id, |
| 36 jint arrow_up_resource_id, | 59 jint arrow_up_resource_id, |
| 37 jint close_icon_resource_id, | 60 jint close_icon_resource_id, |
| 38 jint progress_bar_background_resource_id, | 61 jint progress_bar_background_resource_id, |
| 39 jint progress_bar_resource_id, | 62 jint progress_bar_resource_id, |
| 40 jint search_promo_resource_id, | 63 jint search_promo_resource_id, |
| 41 jint peek_promo_ripple_resource_id, | 64 jint peek_promo_ripple_resource_id, |
| 42 jint peek_promo_text_resource_id, | 65 jint peek_promo_text_resource_id, |
| 43 jfloat dp_to_px, | 66 jfloat dp_to_px, |
| 67 jfloat base_page_brightness, |
| 68 jfloat base_page_offset, |
| 44 const JavaParamRef<jobject>& jcontent_view_core, | 69 const JavaParamRef<jobject>& jcontent_view_core, |
| 45 jboolean search_promo_visible, | 70 jboolean search_promo_visible, |
| 46 jfloat search_promo_height, | 71 jfloat search_promo_height, |
| 47 jfloat search_promo_opacity, | 72 jfloat search_promo_opacity, |
| 48 jboolean search_peek_promo_visible, | 73 jboolean search_peek_promo_visible, |
| 49 jfloat search_peek_promo_height, | 74 jfloat search_peek_promo_height, |
| 50 jfloat search_peek_promo_padding, | 75 jfloat search_peek_promo_padding, |
| 51 jfloat search_peek_promo_ripple_width, | 76 jfloat search_peek_promo_ripple_width, |
| 52 jfloat search_peek_promo_ripple_opacity, | 77 jfloat search_peek_promo_ripple_opacity, |
| 53 jfloat search_peek_promo_text_opacity, | 78 jfloat search_peek_promo_text_opacity, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 65 jboolean search_bar_shadow_visible, | 90 jboolean search_bar_shadow_visible, |
| 66 jfloat search_bar_shadow_opacity, | 91 jfloat search_bar_shadow_opacity, |
| 67 jboolean search_provider_icon_sprite_visible, | 92 jboolean search_provider_icon_sprite_visible, |
| 68 jfloat search_provider_icon_sprite_completion_percentage, | 93 jfloat search_provider_icon_sprite_completion_percentage, |
| 69 jfloat arrow_icon_opacity, | 94 jfloat arrow_icon_opacity, |
| 70 jfloat arrow_icon_rotation, | 95 jfloat arrow_icon_rotation, |
| 71 jfloat close_icon_opacity, | 96 jfloat close_icon_opacity, |
| 72 jboolean progress_bar_visible, | 97 jboolean progress_bar_visible, |
| 73 jfloat progress_bar_height, | 98 jfloat progress_bar_height, |
| 74 jfloat progress_bar_opacity, | 99 jfloat progress_bar_opacity, |
| 75 jint progress_bar_completion, | 100 jint progress_bar_completion) { |
| 76 const JavaParamRef<jobject>& jresource_manager) { | |
| 77 ui::ResourceManager* resource_manager = | |
| 78 ui::ResourceManagerImpl::FromJavaObject(jresource_manager); | |
| 79 // Lazily construct the contextual search layer, as the feature is only | |
| 80 // conditionally enabled. | |
| 81 if (!contextual_search_layer_.get()) { | |
| 82 if (!resource_manager) | |
| 83 return; | |
| 84 contextual_search_layer_ = ContextualSearchLayer::Create(resource_manager); | |
| 85 layer_->AddChild(contextual_search_layer_->layer()); | |
| 86 } | |
| 87 | |
| 88 // NOTE(pedrosimonetti): The ContentViewCore might not exist at this time if | 101 // NOTE(pedrosimonetti): The ContentViewCore might not exist at this time if |
| 89 // the Contextual Search Result has not been requested yet. In this case, | 102 // the Contextual Search Result has not been requested yet. In this case, |
| 90 // we'll pass NULL to Contextual Search's Layer Tree. | 103 // we'll pass NULL to Contextual Search's Layer Tree. |
| 91 content::ContentViewCore* content_view_core = | 104 content::ContentViewCore* content_view_core = |
| 92 !jcontent_view_core ? NULL | 105 !jcontent_view_core ? NULL |
| 93 : content::ContentViewCore::GetNativeContentViewCore( | 106 : content::ContentViewCore::GetNativeContentViewCore( |
| 94 env, jcontent_view_core); | 107 env, jcontent_view_core); |
| 95 | 108 |
| 109 // Fade the base page out. |
| 110 if (base_page_brightness_ != base_page_brightness) { |
| 111 base_page_brightness_ = base_page_brightness; |
| 112 cc::FilterOperations filters; |
| 113 if (base_page_brightness < 1.f) |
| 114 filters.Append( |
| 115 cc::FilterOperation::CreateBrightnessFilter(base_page_brightness)); |
| 116 content_container_->SetFilters(filters); |
| 117 } |
| 118 |
| 119 // Move the base page contents up. |
| 120 content_container_->SetPosition(gfx::PointF(0.0f, base_page_offset)); |
| 121 |
| 96 contextual_search_layer_->SetProperties( | 122 contextual_search_layer_->SetProperties( |
| 97 search_bar_background_resource_id, | 123 search_bar_background_resource_id, |
| 98 search_context_resource_id, | 124 search_context_resource_id, |
| 99 search_term_resource_id, | 125 search_term_resource_id, |
| 100 search_caption_resource_id, | 126 search_caption_resource_id, |
| 101 search_bar_shadow_resource_id, | 127 search_bar_shadow_resource_id, |
| 102 panel_icon_resource_id, | 128 panel_icon_resource_id, |
| 103 search_provider_icon_sprite_metadata_resource_id, | 129 search_provider_icon_sprite_metadata_resource_id, |
| 104 arrow_up_resource_id, | 130 arrow_up_resource_id, |
| 105 close_icon_resource_id, | 131 close_icon_resource_id, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 134 search_bar_shadow_opacity, | 160 search_bar_shadow_opacity, |
| 135 search_provider_icon_sprite_visible, | 161 search_provider_icon_sprite_visible, |
| 136 search_provider_icon_sprite_completion_percentage, | 162 search_provider_icon_sprite_completion_percentage, |
| 137 arrow_icon_opacity, | 163 arrow_icon_opacity, |
| 138 arrow_icon_rotation, | 164 arrow_icon_rotation, |
| 139 close_icon_opacity, | 165 close_icon_opacity, |
| 140 progress_bar_visible, | 166 progress_bar_visible, |
| 141 progress_bar_height, | 167 progress_bar_height, |
| 142 progress_bar_opacity, | 168 progress_bar_opacity, |
| 143 progress_bar_completion); | 169 progress_bar_completion); |
| 170 |
| 171 // Make the layer visible if it is not already. |
| 172 contextual_search_layer_->layer()->SetHideLayerAndSubtree(false); |
| 173 } |
| 174 |
| 175 void ContextualSearchSceneLayer::SetContentTree( |
| 176 JNIEnv* env, |
| 177 const JavaParamRef<jobject>& jobj, |
| 178 const JavaParamRef<jobject>& jcontent_tree) { |
| 179 SceneLayer* content_tree = FromJavaObject(env, jcontent_tree); |
| 180 if (!content_tree || !content_tree->layer()) return; |
| 181 |
| 182 if (!content_tree->layer()->parent() |
| 183 || (content_tree->layer()->parent()->id() != content_container_->id())) { |
| 184 content_container_->AddChild(content_tree->layer()); |
| 185 } |
| 186 } |
| 187 |
| 188 void ContextualSearchSceneLayer::HideTree(JNIEnv* env, |
| 189 const JavaParamRef<jobject>& jobj) { |
| 190 if (contextual_search_layer_) { |
| 191 contextual_search_layer_->layer()->SetHideLayerAndSubtree(true); |
| 192 } |
| 193 // Reset base page brightness. |
| 194 cc::FilterOperations filters; |
| 195 filters.Append(cc::FilterOperation::CreateBrightnessFilter(1.0f)); |
| 196 content_container_->SetFilters(filters); |
| 197 // Reset base page offset. |
| 198 content_container_->SetPosition(gfx::PointF(0.0f, 0.0f)); |
| 144 } | 199 } |
| 145 | 200 |
| 146 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) { | 201 static jlong Init(JNIEnv* env, const JavaParamRef<jobject>& jobj) { |
| 147 // This will automatically bind to the Java object and pass ownership there. | 202 // This will automatically bind to the Java object and pass ownership there. |
| 148 ContextualSearchSceneLayer* tree_provider = | 203 ContextualSearchSceneLayer* tree_provider = |
| 149 new ContextualSearchSceneLayer(env, jobj); | 204 new ContextualSearchSceneLayer(env, jobj); |
| 150 return reinterpret_cast<intptr_t>(tree_provider); | 205 return reinterpret_cast<intptr_t>(tree_provider); |
| 151 } | 206 } |
| 152 | 207 |
| 153 bool RegisterContextualSearchSceneLayer(JNIEnv* env) { | 208 bool RegisterContextualSearchSceneLayer(JNIEnv* env) { |
| 154 return RegisterNativesImpl(env); | 209 return RegisterNativesImpl(env); |
| 155 } | 210 } |
| 156 | 211 |
| 157 } // namespace android | 212 } // namespace android |
| 158 } // namespace chrome | 213 } // namespace chrome |
| OLD | NEW |