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

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

Issue 1050163004: [Contextual Search] Implements Opt-out promo. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactoring Created 5 years, 8 months 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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/layer/contextual_search_layer.h" 5 #include "chrome/browser/android/compositor/layer/contextual_search_layer.h"
6 6
7 #include "cc/layers/layer.h" 7 #include "cc/layers/layer.h"
8 #include "cc/layers/nine_patch_layer.h" 8 #include "cc/layers/nine_patch_layer.h"
9 #include "cc/layers/solid_color_layer.h" 9 #include "cc/layers/solid_color_layer.h"
10 #include "cc/layers/ui_resource_layer.h" 10 #include "cc/layers/ui_resource_layer.h"
11 #include "content/public/browser/android/content_view_core.h" 11 #include "content/public/browser/android/content_view_core.h"
12 #include "third_party/skia/include/core/SkColor.h" 12 #include "third_party/skia/include/core/SkColor.h"
13 #include "ui/android/resources/resource_manager.h" 13 #include "ui/android/resources/resource_manager.h"
14 #include "ui/android/resources/ui_resource_android.h" 14 #include "ui/android/resources/ui_resource_android.h"
15 15
16 namespace { 16 namespace {
17 17
18 const SkColor kContextualSearchBarBorderColor = SkColorSetRGB(0xf1, 0xf1, 0xf1); 18 const SkColor kSearchBackgroundColor = SkColorSetRGB(0xee, 0xee, 0xee);
19 const SkColor kSearchBarBorderColor = SkColorSetRGB(0xf1, 0xf1, 0xf1);
19 20
20 } // namespace 21 } // namespace
21 22
22 namespace chrome { 23 namespace chrome {
23 namespace android { 24 namespace android {
24 25
25 // static 26 // static
26 scoped_refptr<ContextualSearchLayer> ContextualSearchLayer::Create( 27 scoped_refptr<ContextualSearchLayer> ContextualSearchLayer::Create(
27 ui::ResourceManager* resource_manager) { 28 ui::ResourceManager* resource_manager) {
28 return make_scoped_refptr(new ContextualSearchLayer(resource_manager)); 29 return make_scoped_refptr(new ContextualSearchLayer(resource_manager));
29 } 30 }
30 31
31 void ContextualSearchLayer::SetProperties( 32 void ContextualSearchLayer::SetProperties(
32 int search_bar_background_resource_id, 33 int search_bar_background_resource_id,
33 int search_bar_text_resource_id, 34 int search_bar_text_resource_id,
35 int search_bar_shadow_resource_id,
34 int search_provider_icon_resource_id, 36 int search_provider_icon_resource_id,
35 int search_icon_resource_id, 37 int search_icon_resource_id,
36 int progress_bar_background_resource_id, 38 int progress_bar_background_resource_id,
37 int progress_bar_resource_id, 39 int progress_bar_resource_id,
40 int search_promo_resource_id,
38 content::ContentViewCore* content_view_core, 41 content::ContentViewCore* content_view_core,
42 bool search_promo_visible,
43 float search_promo_height,
44 float search_promo_opacity,
39 float search_panel_y, 45 float search_panel_y,
40 float search_panel_width, 46 float search_panel_width,
41 float search_bar_margin_top, 47 float search_bar_margin_top,
42 float search_bar_height, 48 float search_bar_height,
43 float search_bar_text_opacity, 49 float search_bar_text_opacity,
44 bool search_bar_border_visible, 50 bool search_bar_border_visible,
45 float search_bar_border_y, 51 float search_bar_border_y,
46 float search_bar_border_height, 52 float search_bar_border_height,
53 bool search_bar_shadow_visible,
54 float search_bar_shadow_opacity,
47 float search_provider_icon_opacity, 55 float search_provider_icon_opacity,
48 float search_icon_padding_left, 56 float search_icon_padding_left,
49 float search_icon_opacity, 57 float search_icon_opacity,
50 bool progress_bar_visible, 58 bool progress_bar_visible,
51 float progress_bar_y, 59 float progress_bar_y,
52 float progress_bar_height, 60 float progress_bar_height,
53 float progress_bar_opacity, 61 float progress_bar_opacity,
54 int progress_bar_completion) { 62 int progress_bar_completion) {
55 // Grab the dynamic Search Bar Text resource. 63 // Grab the dynamic Search Bar Text resource.
56 ui::ResourceManager::Resource* search_bar_text_resource = 64 ui::ResourceManager::Resource* search_bar_text_resource =
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 float search_icon_padding_top = 132 float search_icon_padding_top =
125 search_bar_margin_top + (search_bar_height - search_bar_margin_top) / 2 - 133 search_bar_margin_top + (search_bar_height - search_bar_margin_top) / 2 -
126 search_icon_resource->size.height() / 2; 134 search_icon_resource->size.height() / 2;
127 search_icon_->SetUIResourceId(search_icon_resource->ui_resource->id()); 135 search_icon_->SetUIResourceId(search_icon_resource->ui_resource->id());
128 search_icon_->SetBounds(search_icon_resource->size); 136 search_icon_->SetBounds(search_icon_resource->size);
129 search_icon_->SetPosition( 137 search_icon_->SetPosition(
130 gfx::PointF(search_icon_padding_left, search_icon_padding_top)); 138 gfx::PointF(search_icon_padding_left, search_icon_padding_top));
131 search_icon_->SetOpacity(search_icon_opacity); 139 search_icon_->SetOpacity(search_icon_opacity);
132 140
133 // --------------------------------------------------------------------------- 141 // ---------------------------------------------------------------------------
142 // Search Promo
143 // ---------------------------------------------------------------------------
144 if (search_promo_visible) {
145 // Grab the Search Opt Out Promo resource.
146 ui::ResourceManager::Resource* search_promo_resource =
147 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC,
148 search_promo_resource_id);
149
150 if (search_promo_resource) {
151 // Search Promo Container
152 if (search_promo_container_->parent() != layer_)
153 layer_->AddChild(search_promo_container_);
154
155 int search_promo_content_height = search_promo_resource->size.height();
156 gfx::Size search_promo_size(search_panel_width, search_promo_height);
157 search_promo_container_->SetBounds(search_promo_size);
158 search_promo_container_->SetPosition(gfx::PointF(0.f, search_bar_height));
159 search_promo_container_->SetMasksToBounds(true);
160
161 // Search Promo
162 if (search_promo_->parent() != search_promo_container_)
163 search_promo_container_->AddChild(search_promo_);
164
165 search_promo_->SetUIResourceId(search_promo_resource->ui_resource->id());
166 search_promo_->SetBounds(search_promo_resource->size);
167 // Align promo at the bottom of the container so the confirmation button
168 // is is not clipped when resizing the promo.
169 search_promo_->SetPosition(
170 gfx::PointF(0.f, search_promo_height - search_promo_content_height));
171 search_promo_->SetOpacity(search_promo_opacity);
172 }
173 } else {
174 // Search Promo
175 if (search_promo_.get() && search_promo_->parent())
David Trainor- moved to gerrit 2015/04/02 20:38:24 Don't need these if checks right?
pedro (no code reviews) 2015/04/03 21:01:02 Acknowledged.
176 search_promo_->RemoveFromParent();
David Trainor- moved to gerrit 2015/04/02 20:38:24 Do we need this call?
pedro (no code reviews) 2015/04/03 21:01:02 Are you saying that removing the parent is enough?
177
178 // Search Promo Container
179 if (search_promo_container_.get() && search_promo_container_->parent())
180 search_promo_container_->RemoveFromParent();
181 }
182
183 // ---------------------------------------------------------------------------
134 // Search Content View 184 // Search Content View
135 // --------------------------------------------------------------------------- 185 // ---------------------------------------------------------------------------
136 content_view_container_->SetPosition(gfx::PointF(0.f, search_bar_height)); 186 content_view_container_->SetPosition(
187 gfx::PointF(0.f, search_bar_height + search_promo_height));
137 if (content_view_core && content_view_core->GetLayer().get()) { 188 if (content_view_core && content_view_core->GetLayer().get()) {
138 scoped_refptr<cc::Layer> content_view_layer = content_view_core->GetLayer(); 189 scoped_refptr<cc::Layer> content_view_layer = content_view_core->GetLayer();
139 if (content_view_layer->parent() != content_view_container_) 190 if (content_view_layer->parent() != content_view_container_)
140 content_view_container_->AddChild(content_view_layer); 191 content_view_container_->AddChild(content_view_layer);
141 } else { 192 } else {
142 content_view_container_->RemoveAllChildren(); 193 content_view_container_->RemoveAllChildren();
143 } 194 }
144 195
145 // --------------------------------------------------------------------------- 196 // ---------------------------------------------------------------------------
197 // Search Bar Shadow
198 // ---------------------------------------------------------------------------
199 if (search_bar_shadow_visible) {
200 ui::ResourceManager::Resource* search_bar_shadow_resource =
201 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC,
202 search_bar_shadow_resource_id);
203
204 if (search_bar_shadow_resource) {
205 if (search_bar_shadow_->parent() != layer_)
206 layer_->AddChild(search_bar_shadow_);
207 }
208
209 int shadow_height = search_bar_shadow_resource->size.height();
210 gfx::Size shadow_size(search_panel_width, shadow_height);
211
212 search_bar_shadow_->SetUIResourceId(
213 search_bar_shadow_resource->ui_resource->id());
214 search_bar_shadow_->SetBounds(shadow_size);
215 search_bar_shadow_->SetPosition(gfx::PointF(0.f, search_bar_height));
216 search_bar_shadow_->SetOpacity(1.f);
217 } else {
218 if (search_bar_shadow_.get() && search_bar_shadow_->parent())
219 search_bar_shadow_->RemoveFromParent();
220 }
221
222 // ---------------------------------------------------------------------------
146 // Search Panel. 223 // Search Panel.
147 // --------------------------------------------------------------------------- 224 // ---------------------------------------------------------------------------
148 layer_->SetPosition(gfx::PointF(0.f, search_panel_y)); 225 layer_->SetPosition(gfx::PointF(0.f, search_panel_y));
149 226
150 // --------------------------------------------------------------------------- 227 // ---------------------------------------------------------------------------
151 // Progress Bar 228 // Progress Bar
152 // --------------------------------------------------------------------------- 229 // ---------------------------------------------------------------------------
153 bool should_render_progress_bar = 230 bool should_render_progress_bar =
154 progress_bar_visible && progress_bar_opacity > 0.f; 231 progress_bar_visible && progress_bar_opacity > 0.f;
155 if (should_render_progress_bar) { 232 if (should_render_progress_bar) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 search_bar_border_->RemoveFromParent(); 292 search_bar_border_->RemoveFromParent();
216 } 293 }
217 } 294 }
218 295
219 ContextualSearchLayer::ContextualSearchLayer( 296 ContextualSearchLayer::ContextualSearchLayer(
220 ui::ResourceManager* resource_manager) 297 ui::ResourceManager* resource_manager)
221 : resource_manager_(resource_manager), 298 : resource_manager_(resource_manager),
222 layer_(cc::Layer::Create()), 299 layer_(cc::Layer::Create()),
223 search_bar_background_(cc::NinePatchLayer::Create()), 300 search_bar_background_(cc::NinePatchLayer::Create()),
224 search_bar_text_(cc::UIResourceLayer::Create()), 301 search_bar_text_(cc::UIResourceLayer::Create()),
302 search_bar_shadow_(cc::UIResourceLayer::Create()),
225 search_provider_icon_(cc::UIResourceLayer::Create()), 303 search_provider_icon_(cc::UIResourceLayer::Create()),
226 search_icon_(cc::UIResourceLayer::Create()), 304 search_icon_(cc::UIResourceLayer::Create()),
227 content_view_container_(cc::Layer::Create()), 305 content_view_container_(cc::Layer::Create()),
228 search_bar_border_(cc::SolidColorLayer::Create()), 306 search_bar_border_(cc::SolidColorLayer::Create()),
229 progress_bar_(cc::NinePatchLayer::Create()), 307 progress_bar_(cc::NinePatchLayer::Create()),
230 progress_bar_background_(cc::NinePatchLayer::Create()) { 308 progress_bar_background_(cc::NinePatchLayer::Create()),
309 search_promo_(cc::UIResourceLayer::Create()),
310 search_promo_container_(cc::SolidColorLayer::Create()) {
231 layer_->SetMasksToBounds(false); 311 layer_->SetMasksToBounds(false);
232 layer_->SetIsDrawable(true); 312 layer_->SetIsDrawable(true);
233 313
234 // Search Bar Background 314 // Search Bar Background
235 search_bar_background_->SetIsDrawable(true); 315 search_bar_background_->SetIsDrawable(true);
236 search_bar_background_->SetFillCenter(true); 316 search_bar_background_->SetFillCenter(true);
237 layer_->AddChild(search_bar_background_); 317 layer_->AddChild(search_bar_background_);
238 318
239 // Search Bar Text 319 // Search Bar Text
240 search_bar_text_->SetIsDrawable(true); 320 search_bar_text_->SetIsDrawable(true);
241 layer_->AddChild(search_bar_text_); 321 layer_->AddChild(search_bar_text_);
242 322
243 // Search Provider Icon 323 // Search Provider Icon
244 search_provider_icon_->SetIsDrawable(true); 324 search_provider_icon_->SetIsDrawable(true);
245 layer_->AddChild(search_provider_icon_); 325 layer_->AddChild(search_provider_icon_);
246 326
247 // Search Icon 327 // Search Icon
248 search_icon_->SetIsDrawable(true); 328 search_icon_->SetIsDrawable(true);
249 layer_->AddChild(search_icon_); 329 layer_->AddChild(search_icon_);
250 330
331 // Search Opt Out Promo
332 search_promo_container_->SetIsDrawable(true);
333 search_promo_container_->SetBackgroundColor(kSearchBackgroundColor);
334 search_promo_->SetIsDrawable(true);
335
251 // Search Bar Border 336 // Search Bar Border
252 search_bar_border_->SetIsDrawable(true); 337 search_bar_border_->SetIsDrawable(true);
253 search_bar_border_->SetBackgroundColor(kContextualSearchBarBorderColor); 338 search_bar_border_->SetBackgroundColor(kSearchBarBorderColor);
254 339
255 // Progress Bar Background 340 // Progress Bar Background
256 progress_bar_background_->SetIsDrawable(true); 341 progress_bar_background_->SetIsDrawable(true);
257 progress_bar_background_->SetFillCenter(true); 342 progress_bar_background_->SetFillCenter(true);
258 343
259 // Progress Bar 344 // Progress Bar
260 progress_bar_->SetIsDrawable(true); 345 progress_bar_->SetIsDrawable(true);
261 progress_bar_->SetFillCenter(true); 346 progress_bar_->SetFillCenter(true);
262 347
263 // Search Content View 348 // Search Content View Container
264 layer_->AddChild(content_view_container_); 349 layer_->AddChild(content_view_container_);
350
351 // Search Bar Shadow
352 search_bar_shadow_->SetIsDrawable(true);
265 } 353 }
266 354
267 ContextualSearchLayer::~ContextualSearchLayer() { 355 ContextualSearchLayer::~ContextualSearchLayer() {
268 } 356 }
269 357
270 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() { 358 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() {
271 return layer_; 359 return layer_;
272 } 360 }
273 361
274 } // namespace android 362 } // namespace android
275 } // namespace chrome 363 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698