Chromium Code Reviews| 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 layer()->AddChild(content_container_); | |
| 29 } | |
| 30 | |
| 31 void ContextualSearchSceneLayer::CreateContextualSearchLayer( | |
| 32 JNIEnv* env, | |
| 33 const JavaParamRef<jobject>& object, | |
| 34 const JavaParamRef<jobject>& jresource_manager) { | |
| 35 ui::ResourceManager* resource_manager = | |
| 36 ui::ResourceManagerImpl::FromJavaObject(jresource_manager); | |
| 37 contextual_search_layer_ = ContextualSearchLayer::Create(resource_manager); | |
| 38 | |
| 39 // The Contextual Search layer is initially invisible. | |
| 40 contextual_search_layer_->layer()->SetHideLayerAndSubtree(true); | |
| 41 | |
| 42 layer()->AddChild(contextual_search_layer_->layer()); | |
| 21 } | 43 } |
| 22 | 44 |
| 23 ContextualSearchSceneLayer::~ContextualSearchSceneLayer() { | 45 ContextualSearchSceneLayer::~ContextualSearchSceneLayer() { |
| 24 } | 46 } |
| 25 | 47 |
| 26 void ContextualSearchSceneLayer::UpdateContextualSearchLayer( | 48 void ContextualSearchSceneLayer::UpdateContextualSearchLayer( |
| 27 JNIEnv* env, | 49 JNIEnv* env, |
| 28 const JavaParamRef<jobject>& object, | 50 const JavaParamRef<jobject>& object, |
| 29 jint search_bar_background_resource_id, | 51 jint search_bar_background_resource_id, |
| 30 jint search_context_resource_id, | 52 jint search_context_resource_id, |
| 31 jint search_term_resource_id, | 53 jint search_term_resource_id, |
| 32 jint search_caption_resource_id, | 54 jint search_caption_resource_id, |
| 33 jint search_bar_shadow_resource_id, | 55 jint search_bar_shadow_resource_id, |
| 34 jint panel_icon_resource_id, | 56 jint panel_icon_resource_id, |
| 35 jint search_provider_icon_sprite_metadata_resource_id, | 57 jint search_provider_icon_sprite_metadata_resource_id, |
| 36 jint arrow_up_resource_id, | 58 jint arrow_up_resource_id, |
| 37 jint close_icon_resource_id, | 59 jint close_icon_resource_id, |
| 38 jint progress_bar_background_resource_id, | 60 jint progress_bar_background_resource_id, |
| 39 jint progress_bar_resource_id, | 61 jint progress_bar_resource_id, |
| 40 jint search_promo_resource_id, | 62 jint search_promo_resource_id, |
| 41 jint peek_promo_ripple_resource_id, | 63 jint peek_promo_ripple_resource_id, |
| 42 jint peek_promo_text_resource_id, | 64 jint peek_promo_text_resource_id, |
| 43 jfloat dp_to_px, | 65 jfloat dp_to_px, |
| 66 jfloat base_page_brightness, | |
| 67 jfloat base_page_offset, | |
| 44 const JavaParamRef<jobject>& jcontent_view_core, | 68 const JavaParamRef<jobject>& jcontent_view_core, |
| 45 jboolean search_promo_visible, | 69 jboolean search_promo_visible, |
| 46 jfloat search_promo_height, | 70 jfloat search_promo_height, |
| 47 jfloat search_promo_opacity, | 71 jfloat search_promo_opacity, |
| 48 jboolean search_peek_promo_visible, | 72 jboolean search_peek_promo_visible, |
| 49 jfloat search_peek_promo_height, | 73 jfloat search_peek_promo_height, |
| 50 jfloat search_peek_promo_padding, | 74 jfloat search_peek_promo_padding, |
| 51 jfloat search_peek_promo_ripple_width, | 75 jfloat search_peek_promo_ripple_width, |
| 52 jfloat search_peek_promo_ripple_opacity, | 76 jfloat search_peek_promo_ripple_opacity, |
| 53 jfloat search_peek_promo_text_opacity, | 77 jfloat search_peek_promo_text_opacity, |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 65 jboolean search_bar_shadow_visible, | 89 jboolean search_bar_shadow_visible, |
| 66 jfloat search_bar_shadow_opacity, | 90 jfloat search_bar_shadow_opacity, |
| 67 jboolean search_provider_icon_sprite_visible, | 91 jboolean search_provider_icon_sprite_visible, |
| 68 jfloat search_provider_icon_sprite_completion_percentage, | 92 jfloat search_provider_icon_sprite_completion_percentage, |
| 69 jfloat arrow_icon_opacity, | 93 jfloat arrow_icon_opacity, |
| 70 jfloat arrow_icon_rotation, | 94 jfloat arrow_icon_rotation, |
| 71 jfloat close_icon_opacity, | 95 jfloat close_icon_opacity, |
| 72 jboolean progress_bar_visible, | 96 jboolean progress_bar_visible, |
| 73 jfloat progress_bar_height, | 97 jfloat progress_bar_height, |
| 74 jfloat progress_bar_opacity, | 98 jfloat progress_bar_opacity, |
| 75 jint progress_bar_completion, | 99 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 | 100 // NOTE(pedrosimonetti): The ContentViewCore might not exist at this time if |
| 89 // the Contextual Search Result has not been requested yet. In this case, | 101 // the Contextual Search Result has not been requested yet. In this case, |
| 90 // we'll pass NULL to Contextual Search's Layer Tree. | 102 // we'll pass NULL to Contextual Search's Layer Tree. |
| 91 content::ContentViewCore* content_view_core = | 103 content::ContentViewCore* content_view_core = |
| 92 !jcontent_view_core ? NULL | 104 !jcontent_view_core ? NULL |
| 93 : content::ContentViewCore::GetNativeContentViewCore( | 105 : content::ContentViewCore::GetNativeContentViewCore( |
| 94 env, jcontent_view_core); | 106 env, jcontent_view_core); |
| 95 | 107 |
| 108 // Fade the base page out. | |
| 109 if (base_page_brightness_ != base_page_brightness) { | |
| 110 base_page_brightness_ = base_page_brightness; | |
| 111 cc::FilterOperations filters; | |
| 112 if (base_page_brightness < 1.f) | |
|
David Trainor- moved to gerrit
2016/05/13 16:14:34
I would just add {} since it's a wrapped line belo
mdjones
2016/05/13 20:30:07
Done.
| |
| 113 filters.Append( | |
| 114 cc::FilterOperation::CreateBrightnessFilter(base_page_brightness)); | |
| 115 content_container_->SetFilters(filters); | |
| 116 } | |
| 117 | |
| 118 // Move the base page contents up. | |
| 119 content_container_->SetPosition(gfx::PointF(0.0f, base_page_offset)); | |
| 120 | |
| 96 contextual_search_layer_->SetProperties( | 121 contextual_search_layer_->SetProperties( |
| 97 search_bar_background_resource_id, | 122 search_bar_background_resource_id, |
| 98 search_context_resource_id, | 123 search_context_resource_id, |
| 99 search_term_resource_id, | 124 search_term_resource_id, |
| 100 search_caption_resource_id, | 125 search_caption_resource_id, |
| 101 search_bar_shadow_resource_id, | 126 search_bar_shadow_resource_id, |
| 102 panel_icon_resource_id, | 127 panel_icon_resource_id, |
| 103 search_provider_icon_sprite_metadata_resource_id, | 128 search_provider_icon_sprite_metadata_resource_id, |
| 104 arrow_up_resource_id, | 129 arrow_up_resource_id, |
| 105 close_icon_resource_id, | 130 close_icon_resource_id, |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 134 search_bar_shadow_opacity, | 159 search_bar_shadow_opacity, |
| 135 search_provider_icon_sprite_visible, | 160 search_provider_icon_sprite_visible, |
| 136 search_provider_icon_sprite_completion_percentage, | 161 search_provider_icon_sprite_completion_percentage, |
| 137 arrow_icon_opacity, | 162 arrow_icon_opacity, |
| 138 arrow_icon_rotation, | 163 arrow_icon_rotation, |
| 139 close_icon_opacity, | 164 close_icon_opacity, |
| 140 progress_bar_visible, | 165 progress_bar_visible, |
| 141 progress_bar_height, | 166 progress_bar_height, |
| 142 progress_bar_opacity, | 167 progress_bar_opacity, |
| 143 progress_bar_completion); | 168 progress_bar_completion); |
| 169 | |
| 170 // Make the layer visible if it is not already. | |
| 171 contextual_search_layer_->layer()->SetHideLayerAndSubtree(false); | |
| 172 } | |
| 173 | |
| 174 void ContextualSearchSceneLayer::SetContentTree( | |
| 175 JNIEnv* env, | |
| 176 const JavaParamRef<jobject>& jobj, | |
| 177 const JavaParamRef<jobject>& jcontent_tree) { | |
| 178 SceneLayer* content_tree = FromJavaObject(env, jcontent_tree); | |
| 179 if (!content_tree || !content_tree->layer()) return; | |
| 180 | |
| 181 if (!content_tree->layer()->parent() | |
| 182 || (content_tree->layer()->parent()->id() != content_container_->id())) { | |
| 183 content_container_->AddChild(content_tree->layer()); | |
| 184 } | |
| 185 } | |
| 186 | |
| 187 void ContextualSearchSceneLayer::HideTree(JNIEnv* env, | |
| 188 const JavaParamRef<jobject>& jobj) { | |
| 189 // TODO(mdjones): Create super class for this logic. | |
| 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 |