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 e97ad1255daf5bccc7ba986b74dc0a265e862053..32330b1022b6142b3473f7f7597be215dcc43078 100644 |
| --- a/chrome/browser/android/compositor/layer/contextual_search_layer.cc |
| +++ b/chrome/browser/android/compositor/layer/contextual_search_layer.cc |
| @@ -43,8 +43,9 @@ void ContextualSearchLayer::SetProperties( |
| int search_term_resource_id, |
| int search_caption_resource_id, |
| int search_bar_shadow_resource_id, |
| - int panel_icon_resource_id, |
| + int sprite_resource_id, |
| int search_provider_icon_sprite_metadata_resource_id, |
| + int static_icon_resource_id, |
| int arrow_up_resource_id, |
| int close_icon_resource_id, |
| int progress_bar_background_resource_id, |
| @@ -81,9 +82,10 @@ void ContextualSearchLayer::SetProperties( |
| float search_bar_shadow_opacity, |
| bool search_provider_icon_sprite_visible, |
| float search_provider_icon_sprite_completion_percentage, |
| + bool static_icon_visible, |
| bool thumbnail_visible, |
| - float thumbnail_visibility_percentage, |
| - int thumbnail_size, |
| + float static_image_visibility_percentage, |
| + int static_image_size, |
| float arrow_icon_opacity, |
| float arrow_icon_rotation, |
| float close_icon_opacity, |
| @@ -104,7 +106,7 @@ void ContextualSearchLayer::SetProperties( |
| search_term_resource_id, |
| panel_shadow_resource_id, |
| search_bar_shadow_resource_id, |
| - panel_icon_resource_id, |
| + sprite_resource_id, |
| close_icon_resource_id); |
| float content_view_top = search_bar_bottom + search_promo_height; |
| @@ -378,12 +380,14 @@ void ContextualSearchLayer::SetProperties( |
| // --------------------------------------------------------------------------- |
| // Icon Layer |
| // --------------------------------------------------------------------------- |
| - thumbnail_size_ = thumbnail_size; |
| + static_image_size_ = static_image_size; |
| SetupIconLayer(search_provider_icon_sprite_visible, |
| search_provider_icon_sprite_metadata_resource_id, |
| search_provider_icon_sprite_completion_percentage, |
| + static_icon_visible, |
| + static_icon_resource_id, |
| thumbnail_visible, |
| - thumbnail_visibility_percentage); |
| + static_image_visibility_percentage); |
| } |
| scoped_refptr<cc::Layer> ContextualSearchLayer::GetIconLayer() { |
| @@ -394,30 +398,42 @@ void ContextualSearchLayer::SetupIconLayer( |
| bool search_provider_icon_sprite_visible, |
| int search_provider_icon_sprite_metadata_resource_id, |
| float search_provider_icon_sprite_completion_percentage, |
| + bool static_icon_visible, |
| + int static_icon_resource_id, |
| bool thumbnail_visible, |
| - float thumbnail_visibility_percentage) { |
| - icon_layer_->SetBounds(gfx::Size(thumbnail_size_, thumbnail_size_)); |
| + float static_image_visibility_percentage) { |
| + icon_layer_->SetBounds(gfx::Size(static_image_size_, static_image_size_)); |
| icon_layer_->SetMasksToBounds(true); |
| + scoped_refptr<cc::UIResourceLayer> static_image_layer; |
| + |
| + if (static_icon_visible) { |
| + if (static_icon_layer_->parent() != icon_layer_) |
| + icon_layer_->AddChild(static_icon_layer_); |
| + |
| + ui::ResourceManager::Resource* static_icon_resource = |
| + resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
| + static_icon_resource_id); |
| + static_icon_layer_->SetUIResourceId( |
| + static_icon_resource->ui_resource->id()); |
| + static_icon_layer_->SetBounds(gfx::Size(static_image_size_, |
| + static_image_size_)); |
| + |
| + SetStaticImageProperties(static_icon_layer_, 0, 0, |
| + static_image_visibility_percentage); |
| + } else if (static_icon_layer_->parent()) { |
| + static_icon_layer_->RemoveFromParent(); |
| + } |
| + |
| // Thumbnail |
| - if (thumbnail_visible) { |
| + if (!static_icon_visible && thumbnail_visible) { |
| if (thumbnail_layer_->parent() != icon_layer_) |
| icon_layer_->AddChild(thumbnail_layer_); |
| - thumbnail_layer_->SetOpacity(thumbnail_visibility_percentage); |
| - |
| - // When animating, the thumbnail and icon sprite slide through |
| - // |icon_layer_|. This effect is achieved by changing the y-offset |
| - // for each child layer. |
| - // If the thumbnail has a height less than |thumbnail_size_|, it will have |
| - // a top margin that needs to be accounted for while running the |
| - // animation. The final |thumbnail_y_offset| should be equal to |
| - // |thumbnail_top_margin_|. |
| - float thumbnail_y_offset = |
| - (thumbnail_size_ * (1.f - thumbnail_visibility_percentage)) |
| - + thumbnail_top_margin_; |
| - thumbnail_layer_->SetPosition( |
| - gfx::PointF(thumbnail_side_margin_, thumbnail_y_offset)); |
| + SetStaticImageProperties(thumbnail_layer_, |
| + thumbnail_top_margin_, |
| + thumbnail_side_margin_, |
| + static_image_visibility_percentage); |
| } else if (thumbnail_layer_->parent()) { |
| thumbnail_layer_->RemoveFromParent(); |
| } |
| @@ -434,10 +450,10 @@ void ContextualSearchLayer::SetupIconLayer( |
| search_provider_icon_sprite_completion_percentage); |
| search_provider_icon_sprite_->layer()->SetOpacity( |
| - 1.f - thumbnail_visibility_percentage); |
| + 1.f - static_image_visibility_percentage); |
| float icon_y_offset = |
| - -(thumbnail_size_ * thumbnail_visibility_percentage); |
| + -(static_image_size_ * static_image_visibility_percentage); |
| search_provider_icon_sprite_->layer()->SetPosition( |
| gfx::PointF(0.f, icon_y_offset)); |
| @@ -447,6 +463,27 @@ void ContextualSearchLayer::SetupIconLayer( |
| } |
| } |
| +void ContextualSearchLayer::SetStaticImageProperties( |
| + scoped_refptr<cc::UIResourceLayer> static_image_layer, |
| + float top_margin, |
| + float side_margin, |
| + float visibility_percentage) { |
| + static_image_layer->SetOpacity(visibility_percentage); |
| + |
| + // When animating, the static image and icon sprite slide through |
| + // |icon_layer_|. This effect is achieved by changing the y-offset |
| + // for each child layer. |
| + // If the static image has a height less than |static_image_size_|, it will |
| + // have a top margin that needs to be accounted for while running the |
| + // animation. The final |static_image_y_offset| should be equal to |
| + // |tpp_margin|. |
| + float thumbnail_y_offset = |
|
Donn Denman
2016/10/24 23:56:20
Nit: change to static_image_y_offset.
Theresa
2016/10/25 00:32:48
Done.
|
| + (static_image_size_ * (1.f - visibility_percentage)) |
| + + top_margin; |
| + static_image_layer->SetPosition( |
| + gfx::PointF(side_margin, thumbnail_y_offset)); |
| +} |
| + |
| void ContextualSearchLayer::SetupTextLayer( |
| float bar_top, |
| float bar_height, |
| @@ -576,16 +613,16 @@ void ContextualSearchLayer::SetupTextLayer( |
| void ContextualSearchLayer::SetThumbnail(const SkBitmap* thumbnail) { |
| // Determine the scaled thumbnail width and height. If both the height and |
| - // width of |thumbnail| are larger than |thumbnail_size_|, the thumbnail will |
| - // be scaled down by a call to Layer::SetBounds() below. |
| + // width of |thumbnail| are larger than |static_image_size_|, the thumbnail |
| + // will be scaled down by a call to Layer::SetBounds() below. |
| int min_dimension = std::min(thumbnail->width(), thumbnail->height()); |
| int scaled_thumbnail_width = thumbnail->width(); |
| int scaled_thumbnail_height = thumbnail->height(); |
| - if (min_dimension > thumbnail_size_) { |
| + if (min_dimension > static_image_size_) { |
| scaled_thumbnail_width = |
| - scaled_thumbnail_width * thumbnail_size_ / min_dimension; |
| + scaled_thumbnail_width * static_image_size_ / min_dimension; |
| scaled_thumbnail_height = |
| - scaled_thumbnail_height * thumbnail_size_ / min_dimension; |
| + scaled_thumbnail_height * static_image_size_ / min_dimension; |
| } |
| // Determine the UV transform coordinates. This will crop the thumbnail. |
| @@ -596,42 +633,44 @@ void ContextualSearchLayer::SetThumbnail(const SkBitmap* thumbnail) { |
| float bottom_right_x = 1; |
| float bottom_right_y = 1; |
| - if (scaled_thumbnail_width > thumbnail_size_) { |
| + if (scaled_thumbnail_width > static_image_size_) { |
| // Crop an even amount on the left and right sides of the thumbnail. |
| - float top_left_x_px = (scaled_thumbnail_width - thumbnail_size_) / 2.f; |
| - float bottom_right_x_px = top_left_x_px + thumbnail_size_; |
| + float top_left_x_px = (scaled_thumbnail_width - static_image_size_) / 2.f; |
| + float bottom_right_x_px = top_left_x_px + static_image_size_; |
| top_left_x = top_left_x_px / scaled_thumbnail_width; |
| bottom_right_x = bottom_right_x_px / scaled_thumbnail_width; |
| - } else if (scaled_thumbnail_height > thumbnail_size_) { |
| + } else if (scaled_thumbnail_height > static_image_size_) { |
| // Crop an even amount on the top and bottom of the thumbnail. |
| - float top_left_y_px = (scaled_thumbnail_height - thumbnail_size_) / 2.f; |
| - float bottom_right_y_px = top_left_y_px + thumbnail_size_; |
| + float top_left_y_px = (scaled_thumbnail_height - static_image_size_) / 2.f; |
| + float bottom_right_y_px = top_left_y_px + static_image_size_; |
| top_left_y = top_left_y_px / scaled_thumbnail_height; |
| bottom_right_y = bottom_right_y_px / scaled_thumbnail_height; |
| } |
| // If the original |thumbnail| height or width is smaller than |
| - // |thumbnail_size_| determine the side and top margins needed to center |
| + // |static_image_size_| determine the side and top margins needed to center |
| // the thumbnail. |
| thumbnail_side_margin_ = 0; |
| thumbnail_top_margin_ = 0; |
| - if (scaled_thumbnail_width < thumbnail_size_) { |
| - thumbnail_side_margin_ = (thumbnail_size_ - scaled_thumbnail_width) / 2.f; |
| + if (scaled_thumbnail_width < static_image_size_) { |
| + thumbnail_side_margin_ = |
| + (static_image_size_ - scaled_thumbnail_width) / 2.f; |
| } |
| - if (scaled_thumbnail_height < thumbnail_size_) { |
| - thumbnail_top_margin_ = (thumbnail_size_ - scaled_thumbnail_height) / 2.f; |
| + if (scaled_thumbnail_height < static_image_size_) { |
| + thumbnail_top_margin_ = |
| + (static_image_size_ - scaled_thumbnail_height) / 2.f; |
| } |
| // Determine the layer bounds. This will down scale the thumbnail if |
| - // necessary and ensure it is displayed at |thumbnail_size_|. If |
| + // necessary and ensure it is displayed at |static_image_size_|. If |
| // either the original |thumbnail| height or width is smaller than |
| - // |thumbnail_size_|, the thumbnail will not be scaled. |
| - int layer_width = std::min(thumbnail_size_, scaled_thumbnail_width); |
| - int layer_height = std::min(thumbnail_size_, scaled_thumbnail_height); |
| + // |static_image_size_|, the thumbnail will not be scaled. |
| + int layer_width = std::min(static_image_size_, scaled_thumbnail_width); |
| + int layer_height = std::min(static_image_size_, scaled_thumbnail_height); |
| // UIResourceLayer requires an immutable copy of the input |thumbnail|. |
| SkBitmap thumbnail_copy; |
| @@ -657,6 +696,7 @@ ContextualSearchLayer::ContextualSearchLayer( |
| icon_layer_(cc::Layer::Create()), |
| search_provider_icon_sprite_(CrushedSpriteLayer::Create()), |
| thumbnail_layer_(cc::UIResourceLayer::Create()), |
| + static_icon_layer_(cc::UIResourceLayer::Create()), |
| arrow_icon_(cc::UIResourceLayer::Create()), |
| search_promo_(cc::UIResourceLayer::Create()), |
| search_promo_container_(cc::SolidColorLayer::Create()), |
| @@ -699,13 +739,16 @@ ContextualSearchLayer::ContextualSearchLayer( |
| progress_bar_->SetIsDrawable(true); |
| progress_bar_->SetFillCenter(true); |
| - // Icon |
| + // Icon - holds thumbnail, search provider sprite and/or static icon |
| icon_layer_->SetIsDrawable(true); |
| layer_->AddChild(icon_layer_); |
| // Thumbnail |
| thumbnail_layer_->SetIsDrawable(true); |
| + // Static icon |
| + static_icon_layer_->SetIsDrawable(true); |
| + |
| // Content layer |
| text_layer_->SetIsDrawable(true); |
| // NOTE(mdjones): This can be called multiple times to add other text layers. |