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" |
11 #include "cc/resources/scoped_ui_resource.h" | 11 #include "cc/resources/scoped_ui_resource.h" |
| 12 #include "chrome/browser/android/compositor/layer/crushed_sprite_layer.h" |
12 #include "content/public/browser/android/compositor.h" | 13 #include "content/public/browser/android/compositor.h" |
13 #include "content/public/browser/android/content_view_core.h" | 14 #include "content/public/browser/android/content_view_core.h" |
14 #include "third_party/skia/include/core/SkColor.h" | 15 #include "third_party/skia/include/core/SkColor.h" |
| 16 #include "ui/android/resources/crushed_sprite_resource.h" |
15 #include "ui/android/resources/resource_manager.h" | 17 #include "ui/android/resources/resource_manager.h" |
16 #include "ui/base/l10n/l10n_util_android.h" | 18 #include "ui/base/l10n/l10n_util_android.h" |
17 #include "ui/gfx/color_utils.h" | 19 #include "ui/gfx/color_utils.h" |
18 | 20 |
19 namespace { | 21 namespace { |
20 | 22 |
21 const SkColor kSearchBackgroundColor = SkColorSetRGB(0xee, 0xee, 0xee); | 23 const SkColor kSearchBackgroundColor = SkColorSetRGB(0xee, 0xee, 0xee); |
22 const SkColor kSearchBarBackgroundColor = SkColorSetRGB(0xff, 0xff, 0xff); | 24 const SkColor kSearchBarBackgroundColor = SkColorSetRGB(0xff, 0xff, 0xff); |
23 const SkColor kSearchBarBorderColor = SkColorSetRGB(0xf1, 0xf1, 0xf1); | 25 const SkColor kSearchBarBorderColor = SkColorSetRGB(0xf1, 0xf1, 0xf1); |
24 const SkColor kPeekPromoRippleBackgroundColor = SkColorSetRGB(0x42, 0x85, 0xF4); | 26 const SkColor kPeekPromoRippleBackgroundColor = SkColorSetRGB(0x42, 0x85, 0xF4); |
(...skipping 11 matching lines...) Expand all Loading... |
36 scoped_refptr<ContextualSearchLayer> ContextualSearchLayer::Create( | 38 scoped_refptr<ContextualSearchLayer> ContextualSearchLayer::Create( |
37 ui::ResourceManager* resource_manager) { | 39 ui::ResourceManager* resource_manager) { |
38 return make_scoped_refptr(new ContextualSearchLayer(resource_manager)); | 40 return make_scoped_refptr(new ContextualSearchLayer(resource_manager)); |
39 } | 41 } |
40 | 42 |
41 void ContextualSearchLayer::SetProperties( | 43 void ContextualSearchLayer::SetProperties( |
42 int panel_shadow_resource_id, | 44 int panel_shadow_resource_id, |
43 int search_context_resource_id, | 45 int search_context_resource_id, |
44 int search_term_resource_id, | 46 int search_term_resource_id, |
45 int search_bar_shadow_resource_id, | 47 int search_bar_shadow_resource_id, |
46 int search_provider_icon_resource_id, | 48 int panel_icon_resource_id, |
47 int arrow_up_resource_id, | 49 int arrow_up_resource_id, |
48 int close_icon_resource_id, | 50 int close_icon_resource_id, |
49 int progress_bar_background_resource_id, | 51 int progress_bar_background_resource_id, |
50 int progress_bar_resource_id, | 52 int progress_bar_resource_id, |
51 int search_promo_resource_id, | 53 int search_promo_resource_id, |
52 int peek_promo_ripple_resource_id, | 54 int peek_promo_ripple_resource_id, |
53 int peek_promo_text_resource_id, | 55 int peek_promo_text_resource_id, |
| 56 int search_provider_icon_sprite_bitmap_resource_id, |
| 57 int search_provider_icon_sprite_metadata_resource_id, |
54 content::ContentViewCore* content_view_core, | 58 content::ContentViewCore* content_view_core, |
55 bool search_promo_visible, | 59 bool search_promo_visible, |
56 float search_promo_height, | 60 float search_promo_height, |
57 float search_promo_opacity, | 61 float search_promo_opacity, |
58 bool search_peek_promo_visible, | 62 bool search_peek_promo_visible, |
59 float search_peek_promo_height, | 63 float search_peek_promo_height, |
60 float search_peek_promo_padding, | 64 float search_peek_promo_padding, |
61 float search_peek_promo_ripple_width, | 65 float search_peek_promo_ripple_width, |
62 float search_peek_promo_ripple_opacity, | 66 float search_peek_promo_ripple_opacity, |
63 float search_peek_promo_text_opacity, | 67 float search_peek_promo_text_opacity, |
64 float search_panel_x, | 68 float search_panel_x, |
65 float search_panel_y, | 69 float search_panel_y, |
66 float search_panel_width, | 70 float search_panel_width, |
67 float search_panel_height, | 71 float search_panel_height, |
68 float search_bar_margin_side, | 72 float search_bar_margin_side, |
69 float search_bar_height, | 73 float search_bar_height, |
70 float search_context_opacity, | 74 float search_context_opacity, |
71 float search_term_opacity, | 75 float search_term_opacity, |
72 bool search_bar_border_visible, | 76 bool search_bar_border_visible, |
73 float search_bar_border_height, | 77 float search_bar_border_height, |
74 bool search_bar_shadow_visible, | 78 bool search_bar_shadow_visible, |
75 float search_bar_shadow_opacity, | 79 float search_bar_shadow_opacity, |
| 80 bool search_provider_icon_sprite_visible, |
| 81 float search_provider_icon_sprite_completion_percentage, |
| 82 float search_provider_icon_sprite_size, |
76 float arrow_icon_opacity, | 83 float arrow_icon_opacity, |
77 float arrow_icon_rotation, | 84 float arrow_icon_rotation, |
78 float close_icon_opacity, | 85 float close_icon_opacity, |
79 bool progress_bar_visible, | 86 bool progress_bar_visible, |
80 float progress_bar_height, | 87 float progress_bar_height, |
81 float progress_bar_opacity, | 88 float progress_bar_opacity, |
82 int progress_bar_completion) { | 89 int progress_bar_completion) { |
83 // Grabs the dynamic Search Bar Text resource. | 90 // Grabs the dynamic Search Bar Text resource. |
84 ui::ResourceManager::Resource* search_context_resource = | 91 ui::ResourceManager::Resource* search_context_resource = |
85 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, | 92 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, |
86 search_context_resource_id); | 93 search_context_resource_id); |
87 ui::ResourceManager::Resource* search_term_resource = | 94 ui::ResourceManager::Resource* search_term_resource = |
88 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, | 95 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, |
89 search_term_resource_id); | 96 search_term_resource_id); |
90 | 97 |
91 // Grabs required static resources. | 98 // Grabs required static resources. |
92 ui::ResourceManager::Resource* panel_shadow_resource = | 99 ui::ResourceManager::Resource* panel_shadow_resource = |
93 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 100 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
94 panel_shadow_resource_id); | 101 panel_shadow_resource_id); |
95 ui::ResourceManager::Resource* search_provider_icon_resource = | |
96 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | |
97 search_provider_icon_resource_id); | |
98 | 102 |
99 DCHECK(panel_shadow_resource); | 103 DCHECK(panel_shadow_resource); |
100 DCHECK(search_provider_icon_resource); | |
101 | 104 |
102 // Round values to avoid pixel gap between layers. | 105 // Round values to avoid pixel gap between layers. |
103 search_bar_height = floor(search_bar_height); | 106 search_bar_height = floor(search_bar_height); |
104 | 107 |
105 float search_bar_top = search_peek_promo_height; | 108 float search_bar_top = search_peek_promo_height; |
106 float search_bar_bottom = search_bar_top + search_bar_height; | 109 float search_bar_bottom = search_bar_top + search_bar_height; |
107 | 110 |
108 bool is_rtl = l10n_util::IsLayoutRtl(); | 111 bool is_rtl = l10n_util::IsLayoutRtl(); |
109 | 112 |
| 113 // If |panel_icon_resource_id| != 0, the static resource associated with that |
| 114 // id will be displayed. If |panel_icon_resource_id| == 0, then the |
| 115 // search provider icon sprite will be shown instead. |
| 116 bool should_use_static_icon = panel_icon_resource_id != 0; |
| 117 |
110 // --------------------------------------------------------------------------- | 118 // --------------------------------------------------------------------------- |
111 // Panel Shadow | 119 // Panel Shadow |
112 // --------------------------------------------------------------------------- | 120 // --------------------------------------------------------------------------- |
113 gfx::Size shadow_res_size = panel_shadow_resource->size; | 121 gfx::Size shadow_res_size = panel_shadow_resource->size; |
114 gfx::Rect shadow_res_padding = panel_shadow_resource->padding; | 122 gfx::Rect shadow_res_padding = panel_shadow_resource->padding; |
115 gfx::Size shadow_bounds( | 123 gfx::Size shadow_bounds( |
116 search_panel_width + shadow_res_size.width() | 124 search_panel_width + shadow_res_size.width() |
117 - shadow_res_padding.size().width(), | 125 - shadow_res_padding.size().width(), |
118 search_panel_height + shadow_res_size.height() | 126 search_panel_height + shadow_res_size.height() |
119 - shadow_res_padding.size().height()); | 127 - shadow_res_padding.size().height()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 160 |
153 // Apply a blend based on the ripple opacity. The resulting color will | 161 // Apply a blend based on the ripple opacity. The resulting color will |
154 // be an interpolation between the background color of the Search Bar and | 162 // be an interpolation between the background color of the Search Bar and |
155 // a lighter shade of the background color of the Ripple. The range of | 163 // a lighter shade of the background color of the Ripple. The range of |
156 // the alpha value used in the blend will be: | 164 // the alpha value used in the blend will be: |
157 // [0.f, kPeekPromoBackgroundMaximumAlphaBlend] | 165 // [0.f, kPeekPromoBackgroundMaximumAlphaBlend] |
158 peek_promo_container_->SetBackgroundColor( | 166 peek_promo_container_->SetBackgroundColor( |
159 color_utils::AlphaBlend(kPeekPromoRippleBackgroundColor, | 167 color_utils::AlphaBlend(kPeekPromoRippleBackgroundColor, |
160 kSearchBarBackgroundColor, | 168 kSearchBarBackgroundColor, |
161 kPeekPromoBackgroundMaximumAlphaBlend * | 169 kPeekPromoBackgroundMaximumAlphaBlend * |
162 search_peek_promo_ripple_opacity | 170 search_peek_promo_ripple_opacity)); |
163 )); | |
164 | 171 |
165 // ----------------------------------------------------------------- | 172 // ----------------------------------------------------------------- |
166 // Peek Promo Ripple | 173 // Peek Promo Ripple |
167 // ----------------------------------------------------------------- | 174 // ----------------------------------------------------------------- |
168 gfx::Size peek_promo_ripple_size( | 175 gfx::Size peek_promo_ripple_size( |
169 search_peek_promo_ripple_width, search_peek_promo_height); | 176 search_peek_promo_ripple_width, search_peek_promo_height); |
170 gfx::Rect peek_promo_ripple_border( | 177 gfx::Rect peek_promo_ripple_border( |
171 peek_promo_ripple_resource->Border(peek_promo_ripple_size)); | 178 peek_promo_ripple_resource->Border(peek_promo_ripple_size)); |
172 | 179 |
173 // Add padding so the ripple will occupy the whole width at 100%. | 180 // Add padding so the ripple will occupy the whole width at 100%. |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 search_bar_top + | 255 search_bar_top + |
249 search_bar_height / 2 - | 256 search_bar_height / 2 - |
250 search_term_resource->size.height() / 2; | 257 search_term_resource->size.height() / 2; |
251 search_term_->SetUIResourceId(search_term_resource->ui_resource->id()); | 258 search_term_->SetUIResourceId(search_term_resource->ui_resource->id()); |
252 search_term_->SetBounds(search_term_resource->size); | 259 search_term_->SetBounds(search_term_resource->size); |
253 search_term_->SetPosition(gfx::PointF(0.f, search_bar_padding_top)); | 260 search_term_->SetPosition(gfx::PointF(0.f, search_bar_padding_top)); |
254 search_term_->SetOpacity(search_term_opacity); | 261 search_term_->SetOpacity(search_term_opacity); |
255 } | 262 } |
256 | 263 |
257 // --------------------------------------------------------------------------- | 264 // --------------------------------------------------------------------------- |
258 // Search Provider Icon | 265 // Panel Icon (Static) |
259 // --------------------------------------------------------------------------- | 266 // --------------------------------------------------------------------------- |
260 // Positions the Search Provider Icon at the start of the Search Bar. | 267 if (should_use_static_icon) { |
261 float search_provider_icon_left; | 268 if (panel_icon_->parent() != layer_) { |
262 if (is_rtl) { | 269 layer_->AddChild(panel_icon_); |
263 search_provider_icon_left = search_panel_width - | 270 } |
264 search_provider_icon_resource->size.width() - search_bar_margin_side; | 271 ui::ResourceManager::Resource* panel_icon_resource = |
265 } else { | 272 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
266 search_provider_icon_left = search_bar_margin_side; | 273 panel_icon_resource_id); |
| 274 DCHECK(panel_icon_resource); |
| 275 |
| 276 // Positions the Icon at the start of the Search Bar. |
| 277 float search_provider_icon_left; |
| 278 if (is_rtl) { |
| 279 search_provider_icon_left = search_panel_width - |
| 280 panel_icon_resource->size.width() - search_bar_margin_side; |
| 281 } else { |
| 282 search_provider_icon_left = search_bar_margin_side; |
| 283 } |
| 284 |
| 285 // Centers the Icon vertically in the Search Bar. |
| 286 float search_provider_icon_top = search_bar_top + |
| 287 search_bar_height / 2 - |
| 288 panel_icon_resource->size.height() / 2; |
| 289 |
| 290 panel_icon_->SetUIResourceId( |
| 291 panel_icon_resource->ui_resource->id()); |
| 292 panel_icon_->SetBounds(panel_icon_resource->size); |
| 293 panel_icon_->SetPosition( |
| 294 gfx::PointF(search_provider_icon_left, search_provider_icon_top)); |
267 } | 295 } |
268 | 296 |
269 // Centers the Search Provider Icon vertically in the Search Bar. | 297 // --------------------------------------------------------------------------- |
270 float search_provider_icon_top = search_bar_top + | 298 // Search Provider Icon Sprite (Animated) |
271 search_bar_height / 2 - | 299 // --------------------------------------------------------------------------- |
272 search_provider_icon_resource->size.height() / 2; | 300 if (!should_use_static_icon) { |
| 301 if (search_provider_icon_sprite_visible) { |
| 302 if (search_provider_icon_sprite_->layer()->parent() != layer_) { |
| 303 layer_->AddChild(search_provider_icon_sprite_->layer()); |
| 304 } |
273 | 305 |
274 search_provider_icon_->SetUIResourceId( | 306 search_provider_icon_sprite_->DrawSpriteFrame( |
275 search_provider_icon_resource->ui_resource->id()); | 307 resource_manager_, |
276 search_provider_icon_->SetBounds(search_provider_icon_resource->size); | 308 search_provider_icon_sprite_bitmap_resource_id, |
277 search_provider_icon_->SetPosition( | 309 search_provider_icon_sprite_metadata_resource_id, |
278 gfx::PointF(search_provider_icon_left, search_provider_icon_top)); | 310 search_provider_icon_sprite_completion_percentage); |
| 311 |
| 312 // Positions the Search Provider Icon at the start of the Search Bar. |
| 313 float icon_x; |
| 314 if (is_rtl) { |
| 315 icon_x = search_panel_width - search_provider_icon_sprite_size - |
| 316 search_bar_margin_side; |
| 317 } else { |
| 318 icon_x = search_bar_margin_side; |
| 319 } |
| 320 |
| 321 // Centers the Search Provider Icon vertically in the Search Bar. |
| 322 float icon_y = search_bar_top + search_bar_height / 2 |
| 323 - search_provider_icon_sprite_size / 2; |
| 324 search_provider_icon_sprite_->layer()->SetPosition( |
| 325 gfx::PointF(icon_x, icon_y)); |
| 326 |
| 327 // Scales the layer to the correct size. |
| 328 search_provider_icon_sprite_->layer()->SetBounds( |
| 329 gfx::Size(search_provider_icon_sprite_size, |
| 330 search_provider_icon_sprite_size)); |
| 331 |
| 332 } else { |
| 333 if (search_provider_icon_sprite_->layer().get() && |
| 334 search_provider_icon_sprite_->layer()->parent()) { |
| 335 search_provider_icon_sprite_->layer()->RemoveFromParent(); |
| 336 } |
| 337 } |
| 338 } |
279 | 339 |
280 // --------------------------------------------------------------------------- | 340 // --------------------------------------------------------------------------- |
281 // Arrow Icon | 341 // Arrow Icon |
282 // --------------------------------------------------------------------------- | 342 // --------------------------------------------------------------------------- |
283 // Grabs the Search Arrow Icon resource. | 343 // Grabs the Search Arrow Icon resource. |
284 ui::ResourceManager::Resource* arrow_icon_resource = | 344 ui::ResourceManager::Resource* arrow_icon_resource = |
285 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 345 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
286 arrow_up_resource_id); | 346 arrow_up_resource_id); |
287 | 347 |
288 // Positions the icon at the end of the Search Bar. | 348 // Positions the icon at the end of the Search Bar. |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 panel_shadow_( | 571 panel_shadow_( |
512 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), | 572 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), |
513 search_bar_background_( | 573 search_bar_background_( |
514 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), | 574 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), |
515 search_context_( | 575 search_context_( |
516 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 576 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
517 search_term_( | 577 search_term_( |
518 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 578 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
519 search_bar_shadow_( | 579 search_bar_shadow_( |
520 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 580 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
521 search_provider_icon_( | 581 panel_icon_( |
522 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 582 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
| 583 search_provider_icon_sprite_(CrushedSpriteLayer::Create()), |
523 arrow_icon_( | 584 arrow_icon_( |
524 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 585 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
525 close_icon_( | 586 close_icon_( |
526 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 587 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
527 content_view_container_( | 588 content_view_container_( |
528 cc::Layer::Create(content::Compositor::LayerSettings())), | 589 cc::Layer::Create(content::Compositor::LayerSettings())), |
529 search_bar_border_( | 590 search_bar_border_( |
530 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), | 591 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), |
531 progress_bar_( | 592 progress_bar_( |
532 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), | 593 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), |
(...skipping 30 matching lines...) Expand all Loading... |
563 search_bar_background_->SetIsDrawable(true); | 624 search_bar_background_->SetIsDrawable(true); |
564 search_bar_background_->SetBackgroundColor(kSearchBarBackgroundColor); | 625 search_bar_background_->SetBackgroundColor(kSearchBarBackgroundColor); |
565 layer_->AddChild(search_bar_background_); | 626 layer_->AddChild(search_bar_background_); |
566 | 627 |
567 // Search Bar Text | 628 // Search Bar Text |
568 search_context_->SetIsDrawable(true); | 629 search_context_->SetIsDrawable(true); |
569 layer_->AddChild(search_context_); | 630 layer_->AddChild(search_context_); |
570 search_term_->SetIsDrawable(true); | 631 search_term_->SetIsDrawable(true); |
571 layer_->AddChild(search_term_); | 632 layer_->AddChild(search_term_); |
572 | 633 |
573 // Search Provider Icon | 634 // Panel Icon |
574 search_provider_icon_->SetIsDrawable(true); | 635 panel_icon_->SetIsDrawable(true); |
575 layer_->AddChild(search_provider_icon_); | |
576 | 636 |
577 // Arrow Icon | 637 // Arrow Icon |
578 arrow_icon_->SetIsDrawable(true); | 638 arrow_icon_->SetIsDrawable(true); |
579 layer_->AddChild(arrow_icon_); | 639 layer_->AddChild(arrow_icon_); |
580 | 640 |
581 // Close Icon | 641 // Close Icon |
582 close_icon_->SetIsDrawable(true); | 642 close_icon_->SetIsDrawable(true); |
583 layer_->AddChild(close_icon_); | 643 layer_->AddChild(close_icon_); |
584 | 644 |
585 // Search Opt Out Promo | 645 // Search Opt Out Promo |
(...skipping 22 matching lines...) Expand all Loading... |
608 | 668 |
609 ContextualSearchLayer::~ContextualSearchLayer() { | 669 ContextualSearchLayer::~ContextualSearchLayer() { |
610 } | 670 } |
611 | 671 |
612 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() { | 672 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() { |
613 return layer_; | 673 return layer_; |
614 } | 674 } |
615 | 675 |
616 } // namespace android | 676 } // namespace android |
617 } // namespace chrome | 677 } // namespace chrome |
OLD | NEW |