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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 float progress_bar_height, | 90 float progress_bar_height, |
91 float progress_bar_opacity, | 91 float progress_bar_opacity, |
92 int progress_bar_completion, | 92 int progress_bar_completion, |
93 float divider_line_visibility_percentage, | 93 float divider_line_visibility_percentage, |
94 float divider_line_width, | 94 float divider_line_width, |
95 float divider_line_height, | 95 float divider_line_height, |
96 int divider_line_color, | 96 int divider_line_color, |
97 float divider_line_x_offset, | 97 float divider_line_x_offset, |
98 bool touch_highlight_visible, | 98 bool touch_highlight_visible, |
99 float touch_highlight_x_offset, | 99 float touch_highlight_x_offset, |
100 float touch_highlight_width) { | 100 float touch_highlight_width, |
| 101 int bar_handle_resource_id, |
| 102 float bar_handle_offset_y, |
| 103 float bar_padding_bottom) { |
101 // Round values to avoid pixel gap between layers. | 104 // Round values to avoid pixel gap between layers. |
102 search_bar_height = floor(search_bar_height); | 105 search_bar_height = floor(search_bar_height); |
103 | 106 |
104 float search_bar_top = search_peek_promo_height; | 107 float search_bar_top = search_peek_promo_height; |
105 float search_bar_bottom = search_bar_top + search_bar_height; | 108 float search_bar_bottom = search_bar_top + search_bar_height; |
106 bool should_render_progress_bar = | 109 bool should_render_progress_bar = |
107 progress_bar_visible && progress_bar_opacity > 0.f; | 110 progress_bar_visible && progress_bar_opacity > 0.f; |
108 | 111 |
109 OverlayPanelLayer::SetResourceIds( | 112 OverlayPanelLayer::SetResourceIds( |
110 search_term_resource_id, panel_shadow_resource_id, | 113 search_term_resource_id, panel_shadow_resource_id, |
111 search_bar_shadow_resource_id, search_provider_icon_resource_id, | 114 search_bar_shadow_resource_id, search_provider_icon_resource_id, |
112 close_icon_resource_id); | 115 close_icon_resource_id, bar_handle_resource_id); |
113 | 116 |
114 float content_view_top = search_bar_bottom + search_promo_height; | 117 float content_view_top = search_bar_bottom + search_promo_height; |
115 float should_render_bar_border = search_bar_border_visible | 118 float should_render_bar_border = search_bar_border_visible |
116 && !should_render_progress_bar; | 119 && !should_render_progress_bar; |
117 | 120 |
118 // ----------------------------------------------------------------- | 121 // ----------------------------------------------------------------- |
119 // Overlay Panel | 122 // Overlay Panel |
120 // ----------------------------------------------------------------- | 123 // ----------------------------------------------------------------- |
121 OverlayPanelLayer::SetProperties( | 124 OverlayPanelLayer::SetProperties( |
122 dp_to_px, | 125 dp_to_px, content_layer, content_view_top, search_panel_x, search_panel_y, |
123 content_layer, | 126 search_panel_width, search_panel_height, search_bar_margin_side, |
124 content_view_top, | 127 search_bar_height, search_bar_top, search_term_opacity, |
125 search_panel_x, | 128 should_render_bar_border, search_bar_border_height, |
126 search_panel_y, | 129 search_bar_shadow_visible, search_bar_shadow_opacity, close_icon_opacity, |
127 search_panel_width, | 130 bar_handle_offset_y, bar_padding_bottom); |
128 search_panel_height, | |
129 search_bar_margin_side, | |
130 search_bar_height, | |
131 search_bar_top, | |
132 search_term_opacity, | |
133 should_render_bar_border, | |
134 search_bar_border_height, | |
135 search_bar_shadow_visible, | |
136 search_bar_shadow_opacity, | |
137 close_icon_opacity); | |
138 | 131 |
139 bool is_rtl = l10n_util::IsLayoutRtl(); | 132 bool is_rtl = l10n_util::IsLayoutRtl(); |
140 | 133 |
141 // --------------------------------------------------------------------------- | 134 // --------------------------------------------------------------------------- |
142 // Peek Promo | 135 // Peek Promo |
143 // --------------------------------------------------------------------------- | 136 // --------------------------------------------------------------------------- |
144 if (search_peek_promo_visible) { | 137 if (search_peek_promo_visible) { |
145 // Grabs the Search Opt Out Promo resource. | 138 // Grabs the Search Opt Out Promo resource. |
146 ui::Resource* peek_promo_text_resource = resource_manager_->GetResource( | 139 ui::Resource* peek_promo_text_resource = resource_manager_->GetResource( |
147 ui::ANDROID_RESOURCE_TYPE_DYNAMIC, peek_promo_text_resource_id); | 140 ui::ANDROID_RESOURCE_TYPE_DYNAMIC, peek_promo_text_resource_id); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 } | 219 } |
227 } else { | 220 } else { |
228 // Peek Promo Container | 221 // Peek Promo Container |
229 if (peek_promo_container_.get() && peek_promo_container_->parent()) | 222 if (peek_promo_container_.get() && peek_promo_container_->parent()) |
230 peek_promo_container_->RemoveFromParent(); | 223 peek_promo_container_->RemoveFromParent(); |
231 } | 224 } |
232 | 225 |
233 // --------------------------------------------------------------------------- | 226 // --------------------------------------------------------------------------- |
234 // Search Term, Context and Search Caption | 227 // Search Term, Context and Search Caption |
235 // --------------------------------------------------------------------------- | 228 // --------------------------------------------------------------------------- |
236 SetupTextLayer( | 229 SetupTextLayer(bar_content_height_, search_text_layer_min_height, |
237 search_bar_top, | 230 search_caption_resource_id, search_caption_visible, |
238 search_bar_height, | 231 search_caption_animation_percentage, search_term_opacity, |
239 search_text_layer_min_height, | 232 search_context_resource_id, search_context_opacity, |
240 search_caption_resource_id, | 233 search_term_caption_spacing); |
241 search_caption_visible, | |
242 search_caption_animation_percentage, | |
243 search_term_opacity, | |
244 search_context_resource_id, | |
245 search_context_opacity, | |
246 search_term_caption_spacing); | |
247 | 234 |
248 // --------------------------------------------------------------------------- | 235 // --------------------------------------------------------------------------- |
249 // Arrow Icon | 236 // Arrow Icon |
250 // --------------------------------------------------------------------------- | 237 // --------------------------------------------------------------------------- |
251 // Grabs the arrow icon resource. | 238 // Grabs the arrow icon resource. |
252 ui::Resource* arrow_icon_resource = resource_manager_->GetResource( | 239 ui::Resource* arrow_icon_resource = resource_manager_->GetResource( |
253 ui::ANDROID_RESOURCE_TYPE_STATIC, arrow_up_resource_id); | 240 ui::ANDROID_RESOURCE_TYPE_STATIC, arrow_up_resource_id); |
254 | 241 |
255 // Positions the icon at the end of the bar. | 242 // Positions the icon at the end of the bar. |
256 float arrow_icon_left; | 243 float arrow_icon_left; |
257 if (is_rtl) { | 244 if (is_rtl) { |
258 arrow_icon_left = search_bar_margin_side; | 245 arrow_icon_left = search_bar_margin_side; |
259 } else { | 246 } else { |
260 arrow_icon_left = search_panel_width - arrow_icon_resource->size().width() - | 247 arrow_icon_left = search_panel_width - arrow_icon_resource->size().width() - |
261 search_bar_margin_side; | 248 search_bar_margin_side; |
262 } | 249 } |
263 | 250 |
264 // Centers the Arrow Icon vertically in the bar. | 251 // Centers the Arrow Icon vertically in the bar. |
265 float arrow_icon_top = search_bar_top + search_bar_height / 2 - | 252 float arrow_icon_top = |
266 arrow_icon_resource->size().height() / 2; | 253 (bar_content_height_ - arrow_icon_resource->size().height()) / 2; |
267 | 254 |
268 arrow_icon_->SetUIResourceId(arrow_icon_resource->ui_resource()->id()); | 255 arrow_icon_->SetUIResourceId(arrow_icon_resource->ui_resource()->id()); |
269 arrow_icon_->SetBounds(arrow_icon_resource->size()); | 256 arrow_icon_->SetBounds(arrow_icon_resource->size()); |
270 arrow_icon_->SetPosition( | 257 arrow_icon_->SetPosition( |
271 gfx::PointF(arrow_icon_left, arrow_icon_top)); | 258 gfx::PointF(arrow_icon_left, arrow_icon_top)); |
272 arrow_icon_->SetOpacity(arrow_icon_opacity); | 259 arrow_icon_->SetOpacity(arrow_icon_opacity); |
273 | 260 |
274 gfx::Transform transform; | 261 gfx::Transform transform; |
275 if (arrow_icon_rotation != 0.f) { | 262 if (arrow_icon_rotation != 0.f) { |
276 // Apply rotation about the center of the icon. | 263 // Apply rotation about the center of the icon. |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 | 364 |
378 if (progress_bar_.get() && progress_bar_->parent()) | 365 if (progress_bar_.get() && progress_bar_->parent()) |
379 progress_bar_->RemoveFromParent(); | 366 progress_bar_->RemoveFromParent(); |
380 } | 367 } |
381 | 368 |
382 // --------------------------------------------------------------------------- | 369 // --------------------------------------------------------------------------- |
383 // Divider Line | 370 // Divider Line |
384 // --------------------------------------------------------------------------- | 371 // --------------------------------------------------------------------------- |
385 if (divider_line_visibility_percentage > 0.f) { | 372 if (divider_line_visibility_percentage > 0.f) { |
386 if (divider_line_->parent() != layer_) | 373 if (divider_line_->parent() != layer_) |
387 layer_->AddChild(divider_line_); | 374 bar_content_layer_->AddChild(divider_line_); |
388 | 375 |
389 // The divider line animates in from the bottom. | 376 // The divider line animates in from the bottom. |
390 float divider_line_y_offset = | 377 float divider_line_y_offset = |
391 ((search_bar_height - divider_line_height) / 2) + | 378 ((bar_content_height_ - divider_line_height) / 2) + |
392 (divider_line_height * (1.f - divider_line_visibility_percentage)); | 379 (divider_line_height * (1.f - divider_line_visibility_percentage)); |
393 divider_line_->SetPosition(gfx::PointF(divider_line_x_offset, | 380 divider_line_->SetPosition(gfx::PointF(divider_line_x_offset, |
394 divider_line_y_offset)); | 381 divider_line_y_offset)); |
395 | 382 |
396 // The divider line should not draw below its final resting place. | 383 // The divider line should not draw below its final resting place. |
397 // Set bounds to restrict the vertical draw position. | 384 // Set bounds to restrict the vertical draw position. |
398 divider_line_->SetBounds( | 385 divider_line_->SetBounds( |
399 gfx::Size(divider_line_width, | 386 gfx::Size(divider_line_width, |
400 divider_line_height * divider_line_visibility_percentage)); | 387 divider_line_height * divider_line_visibility_percentage)); |
401 divider_line_->SetBackgroundColor(divider_line_color); | 388 divider_line_->SetBackgroundColor(divider_line_color); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 // If the custom image has a height less than |bar_image_size_|, it will | 499 // If the custom image has a height less than |bar_image_size_|, it will |
513 // have a top margin that needs to be accounted for while running the | 500 // have a top margin that needs to be accounted for while running the |
514 // animation. The final |custom_image_y_offset| should be equal to | 501 // animation. The final |custom_image_y_offset| should be equal to |
515 // |tpp_margin|. | 502 // |tpp_margin|. |
516 float custom_image_y_offset = | 503 float custom_image_y_offset = |
517 (bar_image_size_ * (1.f - visibility_percentage)) + top_margin; | 504 (bar_image_size_ * (1.f - visibility_percentage)) + top_margin; |
518 custom_image_layer->SetPosition( | 505 custom_image_layer->SetPosition( |
519 gfx::PointF(side_margin, custom_image_y_offset)); | 506 gfx::PointF(side_margin, custom_image_y_offset)); |
520 } | 507 } |
521 | 508 |
522 void ContextualSearchLayer::SetupTextLayer(float bar_top, | 509 void ContextualSearchLayer::SetupTextLayer(float bar_height, |
523 float bar_height, | |
524 float search_text_layer_min_height, | 510 float search_text_layer_min_height, |
525 int caption_resource_id, | 511 int caption_resource_id, |
526 bool caption_visible, | 512 bool caption_visible, |
527 float animation_percentage, | 513 float animation_percentage, |
528 float search_term_opacity, | 514 float search_term_opacity, |
529 int context_resource_id, | 515 int context_resource_id, |
530 float context_opacity, | 516 float context_opacity, |
531 float term_caption_spacing) { | 517 float term_caption_spacing) { |
532 // --------------------------------------------------------------------------- | 518 // --------------------------------------------------------------------------- |
533 // Setup the Drawing Hierarchy | 519 // Setup the Drawing Hierarchy |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 // The search_caption_ may not have had it's resource set by this point, if so | 570 // The search_caption_ may not have had it's resource set by this point, if so |
585 // the bounds will be zero and everything will still work. | 571 // the bounds will be zero and everything will still work. |
586 float term_height = main_text->bounds().height(); | 572 float term_height = main_text->bounds().height(); |
587 float caption_height = search_caption_->bounds().height(); | 573 float caption_height = search_caption_->bounds().height(); |
588 | 574 |
589 float layer_height = std::max(search_text_layer_min_height, | 575 float layer_height = std::max(search_text_layer_min_height, |
590 term_height + caption_height + term_caption_spacing); | 576 term_height + caption_height + term_caption_spacing); |
591 float layer_width = | 577 float layer_width = |
592 std::max(main_text->bounds().width(), search_caption_->bounds().width()); | 578 std::max(main_text->bounds().width(), search_caption_->bounds().width()); |
593 | 579 |
594 float layer_top = bar_top + (bar_height - layer_height) / 2; | 580 float layer_top = (bar_height - layer_height) / 2; |
595 text_layer_->SetBounds(gfx::Size(layer_width, layer_height)); | 581 text_layer_->SetBounds(gfx::Size(layer_width, layer_height)); |
596 text_layer_->SetPosition(gfx::PointF(0.f, layer_top)); | 582 text_layer_->SetPosition(gfx::PointF(0.f, layer_top)); |
597 text_layer_->SetMasksToBounds(true); | 583 text_layer_->SetMasksToBounds(true); |
598 | 584 |
599 // --------------------------------------------------------------------------- | 585 // --------------------------------------------------------------------------- |
600 // Layout Text Layer | 586 // Layout Text Layer |
601 // --------------------------------------------------------------------------- | 587 // --------------------------------------------------------------------------- |
602 // ---Top of Search Bar--- <- bar_top | 588 // ---Top of Search Bar--- <- bar_top |
603 // | 589 // |
604 // ---Top of Text Layer--- <- layer_top | 590 // ---Top of Text Layer--- <- layer_top |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 peek_promo_container_->AddChild(peek_promo_text_); | 746 peek_promo_container_->AddChild(peek_promo_text_); |
761 | 747 |
762 // Search Bar Text | 748 // Search Bar Text |
763 search_context_->SetIsDrawable(true); | 749 search_context_->SetIsDrawable(true); |
764 | 750 |
765 // Search Bar Caption | 751 // Search Bar Caption |
766 search_caption_->SetIsDrawable(true); | 752 search_caption_->SetIsDrawable(true); |
767 | 753 |
768 // Arrow Icon | 754 // Arrow Icon |
769 arrow_icon_->SetIsDrawable(true); | 755 arrow_icon_->SetIsDrawable(true); |
770 layer_->AddChild(arrow_icon_); | 756 bar_content_layer_->AddChild(arrow_icon_); |
771 | 757 |
772 // Search Opt Out Promo | 758 // Search Opt Out Promo |
773 search_promo_container_->SetIsDrawable(true); | 759 search_promo_container_->SetIsDrawable(true); |
774 search_promo_container_->SetBackgroundColor(kSearchBackgroundColor); | 760 search_promo_container_->SetBackgroundColor(kSearchBackgroundColor); |
775 search_promo_->SetIsDrawable(true); | 761 search_promo_->SetIsDrawable(true); |
776 | 762 |
777 // Progress Bar Background | 763 // Progress Bar Background |
778 progress_bar_background_->SetIsDrawable(true); | 764 progress_bar_background_->SetIsDrawable(true); |
779 progress_bar_background_->SetFillCenter(true); | 765 progress_bar_background_->SetFillCenter(true); |
780 | 766 |
781 // Progress Bar | 767 // Progress Bar |
782 progress_bar_->SetIsDrawable(true); | 768 progress_bar_->SetIsDrawable(true); |
783 progress_bar_->SetFillCenter(true); | 769 progress_bar_->SetFillCenter(true); |
784 | 770 |
785 // Icon - holds thumbnail, search provider icon and/or quick action icon | 771 // Icon - holds thumbnail, search provider icon and/or quick action icon |
786 icon_layer_->SetIsDrawable(true); | 772 icon_layer_->SetIsDrawable(true); |
787 layer_->AddChild(icon_layer_); | 773 bar_content_layer_->AddChild(icon_layer_); |
788 | 774 |
789 // Search provider icon | 775 // Search provider icon |
790 search_provider_icon_layer_->SetIsDrawable(true); | 776 search_provider_icon_layer_->SetIsDrawable(true); |
791 | 777 |
792 // Thumbnail | 778 // Thumbnail |
793 thumbnail_layer_->SetIsDrawable(true); | 779 thumbnail_layer_->SetIsDrawable(true); |
794 | 780 |
795 // Quick action icon | 781 // Quick action icon |
796 quick_action_icon_layer_->SetIsDrawable(true); | 782 quick_action_icon_layer_->SetIsDrawable(true); |
797 | 783 |
798 // Divider line | 784 // Divider line |
799 divider_line_->SetIsDrawable(true); | 785 divider_line_->SetIsDrawable(true); |
800 | 786 |
801 // Content layer | 787 // Content layer |
802 text_layer_->SetIsDrawable(true); | 788 text_layer_->SetIsDrawable(true); |
803 // NOTE(mdjones): This can be called multiple times to add other text layers. | 789 // NOTE(mdjones): This can be called multiple times to add other text layers. |
804 AddBarTextLayer(text_layer_); | 790 AddBarTextLayer(text_layer_); |
805 text_layer_->AddChild(search_context_); | 791 text_layer_->AddChild(search_context_); |
806 | 792 |
807 // Touch Highlight Layer | 793 // Touch Highlight Layer |
808 touch_highlight_layer_->SetIsDrawable(true); | 794 touch_highlight_layer_->SetIsDrawable(true); |
809 touch_highlight_layer_->SetBackgroundColor(kTouchHighlightColor); | 795 touch_highlight_layer_->SetBackgroundColor(kTouchHighlightColor); |
810 } | 796 } |
811 | 797 |
812 ContextualSearchLayer::~ContextualSearchLayer() { | 798 ContextualSearchLayer::~ContextualSearchLayer() { |
813 } | 799 } |
814 | 800 |
815 } // namespace android | 801 } // namespace android |
OLD | NEW |