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.
5 #include "chrome/browser/android/compositor/scene_layer/contextual_search_scene_layer.h"
7 #include "base/android/jni_android.h"
8 #include "chrome/browser/android/compositor/layer/contextual_search_layer.h"
9 #include "content/public/browser/android/content_view_core.h"
10 #include "jni/ContextualSearchSceneLayer_jni.h"
11 #include "ui/android/resources/resource_manager_impl.h"
16 ContextualSearchSceneLayer::ContextualSearchSceneLayer(JNIEnv
* env
,
18 : SceneLayer(env
, jobj
) {
21 ContextualSearchSceneLayer::~ContextualSearchSceneLayer() {
24 void ContextualSearchSceneLayer::UpdateContextualSearchLayer(
27 jint search_bar_background_resource_id
,
28 jint search_context_resource_id
,
29 jint search_term_resource_id
,
30 jint search_bar_shadow_resource_id
,
31 jint search_provider_icon_resource_id
,
32 jint arrow_up_resource_id
,
33 jint close_icon_resource_id
,
34 jint progress_bar_background_resource_id
,
35 jint progress_bar_resource_id
,
36 jint search_promo_resource_id
,
37 jobject jcontent_view_core
,
38 jboolean search_promo_visible
,
39 jfloat search_promo_height
,
40 jfloat search_promo_opacity
,
41 jfloat search_panel_X
,
42 jfloat search_panel_y
,
43 jfloat search_panel_width
,
44 jfloat search_panel_height
,
45 jfloat search_bar_margin_side
,
46 jfloat search_bar_height
,
47 jfloat search_context_opacity
,
48 jfloat search_term_opacity
,
49 jboolean search_bar_border_visible
,
50 jfloat search_bar_border_y
,
51 jfloat search_bar_border_height
,
52 jboolean search_bar_shadow_visible
,
53 jfloat search_bar_shadow_opacity
,
54 jfloat arrow_icon_opacity
,
55 jfloat arrow_icon_rotation
,
56 jboolean close_icon_visible
,
57 jfloat close_icon_opacity
,
58 jboolean progress_bar_visible
,
59 jfloat progress_bar_y
,
60 jfloat progress_bar_height
,
61 jfloat progress_bar_opacity
,
62 jint progress_bar_completion
,
63 jobject jresource_manager
) {
64 ui::ResourceManager
* resource_manager
=
65 ui::ResourceManagerImpl::FromJavaObject(jresource_manager
);
66 // Lazily construct the contextual search layer, as the feature is only
67 // conditionally enabled.
68 if (!contextual_search_layer_
.get()) {
69 if (!resource_manager
)
71 contextual_search_layer_
= ContextualSearchLayer::Create(resource_manager
);
72 layer_
->AddChild(contextual_search_layer_
->layer());
75 // NOTE(pedrosimonetti): The ContentViewCore might not exist at this time if
76 // the Contextual Search Result has not been requested yet. In this case,
77 // we'll pass NULL to Contextual Search's Layer Tree.
78 content::ContentViewCore
* content_view_core
=
79 !jcontent_view_core
? NULL
80 : content::ContentViewCore::GetNativeContentViewCore(
81 env
, jcontent_view_core
);
83 contextual_search_layer_
->SetProperties(
84 search_bar_background_resource_id
,
85 search_context_resource_id
,
86 search_term_resource_id
,
87 search_bar_shadow_resource_id
,
88 search_provider_icon_resource_id
,
90 close_icon_resource_id
,
91 progress_bar_background_resource_id
,
92 progress_bar_resource_id
,
93 search_promo_resource_id
,
102 search_bar_margin_side
,
104 search_context_opacity
,
106 search_bar_border_visible
,
108 search_bar_border_height
,
109 search_bar_shadow_visible
,
110 search_bar_shadow_opacity
,
115 progress_bar_visible
,
118 progress_bar_opacity
,
119 progress_bar_completion
);
122 static jlong
Init(JNIEnv
* env
, const JavaParamRef
<jobject
>& jobj
) {
123 // This will automatically bind to the Java object and pass ownership there.
124 ContextualSearchSceneLayer
* tree_provider
=
125 new ContextualSearchSceneLayer(env
, jobj
);
126 return reinterpret_cast<intptr_t>(tree_provider
);
129 bool RegisterContextualSearchSceneLayer(JNIEnv
* env
) {
130 return RegisterNativesImpl(env
);
133 } // namespace android
134 } // namespace chrome