| 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 "cc/resources/scoped_ui_resource.h" | 11 #include "cc/resources/scoped_ui_resource.h" |
| 12 #include "chrome/browser/android/compositor/layer/crushed_sprite_layer.h" | |
| 13 #include "content/public/browser/android/compositor.h" | 12 #include "content/public/browser/android/compositor.h" |
| 14 #include "third_party/skia/include/core/SkColor.h" | 13 #include "third_party/skia/include/core/SkColor.h" |
| 15 #include "ui/android/resources/crushed_sprite_resource.h" | |
| 16 #include "ui/android/resources/nine_patch_resource.h" | 14 #include "ui/android/resources/nine_patch_resource.h" |
| 17 #include "ui/android/resources/resource_manager.h" | 15 #include "ui/android/resources/resource_manager.h" |
| 18 #include "ui/base/l10n/l10n_util_android.h" | 16 #include "ui/base/l10n/l10n_util_android.h" |
| 19 #include "ui/gfx/color_utils.h" | 17 #include "ui/gfx/color_utils.h" |
| 20 | 18 |
| 21 namespace { | 19 namespace { |
| 22 | 20 |
| 23 const SkColor kSearchBackgroundColor = SkColorSetRGB(0xee, 0xee, 0xee); | 21 const SkColor kSearchBackgroundColor = SkColorSetRGB(0xee, 0xee, 0xee); |
| 24 const SkColor kSearchBarBackgroundColor = SkColorSetRGB(0xff, 0xff, 0xff); | 22 const SkColor kSearchBarBackgroundColor = SkColorSetRGB(0xff, 0xff, 0xff); |
| 25 const SkColor kPeekPromoRippleBackgroundColor = SkColorSetRGB(0x42, 0x85, 0xF4); | 23 const SkColor kPeekPromoRippleBackgroundColor = SkColorSetRGB(0x42, 0x85, 0xF4); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 38 ui::ResourceManager* resource_manager) { | 36 ui::ResourceManager* resource_manager) { |
| 39 return make_scoped_refptr(new ContextualSearchLayer(resource_manager)); | 37 return make_scoped_refptr(new ContextualSearchLayer(resource_manager)); |
| 40 } | 38 } |
| 41 | 39 |
| 42 void ContextualSearchLayer::SetProperties( | 40 void ContextualSearchLayer::SetProperties( |
| 43 int panel_shadow_resource_id, | 41 int panel_shadow_resource_id, |
| 44 int search_context_resource_id, | 42 int search_context_resource_id, |
| 45 int search_term_resource_id, | 43 int search_term_resource_id, |
| 46 int search_caption_resource_id, | 44 int search_caption_resource_id, |
| 47 int search_bar_shadow_resource_id, | 45 int search_bar_shadow_resource_id, |
| 48 int sprite_resource_id, | 46 int search_provider_icon_resource_id, |
| 49 int search_provider_icon_sprite_metadata_resource_id, | |
| 50 int quick_action_icon_resource_id, | 47 int quick_action_icon_resource_id, |
| 51 int arrow_up_resource_id, | 48 int arrow_up_resource_id, |
| 52 int close_icon_resource_id, | 49 int close_icon_resource_id, |
| 53 int progress_bar_background_resource_id, | 50 int progress_bar_background_resource_id, |
| 54 int progress_bar_resource_id, | 51 int progress_bar_resource_id, |
| 55 int search_promo_resource_id, | 52 int search_promo_resource_id, |
| 56 int peek_promo_ripple_resource_id, | 53 int peek_promo_ripple_resource_id, |
| 57 int peek_promo_text_resource_id, | 54 int peek_promo_text_resource_id, |
| 58 float dp_to_px, | 55 float dp_to_px, |
| 59 const scoped_refptr<cc::Layer>& content_layer, | 56 const scoped_refptr<cc::Layer>& content_layer, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 75 float search_context_opacity, | 72 float search_context_opacity, |
| 76 float search_text_layer_min_height, | 73 float search_text_layer_min_height, |
| 77 float search_term_opacity, | 74 float search_term_opacity, |
| 78 float search_term_caption_spacing, | 75 float search_term_caption_spacing, |
| 79 float search_caption_animation_percentage, | 76 float search_caption_animation_percentage, |
| 80 bool search_caption_visible, | 77 bool search_caption_visible, |
| 81 bool search_bar_border_visible, | 78 bool search_bar_border_visible, |
| 82 float search_bar_border_height, | 79 float search_bar_border_height, |
| 83 bool search_bar_shadow_visible, | 80 bool search_bar_shadow_visible, |
| 84 float search_bar_shadow_opacity, | 81 float search_bar_shadow_opacity, |
| 85 bool search_provider_icon_sprite_visible, | |
| 86 float search_provider_icon_sprite_completion_percentage, | |
| 87 bool quick_action_icon_visible, | 82 bool quick_action_icon_visible, |
| 88 bool thumbnail_visible, | 83 bool thumbnail_visible, |
| 89 float static_image_visibility_percentage, | 84 float custom_image_visibility_percentage, |
| 90 int static_image_size, | 85 int bar_image_size, |
| 91 float arrow_icon_opacity, | 86 float arrow_icon_opacity, |
| 92 float arrow_icon_rotation, | 87 float arrow_icon_rotation, |
| 93 float close_icon_opacity, | 88 float close_icon_opacity, |
| 94 bool progress_bar_visible, | 89 bool progress_bar_visible, |
| 95 float progress_bar_height, | 90 float progress_bar_height, |
| 96 float progress_bar_opacity, | 91 float progress_bar_opacity, |
| 97 int progress_bar_completion, | 92 int progress_bar_completion, |
| 98 float divider_line_visibility_percentage, | 93 float divider_line_visibility_percentage, |
| 99 float divider_line_width, | 94 float divider_line_width, |
| 100 float divider_line_height, | 95 float divider_line_height, |
| 101 int divider_line_color, | 96 int divider_line_color, |
| 102 float divider_line_x_offset, | 97 float divider_line_x_offset, |
| 103 bool touch_highlight_visible, | 98 bool touch_highlight_visible, |
| 104 float touch_highlight_x_offset, | 99 float touch_highlight_x_offset, |
| 105 float touch_highlight_width) { | 100 float touch_highlight_width) { |
| 106 | |
| 107 // Round values to avoid pixel gap between layers. | 101 // Round values to avoid pixel gap between layers. |
| 108 search_bar_height = floor(search_bar_height); | 102 search_bar_height = floor(search_bar_height); |
| 109 | 103 |
| 110 float search_bar_top = search_peek_promo_height; | 104 float search_bar_top = search_peek_promo_height; |
| 111 float search_bar_bottom = search_bar_top + search_bar_height; | 105 float search_bar_bottom = search_bar_top + search_bar_height; |
| 112 bool should_render_progress_bar = | 106 bool should_render_progress_bar = |
| 113 progress_bar_visible && progress_bar_opacity > 0.f; | 107 progress_bar_visible && progress_bar_opacity > 0.f; |
| 114 | 108 |
| 115 OverlayPanelLayer::SetResourceIds( | 109 OverlayPanelLayer::SetResourceIds( |
| 116 search_term_resource_id, | 110 search_term_resource_id, panel_shadow_resource_id, |
| 117 panel_shadow_resource_id, | 111 search_bar_shadow_resource_id, search_provider_icon_resource_id, |
| 118 search_bar_shadow_resource_id, | |
| 119 sprite_resource_id, | |
| 120 close_icon_resource_id); | 112 close_icon_resource_id); |
| 121 | 113 |
| 122 float content_view_top = search_bar_bottom + search_promo_height; | 114 float content_view_top = search_bar_bottom + search_promo_height; |
| 123 float should_render_bar_border = search_bar_border_visible | 115 float should_render_bar_border = search_bar_border_visible |
| 124 && !should_render_progress_bar; | 116 && !should_render_progress_bar; |
| 125 | 117 |
| 126 // ----------------------------------------------------------------- | 118 // ----------------------------------------------------------------- |
| 127 // Overlay Panel | 119 // Overlay Panel |
| 128 // ----------------------------------------------------------------- | 120 // ----------------------------------------------------------------- |
| 129 OverlayPanelLayer::SetProperties( | 121 OverlayPanelLayer::SetProperties( |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 touch_highlight_layer_->SetBounds(background_size); | 413 touch_highlight_layer_->SetBounds(background_size); |
| 422 touch_highlight_layer_->SetPosition(gfx::PointF( | 414 touch_highlight_layer_->SetPosition(gfx::PointF( |
| 423 touch_highlight_x_offset, search_bar_top)); | 415 touch_highlight_x_offset, search_bar_top)); |
| 424 } else { | 416 } else { |
| 425 touch_highlight_layer_->RemoveFromParent(); | 417 touch_highlight_layer_->RemoveFromParent(); |
| 426 } | 418 } |
| 427 | 419 |
| 428 // --------------------------------------------------------------------------- | 420 // --------------------------------------------------------------------------- |
| 429 // Icon Layer | 421 // Icon Layer |
| 430 // --------------------------------------------------------------------------- | 422 // --------------------------------------------------------------------------- |
| 431 static_image_size_ = static_image_size; | 423 bar_image_size_ = bar_image_size; |
| 432 SetupIconLayer(search_provider_icon_sprite_visible, | 424 SetupIconLayer(search_provider_icon_resource_id, quick_action_icon_visible, |
| 433 search_provider_icon_sprite_metadata_resource_id, | 425 quick_action_icon_resource_id, thumbnail_visible, |
| 434 search_provider_icon_sprite_completion_percentage, | 426 custom_image_visibility_percentage); |
| 435 quick_action_icon_visible, | |
| 436 quick_action_icon_resource_id, | |
| 437 thumbnail_visible, | |
| 438 static_image_visibility_percentage); | |
| 439 } | 427 } |
| 440 | 428 |
| 441 scoped_refptr<cc::Layer> ContextualSearchLayer::GetIconLayer() { | 429 scoped_refptr<cc::Layer> ContextualSearchLayer::GetIconLayer() { |
| 442 return icon_layer_; | 430 return icon_layer_; |
| 443 } | 431 } |
| 444 | 432 |
| 445 void ContextualSearchLayer::SetupIconLayer( | 433 void ContextualSearchLayer::SetupIconLayer( |
| 446 bool search_provider_icon_sprite_visible, | 434 int search_provider_icon_resource_id, |
| 447 int search_provider_icon_sprite_metadata_resource_id, | |
| 448 float search_provider_icon_sprite_completion_percentage, | |
| 449 bool quick_action_icon_visible, | 435 bool quick_action_icon_visible, |
| 450 int quick_action_icon_resource_id, | 436 int quick_action_icon_resource_id, |
| 451 bool thumbnail_visible, | 437 bool thumbnail_visible, |
| 452 float static_image_visibility_percentage) { | 438 float custom_image_visibility_percentage) { |
| 453 icon_layer_->SetBounds(gfx::Size(static_image_size_, static_image_size_)); | 439 icon_layer_->SetBounds(gfx::Size(bar_image_size_, bar_image_size_)); |
| 454 icon_layer_->SetMasksToBounds(true); | 440 icon_layer_->SetMasksToBounds(true); |
| 455 | 441 |
| 456 scoped_refptr<cc::UIResourceLayer> static_image_layer; | 442 scoped_refptr<cc::UIResourceLayer> custom_image_layer; |
| 457 | 443 |
| 458 if (quick_action_icon_visible) { | 444 if (quick_action_icon_visible) { |
| 459 if (quick_action_icon_layer_->parent() != icon_layer_) | 445 if (quick_action_icon_layer_->parent() != icon_layer_) |
| 460 icon_layer_->AddChild(quick_action_icon_layer_); | 446 icon_layer_->AddChild(quick_action_icon_layer_); |
| 461 | 447 |
| 462 ui::Resource* quick_action_icon_resource = resource_manager_->GetResource( | 448 ui::Resource* quick_action_icon_resource = resource_manager_->GetResource( |
| 463 ui::ANDROID_RESOURCE_TYPE_DYNAMIC, quick_action_icon_resource_id); | 449 ui::ANDROID_RESOURCE_TYPE_DYNAMIC, quick_action_icon_resource_id); |
| 464 if (quick_action_icon_resource) { | 450 if (quick_action_icon_resource) { |
| 465 quick_action_icon_layer_->SetUIResourceId( | 451 quick_action_icon_layer_->SetUIResourceId( |
| 466 quick_action_icon_resource->ui_resource()->id()); | 452 quick_action_icon_resource->ui_resource()->id()); |
| 467 quick_action_icon_layer_->SetBounds(gfx::Size(static_image_size_, | 453 quick_action_icon_layer_->SetBounds( |
| 468 static_image_size_)); | 454 gfx::Size(bar_image_size_, bar_image_size_)); |
| 469 | 455 |
| 470 SetStaticImageProperties(quick_action_icon_layer_, 0, 0, | 456 SetCustomImageProperties(quick_action_icon_layer_, 0, 0, |
| 471 static_image_visibility_percentage); | 457 custom_image_visibility_percentage); |
| 472 } | 458 } |
| 473 } else if (quick_action_icon_layer_->parent()) { | 459 } else if (quick_action_icon_layer_->parent()) { |
| 474 quick_action_icon_layer_->RemoveFromParent(); | 460 quick_action_icon_layer_->RemoveFromParent(); |
| 475 } | 461 } |
| 476 | 462 |
| 477 // Thumbnail | 463 // Thumbnail |
| 478 if (!quick_action_icon_visible && thumbnail_visible) { | 464 if (!quick_action_icon_visible && thumbnail_visible) { |
| 479 if (thumbnail_layer_->parent() != icon_layer_) | 465 if (thumbnail_layer_->parent() != icon_layer_) |
| 480 icon_layer_->AddChild(thumbnail_layer_); | 466 icon_layer_->AddChild(thumbnail_layer_); |
| 481 | 467 |
| 482 SetStaticImageProperties(thumbnail_layer_, | 468 SetCustomImageProperties(thumbnail_layer_, thumbnail_top_margin_, |
| 483 thumbnail_top_margin_, | |
| 484 thumbnail_side_margin_, | 469 thumbnail_side_margin_, |
| 485 static_image_visibility_percentage); | 470 custom_image_visibility_percentage); |
| 486 } else if (thumbnail_layer_->parent()) { | 471 } else if (thumbnail_layer_->parent()) { |
| 487 thumbnail_layer_->RemoveFromParent(); | 472 thumbnail_layer_->RemoveFromParent(); |
| 488 } | 473 } |
| 489 | 474 |
| 490 // Search Provider Icon Sprite | 475 // Search Provider Icon |
| 491 if (search_provider_icon_sprite_visible) { | 476 if (search_provider_icon_layer_->parent() != icon_layer_) |
| 492 if (search_provider_icon_sprite_->layer()->parent() != icon_layer_) | 477 icon_layer_->AddChild(search_provider_icon_layer_); |
| 493 icon_layer_->AddChild(search_provider_icon_sprite_->layer().get()); | |
| 494 | 478 |
| 495 search_provider_icon_sprite_->DrawSpriteFrame( | 479 ui::Resource* search_provider_icon_resource = resource_manager_->GetResource( |
| 496 resource_manager_, | 480 ui::ANDROID_RESOURCE_TYPE_STATIC, search_provider_icon_resource_id); |
| 497 panel_icon_resource_id_, | 481 if (search_provider_icon_resource) { |
| 498 search_provider_icon_sprite_metadata_resource_id, | 482 gfx::Size icon_size = search_provider_icon_resource->size(); |
| 499 search_provider_icon_sprite_completion_percentage); | 483 search_provider_icon_layer_->SetUIResourceId( |
| 484 search_provider_icon_resource->ui_resource()->id()); |
| 485 search_provider_icon_layer_->SetBounds(icon_size); |
| 500 | 486 |
| 501 search_provider_icon_sprite_->layer()->SetOpacity( | 487 search_provider_icon_layer_->SetOpacity(1.f - |
| 502 1.f - static_image_visibility_percentage); | 488 custom_image_visibility_percentage); |
| 503 | 489 |
| 504 float icon_y_offset = | 490 // Determine x and y offsets to center the icon in its parent layer |
| 505 -(static_image_size_ * static_image_visibility_percentage); | 491 float icon_x_offset = (bar_image_size_ - icon_size.width()) / 2; |
| 506 search_provider_icon_sprite_->layer()->SetPosition( | 492 float icon_y_offset = (bar_image_size_ - icon_size.height()) / 2; |
| 507 gfx::PointF(0.f, icon_y_offset)); | |
| 508 | 493 |
| 509 } else if (search_provider_icon_sprite_->layer().get() && | 494 // Determine extra y-offset if thumbnail or quick action are visible. |
| 510 search_provider_icon_sprite_->layer()->parent()) { | 495 icon_y_offset -= (bar_image_size_ * custom_image_visibility_percentage); |
| 511 search_provider_icon_sprite_->layer()->RemoveFromParent(); | 496 |
| 497 search_provider_icon_layer_->SetPosition( |
| 498 gfx::PointF(icon_x_offset, icon_y_offset)); |
| 512 } | 499 } |
| 513 } | 500 } |
| 514 | 501 |
| 515 void ContextualSearchLayer::SetStaticImageProperties( | 502 void ContextualSearchLayer::SetCustomImageProperties( |
| 516 scoped_refptr<cc::UIResourceLayer> static_image_layer, | 503 scoped_refptr<cc::UIResourceLayer> custom_image_layer, |
| 517 float top_margin, | 504 float top_margin, |
| 518 float side_margin, | 505 float side_margin, |
| 519 float visibility_percentage) { | 506 float visibility_percentage) { |
| 520 static_image_layer->SetOpacity(visibility_percentage); | 507 custom_image_layer->SetOpacity(visibility_percentage); |
| 521 | 508 |
| 522 // When animating, the static image and icon sprite slide through | 509 // When animating, the custom image and search provider icon slide through |
| 523 // |icon_layer_|. This effect is achieved by changing the y-offset | 510 // |icon_layer_|. This effect is achieved by changing the y-offset |
| 524 // for each child layer. | 511 // for each child layer. |
| 525 // If the static image has a height less than |static_image_size_|, it will | 512 // If the custom image has a height less than |bar_image_size_|, it will |
| 526 // have a top margin that needs to be accounted for while running the | 513 // 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 | 514 // animation. The final |custom_image_y_offset| should be equal to |
| 528 // |tpp_margin|. | 515 // |tpp_margin|. |
| 529 float static_image_y_offset = | 516 float custom_image_y_offset = |
| 530 (static_image_size_ * (1.f - visibility_percentage)) | 517 (bar_image_size_ * (1.f - visibility_percentage)) + top_margin; |
| 531 + top_margin; | 518 custom_image_layer->SetPosition( |
| 532 static_image_layer->SetPosition( | 519 gfx::PointF(side_margin, custom_image_y_offset)); |
| 533 gfx::PointF(side_margin, static_image_y_offset)); | |
| 534 } | 520 } |
| 535 | 521 |
| 536 void ContextualSearchLayer::SetupTextLayer(float bar_top, | 522 void ContextualSearchLayer::SetupTextLayer(float bar_top, |
| 537 float bar_height, | 523 float bar_height, |
| 538 float search_text_layer_min_height, | 524 float search_text_layer_min_height, |
| 539 int caption_resource_id, | 525 int caption_resource_id, |
| 540 bool caption_visible, | 526 bool caption_visible, |
| 541 float animation_percentage, | 527 float animation_percentage, |
| 542 float search_term_opacity, | 528 float search_term_opacity, |
| 543 int context_resource_id, | 529 int context_resource_id, |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 float caption_top = layer_height * (1.f - animation_percentage) | 649 float caption_top = layer_height * (1.f - animation_percentage) |
| 664 + caption_top_end * animation_percentage; | 650 + caption_top_end * animation_percentage; |
| 665 | 651 |
| 666 bar_text_->SetPosition(gfx::PointF(0.f, term_top)); | 652 bar_text_->SetPosition(gfx::PointF(0.f, term_top)); |
| 667 search_context_->SetPosition(gfx::PointF(0.f, term_top)); | 653 search_context_->SetPosition(gfx::PointF(0.f, term_top)); |
| 668 search_caption_->SetPosition(gfx::PointF(0.f, caption_top)); | 654 search_caption_->SetPosition(gfx::PointF(0.f, caption_top)); |
| 669 } | 655 } |
| 670 | 656 |
| 671 void ContextualSearchLayer::SetThumbnail(const SkBitmap* thumbnail) { | 657 void ContextualSearchLayer::SetThumbnail(const SkBitmap* thumbnail) { |
| 672 // Determine the scaled thumbnail width and height. If both the height and | 658 // Determine the scaled thumbnail width and height. If both the height and |
| 673 // width of |thumbnail| are larger than |static_image_size_|, the thumbnail | 659 // width of |thumbnail| are larger than |bar_image_size_|, the thumbnail |
| 674 // will be scaled down by a call to Layer::SetBounds() below. | 660 // will be scaled down by a call to Layer::SetBounds() below. |
| 675 int min_dimension = std::min(thumbnail->width(), thumbnail->height()); | 661 int min_dimension = std::min(thumbnail->width(), thumbnail->height()); |
| 676 int scaled_thumbnail_width = thumbnail->width(); | 662 int scaled_thumbnail_width = thumbnail->width(); |
| 677 int scaled_thumbnail_height = thumbnail->height(); | 663 int scaled_thumbnail_height = thumbnail->height(); |
| 678 if (min_dimension > static_image_size_) { | 664 if (min_dimension > bar_image_size_) { |
| 679 scaled_thumbnail_width = | 665 scaled_thumbnail_width = |
| 680 scaled_thumbnail_width * static_image_size_ / min_dimension; | 666 scaled_thumbnail_width * bar_image_size_ / min_dimension; |
| 681 scaled_thumbnail_height = | 667 scaled_thumbnail_height = |
| 682 scaled_thumbnail_height * static_image_size_ / min_dimension; | 668 scaled_thumbnail_height * bar_image_size_ / min_dimension; |
| 683 } | 669 } |
| 684 | 670 |
| 685 // Determine the UV transform coordinates. This will crop the thumbnail. | 671 // Determine the UV transform coordinates. This will crop the thumbnail. |
| 686 // (0, 0) is the default top left corner. (1, 1) is the default bottom | 672 // (0, 0) is the default top left corner. (1, 1) is the default bottom |
| 687 // right corner. | 673 // right corner. |
| 688 float top_left_x = 0; | 674 float top_left_x = 0; |
| 689 float top_left_y = 0; | 675 float top_left_y = 0; |
| 690 float bottom_right_x = 1; | 676 float bottom_right_x = 1; |
| 691 float bottom_right_y = 1; | 677 float bottom_right_y = 1; |
| 692 | 678 |
| 693 if (scaled_thumbnail_width > static_image_size_) { | 679 if (scaled_thumbnail_width > bar_image_size_) { |
| 694 // Crop an even amount on the left and right sides of the thumbnail. | 680 // Crop an even amount on the left and right sides of the thumbnail. |
| 695 float top_left_x_px = (scaled_thumbnail_width - static_image_size_) / 2.f; | 681 float top_left_x_px = (scaled_thumbnail_width - bar_image_size_) / 2.f; |
| 696 float bottom_right_x_px = top_left_x_px + static_image_size_; | 682 float bottom_right_x_px = top_left_x_px + bar_image_size_; |
| 697 | 683 |
| 698 top_left_x = top_left_x_px / scaled_thumbnail_width; | 684 top_left_x = top_left_x_px / scaled_thumbnail_width; |
| 699 bottom_right_x = bottom_right_x_px / scaled_thumbnail_width; | 685 bottom_right_x = bottom_right_x_px / scaled_thumbnail_width; |
| 700 } else if (scaled_thumbnail_height > static_image_size_) { | 686 } else if (scaled_thumbnail_height > bar_image_size_) { |
| 701 // Crop an even amount on the top and bottom of the thumbnail. | 687 // Crop an even amount on the top and bottom of the thumbnail. |
| 702 float top_left_y_px = (scaled_thumbnail_height - static_image_size_) / 2.f; | 688 float top_left_y_px = (scaled_thumbnail_height - bar_image_size_) / 2.f; |
| 703 float bottom_right_y_px = top_left_y_px + static_image_size_; | 689 float bottom_right_y_px = top_left_y_px + bar_image_size_; |
| 704 | 690 |
| 705 top_left_y = top_left_y_px / scaled_thumbnail_height; | 691 top_left_y = top_left_y_px / scaled_thumbnail_height; |
| 706 bottom_right_y = bottom_right_y_px / scaled_thumbnail_height; | 692 bottom_right_y = bottom_right_y_px / scaled_thumbnail_height; |
| 707 } | 693 } |
| 708 | 694 |
| 709 // If the original |thumbnail| height or width is smaller than | 695 // If the original |thumbnail| height or width is smaller than |
| 710 // |static_image_size_| determine the side and top margins needed to center | 696 // |bar_image_size_| determine the side and top margins needed to center |
| 711 // the thumbnail. | 697 // the thumbnail. |
| 712 thumbnail_side_margin_ = 0; | 698 thumbnail_side_margin_ = 0; |
| 713 thumbnail_top_margin_ = 0; | 699 thumbnail_top_margin_ = 0; |
| 714 | 700 |
| 715 if (scaled_thumbnail_width < static_image_size_) { | 701 if (scaled_thumbnail_width < bar_image_size_) { |
| 716 thumbnail_side_margin_ = | 702 thumbnail_side_margin_ = (bar_image_size_ - scaled_thumbnail_width) / 2.f; |
| 717 (static_image_size_ - scaled_thumbnail_width) / 2.f; | |
| 718 } | 703 } |
| 719 | 704 |
| 720 if (scaled_thumbnail_height < static_image_size_) { | 705 if (scaled_thumbnail_height < bar_image_size_) { |
| 721 thumbnail_top_margin_ = | 706 thumbnail_top_margin_ = (bar_image_size_ - scaled_thumbnail_height) / 2.f; |
| 722 (static_image_size_ - scaled_thumbnail_height) / 2.f; | |
| 723 } | 707 } |
| 724 | 708 |
| 725 // Determine the layer bounds. This will down scale the thumbnail if | 709 // Determine the layer bounds. This will down scale the thumbnail if |
| 726 // necessary and ensure it is displayed at |static_image_size_|. If | 710 // necessary and ensure it is displayed at |bar_image_size_|. If |
| 727 // either the original |thumbnail| height or width is smaller than | 711 // either the original |thumbnail| height or width is smaller than |
| 728 // |static_image_size_|, the thumbnail will not be scaled. | 712 // |bar_image_size_|, the thumbnail will not be scaled. |
| 729 int layer_width = std::min(static_image_size_, scaled_thumbnail_width); | 713 int layer_width = std::min(bar_image_size_, scaled_thumbnail_width); |
| 730 int layer_height = std::min(static_image_size_, scaled_thumbnail_height); | 714 int layer_height = std::min(bar_image_size_, scaled_thumbnail_height); |
| 731 | 715 |
| 732 // UIResourceLayer requires an immutable copy of the input |thumbnail|. | 716 // UIResourceLayer requires an immutable copy of the input |thumbnail|. |
| 733 SkBitmap thumbnail_copy; | 717 SkBitmap thumbnail_copy; |
| 734 if (thumbnail->isImmutable()) { | 718 if (thumbnail->isImmutable()) { |
| 735 thumbnail_copy = *thumbnail; | 719 thumbnail_copy = *thumbnail; |
| 736 } else { | 720 } else { |
| 737 thumbnail->copyTo(&thumbnail_copy); | 721 thumbnail->copyTo(&thumbnail_copy); |
| 738 thumbnail_copy.setImmutable(); | 722 thumbnail_copy.setImmutable(); |
| 739 } | 723 } |
| 740 | 724 |
| 741 thumbnail_layer_->SetBitmap(thumbnail_copy); | 725 thumbnail_layer_->SetBitmap(thumbnail_copy); |
| 742 thumbnail_layer_->SetBounds(gfx::Size(layer_width, layer_height)); | 726 thumbnail_layer_->SetBounds(gfx::Size(layer_width, layer_height)); |
| 743 thumbnail_layer_->SetPosition( | 727 thumbnail_layer_->SetPosition( |
| 744 gfx::PointF(thumbnail_side_margin_, thumbnail_top_margin_)); | 728 gfx::PointF(thumbnail_side_margin_, thumbnail_top_margin_)); |
| 745 thumbnail_layer_->SetUV(gfx::PointF(top_left_x, top_left_y), | 729 thumbnail_layer_->SetUV(gfx::PointF(top_left_x, top_left_y), |
| 746 gfx::PointF(bottom_right_x, bottom_right_y)); | 730 gfx::PointF(bottom_right_x, bottom_right_y)); |
| 747 } | 731 } |
| 748 | 732 |
| 749 ContextualSearchLayer::ContextualSearchLayer( | 733 ContextualSearchLayer::ContextualSearchLayer( |
| 750 ui::ResourceManager* resource_manager) | 734 ui::ResourceManager* resource_manager) |
| 751 : OverlayPanelLayer(resource_manager), | 735 : OverlayPanelLayer(resource_manager), |
| 752 search_context_(cc::UIResourceLayer::Create()), | 736 search_context_(cc::UIResourceLayer::Create()), |
| 753 icon_layer_(cc::Layer::Create()), | 737 icon_layer_(cc::Layer::Create()), |
| 754 search_provider_icon_sprite_(CrushedSpriteLayer::Create()), | 738 search_provider_icon_layer_(cc::UIResourceLayer::Create()), |
| 755 thumbnail_layer_(cc::UIResourceLayer::Create()), | 739 thumbnail_layer_(cc::UIResourceLayer::Create()), |
| 756 quick_action_icon_layer_(cc::UIResourceLayer::Create()), | 740 quick_action_icon_layer_(cc::UIResourceLayer::Create()), |
| 757 arrow_icon_(cc::UIResourceLayer::Create()), | 741 arrow_icon_(cc::UIResourceLayer::Create()), |
| 758 search_promo_(cc::UIResourceLayer::Create()), | 742 search_promo_(cc::UIResourceLayer::Create()), |
| 759 search_promo_container_(cc::SolidColorLayer::Create()), | 743 search_promo_container_(cc::SolidColorLayer::Create()), |
| 760 peek_promo_container_(cc::SolidColorLayer::Create()), | 744 peek_promo_container_(cc::SolidColorLayer::Create()), |
| 761 peek_promo_ripple_(cc::NinePatchLayer::Create()), | 745 peek_promo_ripple_(cc::NinePatchLayer::Create()), |
| 762 peek_promo_text_(cc::UIResourceLayer::Create()), | 746 peek_promo_text_(cc::UIResourceLayer::Create()), |
| 763 progress_bar_(cc::NinePatchLayer::Create()), | 747 progress_bar_(cc::NinePatchLayer::Create()), |
| 764 progress_bar_background_(cc::NinePatchLayer::Create()), | 748 progress_bar_background_(cc::NinePatchLayer::Create()), |
| (...skipping 26 matching lines...) Expand all Loading... |
| 791 search_promo_->SetIsDrawable(true); | 775 search_promo_->SetIsDrawable(true); |
| 792 | 776 |
| 793 // Progress Bar Background | 777 // Progress Bar Background |
| 794 progress_bar_background_->SetIsDrawable(true); | 778 progress_bar_background_->SetIsDrawable(true); |
| 795 progress_bar_background_->SetFillCenter(true); | 779 progress_bar_background_->SetFillCenter(true); |
| 796 | 780 |
| 797 // Progress Bar | 781 // Progress Bar |
| 798 progress_bar_->SetIsDrawable(true); | 782 progress_bar_->SetIsDrawable(true); |
| 799 progress_bar_->SetFillCenter(true); | 783 progress_bar_->SetFillCenter(true); |
| 800 | 784 |
| 801 // Icon - holds thumbnail, search provider sprite and/or quick action icon | 785 // Icon - holds thumbnail, search provider icon and/or quick action icon |
| 802 icon_layer_->SetIsDrawable(true); | 786 icon_layer_->SetIsDrawable(true); |
| 803 layer_->AddChild(icon_layer_); | 787 layer_->AddChild(icon_layer_); |
| 804 | 788 |
| 789 // Search provider icon |
| 790 search_provider_icon_layer_->SetIsDrawable(true); |
| 791 |
| 805 // Thumbnail | 792 // Thumbnail |
| 806 thumbnail_layer_->SetIsDrawable(true); | 793 thumbnail_layer_->SetIsDrawable(true); |
| 807 | 794 |
| 808 // Quick action icon | 795 // Quick action icon |
| 809 quick_action_icon_layer_->SetIsDrawable(true); | 796 quick_action_icon_layer_->SetIsDrawable(true); |
| 810 | 797 |
| 811 // Divider line | 798 // Divider line |
| 812 divider_line_->SetIsDrawable(true); | 799 divider_line_->SetIsDrawable(true); |
| 813 | 800 |
| 814 // Content layer | 801 // Content layer |
| 815 text_layer_->SetIsDrawable(true); | 802 text_layer_->SetIsDrawable(true); |
| 816 // NOTE(mdjones): This can be called multiple times to add other text layers. | 803 // NOTE(mdjones): This can be called multiple times to add other text layers. |
| 817 AddBarTextLayer(text_layer_); | 804 AddBarTextLayer(text_layer_); |
| 818 text_layer_->AddChild(search_context_); | 805 text_layer_->AddChild(search_context_); |
| 819 | 806 |
| 820 // Touch Highlight Layer | 807 // Touch Highlight Layer |
| 821 touch_highlight_layer_->SetIsDrawable(true); | 808 touch_highlight_layer_->SetIsDrawable(true); |
| 822 touch_highlight_layer_->SetBackgroundColor(kTouchHighlightColor); | 809 touch_highlight_layer_->SetBackgroundColor(kTouchHighlightColor); |
| 823 } | 810 } |
| 824 | 811 |
| 825 ContextualSearchLayer::~ContextualSearchLayer() { | 812 ContextualSearchLayer::~ContextualSearchLayer() { |
| 826 } | 813 } |
| 827 | 814 |
| 828 } // namespace android | 815 } // namespace android |
| OLD | NEW |