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 #ifndef CHROME_BROWSER_ANDROID_COMPOSITOR_SCENE_LAYER_CONTEXTUAL_SEARCH_SCENE_LAYER_H_
6 #define CHROME_BROWSER_ANDROID_COMPOSITOR_SCENE_LAYER_CONTEXTUAL_SEARCH_SCENE_LAYER_H_
7 
8 #include <memory>
9 #include <vector>
10 
11 #include "base/android/jni_android.h"
12 #include "base/android/jni_weak_ref.h"
13 #include "base/android/scoped_java_ref.h"
14 #include "base/macros.h"
15 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher.h"
16 #include "chrome/browser/ui/android/layouts/scene_layer.h"
17 
18 namespace cc {
19 class Layer;
20 class SolidColorLayer;
21 }
22 
23 namespace android {
24 
25 class ContextualSearchLayer;
26 
27 // A native-side, cc::Layer-based representation of how a Contextual Search
28 // scene should be drawn.
29 // This class delegates to the ContextualSearchLayer
30 // that does the actual rendering of the Contextual Search Bar and content.
31 class ContextualSearchSceneLayer : public SceneLayer,
32                                    public BitmapFetcherDelegate {
33  public:
34   ContextualSearchSceneLayer(JNIEnv* env,
35                              const base::android::JavaRef<jobject>& jobj);
36   ~ContextualSearchSceneLayer() override;
37 
38   void CreateContextualSearchLayer(
39       JNIEnv* env,
40       const base::android::JavaParamRef<jobject>& object,
41       const base::android::JavaParamRef<jobject>& jresource_manager);
42 
43   void UpdateContextualSearchLayer(
44       JNIEnv* env,
45       const base::android::JavaParamRef<jobject>& object,
46       jint search_bar_background_resource_id,
47       jint search_bar_background_color,
48       jint search_context_resource_id,
49       jint search_term_resource_id,
50       jint search_caption_resource_id,
51       jint search_bar_shadow_resource_id,
52       jint search_provider_icon_resource_id,
53       jint quick_action_icon_resource_id,
54       jint arrow_up_resource_id,
55       jint drag_handlebar_resource_id,
56       jint open_tab_icon_resource_id,
57       jint close_icon_resource_id,
58       jint progress_bar_background_resource_id,
59       jint progress_bar_resource_id,
60       jint search_promo_resource_id,
61       jint bar_banner_ripple_resource_id,
62       jint bar_banner_text_resource_id,
63       jfloat dp_to_px,
64       jfloat layout_width,
65       jfloat layout_height,
66       jfloat base_page_brightness,
67       jfloat base_page_offset,
68       const base::android::JavaParamRef<jobject>& jweb_contents,
69       jboolean search_promo_visible,
70       jfloat search_promo_height,
71       jfloat search_promo_opacity,
72       jint search_prmomo_background_color,
73       jboolean search_bar_banner_visible,
74       jfloat search_bar_banner_height,
75       jfloat search_bar_banner_padding,
76       jfloat search_bar_banner_ripple_width,
77       jfloat search_bar_banner_ripple_opacity,
78       jfloat search_bar_banner_text_opacity,
79       jfloat search_panel_x,
80       jfloat search_panel_y,
81       jfloat search_panel_width,
82       jfloat search_panel_height,
83       jfloat search_bar_margin_side,
84       jfloat search_bar_margin_top,
85       jfloat search_bar_height,
86       jfloat search_context_opacity,
87       jfloat search_text_layer_min_height,
88       jfloat search_term_opacity,
89       jfloat search_term_caption_spacing,
90       jfloat search_caption_animation_percentage,
91       jboolean search_caption_visible,
92       jboolean search_bar_border_visible,
93       jfloat search_bar_border_height,
94       jboolean quick_action_icon_visible,
95       jboolean thumbnail_visible,
96       jstring j_thumbnail_url,
97       jfloat custom_image_visibility_percentage,
98       jint bar_image_size,
99       jint icon_color,
100       jint drag_handlebar_color,
101       jfloat arrow_icon_opacity,
102       jfloat arrow_icon_rotation,
103       jfloat close_icon_opacity,
104       jboolean progress_bar_visible,
105       jfloat progress_bar_height,
106       jfloat progress_bar_opacity,
107       jfloat progress_bar_completion,
108       jfloat divider_line_visibility_percentage,
109       jfloat divider_line_width,
110       jfloat divider_line_height,
111       jint divider_line_color,
112       jfloat divider_line_x_offset,
113       jboolean touch_highlight_visible,
114       jfloat touch_highlight_x_offset,
115       jfloat touch_highlight_width,
116       const base::android::JavaRef<jobject>& j_profile,
117       jint bar_background_resource_id,
118       jint separator_line_color);
119 
120   // Inherited from BitmapFetcherDelegate
121   void OnFetchComplete(
122       const GURL& url,
123       const SkBitmap* bitmap) override;
124 
125   void SetContentTree(
126       JNIEnv* env,
127       const base::android::JavaParamRef<jobject>& jobj,
128       const base::android::JavaParamRef<jobject>& jcontent_tree);
129 
130   void HideTree(
131       JNIEnv* env,
132       const base::android::JavaParamRef<jobject>& jobj);
133 
134  private:
135   void FetchThumbnail(const base::android::JavaRef<jobject>& j_profile);
136 
137   JNIEnv* env_;
138   base::android::ScopedJavaGlobalRef<jobject> object_;
139   std::string thumbnail_url_;
140   std::unique_ptr<BitmapFetcher> fetcher_;
141 
142   scoped_refptr<ContextualSearchLayer> contextual_search_layer_;
143   // Responsible for fading the base page content.
144   scoped_refptr<cc::SolidColorLayer> color_overlay_;
145   scoped_refptr<cc::Layer> content_container_;
146 
147   DISALLOW_COPY_AND_ASSIGN(ContextualSearchSceneLayer);
148 };
149 
150 }  // namespace android
151 
152 #endif  // CHROME_BROWSER_ANDROID_COMPOSITOR_SCENE_LAYER_CONTEXTUAL_SEARCH_SCENE_LAYER_H_
153