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

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

Issue 2363843002: [Contextual Search] Animate thumbnail appearance (Closed)
Patch Set: [Contextual Search] Animate thumbnail appearance Created 4 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 20 matching lines...) Expand all
31 31
32 namespace chrome { 32 namespace chrome {
33 namespace android { 33 namespace android {
34 34
35 // static 35 // static
36 scoped_refptr<ContextualSearchLayer> ContextualSearchLayer::Create( 36 scoped_refptr<ContextualSearchLayer> ContextualSearchLayer::Create(
37 ui::ResourceManager* resource_manager) { 37 ui::ResourceManager* resource_manager) {
38 return make_scoped_refptr(new ContextualSearchLayer(resource_manager)); 38 return make_scoped_refptr(new ContextualSearchLayer(resource_manager));
39 } 39 }
40 40
41 scoped_refptr<cc::Layer> ContextualSearchLayer::GetIconLayer() {
42 scoped_refptr<cc::Layer> icon = nullptr;
43
44 // Thumbnail.
45 if (thumbnail_visible_) {
46 if (thumbnail_layer_->parent() != layer_)
47 layer_->AddChild(thumbnail_layer_);
48
49 icon = thumbnail_layer_;
50 } else if (thumbnail_layer_->parent()) {
51 thumbnail_layer_->RemoveFromParent();
52 }
53
54 // Search Provider Icon Sprite (Animated).
55 if (search_provider_icon_sprite_visible_) {
56 if (search_provider_icon_sprite_->layer()->parent() != layer_)
57 layer_->AddChild(search_provider_icon_sprite_->layer().get());
58
59 search_provider_icon_sprite_->DrawSpriteFrame(
60 resource_manager_,
61 panel_icon_resource_id_,
62 search_provider_icon_sprite_metadata_resource_id_,
63 search_provider_icon_sprite_completion_percentage_);
64 icon = search_provider_icon_sprite_->layer();
65 } else if (search_provider_icon_sprite_->layer().get() &&
66 search_provider_icon_sprite_->layer()->parent()) {
67 search_provider_icon_sprite_->layer()->RemoveFromParent();
68 }
69
70 return icon;
71 }
72
73 void ContextualSearchLayer::SetProperties( 41 void ContextualSearchLayer::SetProperties(
74 int panel_shadow_resource_id, 42 int panel_shadow_resource_id,
75 int search_context_resource_id, 43 int search_context_resource_id,
76 int search_term_resource_id, 44 int search_term_resource_id,
77 int search_caption_resource_id, 45 int search_caption_resource_id,
78 int search_bar_shadow_resource_id, 46 int search_bar_shadow_resource_id,
79 int panel_icon_resource_id, 47 int panel_icon_resource_id,
80 int search_provider_icon_sprite_metadata_resource_id, 48 int search_provider_icon_sprite_metadata_resource_id,
81 int arrow_up_resource_id, 49 int arrow_up_resource_id,
82 int close_icon_resource_id, 50 int close_icon_resource_id,
(...skipping 23 matching lines...) Expand all
106 float search_term_opacity, 74 float search_term_opacity,
107 float search_caption_animation_percentage, 75 float search_caption_animation_percentage,
108 bool search_caption_visible, 76 bool search_caption_visible,
109 bool search_bar_border_visible, 77 bool search_bar_border_visible,
110 float search_bar_border_height, 78 float search_bar_border_height,
111 bool search_bar_shadow_visible, 79 bool search_bar_shadow_visible,
112 float search_bar_shadow_opacity, 80 float search_bar_shadow_opacity,
113 bool search_provider_icon_sprite_visible, 81 bool search_provider_icon_sprite_visible,
114 float search_provider_icon_sprite_completion_percentage, 82 float search_provider_icon_sprite_completion_percentage,
115 bool thumbnail_visible, 83 bool thumbnail_visible,
84 float thumbnail_visibility_percentage,
116 int thumbnail_size, 85 int thumbnail_size,
117 float arrow_icon_opacity, 86 float arrow_icon_opacity,
118 float arrow_icon_rotation, 87 float arrow_icon_rotation,
119 float close_icon_opacity, 88 float close_icon_opacity,
120 bool progress_bar_visible, 89 bool progress_bar_visible,
121 float progress_bar_height, 90 float progress_bar_height,
122 float progress_bar_opacity, 91 float progress_bar_opacity,
123 int progress_bar_completion) { 92 int progress_bar_completion) {
124 93
125 search_provider_icon_sprite_visible_ = search_provider_icon_sprite_visible;
126 search_provider_icon_sprite_metadata_resource_id_ =
127 search_provider_icon_sprite_metadata_resource_id;
128 search_provider_icon_sprite_completion_percentage_ =
129 search_provider_icon_sprite_completion_percentage;
130
131 thumbnail_visible_ = thumbnail_visible;
132 thumbnail_size_ = thumbnail_size;
133
134 // Grabs the dynamic Search Context resource. 94 // Grabs the dynamic Search Context resource.
135 ui::ResourceManager::Resource* search_context_resource = 95 ui::ResourceManager::Resource* search_context_resource =
136 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, 96 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC,
137 search_context_resource_id); 97 search_context_resource_id);
138 98
139 // Round values to avoid pixel gap between layers. 99 // Round values to avoid pixel gap between layers.
140 search_bar_height = floor(search_bar_height); 100 search_bar_height = floor(search_bar_height);
141 101
142 float search_bar_top = search_peek_promo_height; 102 float search_bar_top = search_peek_promo_height;
143 float search_bar_bottom = search_bar_top + search_bar_height; 103 float search_bar_bottom = search_bar_top + search_bar_height;
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 progress_bar_->SetPosition(gfx::PointF(0.f, progress_bar_y)); 422 progress_bar_->SetPosition(gfx::PointF(0.f, progress_bar_y));
463 progress_bar_->SetOpacity(progress_bar_opacity); 423 progress_bar_->SetOpacity(progress_bar_opacity);
464 } else { 424 } else {
465 // Removes Progress Bar and its Background from the Layer Tree. 425 // Removes Progress Bar and its Background from the Layer Tree.
466 if (progress_bar_background_.get() && progress_bar_background_->parent()) 426 if (progress_bar_background_.get() && progress_bar_background_->parent())
467 progress_bar_background_->RemoveFromParent(); 427 progress_bar_background_->RemoveFromParent();
468 428
469 if (progress_bar_.get() && progress_bar_->parent()) 429 if (progress_bar_.get() && progress_bar_->parent())
470 progress_bar_->RemoveFromParent(); 430 progress_bar_->RemoveFromParent();
471 } 431 }
432
433 // ---------------------------------------------------------------------------
434 // Icon Layer
435 // ---------------------------------------------------------------------------
436 thumbnail_size_ = thumbnail_size;
437 SetupIconLayer(search_provider_icon_sprite_visible,
438 search_provider_icon_sprite_metadata_resource_id,
439 search_provider_icon_sprite_completion_percentage,
440 thumbnail_visible,
441 thumbnail_visibility_percentage);
442 }
443
444 scoped_refptr<cc::Layer> ContextualSearchLayer::GetIconLayer() {
445 return icon_layer_;
446 }
447
448 void ContextualSearchLayer::SetupIconLayer(
449 bool search_provider_icon_sprite_visible,
450 int search_provider_icon_sprite_metadata_resource_id,
451 float search_provider_icon_sprite_completion_percentage,
452 bool thumbnail_visible,
453 float thumbnail_visibility_percentage) {
454 icon_layer_->SetBounds(gfx::Size(thumbnail_size_, thumbnail_size_));
455 icon_layer_->SetMasksToBounds(true);
456
457 // Thumbnail
458 if (thumbnail_visible) {
459 if (thumbnail_layer_->parent() != icon_layer_)
460 icon_layer_->AddChild(thumbnail_layer_);
461
462 thumbnail_layer_->SetOpacity(thumbnail_visibility_percentage);
463
464 float thumbnail_y_offset =
465 thumbnail_size_ * (1.f - thumbnail_visibility_percentage);
Donn Denman 2016/09/23 04:05:23 Why is the thumbnail_size_ involved here?
Donn Denman 2016/09/23 04:08:21 Elaborating my question ... maybe the available sp
Theresa 2016/09/23 04:39:57 Good question. The thumbnail and 'G' icon slide t
Theresa 2016/09/23 15:45:46 Done. I also added some comments so hopefully this
466 thumbnail_layer_->SetPosition(gfx::PointF(0.f, thumbnail_y_offset));
467 } else if (thumbnail_layer_->parent()) {
468 thumbnail_layer_->RemoveFromParent();
469 }
470
471 // Search Provider Icon Sprite
472 if (search_provider_icon_sprite_visible) {
473 if (search_provider_icon_sprite_->layer()->parent() != icon_layer_)
474 icon_layer_->AddChild(search_provider_icon_sprite_->layer().get());
475
476 search_provider_icon_sprite_->DrawSpriteFrame(
477 resource_manager_,
478 panel_icon_resource_id_,
479 search_provider_icon_sprite_metadata_resource_id,
480 search_provider_icon_sprite_completion_percentage);
481
482 if (thumbnail_visibility_percentage > 0.f) {
483 search_provider_icon_sprite_->layer()->SetOpacity(
484 1.f - thumbnail_visibility_percentage);
485
486 float icon_y_offset =
487 -(thumbnail_size_ * thumbnail_visibility_percentage);
488 search_provider_icon_sprite_->layer()->SetPosition(
489 gfx::PointF(0.f, icon_y_offset));
490 } else {
Donn Denman 2016/09/23 04:05:23 Nit suggestion: I would think that this else claus
Theresa 2016/09/23 15:45:46 Done.
491 search_provider_icon_sprite_->layer()->SetOpacity(1.f);
492 search_provider_icon_sprite_->layer()->SetPosition(
493 gfx::PointF(0.f, 0.f));
494 }
495
496 } else if (search_provider_icon_sprite_->layer().get() &&
497 search_provider_icon_sprite_->layer()->parent()) {
498 search_provider_icon_sprite_->layer()->RemoveFromParent();
499 }
472 } 500 }
473 501
474 void ContextualSearchLayer::SetThumbnail(const SkBitmap* thumbnail) { 502 void ContextualSearchLayer::SetThumbnail(const SkBitmap* thumbnail) {
475 // Determine the scaled thumbnail width and height. If both the height and 503 // Determine the scaled thumbnail width and height. If both the height and
476 // width of |thumbnail| are larger than |thumbnail_size_|, the thumbnail will 504 // width of |thumbnail| are larger than |thumbnail_size_|, the thumbnail will
477 // be scaled down by a call to Layer::SetBounds() below. 505 // be scaled down by a call to Layer::SetBounds() below.
478 int min_dimension = std::min(thumbnail->width(), thumbnail->height()); 506 int min_dimension = std::min(thumbnail->width(), thumbnail->height());
479 int scaled_thumbnail_width = thumbnail->width(); 507 int scaled_thumbnail_width = thumbnail->width();
480 int scaled_thumbnail_height = thumbnail->height(); 508 int scaled_thumbnail_height = thumbnail->height();
481 if (min_dimension > thumbnail_size_) { 509 if (min_dimension > thumbnail_size_) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 thumbnail_layer_->SetBounds(gfx::Size(layer_width, layer_height)); 571 thumbnail_layer_->SetBounds(gfx::Size(layer_width, layer_height));
544 thumbnail_layer_->SetPosition(gfx::PointF(x_pos, y_pos)); 572 thumbnail_layer_->SetPosition(gfx::PointF(x_pos, y_pos));
545 thumbnail_layer_->SetUV(gfx::PointF(top_left_x, top_left_y), 573 thumbnail_layer_->SetUV(gfx::PointF(top_left_x, top_left_y),
546 gfx::PointF(bottom_right_x, bottom_right_y)); 574 gfx::PointF(bottom_right_x, bottom_right_y));
547 } 575 }
548 576
549 ContextualSearchLayer::ContextualSearchLayer( 577 ContextualSearchLayer::ContextualSearchLayer(
550 ui::ResourceManager* resource_manager) 578 ui::ResourceManager* resource_manager)
551 : OverlayPanelLayer(resource_manager), 579 : OverlayPanelLayer(resource_manager),
552 search_context_(cc::UIResourceLayer::Create()), 580 search_context_(cc::UIResourceLayer::Create()),
581 icon_layer_(cc::Layer::Create()),
553 search_provider_icon_sprite_(CrushedSpriteLayer::Create()), 582 search_provider_icon_sprite_(CrushedSpriteLayer::Create()),
554 thumbnail_layer_(cc::UIResourceLayer::Create()), 583 thumbnail_layer_(cc::UIResourceLayer::Create()),
555 arrow_icon_(cc::UIResourceLayer::Create()), 584 arrow_icon_(cc::UIResourceLayer::Create()),
556 search_promo_(cc::UIResourceLayer::Create()), 585 search_promo_(cc::UIResourceLayer::Create()),
557 search_promo_container_(cc::SolidColorLayer::Create()), 586 search_promo_container_(cc::SolidColorLayer::Create()),
558 peek_promo_container_(cc::SolidColorLayer::Create()), 587 peek_promo_container_(cc::SolidColorLayer::Create()),
559 peek_promo_ripple_(cc::NinePatchLayer::Create()), 588 peek_promo_ripple_(cc::NinePatchLayer::Create()),
560 peek_promo_text_(cc::UIResourceLayer::Create()), 589 peek_promo_text_(cc::UIResourceLayer::Create()),
561 progress_bar_(cc::NinePatchLayer::Create()), 590 progress_bar_(cc::NinePatchLayer::Create()),
562 progress_bar_background_(cc::NinePatchLayer::Create()), 591 progress_bar_background_(cc::NinePatchLayer::Create()),
(...skipping 25 matching lines...) Expand all
588 search_promo_->SetIsDrawable(true); 617 search_promo_->SetIsDrawable(true);
589 618
590 // Progress Bar Background 619 // Progress Bar Background
591 progress_bar_background_->SetIsDrawable(true); 620 progress_bar_background_->SetIsDrawable(true);
592 progress_bar_background_->SetFillCenter(true); 621 progress_bar_background_->SetFillCenter(true);
593 622
594 // Progress Bar 623 // Progress Bar
595 progress_bar_->SetIsDrawable(true); 624 progress_bar_->SetIsDrawable(true);
596 progress_bar_->SetFillCenter(true); 625 progress_bar_->SetFillCenter(true);
597 626
627 // Icon
628 icon_layer_->SetIsDrawable(true);
629 layer_->AddChild(icon_layer_);
630
598 // Thumbnail 631 // Thumbnail
599 thumbnail_layer_->SetIsDrawable(true); 632 thumbnail_layer_->SetIsDrawable(true);
600 } 633 }
601 634
602 ContextualSearchLayer::~ContextualSearchLayer() { 635 ContextualSearchLayer::~ContextualSearchLayer() {
603 } 636 }
604 637
605 } // namespace android 638 } // namespace android
606 } // namespace chrome 639 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698