Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(62)

Side by Side Diff: chrome/browser/android/compositor/layer/contextual_search_layer.cc

Issue 787023002: Upstream more layers, decoration title, layer_title_cache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: upstream resources as well Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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 #include "chrome/browser/android/compositor/layer/contextual_search_layer.h"
6
7 #include "cc/layers/layer.h"
8 #include "cc/layers/nine_patch_layer.h"
9 #include "cc/layers/solid_color_layer.h"
10 #include "cc/layers/ui_resource_layer.h"
11 #include "content/public/browser/android/content_view_core.h"
12 #include "third_party/skia/include/core/SkColor.h"
13 #include "ui/android/resources/resource_manager.h"
14 #include "ui/android/resources/ui_resource_android.h"
15
16 namespace {
17
18 const SkColor kContextualSearchBarBorderColor = SkColorSetRGB(0xf1, 0xf1, 0xf1);
19
20 } // namespace
21
22 namespace chrome {
23 namespace android {
24
25 // static
26 scoped_refptr<ContextualSearchLayer> ContextualSearchLayer::Create(
27 ui::ResourceManager* resource_manager) {
28 return make_scoped_refptr(new ContextualSearchLayer(resource_manager));
29 }
30
31 void ContextualSearchLayer::SetProperties(
32 int search_bar_background_resource_id,
33 int search_bar_text_resource_id,
34 int search_provider_icon_resource_id,
35 int search_icon_resource_id,
36 int progress_bar_background_resource_id,
37 int progress_bar_resource_id,
38 content::ContentViewCore* content_view_core,
39 float search_panel_y,
40 float search_panel_width,
41 float search_bar_margin_top,
42 float search_bar_height,
43 float search_bar_text_opacity,
44 bool search_bar_border_visible,
45 float search_bar_border_y,
46 float search_bar_border_height,
47 float search_provider_icon_opacity,
48 float search_icon_padding_left,
49 float search_icon_opacity,
50 bool progress_bar_visible,
51 float progress_bar_y,
52 float progress_bar_height,
53 float progress_bar_opacity,
54 int progress_bar_completion) {
55 // Grab the dynamic Search Bar Text resource.
56 ui::ResourceManager::Resource* search_bar_text_resource =
57 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC,
58 search_bar_text_resource_id);
59
60 // Grab required static resources.
61 ui::ResourceManager::Resource* search_bar_background_resource =
62 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC,
63 search_bar_background_resource_id);
64 ui::ResourceManager::Resource* search_provider_icon_resource =
65 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC,
66 search_provider_icon_resource_id);
67 ui::ResourceManager::Resource* search_icon_resource =
68 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC,
69 search_icon_resource_id);
70
71 DCHECK(search_bar_background_resource);
72 DCHECK(search_bar_text_resource);
73 DCHECK(search_provider_icon_resource);
74 DCHECK(search_icon_resource);
75
76 // ---------------------------------------------------------------------------
77 // Search Bar Background
78 // ---------------------------------------------------------------------------
79 gfx::Size background_size(search_panel_width, search_bar_height);
80 search_bar_background_->SetUIResourceId(
81 search_bar_background_resource->ui_resource->id());
82 search_bar_background_->SetBorder(
83 search_bar_background_resource->Border(background_size));
84 search_bar_background_->SetAperture(search_bar_background_resource->aperture);
85 search_bar_background_->SetBounds(background_size);
86
87 // ---------------------------------------------------------------------------
88 // Search Bar Text
89 // ---------------------------------------------------------------------------
90 // Centralizes the text vertically in the Search Bar.
91 float search_bar_padding_top =
92 search_bar_margin_top + (search_bar_height - search_bar_margin_top) / 2 -
93 search_bar_text_resource->size.height() / 2;
94 search_bar_text_->SetUIResourceId(
95 search_bar_text_resource->ui_resource->id());
96 search_bar_text_->SetBounds(search_bar_text_resource->size);
97 search_bar_text_->SetPosition(gfx::PointF(0.f, search_bar_padding_top));
98 search_bar_text_->SetOpacity(search_bar_text_opacity);
99
100 // ---------------------------------------------------------------------------
101 // Search Provider Icon
102 // ---------------------------------------------------------------------------
103 // Centralizes the Search Provider Icon horizontally in the Search Bar.
104 float search_provider_icon_left =
105 search_panel_width / 2.f -
106 search_provider_icon_resource->size.width() / 2.f;
107 search_provider_icon_->SetUIResourceId(
108 search_provider_icon_resource->ui_resource->id());
109 search_provider_icon_->SetBounds(search_provider_icon_resource->size);
110 search_provider_icon_->SetPosition(
111 gfx::PointF(search_provider_icon_left, 0.f));
112 search_provider_icon_->SetOpacity(search_provider_icon_opacity);
113
114 // ---------------------------------------------------------------------------
115 // Search Icon
116 // ---------------------------------------------------------------------------
117 // Centralizes the Search Icon vertically in the Search Bar.
118 float search_icon_padding_top =
119 search_bar_margin_top + (search_bar_height - search_bar_margin_top) / 2 -
120 search_icon_resource->size.height() / 2;
121 search_icon_->SetUIResourceId(search_icon_resource->ui_resource->id());
122 search_icon_->SetBounds(search_icon_resource->size);
123 search_icon_->SetPosition(
124 gfx::PointF(search_icon_padding_left, search_icon_padding_top));
125 search_icon_->SetOpacity(search_icon_opacity);
126
127 // ---------------------------------------------------------------------------
128 // Search Content View
129 // ---------------------------------------------------------------------------
130 content_view_container_->SetPosition(gfx::PointF(0.f, search_bar_height));
131 if (content_view_core && content_view_core->GetLayer().get()) {
132 scoped_refptr<cc::Layer> content_view_layer = content_view_core->GetLayer();
133 if (content_view_layer->parent() != content_view_container_)
134 content_view_container_->AddChild(content_view_layer);
135 } else {
136 content_view_container_->RemoveAllChildren();
137 }
138
139 // ---------------------------------------------------------------------------
140 // Search Panel.
141 // ---------------------------------------------------------------------------
142 layer_->SetPosition(gfx::PointF(0.f, search_panel_y));
143
144 // ---------------------------------------------------------------------------
145 // Progress Bar
146 // ---------------------------------------------------------------------------
147 bool should_render_progress_bar =
148 progress_bar_visible && progress_bar_opacity > 0.f;
149 if (should_render_progress_bar) {
150 // Load Progress Bar resources.
151 ui::ResourceManager::Resource* progress_bar_background_resource =
152 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC,
153 progress_bar_background_resource_id);
154 ui::ResourceManager::Resource* progress_bar_resource =
155 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC,
156 progress_bar_resource_id);
157
158 DCHECK(progress_bar_background_resource);
159 DCHECK(progress_bar_resource);
160
161 // Progress Bar Background
162 if (progress_bar_background_->parent() != layer_)
163 layer_->AddChild(progress_bar_background_);
164
165 gfx::Size progress_bar_background_size(search_panel_width,
166 progress_bar_height);
167 progress_bar_background_->SetUIResourceId(
168 progress_bar_background_resource->ui_resource->id());
169 progress_bar_background_->SetBorder(
170 progress_bar_background_resource->Border(progress_bar_background_size));
171 progress_bar_background_->SetAperture(
172 progress_bar_background_resource->aperture);
173 progress_bar_background_->SetBounds(progress_bar_background_size);
174 progress_bar_background_->SetPosition(gfx::PointF(0.f, progress_bar_y));
175 progress_bar_background_->SetOpacity(progress_bar_opacity);
176
177 // Progress Bar
178 if (progress_bar_->parent() != layer_) {
179 layer_->AddChild(progress_bar_);
180 }
181 float progress_bar_width =
182 floor(search_panel_width * progress_bar_completion / 100.f);
183 gfx::Size progress_bar_size(progress_bar_width, progress_bar_height);
184 progress_bar_->SetUIResourceId(progress_bar_resource->ui_resource->id());
185 progress_bar_->SetBorder(progress_bar_resource->Border(progress_bar_size));
186 progress_bar_->SetAperture(progress_bar_resource->aperture);
187 progress_bar_->SetBounds(progress_bar_size);
188 progress_bar_->SetPosition(gfx::PointF(0.f, progress_bar_y));
189 progress_bar_->SetOpacity(progress_bar_opacity);
190 } else {
191 // Removes Progress Bar and its Background from the Layer Tree.
192 if (progress_bar_background_.get() && progress_bar_background_->parent())
193 progress_bar_background_->RemoveFromParent();
194
195 if (progress_bar_.get() && progress_bar_->parent())
196 progress_bar_->RemoveFromParent();
197 }
198
199 // ---------------------------------------------------------------------------
200 // Search Bar border.
201 // ---------------------------------------------------------------------------
202 if (!should_render_progress_bar && search_bar_border_visible) {
203 gfx::Size search_bar_border_size(search_panel_width,
204 search_bar_border_height);
205 search_bar_border_->SetBounds(search_bar_border_size);
206 search_bar_border_->SetPosition(gfx::PointF(0.f, search_bar_border_y));
207 layer_->AddChild(search_bar_border_);
208 } else if (search_bar_border_.get() && search_bar_border_->parent()) {
209 search_bar_border_->RemoveFromParent();
210 }
211 }
212
213 ContextualSearchLayer::ContextualSearchLayer(
214 ui::ResourceManager* resource_manager)
215 : resource_manager_(resource_manager),
216 layer_(cc::Layer::Create()),
217 search_bar_background_(cc::NinePatchLayer::Create()),
218 search_bar_text_(cc::UIResourceLayer::Create()),
219 search_provider_icon_(cc::UIResourceLayer::Create()),
220 search_icon_(cc::UIResourceLayer::Create()),
221 content_view_container_(cc::Layer::Create()),
222 search_bar_border_(cc::SolidColorLayer::Create()),
223 progress_bar_(cc::NinePatchLayer::Create()),
224 progress_bar_background_(cc::NinePatchLayer::Create()) {
225 layer_->SetMasksToBounds(false);
226 layer_->SetIsDrawable(true);
227
228 // Search Bar Background
229 search_bar_background_->SetIsDrawable(true);
230 search_bar_background_->SetFillCenter(true);
231 layer_->AddChild(search_bar_background_);
232
233 // Search Bar Text
234 search_bar_text_->SetIsDrawable(true);
235 layer_->AddChild(search_bar_text_);
236
237 // Search Provider Icon
238 search_provider_icon_->SetIsDrawable(true);
239 layer_->AddChild(search_provider_icon_);
240
241 // Search Icon
242 search_icon_->SetIsDrawable(true);
243 layer_->AddChild(search_icon_);
244
245 // Search Bar Border
246 search_bar_border_->SetIsDrawable(true);
247 search_bar_border_->SetBackgroundColor(kContextualSearchBarBorderColor);
248
249 // Progress Bar Background
250 progress_bar_background_->SetIsDrawable(true);
251 progress_bar_background_->SetFillCenter(true);
252
253 // Progress Bar
254 progress_bar_->SetIsDrawable(true);
255 progress_bar_->SetFillCenter(true);
256
257 // Search Content View
258 layer_->AddChild(content_view_container_);
259 }
260
261 ContextualSearchLayer::~ContextualSearchLayer() {
262 }
263
264 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() {
265 return layer_;
266 }
267
268 } // namespace android
269 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698