Chromium Code Reviews| 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" |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 } | 234 } |
| 235 } else { | 235 } else { |
| 236 // Peek Promo Container | 236 // Peek Promo Container |
| 237 if (peek_promo_container_.get() && peek_promo_container_->parent()) | 237 if (peek_promo_container_.get() && peek_promo_container_->parent()) |
| 238 peek_promo_container_->RemoveFromParent(); | 238 peek_promo_container_->RemoveFromParent(); |
| 239 } | 239 } |
| 240 | 240 |
| 241 // --------------------------------------------------------------------------- | 241 // --------------------------------------------------------------------------- |
| 242 // Search Term, Context and Search Caption | 242 // Search Term, Context and Search Caption |
| 243 // --------------------------------------------------------------------------- | 243 // --------------------------------------------------------------------------- |
| 244 SetupTextLayer( | 244 SetupTextLayer(search_bar_top, search_bar_height, |
|
mdjones
2016/11/22 16:37:49
Unless there was a reason not to, could we leave t
Donn Denman
2016/11/28 17:58:28
Done. I agree with you, but git CL format liked t
| |
| 245 search_bar_top, | 245 search_text_layer_min_height, search_caption_resource_id, |
| 246 search_bar_height, | 246 search_caption_visible, search_caption_animation_percentage, |
| 247 search_text_layer_min_height, | 247 search_term_opacity, search_context_resource_id, |
| 248 search_caption_resource_id, | 248 search_context_opacity, search_term_caption_spacing); |
| 249 search_caption_visible, | |
| 250 search_caption_animation_percentage, | |
| 251 search_context_resource_id, | |
| 252 search_context_opacity, | |
| 253 search_term_caption_spacing); | |
| 254 | 249 |
| 255 // --------------------------------------------------------------------------- | 250 // --------------------------------------------------------------------------- |
| 256 // Arrow Icon | 251 // Arrow Icon |
| 257 // --------------------------------------------------------------------------- | 252 // --------------------------------------------------------------------------- |
| 258 // Grabs the arrow icon resource. | 253 // Grabs the arrow icon resource. |
| 259 ui::ResourceManager::Resource* arrow_icon_resource = | 254 ui::ResourceManager::Resource* arrow_icon_resource = |
| 260 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 255 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
| 261 arrow_up_resource_id); | 256 arrow_up_resource_id); |
| 262 | 257 |
| 263 // Positions the icon at the end of the bar. | 258 // Positions the icon at the end of the bar. |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 526 // have a top margin that needs to be accounted for while running the | 521 // have a top margin that needs to be accounted for while running the |
| 527 // animation. The final |static_image_y_offset| should be equal to | 522 // animation. The final |static_image_y_offset| should be equal to |
| 528 // |tpp_margin|. | 523 // |tpp_margin|. |
| 529 float static_image_y_offset = | 524 float static_image_y_offset = |
| 530 (static_image_size_ * (1.f - visibility_percentage)) | 525 (static_image_size_ * (1.f - visibility_percentage)) |
| 531 + top_margin; | 526 + top_margin; |
| 532 static_image_layer->SetPosition( | 527 static_image_layer->SetPosition( |
| 533 gfx::PointF(side_margin, static_image_y_offset)); | 528 gfx::PointF(side_margin, static_image_y_offset)); |
| 534 } | 529 } |
| 535 | 530 |
| 536 void ContextualSearchLayer::SetupTextLayer( | 531 void ContextualSearchLayer::SetupTextLayer(float bar_top, |
| 537 float bar_top, | 532 float bar_height, |
| 538 float bar_height, | 533 float search_text_layer_min_height, |
| 539 float search_text_layer_min_height, | 534 int caption_resource_id, |
| 540 int caption_resource_id, | 535 bool caption_visible, |
| 541 bool caption_visible, | 536 float animation_percentage, |
| 542 float animation_percentage, | 537 float search_term_opacity, |
| 543 int context_resource_id, | 538 int context_resource_id, |
| 544 float context_opacity, | 539 float context_opacity, |
| 545 float term_caption_spacing) { | 540 float term_caption_spacing) { |
| 546 // --------------------------------------------------------------------------- | 541 // --------------------------------------------------------------------------- |
| 547 // Setup the Drawing Hierarchy | 542 // Setup the Drawing Hierarchy |
| 548 // --------------------------------------------------------------------------- | 543 // --------------------------------------------------------------------------- |
| 549 // Search Term | 544 // Search Term |
| 550 if (bar_text_->parent() != text_layer_) | 545 bool has_bar_text = search_term_opacity > 0.0f; |
| 546 if (has_bar_text && bar_text_->parent() != text_layer_) | |
| 551 text_layer_->AddChild(bar_text_); | 547 text_layer_->AddChild(bar_text_); |
| 552 | 548 |
| 553 // Search Context | 549 // Search Context |
| 554 ui::ResourceManager::Resource* context_resource = | 550 ui::ResourceManager::Resource* context_resource = |
| 555 resource_manager_->GetResource( | 551 resource_manager_->GetResource( |
| 556 ui::ANDROID_RESOURCE_TYPE_DYNAMIC, context_resource_id); | 552 ui::ANDROID_RESOURCE_TYPE_DYNAMIC, context_resource_id); |
| 557 if (context_resource) { | 553 if (context_resource) { |
| 558 search_context_->SetUIResourceId(context_resource->ui_resource->id()); | 554 search_context_->SetUIResourceId(context_resource->ui_resource->id()); |
| 559 search_context_->SetBounds(context_resource->size); | 555 search_context_->SetBounds(context_resource->size); |
| 560 } | 556 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 580 } | 576 } |
| 581 | 577 |
| 582 // --------------------------------------------------------------------------- | 578 // --------------------------------------------------------------------------- |
| 583 // Calculate Text Layer Size | 579 // Calculate Text Layer Size |
| 584 // --------------------------------------------------------------------------- | 580 // --------------------------------------------------------------------------- |
| 585 // If space allows, the Term, Context and Caption should occupy a Text | 581 // If space allows, the Term, Context and Caption should occupy a Text |
| 586 // section of fixed size. | 582 // section of fixed size. |
| 587 // We may not be able to fit these inside the ideal size as the user may have | 583 // We may not be able to fit these inside the ideal size as the user may have |
| 588 // their Font Size set to large. | 584 // their Font Size set to large. |
| 589 | 585 |
| 586 // The Term might not be visible or initialized yet, so set up main_text with | |
| 587 // whichever main bar text seems appropriate. | |
| 588 scoped_refptr<cc::UIResourceLayer> main_text = | |
| 589 (has_bar_text ? bar_text_ : search_context_); | |
| 590 | |
| 590 // The search_caption_ may not have had it's resource set by this point, if so | 591 // The search_caption_ may not have had it's resource set by this point, if so |
| 591 // the bounds will be zero and everything will still work. | 592 // the bounds will be zero and everything will still work. |
| 592 float term_height = bar_text_->bounds().height(); | 593 float term_height = main_text->bounds().height(); |
| 593 float caption_height = search_caption_->bounds().height(); | 594 float caption_height = search_caption_->bounds().height(); |
| 594 | 595 |
| 595 float layer_height = std::max(search_text_layer_min_height, | 596 float layer_height = std::max(search_text_layer_min_height, |
| 596 term_height + caption_height + term_caption_spacing); | 597 term_height + caption_height + term_caption_spacing); |
| 597 float layer_width = std::max(bar_text_->bounds().width(), | 598 float layer_width = |
| 598 search_caption_->bounds().width()); | 599 std::max(main_text->bounds().width(), search_caption_->bounds().width()); |
| 599 | 600 |
| 600 float layer_top = bar_top + (bar_height - layer_height) / 2; | 601 float layer_top = bar_top + (bar_height - layer_height) / 2; |
| 601 text_layer_->SetBounds(gfx::Size(layer_width, layer_height)); | 602 text_layer_->SetBounds(gfx::Size(layer_width, layer_height)); |
| 602 text_layer_->SetPosition(gfx::PointF(0.f, layer_top)); | 603 text_layer_->SetPosition(gfx::PointF(0.f, layer_top)); |
| 603 text_layer_->SetMasksToBounds(true); | 604 text_layer_->SetMasksToBounds(true); |
| 604 | 605 |
| 605 // --------------------------------------------------------------------------- | 606 // --------------------------------------------------------------------------- |
| 606 // Layout Text Layer | 607 // Layout Text Layer |
| 607 // --------------------------------------------------------------------------- | 608 // --------------------------------------------------------------------------- |
| 608 // ---Top of Search Bar--- <- bar_top | 609 // ---Top of Search Bar--- <- bar_top |
| 609 // | 610 // |
| 610 // ---Top of Text Layer--- <- layer_top | 611 // ---Top of Text Layer--- <- layer_top |
| 611 // } remaining_height / 2 | 612 // } remaining_height / 2 |
| 612 // Term & Context } term_height | 613 // Term & Context } term_height |
| 613 // } term_caption_spacing | 614 // } term_caption_spacing |
| 614 // Caption } caption_height | 615 // Caption } caption_height |
| 615 // } remaining_height / 2 | 616 // } remaining_height / 2 |
| 616 // --Bottom of Text Layer- | 617 // --Bottom of Text Layer- |
| 617 // | 618 // |
| 618 // --Bottom of Search Bar- | 619 // --Bottom of Search Bar- |
| 619 // If the Caption is not visible the Term is centered in this space, when | 620 // If the Caption is not visible the Term is centered in this space, when |
| 620 // the Caption becomes visible it is animated sliding up into it's position | 621 // the Caption becomes visible it is animated sliding up into it's position |
| 621 // with the spacings determined by UI. | 622 // with the spacings determined by UI. |
| 622 // The Term and the Context are assumed to be the same height and will be | 623 // The Term and the Context are assumed to be the same height and will be |
| 623 // positioned one on top of the other. When the Context is resolved it will | 624 // positioned one on top of the other. When the Context is resolved it will |
| 624 // fade out and the Term will fade in. | 625 // fade out and the Term will fade in. |
| 625 | 626 |
| 626 search_context_->SetOpacity(context_opacity); | 627 search_context_->SetOpacity(context_opacity); |
| 627 bar_text_->SetOpacity(1.f - context_opacity); | 628 if (has_bar_text) |
|
mdjones
2016/11/22 16:37:49
The bar_text_ object always exists since it is cre
Donn Denman
2016/11/28 17:58:28
You're right, the checks earlier are the only ones
| |
| 629 bar_text_->SetOpacity(1.f - context_opacity); | |
| 628 | 630 |
| 629 // If there is no caption, just vertically center the Search Term. | 631 // If there is no caption, just vertically center the Search Term. |
| 630 float term_top = (layer_height - term_height) / 2; | 632 float term_top = (layer_height - term_height) / 2; |
| 631 | 633 |
| 632 // If we aren't displaying the caption we're done. | 634 // If we aren't displaying the caption we're done. |
| 633 if (!caption_visible || animation_percentage == 0.f || !caption_resource) { | 635 if (!caption_visible || animation_percentage == 0.f || !caption_resource) { |
| 634 bar_text_->SetPosition(gfx::PointF(0.f, term_top)); | 636 if (has_bar_text) |
| 637 bar_text_->SetPosition(gfx::PointF(0.f, term_top)); | |
| 635 search_context_->SetPosition(gfx::PointF(0.f, term_top)); | 638 search_context_->SetPosition(gfx::PointF(0.f, term_top)); |
| 636 return; | 639 return; |
| 637 } | 640 } |
| 638 | 641 |
| 639 // Calculate the positions for the Term and Caption when the Caption | 642 // Calculate the positions for the Term and Caption when the Caption |
| 640 // animation is complete. | 643 // animation is complete. |
| 641 float remaining_height = layer_height | 644 float remaining_height = layer_height |
| 642 - term_height | 645 - term_height |
| 643 - term_caption_spacing | 646 - term_caption_spacing |
| 644 - caption_height; | 647 - caption_height; |
| 645 | 648 |
| 646 float term_top_end = remaining_height / 2; | 649 float term_top_end = remaining_height / 2; |
| 647 float caption_top_end = term_top_end + term_height + term_caption_spacing; | 650 float caption_top_end = term_top_end + term_height + term_caption_spacing; |
| 648 | 651 |
| 649 // Interpolate between the animation start and end positions (short cut | 652 // Interpolate between the animation start and end positions (short cut |
| 650 // if the animation is at the end or start). | 653 // if the animation is at the end or start). |
| 651 term_top = term_top * (1.f - animation_percentage) | 654 term_top = term_top * (1.f - animation_percentage) |
| 652 + term_top_end * animation_percentage; | 655 + term_top_end * animation_percentage; |
| 653 | 656 |
| 654 // The Caption starts off the bottom of the Text Layer. | 657 // The Caption starts off the bottom of the Text Layer. |
| 655 float caption_top = layer_height * (1.f - animation_percentage) | 658 float caption_top = layer_height * (1.f - animation_percentage) |
| 656 + caption_top_end * animation_percentage; | 659 + caption_top_end * animation_percentage; |
| 657 | 660 |
| 658 bar_text_->SetPosition(gfx::PointF(0.f, term_top)); | 661 if (has_bar_text) |
| 662 bar_text_->SetPosition(gfx::PointF(0.f, term_top)); | |
| 659 search_context_->SetPosition(gfx::PointF(0.f, term_top)); | 663 search_context_->SetPosition(gfx::PointF(0.f, term_top)); |
| 660 search_caption_->SetPosition(gfx::PointF(0.f, caption_top)); | 664 search_caption_->SetPosition(gfx::PointF(0.f, caption_top)); |
| 661 } | 665 } |
| 662 | 666 |
| 663 void ContextualSearchLayer::SetThumbnail(const SkBitmap* thumbnail) { | 667 void ContextualSearchLayer::SetThumbnail(const SkBitmap* thumbnail) { |
| 664 // Determine the scaled thumbnail width and height. If both the height and | 668 // Determine the scaled thumbnail width and height. If both the height and |
| 665 // width of |thumbnail| are larger than |static_image_size_|, the thumbnail | 669 // width of |thumbnail| are larger than |static_image_size_|, the thumbnail |
| 666 // will be scaled down by a call to Layer::SetBounds() below. | 670 // will be scaled down by a call to Layer::SetBounds() below. |
| 667 int min_dimension = std::min(thumbnail->width(), thumbnail->height()); | 671 int min_dimension = std::min(thumbnail->width(), thumbnail->height()); |
| 668 int scaled_thumbnail_width = thumbnail->width(); | 672 int scaled_thumbnail_width = thumbnail->width(); |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 811 | 815 |
| 812 // Touch Highlight Layer | 816 // Touch Highlight Layer |
| 813 touch_highlight_layer_->SetIsDrawable(true); | 817 touch_highlight_layer_->SetIsDrawable(true); |
| 814 touch_highlight_layer_->SetBackgroundColor(kTouchHighlightColor); | 818 touch_highlight_layer_->SetBackgroundColor(kTouchHighlightColor); |
| 815 } | 819 } |
| 816 | 820 |
| 817 ContextualSearchLayer::~ContextualSearchLayer() { | 821 ContextualSearchLayer::~ContextualSearchLayer() { |
| 818 } | 822 } |
| 819 | 823 |
| 820 } // namespace android | 824 } // namespace android |
| OLD | NEW |