Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(905)

Side by Side Diff: chrome/browser/android/compositor/layer/contextual_search_layer.cc

Issue 1337703002: [Contextual Search] Add support for crushed sprites and animate the search provider icon (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changes from reviews Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 float search_provider_icon_sprite_size,
64 int search_provider_icon_sprite_frame,
63 float arrow_icon_opacity, 65 float arrow_icon_opacity,
64 float arrow_icon_rotation, 66 float arrow_icon_rotation,
65 bool close_icon_visible, 67 bool close_icon_visible,
66 float close_icon_opacity, 68 float close_icon_opacity,
67 bool progress_bar_visible, 69 bool progress_bar_visible,
68 float progress_bar_y, 70 float progress_bar_y,
69 float progress_bar_height, 71 float progress_bar_height,
70 float progress_bar_opacity, 72 float progress_bar_opacity,
71 int progress_bar_completion) { 73 int progress_bar_completion) {
72 // Grabs the dynamic Search Bar Text resource. 74 // Grabs the dynamic Search Bar Text resource.
73 ui::ResourceManager::Resource* search_context_resource = 75 ui::ResourceManager::Resource* search_context_resource =
74 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, 76 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC,
75 search_context_resource_id); 77 search_context_resource_id);
76 ui::ResourceManager::Resource* search_term_resource = 78 ui::ResourceManager::Resource* search_term_resource =
77 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, 79 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC,
78 search_term_resource_id); 80 search_term_resource_id);
79 81
80 // Grabs required static resources. 82 // Grabs required static resources.
81 ui::ResourceManager::Resource* panel_shadow_resource = 83 ui::ResourceManager::Resource* panel_shadow_resource =
82 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, 84 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC,
83 panel_shadow_resource_id); 85 panel_shadow_resource_id);
84 ui::ResourceManager::Resource* search_provider_icon_resource = 86 ui::ResourceManager::Resource* search_provider_icon_sprite_resource =
85 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, 87 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC,
86 search_provider_icon_resource_id); 88 search_provider_icon_resource_id);
87 89
88 DCHECK(panel_shadow_resource); 90 DCHECK(panel_shadow_resource);
89 DCHECK(search_provider_icon_resource); 91 DCHECK(search_provider_icon_sprite_resource);
90 92
91 // Round values to avoid pixel gap between layers. 93 // Round values to avoid pixel gap between layers.
92 search_bar_height = floor(search_bar_height); 94 search_bar_height = floor(search_bar_height);
93 95
94 bool is_rtl = l10n_util::IsLayoutRtl(); 96 bool is_rtl = l10n_util::IsLayoutRtl();
95 97
96 // --------------------------------------------------------------------------- 98 // ---------------------------------------------------------------------------
97 // Panel Shadow 99 // Panel Shadow
98 // --------------------------------------------------------------------------- 100 // ---------------------------------------------------------------------------
99 gfx::Size shadow_res_size = panel_shadow_resource->size; 101 gfx::Size shadow_res_size = panel_shadow_resource->size;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 search_term_resource->size.height() / 2; 143 search_term_resource->size.height() / 2;
142 search_term_->SetUIResourceId(search_term_resource->ui_resource->id()); 144 search_term_->SetUIResourceId(search_term_resource->ui_resource->id());
143 search_term_->SetBounds(search_term_resource->size); 145 search_term_->SetBounds(search_term_resource->size);
144 search_term_->SetPosition(gfx::PointF(0.f, search_bar_padding_top)); 146 search_term_->SetPosition(gfx::PointF(0.f, search_bar_padding_top));
145 search_term_->SetOpacity(search_term_opacity); 147 search_term_->SetOpacity(search_term_opacity);
146 } 148 }
147 149
148 // --------------------------------------------------------------------------- 150 // ---------------------------------------------------------------------------
149 // Search Provider Icon 151 // Search Provider Icon
150 // --------------------------------------------------------------------------- 152 // ---------------------------------------------------------------------------
153 search_provider_icon_sprites_per_row_ =
Changwan Ryu 2015/09/17 06:10:08 Actually, you don't need to keep these as member v
Theresa 2015/09/25 00:58:13 Done.
154 search_provider_icon_sprite_resource->size.width() /
155 search_provider_icon_sprite_size;
156 search_provider_icon_sprite_rows_ =
157 search_provider_icon_sprite_resource->size.height() /
158 search_provider_icon_sprite_size;
159
151 // Positions the Search Provider Icon at the start of the Search Bar. 160 // Positions the Search Provider Icon at the start of the Search Bar.
152 float search_provider_icon_left; 161 float icon_x;
153 if (is_rtl) { 162 if (is_rtl) {
154 search_provider_icon_left = search_panel_width - 163 icon_x = search_panel_width - search_provider_icon_sprite_size -
155 search_provider_icon_resource->size.width() - search_bar_margin_side; 164 search_bar_margin_side;
156 } else { 165 } else {
157 search_provider_icon_left = search_bar_margin_side; 166 icon_x = search_bar_margin_side;
158 } 167 }
159 168
160 // Centers the Search Provider Icon vertically in the Search Bar. 169 // Centers the Search Provider Icon vertically in the Search Bar.
161 float search_provider_icon_top = 170 float icon_y = search_bar_height / 2 - search_provider_icon_sprite_size / 2;
162 search_bar_height / 2 - 171 search_provider_icon_sprite_->SetUIResourceId(
163 search_provider_icon_resource->size.height() / 2; 172 search_provider_icon_sprite_resource->ui_resource->id());
173 search_provider_icon_sprite_->SetBounds(
174 gfx::Size(search_provider_icon_sprite_size,
175 search_provider_icon_sprite_size));
176 search_provider_icon_sprite_->SetPosition(gfx::PointF(icon_x, icon_y));
164 177
165 search_provider_icon_->SetUIResourceId( 178 // Sets the portion of search_provider_icon_ that gets drawn.
166 search_provider_icon_resource->ui_resource->id()); 179 SetSearchProviderIconSpriteFrame(search_provider_icon_sprite_frame);
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 180
171 // --------------------------------------------------------------------------- 181 // ---------------------------------------------------------------------------
172 // Arrow Icon 182 // Arrow Icon
173 // --------------------------------------------------------------------------- 183 // ---------------------------------------------------------------------------
174 // Grabs the Search Arrow Icon resource. 184 // Grabs the Search Arrow Icon resource.
175 ui::ResourceManager::Resource* arrow_icon_resource = 185 ui::ResourceManager::Resource* arrow_icon_resource =
176 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, 186 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC,
177 arrow_up_resource_id); 187 arrow_up_resource_id);
178 if (arrow_icon_->parent() != layer_) { 188 if (arrow_icon_->parent() != layer_) {
179 layer_->AddChild(arrow_icon_); 189 layer_->AddChild(arrow_icon_);
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 panel_shadow_( 416 panel_shadow_(
407 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), 417 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())),
408 search_bar_background_( 418 search_bar_background_(
409 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), 419 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())),
410 search_context_( 420 search_context_(
411 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), 421 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())),
412 search_term_( 422 search_term_(
413 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), 423 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())),
414 search_bar_shadow_( 424 search_bar_shadow_(
415 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), 425 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())),
416 search_provider_icon_( 426 search_provider_icon_sprite_(
417 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), 427 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())),
418 arrow_icon_( 428 arrow_icon_(
419 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), 429 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())),
420 close_icon_( 430 close_icon_(
421 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), 431 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())),
422 content_view_container_( 432 content_view_container_(
423 cc::Layer::Create(content::Compositor::LayerSettings())), 433 cc::Layer::Create(content::Compositor::LayerSettings())),
424 search_bar_border_( 434 search_bar_border_(
425 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), 435 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())),
426 progress_bar_( 436 progress_bar_(
427 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), 437 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())),
428 progress_bar_background_( 438 progress_bar_background_(
429 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), 439 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())),
430 search_promo_( 440 search_promo_(
431 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), 441 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())),
432 search_promo_container_( 442 search_promo_container_(
433 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())) { 443 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())),
444 search_provider_icon_sprites_per_row_(0),
445 search_provider_icon_sprite_rows_(0) {
434 layer_->SetMasksToBounds(false); 446 layer_->SetMasksToBounds(false);
435 layer_->SetIsDrawable(true); 447 layer_->SetIsDrawable(true);
436 448
437 // Panel Shadow 449 // Panel Shadow
438 panel_shadow_->SetIsDrawable(true); 450 panel_shadow_->SetIsDrawable(true);
439 panel_shadow_->SetFillCenter(false); 451 panel_shadow_->SetFillCenter(false);
440 layer_->AddChild(panel_shadow_); 452 layer_->AddChild(panel_shadow_);
441 453
442 // Search Bar Background 454 // Search Bar Background
443 search_bar_background_->SetIsDrawable(true); 455 search_bar_background_->SetIsDrawable(true);
444 search_bar_background_->SetBackgroundColor(kSearchBarBackgroundColor); 456 search_bar_background_->SetBackgroundColor(kSearchBarBackgroundColor);
445 layer_->AddChild(search_bar_background_); 457 layer_->AddChild(search_bar_background_);
446 458
447 // Search Bar Text 459 // Search Bar Text
448 search_context_->SetIsDrawable(true); 460 search_context_->SetIsDrawable(true);
449 layer_->AddChild(search_context_); 461 layer_->AddChild(search_context_);
450 search_term_->SetIsDrawable(true); 462 search_term_->SetIsDrawable(true);
451 layer_->AddChild(search_term_); 463 layer_->AddChild(search_term_);
452 464
453 // Search Provider Icon 465 // Search Provider Icon
454 search_provider_icon_->SetIsDrawable(true); 466 search_provider_icon_sprite_->SetIsDrawable(true);
455 layer_->AddChild(search_provider_icon_); 467 layer_->AddChild(search_provider_icon_sprite_);
456 468
457 // Arrow Icon 469 // Arrow Icon
458 arrow_icon_->SetIsDrawable(true); 470 arrow_icon_->SetIsDrawable(true);
459 471
460 // Close Icon 472 // Close Icon
461 close_icon_->SetIsDrawable(true); 473 close_icon_->SetIsDrawable(true);
462 474
463 // Search Opt Out Promo 475 // Search Opt Out Promo
464 search_promo_container_->SetIsDrawable(true); 476 search_promo_container_->SetIsDrawable(true);
465 search_promo_container_->SetBackgroundColor(kSearchBackgroundColor); 477 search_promo_container_->SetBackgroundColor(kSearchBackgroundColor);
(...skipping 18 matching lines...) Expand all
484 search_bar_shadow_->SetIsDrawable(true); 496 search_bar_shadow_->SetIsDrawable(true);
485 } 497 }
486 498
487 ContextualSearchLayer::~ContextualSearchLayer() { 499 ContextualSearchLayer::~ContextualSearchLayer() {
488 } 500 }
489 501
490 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() { 502 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() {
491 return layer_; 503 return layer_;
492 } 504 }
493 505
506 void ContextualSearchLayer::SetSearchProviderIconSpriteFrame(int sprite_frame) {
507 float column = static_cast<float>(
508 sprite_frame % search_provider_icon_sprites_per_row_);
509 float row = static_cast<float>(
510 sprite_frame / search_provider_icon_sprites_per_row_);
511 CHECK(row <= search_provider_icon_sprite_rows_);
512
513 float top_left_x = column /
514 static_cast<float>(search_provider_icon_sprites_per_row_);
515 float top_left_y = row /
516 static_cast<float>(search_provider_icon_sprite_rows_);
517 float bottom_right_x = (column + 1.f) /
518 static_cast<float>(search_provider_icon_sprites_per_row_);
519 float bottom_right_y = (row + 1.f) /
520 static_cast<float>(search_provider_icon_sprite_rows_);
521 search_provider_icon_sprite_->SetUV(gfx::PointF(top_left_x, top_left_y),
522 gfx::PointF(bottom_right_x, bottom_right_y));
Changwan Ryu 2015/09/17 06:10:08 nit: indentation
Theresa 2015/09/25 00:58:14 Acknowledged.
523 }
524
494 } // namespace android 525 } // namespace android
495 } // namespace chrome 526 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698