| 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 "chrome/browser/android/compositor/layer/crushed_sprite_layer.h" |
| 11 #include "content/public/browser/android/compositor.h" | 12 #include "content/public/browser/android/compositor.h" |
| 12 #include "content/public/browser/android/content_view_core.h" | 13 #include "content/public/browser/android/content_view_core.h" |
| 13 #include "third_party/skia/include/core/SkColor.h" | 14 #include "third_party/skia/include/core/SkColor.h" |
| 14 #include "ui/android/resources/resource_manager.h" | 15 #include "ui/android/resources/resource_manager.h" |
| 15 #include "ui/android/resources/ui_resource_android.h" | 16 #include "ui/android/resources/ui_resource_android.h" |
| 16 #include "ui/base/l10n/l10n_util_android.h" | 17 #include "ui/base/l10n/l10n_util_android.h" |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 const SkColor kSearchBackgroundColor = SkColorSetRGB(0xee, 0xee, 0xee); | 21 const SkColor kSearchBackgroundColor = SkColorSetRGB(0xee, 0xee, 0xee); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 float search_panel_height, | 54 float search_panel_height, |
| 54 float search_bar_margin_side, | 55 float search_bar_margin_side, |
| 55 float search_bar_height, | 56 float search_bar_height, |
| 56 float search_context_opacity, | 57 float search_context_opacity, |
| 57 float search_term_opacity, | 58 float search_term_opacity, |
| 58 bool search_bar_border_visible, | 59 bool search_bar_border_visible, |
| 59 float search_bar_border_y, | 60 float search_bar_border_y, |
| 60 float search_bar_border_height, | 61 float search_bar_border_height, |
| 61 bool search_bar_shadow_visible, | 62 bool search_bar_shadow_visible, |
| 62 float search_bar_shadow_opacity, | 63 float search_bar_shadow_opacity, |
| 64 bool search_provider_icon_sprite_visible, |
| 65 float search_provider_icon_sprite_size, |
| 66 std::vector<int> search_provider_icon_sprite_rects, |
| 67 bool search_provider_icon_sprite_paint_previous_frames, |
| 63 float arrow_icon_opacity, | 68 float arrow_icon_opacity, |
| 64 float arrow_icon_rotation, | 69 float arrow_icon_rotation, |
| 65 float close_icon_opacity, | 70 float close_icon_opacity, |
| 66 bool progress_bar_visible, | 71 bool progress_bar_visible, |
| 67 float progress_bar_y, | 72 float progress_bar_y, |
| 68 float progress_bar_height, | 73 float progress_bar_height, |
| 69 float progress_bar_opacity, | 74 float progress_bar_opacity, |
| 70 int progress_bar_completion) { | 75 int progress_bar_completion) { |
| 71 // Grabs the dynamic Search Bar Text resource. | 76 // Grabs the dynamic Search Bar Text resource. |
| 72 ui::ResourceManager::Resource* search_context_resource = | 77 ui::ResourceManager::Resource* search_context_resource = |
| 73 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, | 78 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, |
| 74 search_context_resource_id); | 79 search_context_resource_id); |
| 75 ui::ResourceManager::Resource* search_term_resource = | 80 ui::ResourceManager::Resource* search_term_resource = |
| 76 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, | 81 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, |
| 77 search_term_resource_id); | 82 search_term_resource_id); |
| 78 | 83 |
| 79 // Grabs required static resources. | 84 // Grabs required static resources. |
| 80 ui::ResourceManager::Resource* panel_shadow_resource = | 85 ui::ResourceManager::Resource* panel_shadow_resource = |
| 81 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 86 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
| 82 panel_shadow_resource_id); | 87 panel_shadow_resource_id); |
| 83 ui::ResourceManager::Resource* search_provider_icon_resource = | 88 ui::ResourceManager::Resource* search_provider_icon_sprite_resource = |
| 84 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 89 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
| 85 search_provider_icon_resource_id); | 90 search_provider_icon_resource_id); |
| 86 | 91 |
| 87 DCHECK(panel_shadow_resource); | 92 DCHECK(panel_shadow_resource); |
| 88 DCHECK(search_provider_icon_resource); | 93 DCHECK(search_provider_icon_sprite_resource); |
| 89 | 94 |
| 90 // Round values to avoid pixel gap between layers. | 95 // Round values to avoid pixel gap between layers. |
| 91 search_bar_height = floor(search_bar_height); | 96 search_bar_height = floor(search_bar_height); |
| 92 | 97 |
| 93 bool is_rtl = l10n_util::IsLayoutRtl(); | 98 bool is_rtl = l10n_util::IsLayoutRtl(); |
| 94 | 99 |
| 95 // --------------------------------------------------------------------------- | 100 // --------------------------------------------------------------------------- |
| 96 // Panel Shadow | 101 // Panel Shadow |
| 97 // --------------------------------------------------------------------------- | 102 // --------------------------------------------------------------------------- |
| 98 gfx::Size shadow_res_size = panel_shadow_resource->size; | 103 gfx::Size shadow_res_size = panel_shadow_resource->size; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 search_term_resource->size.height() / 2; | 145 search_term_resource->size.height() / 2; |
| 141 search_term_->SetUIResourceId(search_term_resource->ui_resource->id()); | 146 search_term_->SetUIResourceId(search_term_resource->ui_resource->id()); |
| 142 search_term_->SetBounds(search_term_resource->size); | 147 search_term_->SetBounds(search_term_resource->size); |
| 143 search_term_->SetPosition(gfx::PointF(0.f, search_bar_padding_top)); | 148 search_term_->SetPosition(gfx::PointF(0.f, search_bar_padding_top)); |
| 144 search_term_->SetOpacity(search_term_opacity); | 149 search_term_->SetOpacity(search_term_opacity); |
| 145 } | 150 } |
| 146 | 151 |
| 147 // --------------------------------------------------------------------------- | 152 // --------------------------------------------------------------------------- |
| 148 // Search Provider Icon | 153 // Search Provider Icon |
| 149 // --------------------------------------------------------------------------- | 154 // --------------------------------------------------------------------------- |
| 150 // Positions the Search Provider Icon at the start of the Search Bar. | 155 if (search_provider_icon_sprite_visible) { |
| 151 float search_provider_icon_left; | 156 if (search_provider_icon_sprite_->parent() != layer_) { |
| 152 if (is_rtl) { | 157 layer_->AddChild(search_provider_icon_sprite_); |
| 153 search_provider_icon_left = search_panel_width - | 158 } |
| 154 search_provider_icon_resource->size.width() - search_bar_margin_side; | 159 |
| 160 // Positions the Search Provider Icon at the start of the Search Bar. |
| 161 float icon_x; |
| 162 if (is_rtl) { |
| 163 icon_x = search_panel_width - search_provider_icon_sprite_size - |
| 164 search_bar_margin_side; |
| 165 } else { |
| 166 icon_x = search_bar_margin_side; |
| 167 } |
| 168 |
| 169 // Centers the Search Provider Icon vertically in the Search Bar. |
| 170 float icon_y = search_bar_height / 2 - search_provider_icon_sprite_size / 2; |
| 171 search_provider_icon_sprite_->SetBounds( |
| 172 gfx::Size(search_provider_icon_sprite_size, |
| 173 search_provider_icon_sprite_size)); |
| 174 search_provider_icon_sprite_->SetPosition( |
| 175 gfx::PointF(icon_x, icon_y)); |
| 176 |
| 177 // Create source and destination gfx::Rect's for each rectangle in |
| 178 // |search_provider_icon_sprite_rects|. Each rectangle consists of 6 values: |
| 179 // i: destination x i+1: destination y i+2: source x i+3: source y |
| 180 // i+4: width i+5: height |
| 181 std::vector<std::pair<gfx::Rect, gfx::Rect>> rects; |
| 182 for (size_t i = 0; i < search_provider_icon_sprite_rects.size();) { |
| 183 gfx::Rect sprite_rect_destination(search_provider_icon_sprite_rects[i], |
| 184 search_provider_icon_sprite_rects[i+1], |
| 185 search_provider_icon_sprite_rects[i+4], |
| 186 search_provider_icon_sprite_rects[i+5]); |
| 187 gfx::Rect sprite_rect_source(search_provider_icon_sprite_rects[i+2], |
| 188 search_provider_icon_sprite_rects[i+3], |
| 189 search_provider_icon_sprite_rects[i+4], |
| 190 search_provider_icon_sprite_rects[i+5]); |
| 191 rects.push_back(std::pair<gfx::Rect, gfx::Rect>(sprite_rect_source, |
| 192 sprite_rect_destination)); |
| 193 i += 6; |
| 194 } |
| 195 |
| 196 search_provider_icon_sprite_->UpdateCrushedSprite( |
| 197 search_provider_icon_sprite_resource->ui_resource->GetSkBitmap(), rects, |
| 198 search_provider_icon_sprite_paint_previous_frames); |
| 155 } else { | 199 } else { |
| 156 search_provider_icon_left = search_bar_margin_side; | 200 if (search_provider_icon_sprite_.get() && |
| 201 search_provider_icon_sprite_->parent()) { |
| 202 search_provider_icon_sprite_->RemoveFromParent(); |
| 203 } |
| 157 } | 204 } |
| 158 | 205 |
| 159 // Centers the Search Provider Icon vertically in the Search Bar. | |
| 160 float search_provider_icon_top = | |
| 161 search_bar_height / 2 - | |
| 162 search_provider_icon_resource->size.height() / 2; | |
| 163 | |
| 164 search_provider_icon_->SetUIResourceId( | |
| 165 search_provider_icon_resource->ui_resource->id()); | |
| 166 search_provider_icon_->SetBounds(search_provider_icon_resource->size); | |
| 167 search_provider_icon_->SetPosition( | |
| 168 gfx::PointF(search_provider_icon_left, search_provider_icon_top)); | |
| 169 | |
| 170 // --------------------------------------------------------------------------- | 206 // --------------------------------------------------------------------------- |
| 171 // Arrow Icon | 207 // Arrow Icon |
| 172 // --------------------------------------------------------------------------- | 208 // --------------------------------------------------------------------------- |
| 173 // Grabs the Search Arrow Icon resource. | 209 // Grabs the Search Arrow Icon resource. |
| 174 ui::ResourceManager::Resource* arrow_icon_resource = | 210 ui::ResourceManager::Resource* arrow_icon_resource = |
| 175 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 211 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
| 176 arrow_up_resource_id); | 212 arrow_up_resource_id); |
| 177 | 213 |
| 178 // Positions the icon at the end of the Search Bar. | 214 // Positions the icon at the end of the Search Bar. |
| 179 float arrow_icon_left; | 215 float arrow_icon_left; |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 panel_shadow_( | 430 panel_shadow_( |
| 395 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), | 431 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), |
| 396 search_bar_background_( | 432 search_bar_background_( |
| 397 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), | 433 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), |
| 398 search_context_( | 434 search_context_( |
| 399 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 435 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
| 400 search_term_( | 436 search_term_( |
| 401 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 437 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
| 402 search_bar_shadow_( | 438 search_bar_shadow_( |
| 403 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 439 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
| 404 search_provider_icon_( | 440 search_provider_icon_sprite_(CrushedSpriteLayer::Create()), |
| 405 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | |
| 406 arrow_icon_( | 441 arrow_icon_( |
| 407 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 442 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
| 408 close_icon_( | 443 close_icon_( |
| 409 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 444 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
| 410 content_view_container_( | 445 content_view_container_( |
| 411 cc::Layer::Create(content::Compositor::LayerSettings())), | 446 cc::Layer::Create(content::Compositor::LayerSettings())), |
| 412 search_bar_border_( | 447 search_bar_border_( |
| 413 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), | 448 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), |
| 414 progress_bar_( | 449 progress_bar_( |
| 415 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), | 450 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 432 search_bar_background_->SetBackgroundColor(kSearchBarBackgroundColor); | 467 search_bar_background_->SetBackgroundColor(kSearchBarBackgroundColor); |
| 433 layer_->AddChild(search_bar_background_); | 468 layer_->AddChild(search_bar_background_); |
| 434 | 469 |
| 435 // Search Bar Text | 470 // Search Bar Text |
| 436 search_context_->SetIsDrawable(true); | 471 search_context_->SetIsDrawable(true); |
| 437 layer_->AddChild(search_context_); | 472 layer_->AddChild(search_context_); |
| 438 search_term_->SetIsDrawable(true); | 473 search_term_->SetIsDrawable(true); |
| 439 layer_->AddChild(search_term_); | 474 layer_->AddChild(search_term_); |
| 440 | 475 |
| 441 // Search Provider Icon | 476 // Search Provider Icon |
| 442 search_provider_icon_->SetIsDrawable(true); | 477 search_provider_icon_sprite_->SetIsDrawable(true); |
| 443 layer_->AddChild(search_provider_icon_); | |
| 444 | 478 |
| 445 // Arrow Icon | 479 // Arrow Icon |
| 446 arrow_icon_->SetIsDrawable(true); | 480 arrow_icon_->SetIsDrawable(true); |
| 447 layer_->AddChild(arrow_icon_); | 481 layer_->AddChild(arrow_icon_); |
| 448 | 482 |
| 449 // Close Icon | 483 // Close Icon |
| 450 close_icon_->SetIsDrawable(true); | 484 close_icon_->SetIsDrawable(true); |
| 451 layer_->AddChild(close_icon_); | 485 layer_->AddChild(close_icon_); |
| 452 | 486 |
| 453 // Search Opt Out Promo | 487 // Search Opt Out Promo |
| (...skipping 22 matching lines...) Expand all Loading... |
| 476 | 510 |
| 477 ContextualSearchLayer::~ContextualSearchLayer() { | 511 ContextualSearchLayer::~ContextualSearchLayer() { |
| 478 } | 512 } |
| 479 | 513 |
| 480 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() { | 514 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() { |
| 481 return layer_; | 515 return layer_; |
| 482 } | 516 } |
| 483 | 517 |
| 484 } // namespace android | 518 } // namespace android |
| 485 } // namespace chrome | 519 } // namespace chrome |
| OLD | NEW |