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); |
21 const SkColor kSearchBarBackgroundColor = SkColorSetRGB(0xff, 0xff, 0xff); | 22 const SkColor kSearchBarBackgroundColor = SkColorSetRGB(0xff, 0xff, 0xff); |
22 const SkColor kSearchBarBorderColor = SkColorSetRGB(0xf1, 0xf1, 0xf1); | 23 const SkColor kSearchBarBorderColor = SkColorSetRGB(0xf1, 0xf1, 0xf1); |
23 | 24 |
24 } // namespace | 25 } // namespace |
25 | 26 |
26 namespace chrome { | 27 namespace chrome { |
27 namespace android { | 28 namespace android { |
28 | 29 |
29 // static | 30 // static |
30 scoped_refptr<ContextualSearchLayer> ContextualSearchLayer::Create( | 31 scoped_refptr<ContextualSearchLayer> ContextualSearchLayer::Create( |
31 ui::ResourceManager* resource_manager) { | 32 ui::ResourceManager* resource_manager) { |
32 return make_scoped_refptr(new ContextualSearchLayer(resource_manager)); | 33 return make_scoped_refptr(new ContextualSearchLayer(resource_manager)); |
33 } | 34 } |
34 | 35 |
35 void ContextualSearchLayer::SetProperties( | 36 void ContextualSearchLayer::SetProperties( |
36 int panel_shadow_resource_id, | 37 int panel_shadow_resource_id, |
37 int search_context_resource_id, | 38 int search_context_resource_id, |
38 int search_term_resource_id, | 39 int search_term_resource_id, |
39 int search_bar_shadow_resource_id, | 40 int search_bar_shadow_resource_id, |
40 int search_provider_icon_resource_id, | |
41 int arrow_up_resource_id, | 41 int arrow_up_resource_id, |
42 int close_icon_resource_id, | 42 int close_icon_resource_id, |
43 int progress_bar_background_resource_id, | 43 int progress_bar_background_resource_id, |
44 int progress_bar_resource_id, | 44 int progress_bar_resource_id, |
45 int search_promo_resource_id, | 45 int search_promo_resource_id, |
46 content::ContentViewCore* content_view_core, | 46 content::ContentViewCore* content_view_core, |
47 bool search_promo_visible, | 47 bool search_promo_visible, |
48 float search_promo_height, | 48 float search_promo_height, |
49 float search_promo_opacity, | 49 float search_promo_opacity, |
50 float search_panel_x, | 50 float search_panel_x, |
51 float search_panel_y, | 51 float search_panel_y, |
52 float search_panel_width, | 52 float search_panel_width, |
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_sprite_visible, |
| 64 float search_provider_icon_sprite_size, |
| 65 float search_provider_icon_sprite_scale, |
| 66 SkBitmap search_provider_icon_sprite_bitmap, |
| 67 std::vector<int> search_provider_icon_sprite_rects, |
| 68 bool search_provider_icon_sprite_paint_previous_frames, |
63 float arrow_icon_opacity, | 69 float arrow_icon_opacity, |
64 float arrow_icon_rotation, | 70 float arrow_icon_rotation, |
65 float close_icon_opacity, | 71 float close_icon_opacity, |
66 bool progress_bar_visible, | 72 bool progress_bar_visible, |
67 float progress_bar_y, | 73 float progress_bar_y, |
68 float progress_bar_height, | 74 float progress_bar_height, |
69 float progress_bar_opacity, | 75 float progress_bar_opacity, |
70 int progress_bar_completion) { | 76 int progress_bar_completion) { |
71 // Grabs the dynamic Search Bar Text resource. | 77 // Grabs the dynamic Search Bar Text resource. |
72 ui::ResourceManager::Resource* search_context_resource = | 78 ui::ResourceManager::Resource* search_context_resource = |
73 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, | 79 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, |
74 search_context_resource_id); | 80 search_context_resource_id); |
75 ui::ResourceManager::Resource* search_term_resource = | 81 ui::ResourceManager::Resource* search_term_resource = |
76 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, | 82 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, |
77 search_term_resource_id); | 83 search_term_resource_id); |
78 | 84 |
79 // Grabs required static resources. | 85 // Grabs required static resources. |
80 ui::ResourceManager::Resource* panel_shadow_resource = | 86 ui::ResourceManager::Resource* panel_shadow_resource = |
81 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 87 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
82 panel_shadow_resource_id); | 88 panel_shadow_resource_id); |
83 ui::ResourceManager::Resource* search_provider_icon_resource = | |
84 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | |
85 search_provider_icon_resource_id); | |
86 | 89 |
87 DCHECK(panel_shadow_resource); | 90 DCHECK(panel_shadow_resource); |
88 DCHECK(search_provider_icon_resource); | |
89 | 91 |
90 // Round values to avoid pixel gap between layers. | 92 // Round values to avoid pixel gap between layers. |
91 search_bar_height = floor(search_bar_height); | 93 search_bar_height = floor(search_bar_height); |
92 | 94 |
93 bool is_rtl = l10n_util::IsLayoutRtl(); | 95 bool is_rtl = l10n_util::IsLayoutRtl(); |
94 | 96 |
95 // --------------------------------------------------------------------------- | 97 // --------------------------------------------------------------------------- |
96 // Panel Shadow | 98 // Panel Shadow |
97 // --------------------------------------------------------------------------- | 99 // --------------------------------------------------------------------------- |
98 gfx::Size shadow_res_size = panel_shadow_resource->size; | 100 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; | 142 search_term_resource->size.height() / 2; |
141 search_term_->SetUIResourceId(search_term_resource->ui_resource->id()); | 143 search_term_->SetUIResourceId(search_term_resource->ui_resource->id()); |
142 search_term_->SetBounds(search_term_resource->size); | 144 search_term_->SetBounds(search_term_resource->size); |
143 search_term_->SetPosition(gfx::PointF(0.f, search_bar_padding_top)); | 145 search_term_->SetPosition(gfx::PointF(0.f, search_bar_padding_top)); |
144 search_term_->SetOpacity(search_term_opacity); | 146 search_term_->SetOpacity(search_term_opacity); |
145 } | 147 } |
146 | 148 |
147 // --------------------------------------------------------------------------- | 149 // --------------------------------------------------------------------------- |
148 // Search Provider Icon | 150 // Search Provider Icon |
149 // --------------------------------------------------------------------------- | 151 // --------------------------------------------------------------------------- |
150 // Positions the Search Provider Icon at the start of the Search Bar. | 152 if (search_provider_icon_sprite_visible) { |
151 float search_provider_icon_left; | 153 if (search_provider_icon_sprite_->parent() != layer_) { |
152 if (is_rtl) { | 154 layer_->AddChild(search_provider_icon_sprite_); |
153 search_provider_icon_left = search_panel_width - | 155 } |
154 search_provider_icon_resource->size.width() - search_bar_margin_side; | 156 |
| 157 // Positions the Search Provider Icon at the start of the Search Bar. |
| 158 float icon_x; |
| 159 if (is_rtl) { |
| 160 icon_x = search_panel_width - search_provider_icon_sprite_size - |
| 161 search_bar_margin_side; |
| 162 } else { |
| 163 icon_x = search_bar_margin_side; |
| 164 } |
| 165 |
| 166 // Centers the Search Provider Icon vertically in the Search Bar. |
| 167 float icon_y = search_bar_height / 2 - search_provider_icon_sprite_size / 2; |
| 168 search_provider_icon_sprite_->SetBounds( |
| 169 gfx::Size(search_provider_icon_sprite_size, |
| 170 search_provider_icon_sprite_size)); |
| 171 search_provider_icon_sprite_->SetPosition( |
| 172 gfx::PointF(icon_x, icon_y)); |
| 173 |
| 174 // Create source and destination gfx::Rect's for each rectangle in |
| 175 // |search_provider_icon_sprite_rects|. Each rectangle consists of 6 values: |
| 176 // i: destination x i+1: destination y i+2: source x i+3: source y |
| 177 // i+4: width i+5: height |
| 178 std::vector<std::pair<gfx::Rect, gfx::Rect>> rects; |
| 179 for (size_t i = 0; i < search_provider_icon_sprite_rects.size();) { |
| 180 gfx::Rect sprite_rect_destination(search_provider_icon_sprite_rects[i], |
| 181 search_provider_icon_sprite_rects[i+1], |
| 182 search_provider_icon_sprite_rects[i+4], |
| 183 search_provider_icon_sprite_rects[i+5]); |
| 184 gfx::Rect sprite_rect_source(search_provider_icon_sprite_rects[i+2], |
| 185 search_provider_icon_sprite_rects[i+3], |
| 186 search_provider_icon_sprite_rects[i+4], |
| 187 search_provider_icon_sprite_rects[i+5]); |
| 188 rects.push_back(std::pair<gfx::Rect, gfx::Rect>(sprite_rect_source, |
| 189 sprite_rect_destination)); |
| 190 i += 6; |
| 191 } |
| 192 |
| 193 search_provider_icon_sprite_->UpdateCrushedSprite( |
| 194 search_provider_icon_sprite_bitmap, rects, |
| 195 search_provider_icon_sprite_paint_previous_frames, |
| 196 search_provider_icon_sprite_scale); |
155 } else { | 197 } else { |
156 search_provider_icon_left = search_bar_margin_side; | 198 if (search_provider_icon_sprite_.get() && |
| 199 search_provider_icon_sprite_->parent()) { |
| 200 search_provider_icon_sprite_->RemoveFromParent(); |
| 201 } |
157 } | 202 } |
158 | 203 |
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 // --------------------------------------------------------------------------- | 204 // --------------------------------------------------------------------------- |
171 // Arrow Icon | 205 // Arrow Icon |
172 // --------------------------------------------------------------------------- | 206 // --------------------------------------------------------------------------- |
173 // Grabs the Search Arrow Icon resource. | 207 // Grabs the Search Arrow Icon resource. |
174 ui::ResourceManager::Resource* arrow_icon_resource = | 208 ui::ResourceManager::Resource* arrow_icon_resource = |
175 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 209 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
176 arrow_up_resource_id); | 210 arrow_up_resource_id); |
177 | 211 |
178 // Positions the icon at the end of the Search Bar. | 212 // Positions the icon at the end of the Search Bar. |
179 float arrow_icon_left; | 213 float arrow_icon_left; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 panel_shadow_( | 428 panel_shadow_( |
395 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), | 429 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), |
396 search_bar_background_( | 430 search_bar_background_( |
397 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), | 431 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), |
398 search_context_( | 432 search_context_( |
399 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 433 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
400 search_term_( | 434 search_term_( |
401 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 435 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
402 search_bar_shadow_( | 436 search_bar_shadow_( |
403 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 437 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
404 search_provider_icon_( | 438 search_provider_icon_sprite_(CrushedSpriteLayer::Create()), |
405 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | |
406 arrow_icon_( | 439 arrow_icon_( |
407 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 440 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
408 close_icon_( | 441 close_icon_( |
409 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 442 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
410 content_view_container_( | 443 content_view_container_( |
411 cc::Layer::Create(content::Compositor::LayerSettings())), | 444 cc::Layer::Create(content::Compositor::LayerSettings())), |
412 search_bar_border_( | 445 search_bar_border_( |
413 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), | 446 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), |
414 progress_bar_( | 447 progress_bar_( |
415 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), | 448 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), |
(...skipping 16 matching lines...) Expand all Loading... |
432 search_bar_background_->SetBackgroundColor(kSearchBarBackgroundColor); | 465 search_bar_background_->SetBackgroundColor(kSearchBarBackgroundColor); |
433 layer_->AddChild(search_bar_background_); | 466 layer_->AddChild(search_bar_background_); |
434 | 467 |
435 // Search Bar Text | 468 // Search Bar Text |
436 search_context_->SetIsDrawable(true); | 469 search_context_->SetIsDrawable(true); |
437 layer_->AddChild(search_context_); | 470 layer_->AddChild(search_context_); |
438 search_term_->SetIsDrawable(true); | 471 search_term_->SetIsDrawable(true); |
439 layer_->AddChild(search_term_); | 472 layer_->AddChild(search_term_); |
440 | 473 |
441 // Search Provider Icon | 474 // Search Provider Icon |
442 search_provider_icon_->SetIsDrawable(true); | 475 search_provider_icon_sprite_->SetIsDrawable(true); |
443 layer_->AddChild(search_provider_icon_); | |
444 | 476 |
445 // Arrow Icon | 477 // Arrow Icon |
446 arrow_icon_->SetIsDrawable(true); | 478 arrow_icon_->SetIsDrawable(true); |
447 layer_->AddChild(arrow_icon_); | 479 layer_->AddChild(arrow_icon_); |
448 | 480 |
449 // Close Icon | 481 // Close Icon |
450 close_icon_->SetIsDrawable(true); | 482 close_icon_->SetIsDrawable(true); |
451 layer_->AddChild(close_icon_); | 483 layer_->AddChild(close_icon_); |
452 | 484 |
453 // Search Opt Out Promo | 485 // Search Opt Out Promo |
(...skipping 22 matching lines...) Expand all Loading... |
476 | 508 |
477 ContextualSearchLayer::~ContextualSearchLayer() { | 509 ContextualSearchLayer::~ContextualSearchLayer() { |
478 } | 510 } |
479 | 511 |
480 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() { | 512 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() { |
481 return layer_; | 513 return layer_; |
482 } | 514 } |
483 | 515 |
484 } // namespace android | 516 } // namespace android |
485 } // namespace chrome | 517 } // namespace chrome |
OLD | NEW |