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_bar_text_resource_id
,
29 jint search_bar_shadow_resource_id
,
30 jint search_provider_icon_resource_id
,
31 jint search_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_bar_text_opacity
,
48 jboolean search_bar_border_visible
,
49 jfloat search_bar_border_y
,
50 jfloat search_bar_border_height
,
51 jboolean search_bar_shadow_visible
,
52 jfloat search_bar_shadow_opacity
,
53 jboolean side_search_provider_icon_visible
,
54 jfloat search_provider_icon_opacity
,
55 jboolean search_icon_visible
,
56 jfloat search_icon_opacity
,
57 jboolean arrow_icon_visible
,
58 jfloat arrow_icon_opacity
,
59 jfloat arrow_icon_rotation
,
60 jboolean close_icon_visible
,
61 jfloat close_icon_opacity
,
62 jboolean progress_bar_visible
,
63 jfloat progress_bar_y
,
64 jfloat progress_bar_height
,
65 jfloat progress_bar_opacity
,
66 jint progress_bar_completion
,
67 jobject jresource_manager
) {
68 ui::ResourceManager
* resource_manager
=
69 ui::ResourceManagerImpl::FromJavaObject(jresource_manager
);
70 // Lazily construct the contextual search layer, as the feature is only
71 // conditionally enabled.
72 if (!contextual_search_layer_
.get()) {
73 if (!resource_manager
)
75 contextual_search_layer_
= ContextualSearchLayer::Create(resource_manager
);
76 layer_
->AddChild(contextual_search_layer_
->layer());
79 // NOTE(pedrosimonetti): The ContentViewCore might not exist at this time if
80 // the Contextual Search Result has not been requested yet. In this case,
81 // we'll pass NULL to Contextual Search's Layer Tree.
82 content::ContentViewCore
* content_view_core
=
83 !jcontent_view_core
? NULL
84 : content::ContentViewCore::GetNativeContentViewCore(
85 env
, jcontent_view_core
);
87 contextual_search_layer_
->SetProperties(
88 search_bar_background_resource_id
,
89 search_bar_text_resource_id
,
90 search_bar_shadow_resource_id
,
91 search_provider_icon_resource_id
,
92 search_icon_resource_id
,
94 close_icon_resource_id
,
95 progress_bar_background_resource_id
,
96 progress_bar_resource_id
,
97 search_promo_resource_id
,
101 search_promo_opacity
,
106 search_bar_margin_side
,
108 search_bar_text_opacity
,
109 search_bar_border_visible
,
111 search_bar_border_height
,
112 search_bar_shadow_visible
,
113 search_bar_shadow_opacity
,
114 side_search_provider_icon_visible
,
115 search_provider_icon_opacity
,
123 progress_bar_visible
,
126 progress_bar_opacity
,
127 progress_bar_completion
);
130 static jlong
Init(JNIEnv
* env
, jobject jobj
) {
131 // This will automatically bind to the Java object and pass ownership there.
132 ContextualSearchSceneLayer
* tree_provider
=
133 new ContextualSearchSceneLayer(env
, jobj
);
134 return reinterpret_cast<intptr_t>(tree_provider
);
137 bool RegisterContextualSearchSceneLayer(JNIEnv
* env
) {
138 return RegisterNativesImpl(env
);
141 } // namespace android
142 } // namespace chrome