Chromium Code Reviews| 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 float search_panel_height, | 53 float search_panel_height, |
| 54 float search_bar_margin_side, | 54 float search_bar_margin_side, |
| 55 float search_bar_height, | 55 float search_bar_height, |
| 56 float search_context_opacity, | 56 float search_context_opacity, |
| 57 float search_term_opacity, | 57 float search_term_opacity, |
| 58 bool search_bar_border_visible, | 58 bool search_bar_border_visible, |
| 59 float search_bar_border_y, | 59 float search_bar_border_y, |
| 60 float search_bar_border_height, | 60 float search_bar_border_height, |
| 61 bool search_bar_shadow_visible, | 61 bool search_bar_shadow_visible, |
| 62 float search_bar_shadow_opacity, | 62 float search_bar_shadow_opacity, |
| 63 bool search_provider_icon_visible, | |
| 64 int search_provider_icon_sprites_per_row, | |
| 65 int search_provider_icon_sprite_rows, | |
| 66 int search_provider_icon_sprite_frame, | |
| 63 float arrow_icon_opacity, | 67 float arrow_icon_opacity, |
| 64 float arrow_icon_rotation, | 68 float arrow_icon_rotation, |
| 65 bool close_icon_visible, | 69 bool close_icon_visible, |
| 66 float close_icon_opacity, | 70 float close_icon_opacity, |
| 67 bool progress_bar_visible, | 71 bool progress_bar_visible, |
| 68 float progress_bar_y, | 72 float progress_bar_y, |
| 69 float progress_bar_height, | 73 float progress_bar_height, |
| 70 float progress_bar_opacity, | 74 float progress_bar_opacity, |
| 71 int progress_bar_completion) { | 75 int progress_bar_completion) { |
| 72 // Grabs the dynamic Search Bar Text resource. | 76 // Grabs the dynamic Search Bar Text resource. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 search_term_resource->size.height() / 2; | 145 search_term_resource->size.height() / 2; |
| 142 search_term_->SetUIResourceId(search_term_resource->ui_resource->id()); | 146 search_term_->SetUIResourceId(search_term_resource->ui_resource->id()); |
| 143 search_term_->SetBounds(search_term_resource->size); | 147 search_term_->SetBounds(search_term_resource->size); |
| 144 search_term_->SetPosition(gfx::PointF(0.f, search_bar_padding_top)); | 148 search_term_->SetPosition(gfx::PointF(0.f, search_bar_padding_top)); |
| 145 search_term_->SetOpacity(search_term_opacity); | 149 search_term_->SetOpacity(search_term_opacity); |
| 146 } | 150 } |
| 147 | 151 |
| 148 // --------------------------------------------------------------------------- | 152 // --------------------------------------------------------------------------- |
| 149 // Search Provider Icon | 153 // Search Provider Icon |
| 150 // --------------------------------------------------------------------------- | 154 // --------------------------------------------------------------------------- |
| 151 // Positions the Search Provider Icon at the start of the Search Bar. | 155 if (search_provider_icon_visible) { |
| 152 float search_provider_icon_left; | 156 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.
| |
| 153 if (is_rtl) { | 157 layer_->AddChild(search_provider_icon_); |
| 154 search_provider_icon_left = search_panel_width - | 158 } |
| 155 search_provider_icon_resource->size.width() - search_bar_margin_side; | 159 |
| 160 search_provider_icon_sprites_per_row_ = | |
| 161 search_provider_icon_sprites_per_row; | |
| 162 search_provider_icon_sprite_rows_ = search_provider_icon_sprite_rows; | |
| 163 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,
| |
| 164 search_provider_icon_resource->size.width() / | |
| 165 search_provider_icon_sprites_per_row_; | |
| 166 float search_provider_icon_sprite_height = | |
| 167 search_provider_icon_resource->size.height() / | |
| 168 search_provider_icon_sprite_rows_; | |
| 169 | |
| 170 // Positions the Search Provider Icon at the start of the Search Bar. | |
| 171 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.
| |
| 172 if (is_rtl) { | |
| 173 search_provider_icon_left = search_panel_width - | |
| 174 search_provider_icon_sprite_width - search_bar_margin_side; | |
| 175 } else { | |
| 176 search_provider_icon_left = search_bar_margin_side; | |
| 177 } | |
| 178 | |
| 179 // Centers the Search Provider Icon vertically in the Search Bar. | |
| 180 float search_provider_icon_top = | |
| 181 search_bar_height / 2 - | |
| 182 search_provider_icon_sprite_height / 2; | |
| 183 search_provider_icon_->SetUIResourceId( | |
| 184 search_provider_icon_resource->ui_resource->id()); | |
| 185 gfx::Size* size = new gfx::Size(search_provider_icon_sprite_width, | |
| 186 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.
| |
| 187 search_provider_icon_->SetBounds(*size); | |
| 188 search_provider_icon_->SetPosition( | |
| 189 gfx::PointF(search_provider_icon_left, search_provider_icon_top)); | |
| 190 | |
| 191 // Sets the portion of search_provider_icon_ that gets drawn. | |
| 192 SetSearchProviderIconUV(search_provider_icon_sprite_frame); | |
| 156 } else { | 193 } else { |
| 157 search_provider_icon_left = search_bar_margin_side; | 194 if (search_provider_icon_.get() && search_provider_icon_->parent()) { |
| 195 search_provider_icon_->RemoveFromParent(); | |
| 196 } | |
| 158 } | 197 } |
| 159 | 198 |
| 160 // Centers the Search Provider Icon vertically in the Search Bar. | |
| 161 float search_provider_icon_top = | |
| 162 search_bar_height / 2 - | |
| 163 search_provider_icon_resource->size.height() / 2; | |
| 164 | |
| 165 search_provider_icon_->SetUIResourceId( | |
| 166 search_provider_icon_resource->ui_resource->id()); | |
| 167 search_provider_icon_->SetBounds(search_provider_icon_resource->size); | |
| 168 search_provider_icon_->SetPosition( | |
| 169 gfx::PointF(search_provider_icon_left, search_provider_icon_top)); | |
| 170 | |
| 171 // --------------------------------------------------------------------------- | 199 // --------------------------------------------------------------------------- |
| 172 // Arrow Icon | 200 // Arrow Icon |
| 173 // --------------------------------------------------------------------------- | 201 // --------------------------------------------------------------------------- |
| 174 // Grabs the Search Arrow Icon resource. | 202 // Grabs the Search Arrow Icon resource. |
| 175 ui::ResourceManager::Resource* arrow_icon_resource = | 203 ui::ResourceManager::Resource* arrow_icon_resource = |
| 176 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 204 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
| 177 arrow_up_resource_id); | 205 arrow_up_resource_id); |
| 178 if (arrow_icon_->parent() != layer_) { | 206 if (arrow_icon_->parent() != layer_) { |
| 179 layer_->AddChild(arrow_icon_); | 207 layer_->AddChild(arrow_icon_); |
| 180 } | 208 } |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 423 cc::Layer::Create(content::Compositor::LayerSettings())), | 451 cc::Layer::Create(content::Compositor::LayerSettings())), |
| 424 search_bar_border_( | 452 search_bar_border_( |
| 425 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), | 453 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), |
| 426 progress_bar_( | 454 progress_bar_( |
| 427 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), | 455 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), |
| 428 progress_bar_background_( | 456 progress_bar_background_( |
| 429 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), | 457 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), |
| 430 search_promo_( | 458 search_promo_( |
| 431 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 459 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
| 432 search_promo_container_( | 460 search_promo_container_( |
| 433 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())) { | 461 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), |
| 462 search_provider_icon_sprites_per_row_(0), | |
| 463 search_provider_icon_sprite_rows_(0) { | |
| 434 layer_->SetMasksToBounds(false); | 464 layer_->SetMasksToBounds(false); |
| 435 layer_->SetIsDrawable(true); | 465 layer_->SetIsDrawable(true); |
| 436 | 466 |
| 437 // Panel Shadow | 467 // Panel Shadow |
| 438 panel_shadow_->SetIsDrawable(true); | 468 panel_shadow_->SetIsDrawable(true); |
| 439 panel_shadow_->SetFillCenter(false); | 469 panel_shadow_->SetFillCenter(false); |
| 440 layer_->AddChild(panel_shadow_); | 470 layer_->AddChild(panel_shadow_); |
| 441 | 471 |
| 442 // Search Bar Background | 472 // Search Bar Background |
| 443 search_bar_background_->SetIsDrawable(true); | 473 search_bar_background_->SetIsDrawable(true); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 search_bar_shadow_->SetIsDrawable(true); | 514 search_bar_shadow_->SetIsDrawable(true); |
| 485 } | 515 } |
| 486 | 516 |
| 487 ContextualSearchLayer::~ContextualSearchLayer() { | 517 ContextualSearchLayer::~ContextualSearchLayer() { |
| 488 } | 518 } |
| 489 | 519 |
| 490 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() { | 520 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() { |
| 491 return layer_; | 521 return layer_; |
| 492 } | 522 } |
| 493 | 523 |
| 524 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.
| |
| 525 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.
| |
| 526 float row = (float) (sprite_frame / search_provider_icon_sprites_per_row_); | |
| 527 CHECK(row <= search_provider_icon_sprite_rows_); | |
| 528 | |
| 529 float top_left_x = column / ((float) search_provider_icon_sprites_per_row_); | |
| 530 float top_left_y = row / ((float) search_provider_icon_sprite_rows_); | |
| 531 float bottom_right_x = (column + 1.f) / | |
| 532 ((float) search_provider_icon_sprites_per_row_); | |
| 533 float bottom_right_y = (row + 1.f) / | |
| 534 ((float) search_provider_icon_sprite_rows_); | |
| 535 search_provider_icon_->SetUV(gfx::PointF(top_left_x, top_left_y), | |
| 536 gfx::PointF(bottom_right_x, bottom_right_y)); | |
| 537 } | |
| 538 | |
| 494 } // namespace android | 539 } // namespace android |
| 495 } // namespace chrome | 540 } // namespace chrome |
| OLD | NEW |