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

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

Issue 1337703002: [Contextual Search] Add support for crushed sprites and animate the search provider icon (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add TODO's for other planned tests Created 5 years, 2 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 "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
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,
47 int arrow_up_resource_id, 48 int arrow_up_resource_id,
48 int close_icon_resource_id, 49 int close_icon_resource_id,
49 int progress_bar_background_resource_id, 50 int progress_bar_background_resource_id,
50 int progress_bar_resource_id, 51 int progress_bar_resource_id,
51 int search_promo_resource_id, 52 int search_promo_resource_id,
52 int peek_promo_ripple_resource_id, 53 int peek_promo_ripple_resource_id,
53 int peek_promo_text_resource_id, 54 int peek_promo_text_resource_id,
55 int search_provider_icon_sprite_bitmap_resource_id,
56 int search_provider_icon_sprite_metadata_resource_id,
54 content::ContentViewCore* content_view_core, 57 content::ContentViewCore* content_view_core,
55 bool search_promo_visible, 58 bool search_promo_visible,
56 float search_promo_height, 59 float search_promo_height,
57 float search_promo_opacity, 60 float search_promo_opacity,
58 bool search_peek_promo_visible, 61 bool search_peek_promo_visible,
59 float search_peek_promo_height, 62 float search_peek_promo_height,
60 float search_peek_promo_padding, 63 float search_peek_promo_padding,
61 float search_peek_promo_ripple_width, 64 float search_peek_promo_ripple_width,
62 float search_peek_promo_ripple_opacity, 65 float search_peek_promo_ripple_opacity,
63 float search_peek_promo_text_opacity, 66 float search_peek_promo_text_opacity,
64 float search_panel_x, 67 float search_panel_x,
65 float search_panel_y, 68 float search_panel_y,
66 float search_panel_width, 69 float search_panel_width,
67 float search_panel_height, 70 float search_panel_height,
68 float search_bar_margin_side, 71 float search_bar_margin_side,
69 float search_bar_height, 72 float search_bar_height,
70 float search_context_opacity, 73 float search_context_opacity,
71 float search_term_opacity, 74 float search_term_opacity,
72 bool search_bar_border_visible, 75 bool search_bar_border_visible,
73 float search_bar_border_height, 76 float search_bar_border_height,
74 bool search_bar_shadow_visible, 77 bool search_bar_shadow_visible,
75 float search_bar_shadow_opacity, 78 float search_bar_shadow_opacity,
79 bool search_provider_icon_sprite_visible,
80 int search_provider_icon_sprite_frame,
81 float search_provider_icon_sprite_size,
76 float arrow_icon_opacity, 82 float arrow_icon_opacity,
77 float arrow_icon_rotation, 83 float arrow_icon_rotation,
78 float close_icon_opacity, 84 float close_icon_opacity,
79 bool progress_bar_visible, 85 bool progress_bar_visible,
80 float progress_bar_height, 86 float progress_bar_height,
81 float progress_bar_opacity, 87 float progress_bar_opacity,
82 int progress_bar_completion) { 88 int progress_bar_completion) {
83 // Grabs the dynamic Search Bar Text resource. 89 // Grabs the dynamic Search Bar Text resource.
84 ui::ResourceManager::Resource* search_context_resource = 90 ui::ResourceManager::Resource* search_context_resource =
85 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, 91 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC,
86 search_context_resource_id); 92 search_context_resource_id);
87 ui::ResourceManager::Resource* search_term_resource = 93 ui::ResourceManager::Resource* search_term_resource =
88 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, 94 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC,
89 search_term_resource_id); 95 search_term_resource_id);
90 96
91 // Grabs required static resources. 97 // Grabs required static resources.
92 ui::ResourceManager::Resource* panel_shadow_resource = 98 ui::ResourceManager::Resource* panel_shadow_resource =
93 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, 99 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC,
94 panel_shadow_resource_id); 100 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 101
99 DCHECK(panel_shadow_resource); 102 DCHECK(panel_shadow_resource);
100 DCHECK(search_provider_icon_resource);
101 103
102 // Round values to avoid pixel gap between layers. 104 // Round values to avoid pixel gap between layers.
103 search_bar_height = floor(search_bar_height); 105 search_bar_height = floor(search_bar_height);
104 106
105 float search_bar_top = search_peek_promo_height; 107 float search_bar_top = search_peek_promo_height;
106 float search_bar_bottom = search_bar_top + search_bar_height; 108 float search_bar_bottom = search_bar_top + search_bar_height;
107 109
108 bool is_rtl = l10n_util::IsLayoutRtl(); 110 bool is_rtl = l10n_util::IsLayoutRtl();
109 111
110 // --------------------------------------------------------------------------- 112 // ---------------------------------------------------------------------------
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 155
154 // Apply a blend based on the ripple opacity. The resulting color will 156 // Apply a blend based on the ripple opacity. The resulting color will
155 // be an interpolation between the background color of the Search Bar and 157 // be an interpolation between the background color of the Search Bar and
156 // a lighter shade of the background color of the Ripple. The range of 158 // a lighter shade of the background color of the Ripple. The range of
157 // the alpha value used in the blend will be: 159 // the alpha value used in the blend will be:
158 // [0.f, kPeekPromoBackgroundMaximumAlphaBlend] 160 // [0.f, kPeekPromoBackgroundMaximumAlphaBlend]
159 peek_promo_container_->SetBackgroundColor( 161 peek_promo_container_->SetBackgroundColor(
160 color_utils::AlphaBlend(kPeekPromoRippleBackgroundColor, 162 color_utils::AlphaBlend(kPeekPromoRippleBackgroundColor,
161 kSearchBarBackgroundColor, 163 kSearchBarBackgroundColor,
162 kPeekPromoBackgroundMaximumAlphaBlend * 164 kPeekPromoBackgroundMaximumAlphaBlend *
163 search_peek_promo_ripple_opacity 165 search_peek_promo_ripple_opacity));
164 ));
165 166
166 // ----------------------------------------------------------------- 167 // -----------------------------------------------------------------
167 // Peek Promo Ripple 168 // Peek Promo Ripple
168 // ----------------------------------------------------------------- 169 // -----------------------------------------------------------------
169 gfx::Size peek_promo_ripple_size( 170 gfx::Size peek_promo_ripple_size(
170 search_peek_promo_ripple_width, search_peek_promo_height); 171 search_peek_promo_ripple_width, search_peek_promo_height);
171 gfx::Rect peek_promo_ripple_border( 172 gfx::Rect peek_promo_ripple_border(
172 peek_promo_ripple_resource->Border(peek_promo_ripple_size)); 173 peek_promo_ripple_resource->Border(peek_promo_ripple_size));
173 174
174 // Add padding so the ripple will occupy the whole width at 100%. 175 // Add padding so the ripple will occupy the whole width at 100%.
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 search_term_resource->size.height() / 2; 252 search_term_resource->size.height() / 2;
252 search_term_->SetUIResourceId(search_term_resource->ui_resource->id()); 253 search_term_->SetUIResourceId(search_term_resource->ui_resource->id());
253 search_term_->SetBounds(search_term_resource->size); 254 search_term_->SetBounds(search_term_resource->size);
254 search_term_->SetPosition(gfx::PointF(0.f, search_bar_padding_top)); 255 search_term_->SetPosition(gfx::PointF(0.f, search_bar_padding_top));
255 search_term_->SetOpacity(search_term_opacity); 256 search_term_->SetOpacity(search_term_opacity);
256 } 257 }
257 258
258 // --------------------------------------------------------------------------- 259 // ---------------------------------------------------------------------------
259 // Search Provider Icon 260 // Search Provider Icon
260 // --------------------------------------------------------------------------- 261 // ---------------------------------------------------------------------------
261 // Positions the Search Provider Icon at the start of the Search Bar. 262 if (search_provider_icon_sprite_visible) {
262 float search_provider_icon_left; 263 scoped_refptr<ui::CrushedSpriteResource> crushed_sprite_resource =
263 if (is_rtl) { 264 resource_manager_->GetCrushedSpriteResource(
264 search_provider_icon_left = search_panel_width - 265 search_provider_icon_sprite_bitmap_resource_id,
265 search_provider_icon_resource->size.width() - search_bar_margin_side; 266 search_provider_icon_sprite_metadata_resource_id);
267
268 if (search_provider_icon_sprite_->layer()->parent() != layer_) {
269 layer_->AddChild(search_provider_icon_sprite_->layer());
270 }
271
272 search_provider_icon_sprite_->SetCrushedSpriteResource(
273 crushed_sprite_resource);
274 search_provider_icon_sprite_->DrawSpriteFrame(
275 search_provider_icon_sprite_frame);
276
277 // Positions the Search Provider Icon at the start of the Search Bar.
278 float icon_x;
279 if (is_rtl) {
280 icon_x = search_panel_width - search_provider_icon_sprite_size -
281 search_bar_margin_side;
282 } else {
283 icon_x = search_bar_margin_side;
284 }
285
286 // Centers the Search Provider Icon vertically in the Search Bar.
287 float icon_y = search_bar_top +
288 search_bar_height / 2 -
David Trainor- moved to gerrit 2015/10/15 21:04:57 fix indenting.
Theresa 2015/10/24 00:06:44 Done.
289 search_provider_icon_sprite_size / 2;
290 search_provider_icon_sprite_->layer()->SetPosition(
291 gfx::PointF(icon_x, icon_y));
292
293 // Scales the layer to the correct size.
294 search_provider_icon_sprite_->layer()->SetBounds(
295 gfx::Size(search_provider_icon_sprite_size,
296 search_provider_icon_sprite_size));
297
266 } else { 298 } else {
267 search_provider_icon_left = search_bar_margin_side; 299 if (search_provider_icon_sprite_->layer().get() &&
300 search_provider_icon_sprite_->layer()->parent()) {
301 search_provider_icon_sprite_->layer()->RemoveFromParent();
302 }
268 } 303 }
269 304
270 // Centers the Search Provider Icon vertically in the Search Bar.
271 float search_provider_icon_top = search_bar_top +
272 search_bar_height / 2 -
273 search_provider_icon_resource->size.height() / 2;
274
275 search_provider_icon_->SetUIResourceId(
276 search_provider_icon_resource->ui_resource->id());
277 search_provider_icon_->SetBounds(search_provider_icon_resource->size);
278 search_provider_icon_->SetPosition(
279 gfx::PointF(search_provider_icon_left, search_provider_icon_top));
280
281 // --------------------------------------------------------------------------- 305 // ---------------------------------------------------------------------------
282 // Arrow Icon 306 // Arrow Icon
283 // --------------------------------------------------------------------------- 307 // ---------------------------------------------------------------------------
284 // Grabs the Search Arrow Icon resource. 308 // Grabs the Search Arrow Icon resource.
285 ui::ResourceManager::Resource* arrow_icon_resource = 309 ui::ResourceManager::Resource* arrow_icon_resource =
286 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, 310 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC,
287 arrow_up_resource_id); 311 arrow_up_resource_id);
288 312
289 // Positions the icon at the end of the Search Bar. 313 // Positions the icon at the end of the Search Bar.
290 float arrow_icon_left; 314 float arrow_icon_left;
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 panel_shadow_( 536 panel_shadow_(
513 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), 537 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())),
514 search_bar_background_( 538 search_bar_background_(
515 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), 539 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())),
516 search_context_( 540 search_context_(
517 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), 541 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())),
518 search_term_( 542 search_term_(
519 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), 543 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())),
520 search_bar_shadow_( 544 search_bar_shadow_(
521 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), 545 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())),
522 search_provider_icon_( 546 search_provider_icon_sprite_(
523 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), 547 CrushedSpriteLayer::Create(resource_manager)),
524 arrow_icon_( 548 arrow_icon_(
525 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), 549 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())),
526 close_icon_( 550 close_icon_(
527 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), 551 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())),
528 content_view_container_( 552 content_view_container_(
529 cc::Layer::Create(content::Compositor::LayerSettings())), 553 cc::Layer::Create(content::Compositor::LayerSettings())),
530 search_bar_border_( 554 search_bar_border_(
531 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), 555 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())),
532 progress_bar_( 556 progress_bar_(
533 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), 557 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())),
(...skipping 30 matching lines...) Expand all
564 search_bar_background_->SetIsDrawable(true); 588 search_bar_background_->SetIsDrawable(true);
565 search_bar_background_->SetBackgroundColor(kSearchBarBackgroundColor); 589 search_bar_background_->SetBackgroundColor(kSearchBarBackgroundColor);
566 layer_->AddChild(search_bar_background_); 590 layer_->AddChild(search_bar_background_);
567 591
568 // Search Bar Text 592 // Search Bar Text
569 search_context_->SetIsDrawable(true); 593 search_context_->SetIsDrawable(true);
570 layer_->AddChild(search_context_); 594 layer_->AddChild(search_context_);
571 search_term_->SetIsDrawable(true); 595 search_term_->SetIsDrawable(true);
572 layer_->AddChild(search_term_); 596 layer_->AddChild(search_term_);
573 597
574 // Search Provider Icon
575 search_provider_icon_->SetIsDrawable(true);
576 layer_->AddChild(search_provider_icon_);
577
578 // Arrow Icon 598 // Arrow Icon
579 arrow_icon_->SetIsDrawable(true); 599 arrow_icon_->SetIsDrawable(true);
580 layer_->AddChild(arrow_icon_); 600 layer_->AddChild(arrow_icon_);
581 601
582 // Close Icon 602 // Close Icon
583 close_icon_->SetIsDrawable(true); 603 close_icon_->SetIsDrawable(true);
584 layer_->AddChild(close_icon_); 604 layer_->AddChild(close_icon_);
585 605
586 // Search Opt Out Promo 606 // Search Opt Out Promo
587 search_promo_container_->SetIsDrawable(true); 607 search_promo_container_->SetIsDrawable(true);
(...skipping 21 matching lines...) Expand all
609 629
610 ContextualSearchLayer::~ContextualSearchLayer() { 630 ContextualSearchLayer::~ContextualSearchLayer() {
611 } 631 }
612 632
613 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() { 633 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() {
614 return layer_; 634 return layer_;
615 } 635 }
616 636
617 } // namespace android 637 } // namespace android
618 } // namespace chrome 638 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698