Chromium Code Reviews| Index: chrome/browser/android/compositor/layer/contextual_search_layer.cc |
| diff --git a/chrome/browser/android/compositor/layer/contextual_search_layer.cc b/chrome/browser/android/compositor/layer/contextual_search_layer.cc |
| index 15f2b6f977cdf5e5ac241682d169b6cf434eee3c..f5418e237835588fb8e41a8964c6a9b408954504 100644 |
| --- a/chrome/browser/android/compositor/layer/contextual_search_layer.cc |
| +++ b/chrome/browser/android/compositor/layer/contextual_search_layer.cc |
| @@ -60,6 +60,10 @@ void ContextualSearchLayer::SetProperties( |
| float search_bar_border_height, |
| bool search_bar_shadow_visible, |
| float search_bar_shadow_opacity, |
| + bool search_provider_icon_visible, |
| + int search_provider_icon_sprites_per_row, |
| + int search_provider_icon_sprite_rows, |
| + int search_provider_icon_sprite_frame, |
| float arrow_icon_opacity, |
| float arrow_icon_rotation, |
| bool close_icon_visible, |
| @@ -148,25 +152,49 @@ void ContextualSearchLayer::SetProperties( |
| // --------------------------------------------------------------------------- |
| // Search Provider Icon |
| // --------------------------------------------------------------------------- |
| - // Positions the Search Provider Icon at the start of the Search Bar. |
| - float search_provider_icon_left; |
| - if (is_rtl) { |
| - search_provider_icon_left = search_panel_width - |
| - search_provider_icon_resource->size.width() - search_bar_margin_side; |
| - } else { |
| - search_provider_icon_left = search_bar_margin_side; |
| - } |
| + if (search_provider_icon_visible) { |
| + if (search_provider_icon_->parent() != layer_) { |
|
pedro (no code reviews)
2015/09/11 22:49:42
Nit: please rename search_provider_icon_ to search
Theresa
2015/09/14 19:48:25
Done.
|
| + layer_->AddChild(search_provider_icon_); |
| + } |
| - // Centers the Search Provider Icon vertically in the Search Bar. |
| - float search_provider_icon_top = |
| - search_bar_height / 2 - |
| - search_provider_icon_resource->size.height() / 2; |
| + search_provider_icon_sprites_per_row_ = |
| + search_provider_icon_sprites_per_row; |
| + search_provider_icon_sprite_rows_ = search_provider_icon_sprite_rows; |
| + float search_provider_icon_sprite_width = |
|
Changwan Ryu
2015/09/14 01:51:30
Nit: How about just naming them icon_width and ico
Theresa
2015/09/14 19:48:25
Acknowledged. This value is getting passed in now,
|
| + search_provider_icon_resource->size.width() / |
| + search_provider_icon_sprites_per_row_; |
| + float search_provider_icon_sprite_height = |
| + search_provider_icon_resource->size.height() / |
| + search_provider_icon_sprite_rows_; |
| + |
| + // Positions the Search Provider Icon at the start of the Search Bar. |
| + float search_provider_icon_left; |
|
Changwan Ryu
2015/09/14 01:51:30
Nit: how about icon_x and icon_y for simplicity?
Theresa
2015/09/14 19:48:25
Done.
|
| + if (is_rtl) { |
| + search_provider_icon_left = search_panel_width - |
| + search_provider_icon_sprite_width - search_bar_margin_side; |
| + } else { |
| + search_provider_icon_left = search_bar_margin_side; |
| + } |
| - search_provider_icon_->SetUIResourceId( |
| - search_provider_icon_resource->ui_resource->id()); |
| - search_provider_icon_->SetBounds(search_provider_icon_resource->size); |
| - search_provider_icon_->SetPosition( |
| - gfx::PointF(search_provider_icon_left, search_provider_icon_top)); |
| + // Centers the Search Provider Icon vertically in the Search Bar. |
| + float search_provider_icon_top = |
| + search_bar_height / 2 - |
| + search_provider_icon_sprite_height / 2; |
| + search_provider_icon_->SetUIResourceId( |
| + search_provider_icon_resource->ui_resource->id()); |
| + gfx::Size* size = new gfx::Size(search_provider_icon_sprite_width, |
| + search_provider_icon_sprite_height); |
|
Changwan Ryu
2015/09/14 01:51:29
gfx::Size size(search_provider_icon_sprite_width,
Theresa
2015/09/14 19:48:25
Done.
|
| + search_provider_icon_->SetBounds(*size); |
| + search_provider_icon_->SetPosition( |
| + gfx::PointF(search_provider_icon_left, search_provider_icon_top)); |
| + |
| + // Sets the portion of search_provider_icon_ that gets drawn. |
| + SetSearchProviderIconUV(search_provider_icon_sprite_frame); |
| + } else { |
| + if (search_provider_icon_.get() && search_provider_icon_->parent()) { |
| + search_provider_icon_->RemoveFromParent(); |
| + } |
| + } |
| // --------------------------------------------------------------------------- |
| // Arrow Icon |
| @@ -430,7 +458,9 @@ ContextualSearchLayer::ContextualSearchLayer( |
| search_promo_( |
| cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
| search_promo_container_( |
| - cc::SolidColorLayer::Create(content::Compositor::LayerSettings())) { |
| + cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), |
| + search_provider_icon_sprites_per_row_(0), |
| + search_provider_icon_sprite_rows_(0) { |
| layer_->SetMasksToBounds(false); |
| layer_->SetIsDrawable(true); |
| @@ -491,5 +521,20 @@ scoped_refptr<cc::Layer> ContextualSearchLayer::layer() { |
| return layer_; |
| } |
| +void ContextualSearchLayer::SetSearchProviderIconUV(int sprite_frame) { |
|
pedro (no code reviews)
2015/09/11 22:49:42
I think it would make more sense to call this SetS
Theresa
2015/09/14 19:48:25
Done.
|
| + float column = (float) (sprite_frame % search_provider_icon_sprites_per_row_); |
|
Changwan Ryu
2015/09/14 01:51:30
Please do not use C-style casting, and use static_
Theresa
2015/09/14 19:48:25
Done.
|
| + float row = (float) (sprite_frame / search_provider_icon_sprites_per_row_); |
| + CHECK(row <= search_provider_icon_sprite_rows_); |
| + |
| + float top_left_x = column / ((float) search_provider_icon_sprites_per_row_); |
| + float top_left_y = row / ((float) search_provider_icon_sprite_rows_); |
| + float bottom_right_x = (column + 1.f) / |
| + ((float) search_provider_icon_sprites_per_row_); |
| + float bottom_right_y = (row + 1.f) / |
| + ((float) search_provider_icon_sprite_rows_); |
| + search_provider_icon_->SetUV(gfx::PointF(top_left_x, top_left_y), |
| + gfx::PointF(bottom_right_x, bottom_right_y)); |
| +} |
| + |
| } // namespace android |
| } // namespace chrome |