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 bool close_icon_visible, | 70 bool close_icon_visible, |
66 float close_icon_opacity, | 71 float close_icon_opacity, |
67 bool progress_bar_visible, | 72 bool progress_bar_visible, |
68 float progress_bar_y, | 73 float progress_bar_y, |
69 float progress_bar_height, | 74 float progress_bar_height, |
70 float progress_bar_opacity, | 75 float progress_bar_opacity, |
71 int progress_bar_completion) { | 76 int progress_bar_completion) { |
72 // Grabs the dynamic Search Bar Text resource. | 77 // Grabs the dynamic Search Bar Text resource. |
73 ui::ResourceManager::Resource* search_context_resource = | 78 ui::ResourceManager::Resource* search_context_resource = |
74 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, | 79 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, |
75 search_context_resource_id); | 80 search_context_resource_id); |
76 ui::ResourceManager::Resource* search_term_resource = | 81 ui::ResourceManager::Resource* search_term_resource = |
77 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, | 82 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, |
78 search_term_resource_id); | 83 search_term_resource_id); |
79 | 84 |
80 // Grabs required static resources. | 85 // Grabs required static resources. |
81 ui::ResourceManager::Resource* panel_shadow_resource = | 86 ui::ResourceManager::Resource* panel_shadow_resource = |
82 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 87 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
83 panel_shadow_resource_id); | 88 panel_shadow_resource_id); |
84 ui::ResourceManager::Resource* search_provider_icon_resource = | 89 ui::ResourceManager::Resource* search_provider_icon_sprite_resource = |
85 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 90 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
86 search_provider_icon_resource_id); | 91 search_provider_icon_resource_id); |
87 | 92 |
88 DCHECK(panel_shadow_resource); | 93 DCHECK(panel_shadow_resource); |
89 DCHECK(search_provider_icon_resource); | 94 DCHECK(search_provider_icon_sprite_resource); |
90 | 95 |
91 // Round values to avoid pixel gap between layers. | 96 // Round values to avoid pixel gap between layers. |
92 search_bar_height = floor(search_bar_height); | 97 search_bar_height = floor(search_bar_height); |
93 | 98 |
94 bool is_rtl = l10n_util::IsLayoutRtl(); | 99 bool is_rtl = l10n_util::IsLayoutRtl(); |
95 | 100 |
96 // --------------------------------------------------------------------------- | 101 // --------------------------------------------------------------------------- |
97 // Panel Shadow | 102 // Panel Shadow |
98 // --------------------------------------------------------------------------- | 103 // --------------------------------------------------------------------------- |
99 gfx::Size shadow_res_size = panel_shadow_resource->size; | 104 gfx::Size shadow_res_size = panel_shadow_resource->size; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 search_term_resource->size.height() / 2; | 146 search_term_resource->size.height() / 2; |
142 search_term_->SetUIResourceId(search_term_resource->ui_resource->id()); | 147 search_term_->SetUIResourceId(search_term_resource->ui_resource->id()); |
143 search_term_->SetBounds(search_term_resource->size); | 148 search_term_->SetBounds(search_term_resource->size); |
144 search_term_->SetPosition(gfx::PointF(0.f, search_bar_padding_top)); | 149 search_term_->SetPosition(gfx::PointF(0.f, search_bar_padding_top)); |
145 search_term_->SetOpacity(search_term_opacity); | 150 search_term_->SetOpacity(search_term_opacity); |
146 } | 151 } |
147 | 152 |
148 // --------------------------------------------------------------------------- | 153 // --------------------------------------------------------------------------- |
149 // Search Provider Icon | 154 // Search Provider Icon |
150 // --------------------------------------------------------------------------- | 155 // --------------------------------------------------------------------------- |
151 // Positions the Search Provider Icon at the start of the Search Bar. | 156 if (search_provider_icon_sprite_visible) { |
152 float search_provider_icon_left; | 157 if (search_provider_icon_sprite_->layer()->parent() != layer_) { |
153 if (is_rtl) { | 158 layer_->AddChild(search_provider_icon_sprite_->layer()); |
154 search_provider_icon_left = search_panel_width - | 159 } |
155 search_provider_icon_resource->size.width() - search_bar_margin_side; | 160 |
| 161 // Positions the Search Provider Icon at the start of the Search Bar. |
| 162 float icon_x; |
| 163 if (is_rtl) { |
| 164 icon_x = search_panel_width - search_provider_icon_sprite_size - |
| 165 search_bar_margin_side; |
| 166 } else { |
| 167 icon_x = search_bar_margin_side; |
| 168 } |
| 169 |
| 170 // Centers the Search Provider Icon vertically in the Search Bar. |
| 171 float icon_y = search_bar_height / 2 - search_provider_icon_sprite_size / 2; |
| 172 search_provider_icon_sprite_->layer()->SetBounds( |
| 173 gfx::Size(search_provider_icon_sprite_size, |
| 174 search_provider_icon_sprite_size)); |
| 175 search_provider_icon_sprite_->layer()->SetPosition( |
| 176 gfx::PointF(icon_x, icon_y)); |
| 177 |
| 178 // Create source and destination gfx::Rect's for each rectangle in |
| 179 // |search_provider_icon_sprite_rects|. Each rectangle consists of 6 values: |
| 180 // i: destination x i+1: destination y i+2: source x i+3: source y |
| 181 // i+4: width i+5: height |
| 182 std::vector<std::pair<gfx::Rect, gfx::Rect>> rects; |
| 183 for (size_t i = 0; i < search_provider_icon_sprite_rects.size();) { |
| 184 gfx::Rect sprite_rect_destination(search_provider_icon_sprite_rects[i], |
| 185 search_provider_icon_sprite_rects[i+1], |
| 186 search_provider_icon_sprite_rects[i+4], |
| 187 search_provider_icon_sprite_rects[i+5]); |
| 188 gfx::Rect sprite_rect_source(search_provider_icon_sprite_rects[i+2], |
| 189 search_provider_icon_sprite_rects[i+3], |
| 190 search_provider_icon_sprite_rects[i+4], |
| 191 search_provider_icon_sprite_rects[i+5]); |
| 192 rects.push_back(std::pair<gfx::Rect, gfx::Rect>(sprite_rect_source, |
| 193 sprite_rect_destination)); |
| 194 i += 6; |
| 195 } |
| 196 |
| 197 search_provider_icon_sprite_->UpdateCrushedSprite( |
| 198 search_provider_icon_sprite_resource->ui_resource->GetSkBitmap(), rects, |
| 199 search_provider_icon_sprite_paint_previous_frames); |
156 } else { | 200 } else { |
157 search_provider_icon_left = search_bar_margin_side; | 201 if (search_provider_icon_sprite_.get() && |
| 202 search_provider_icon_sprite_->layer()->parent()) { |
| 203 search_provider_icon_sprite_->layer()->RemoveFromParent(); |
| 204 } |
158 } | 205 } |
159 | 206 |
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 // --------------------------------------------------------------------------- | 207 // --------------------------------------------------------------------------- |
172 // Arrow Icon | 208 // Arrow Icon |
173 // --------------------------------------------------------------------------- | 209 // --------------------------------------------------------------------------- |
174 // Grabs the Search Arrow Icon resource. | 210 // Grabs the Search Arrow Icon resource. |
175 ui::ResourceManager::Resource* arrow_icon_resource = | 211 ui::ResourceManager::Resource* arrow_icon_resource = |
176 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 212 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
177 arrow_up_resource_id); | 213 arrow_up_resource_id); |
178 if (arrow_icon_->parent() != layer_) { | 214 if (arrow_icon_->parent() != layer_) { |
179 layer_->AddChild(arrow_icon_); | 215 layer_->AddChild(arrow_icon_); |
180 } | 216 } |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 panel_shadow_( | 442 panel_shadow_( |
407 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), | 443 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), |
408 search_bar_background_( | 444 search_bar_background_( |
409 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), | 445 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), |
410 search_context_( | 446 search_context_( |
411 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 447 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
412 search_term_( | 448 search_term_( |
413 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 449 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
414 search_bar_shadow_( | 450 search_bar_shadow_( |
415 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 451 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
416 search_provider_icon_( | 452 search_provider_icon_sprite_(CrushedSpriteLayer::Create()), |
417 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | |
418 arrow_icon_( | 453 arrow_icon_( |
419 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 454 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
420 close_icon_( | 455 close_icon_( |
421 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 456 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
422 content_view_container_( | 457 content_view_container_( |
423 cc::Layer::Create(content::Compositor::LayerSettings())), | 458 cc::Layer::Create(content::Compositor::LayerSettings())), |
424 search_bar_border_( | 459 search_bar_border_( |
425 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), | 460 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), |
426 progress_bar_( | 461 progress_bar_( |
427 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), | 462 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), |
(...skipping 16 matching lines...) Expand all Loading... |
444 search_bar_background_->SetBackgroundColor(kSearchBarBackgroundColor); | 479 search_bar_background_->SetBackgroundColor(kSearchBarBackgroundColor); |
445 layer_->AddChild(search_bar_background_); | 480 layer_->AddChild(search_bar_background_); |
446 | 481 |
447 // Search Bar Text | 482 // Search Bar Text |
448 search_context_->SetIsDrawable(true); | 483 search_context_->SetIsDrawable(true); |
449 layer_->AddChild(search_context_); | 484 layer_->AddChild(search_context_); |
450 search_term_->SetIsDrawable(true); | 485 search_term_->SetIsDrawable(true); |
451 layer_->AddChild(search_term_); | 486 layer_->AddChild(search_term_); |
452 | 487 |
453 // Search Provider Icon | 488 // Search Provider Icon |
454 search_provider_icon_->SetIsDrawable(true); | 489 search_provider_icon_sprite_->layer()->SetIsDrawable(true); |
455 layer_->AddChild(search_provider_icon_); | |
456 | 490 |
457 // Arrow Icon | 491 // Arrow Icon |
458 arrow_icon_->SetIsDrawable(true); | 492 arrow_icon_->SetIsDrawable(true); |
459 | 493 |
460 // Close Icon | 494 // Close Icon |
461 close_icon_->SetIsDrawable(true); | 495 close_icon_->SetIsDrawable(true); |
462 | 496 |
463 // Search Opt Out Promo | 497 // Search Opt Out Promo |
464 search_promo_container_->SetIsDrawable(true); | 498 search_promo_container_->SetIsDrawable(true); |
465 search_promo_container_->SetBackgroundColor(kSearchBackgroundColor); | 499 search_promo_container_->SetBackgroundColor(kSearchBackgroundColor); |
(...skipping 20 matching lines...) Expand all Loading... |
486 | 520 |
487 ContextualSearchLayer::~ContextualSearchLayer() { | 521 ContextualSearchLayer::~ContextualSearchLayer() { |
488 } | 522 } |
489 | 523 |
490 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() { | 524 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() { |
491 return layer_; | 525 return layer_; |
492 } | 526 } |
493 | 527 |
494 } // namespace android | 528 } // namespace android |
495 } // namespace chrome | 529 } // namespace chrome |
OLD | NEW |