OLD | NEW |
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" |
(...skipping 20 matching lines...) Expand all Loading... |
31 return make_scoped_refptr(new ContextualSearchLayer(resource_manager)); | 31 return make_scoped_refptr(new ContextualSearchLayer(resource_manager)); |
32 } | 32 } |
33 | 33 |
34 void ContextualSearchLayer::SetProperties( | 34 void ContextualSearchLayer::SetProperties( |
35 int search_bar_background_resource_id, | 35 int search_bar_background_resource_id, |
36 int search_bar_text_resource_id, | 36 int search_bar_text_resource_id, |
37 int search_bar_shadow_resource_id, | 37 int search_bar_shadow_resource_id, |
38 int search_provider_icon_resource_id, | 38 int search_provider_icon_resource_id, |
39 int search_icon_resource_id, | 39 int search_icon_resource_id, |
40 int arrow_up_resource_id, | 40 int arrow_up_resource_id, |
| 41 int close_icon_resource_id, |
41 int progress_bar_background_resource_id, | 42 int progress_bar_background_resource_id, |
42 int progress_bar_resource_id, | 43 int progress_bar_resource_id, |
43 int search_promo_resource_id, | 44 int search_promo_resource_id, |
44 content::ContentViewCore* content_view_core, | 45 content::ContentViewCore* content_view_core, |
45 bool search_promo_visible, | 46 bool search_promo_visible, |
46 float search_promo_height, | 47 float search_promo_height, |
47 float search_promo_opacity, | 48 float search_promo_opacity, |
48 float search_panel_y, | 49 float search_panel_y, |
49 float search_panel_width, | 50 float search_panel_width, |
50 float search_bar_margin_top, | 51 float search_bar_margin_top, |
51 float search_bar_margin_side, | 52 float search_bar_margin_side, |
52 float search_bar_height, | 53 float search_bar_height, |
53 float search_bar_text_opacity, | 54 float search_bar_text_opacity, |
54 bool search_bar_border_visible, | 55 bool search_bar_border_visible, |
55 float search_bar_border_y, | 56 float search_bar_border_y, |
56 float search_bar_border_height, | 57 float search_bar_border_height, |
57 bool search_bar_shadow_visible, | 58 bool search_bar_shadow_visible, |
58 float search_bar_shadow_opacity, | 59 float search_bar_shadow_opacity, |
59 bool side_search_provider_icon_visible, | 60 bool side_search_provider_icon_visible, |
60 float search_provider_icon_opacity, | 61 float search_provider_icon_opacity, |
61 bool search_icon_visible, | 62 bool search_icon_visible, |
62 float search_icon_opacity, | 63 float search_icon_opacity, |
63 bool arrow_icon_visible, | 64 bool arrow_icon_visible, |
64 float arrow_icon_opacity, | 65 float arrow_icon_opacity, |
65 float arrow_icon_rotation, | 66 float arrow_icon_rotation, |
| 67 bool close_icon_visible, |
| 68 float close_icon_opacity, |
66 bool progress_bar_visible, | 69 bool progress_bar_visible, |
67 float progress_bar_y, | 70 float progress_bar_y, |
68 float progress_bar_height, | 71 float progress_bar_height, |
69 float progress_bar_opacity, | 72 float progress_bar_opacity, |
70 int progress_bar_completion) { | 73 int progress_bar_completion) { |
71 // Grabs the dynamic Search Bar Text resource. | 74 // Grabs the dynamic Search Bar Text resource. |
72 ui::ResourceManager::Resource* search_bar_text_resource = | 75 ui::ResourceManager::Resource* search_bar_text_resource = |
73 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, | 76 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, |
74 search_bar_text_resource_id); | 77 search_bar_text_resource_id); |
75 | 78 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 transform.RotateAboutZAxis(arrow_icon_rotation); | 228 transform.RotateAboutZAxis(arrow_icon_rotation); |
226 transform.Translate(-pivot_origin.x(), -pivot_origin.y()); | 229 transform.Translate(-pivot_origin.x(), -pivot_origin.y()); |
227 } | 230 } |
228 arrow_icon_->SetTransform(transform); | 231 arrow_icon_->SetTransform(transform); |
229 } else { | 232 } else { |
230 if (arrow_icon_.get() && arrow_icon_->parent()) | 233 if (arrow_icon_.get() && arrow_icon_->parent()) |
231 arrow_icon_->RemoveFromParent(); | 234 arrow_icon_->RemoveFromParent(); |
232 } | 235 } |
233 | 236 |
234 // --------------------------------------------------------------------------- | 237 // --------------------------------------------------------------------------- |
| 238 // Close Icon |
| 239 // --------------------------------------------------------------------------- |
| 240 if (close_icon_visible) { |
| 241 // Grab the Close Icon resource. |
| 242 ui::ResourceManager::Resource* close_icon_resource = |
| 243 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
| 244 close_icon_resource_id); |
| 245 if (close_icon_->parent() != layer_) { |
| 246 layer_->AddChild(close_icon_); |
| 247 } |
| 248 |
| 249 // Positions the icon at the end of the Search Bar. |
| 250 float close_icon_left; |
| 251 if (is_rtl) { |
| 252 close_icon_left = search_bar_margin_side; |
| 253 } else { |
| 254 close_icon_left = search_panel_width - |
| 255 close_icon_resource->size.width() - search_bar_margin_side; |
| 256 } |
| 257 |
| 258 // Centers the Close Icon vertically in the Search Bar. |
| 259 float close_icon_top = search_bar_margin_top + |
| 260 (search_bar_height - search_bar_margin_top) / 2 - |
| 261 close_icon_resource->size.height() / 2; |
| 262 |
| 263 close_icon_->SetUIResourceId(close_icon_resource->ui_resource->id()); |
| 264 close_icon_->SetBounds(close_icon_resource->size); |
| 265 close_icon_->SetPosition( |
| 266 gfx::PointF(close_icon_left, close_icon_top)); |
| 267 close_icon_->SetOpacity(close_icon_opacity); |
| 268 } else { |
| 269 if (close_icon_.get() && close_icon_->parent()) |
| 270 close_icon_->RemoveFromParent(); |
| 271 } |
| 272 |
| 273 // --------------------------------------------------------------------------- |
235 // Search Promo | 274 // Search Promo |
236 // --------------------------------------------------------------------------- | 275 // --------------------------------------------------------------------------- |
237 if (search_promo_visible) { | 276 if (search_promo_visible) { |
238 // Grabs the Search Opt Out Promo resource. | 277 // Grabs the Search Opt Out Promo resource. |
239 ui::ResourceManager::Resource* search_promo_resource = | 278 ui::ResourceManager::Resource* search_promo_resource = |
240 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, | 279 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, |
241 search_promo_resource_id); | 280 search_promo_resource_id); |
242 // Search Promo Container | 281 // Search Promo Container |
243 if (search_promo_container_->parent() != layer_) { | 282 if (search_promo_container_->parent() != layer_) { |
244 // NOTE(pedrosimonetti): The Promo layer should be always placed before | 283 // NOTE(pedrosimonetti): The Promo layer should be always placed before |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 search_bar_text_( | 432 search_bar_text_( |
394 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 433 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
395 search_bar_shadow_( | 434 search_bar_shadow_( |
396 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 435 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
397 search_provider_icon_( | 436 search_provider_icon_( |
398 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 437 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
399 search_icon_( | 438 search_icon_( |
400 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 439 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
401 arrow_icon_( | 440 arrow_icon_( |
402 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 441 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
| 442 close_icon_( |
| 443 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
403 content_view_container_( | 444 content_view_container_( |
404 cc::Layer::Create(content::Compositor::LayerSettings())), | 445 cc::Layer::Create(content::Compositor::LayerSettings())), |
405 search_bar_border_( | 446 search_bar_border_( |
406 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), | 447 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), |
407 progress_bar_( | 448 progress_bar_( |
408 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), | 449 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), |
409 progress_bar_background_( | 450 progress_bar_background_( |
410 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), | 451 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), |
411 search_promo_( | 452 search_promo_( |
412 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 453 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
(...skipping 14 matching lines...) Expand all Loading... |
427 // Search Provider Icon | 468 // Search Provider Icon |
428 search_provider_icon_->SetIsDrawable(true); | 469 search_provider_icon_->SetIsDrawable(true); |
429 layer_->AddChild(search_provider_icon_); | 470 layer_->AddChild(search_provider_icon_); |
430 | 471 |
431 // Search Icon | 472 // Search Icon |
432 search_icon_->SetIsDrawable(true); | 473 search_icon_->SetIsDrawable(true); |
433 | 474 |
434 // Arrow Icon | 475 // Arrow Icon |
435 arrow_icon_->SetIsDrawable(true); | 476 arrow_icon_->SetIsDrawable(true); |
436 | 477 |
| 478 // Close Icon |
| 479 close_icon_->SetIsDrawable(true); |
| 480 |
437 // Search Opt Out Promo | 481 // Search Opt Out Promo |
438 search_promo_container_->SetIsDrawable(true); | 482 search_promo_container_->SetIsDrawable(true); |
439 search_promo_container_->SetBackgroundColor(kSearchBackgroundColor); | 483 search_promo_container_->SetBackgroundColor(kSearchBackgroundColor); |
440 search_promo_->SetIsDrawable(true); | 484 search_promo_->SetIsDrawable(true); |
441 | 485 |
442 // Search Bar Border | 486 // Search Bar Border |
443 search_bar_border_->SetIsDrawable(true); | 487 search_bar_border_->SetIsDrawable(true); |
444 search_bar_border_->SetBackgroundColor(kSearchBarBorderColor); | 488 search_bar_border_->SetBackgroundColor(kSearchBarBorderColor); |
445 | 489 |
446 // Progress Bar Background | 490 // Progress Bar Background |
(...skipping 13 matching lines...) Expand all Loading... |
460 | 504 |
461 ContextualSearchLayer::~ContextualSearchLayer() { | 505 ContextualSearchLayer::~ContextualSearchLayer() { |
462 } | 506 } |
463 | 507 |
464 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() { | 508 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() { |
465 return layer_; | 509 return layer_; |
466 } | 510 } |
467 | 511 |
468 } // namespace android | 512 } // namespace android |
469 } // namespace chrome | 513 } // namespace chrome |
OLD | NEW |