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

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

Issue 2518503004: [TTS] Fix Bar text showing blank after startup. (Closed)
Patch Set: Responded to Matt's comments, removed some checks that were not needed. Created 4 years 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
« no previous file with comments | « chrome/browser/android/compositor/layer/contextual_search_layer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 // --------------------------------------------------------------------------- 241 // ---------------------------------------------------------------------------
242 // Search Term, Context and Search Caption 242 // Search Term, Context and Search Caption
243 // --------------------------------------------------------------------------- 243 // ---------------------------------------------------------------------------
244 SetupTextLayer( 244 SetupTextLayer(
245 search_bar_top, 245 search_bar_top,
246 search_bar_height, 246 search_bar_height,
247 search_text_layer_min_height, 247 search_text_layer_min_height,
248 search_caption_resource_id, 248 search_caption_resource_id,
249 search_caption_visible, 249 search_caption_visible,
250 search_caption_animation_percentage, 250 search_caption_animation_percentage,
251 search_term_opacity,
251 search_context_resource_id, 252 search_context_resource_id,
252 search_context_opacity, 253 search_context_opacity,
253 search_term_caption_spacing); 254 search_term_caption_spacing);
254 255
255 // --------------------------------------------------------------------------- 256 // ---------------------------------------------------------------------------
256 // Arrow Icon 257 // Arrow Icon
257 // --------------------------------------------------------------------------- 258 // ---------------------------------------------------------------------------
258 // Grabs the arrow icon resource. 259 // Grabs the arrow icon resource.
259 ui::ResourceManager::Resource* arrow_icon_resource = 260 ui::ResourceManager::Resource* arrow_icon_resource =
260 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, 261 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC,
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 // have a top margin that needs to be accounted for while running the 527 // 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 528 // animation. The final |static_image_y_offset| should be equal to
528 // |tpp_margin|. 529 // |tpp_margin|.
529 float static_image_y_offset = 530 float static_image_y_offset =
530 (static_image_size_ * (1.f - visibility_percentage)) 531 (static_image_size_ * (1.f - visibility_percentage))
531 + top_margin; 532 + top_margin;
532 static_image_layer->SetPosition( 533 static_image_layer->SetPosition(
533 gfx::PointF(side_margin, static_image_y_offset)); 534 gfx::PointF(side_margin, static_image_y_offset));
534 } 535 }
535 536
536 void ContextualSearchLayer::SetupTextLayer( 537 void ContextualSearchLayer::SetupTextLayer(float bar_top,
537 float bar_top, 538 float bar_height,
538 float bar_height, 539 float search_text_layer_min_height,
539 float search_text_layer_min_height, 540 int caption_resource_id,
540 int caption_resource_id, 541 bool caption_visible,
541 bool caption_visible, 542 float animation_percentage,
542 float animation_percentage, 543 float search_term_opacity,
543 int context_resource_id, 544 int context_resource_id,
544 float context_opacity, 545 float context_opacity,
545 float term_caption_spacing) { 546 float term_caption_spacing) {
546 // --------------------------------------------------------------------------- 547 // ---------------------------------------------------------------------------
547 // Setup the Drawing Hierarchy 548 // Setup the Drawing Hierarchy
548 // --------------------------------------------------------------------------- 549 // ---------------------------------------------------------------------------
549 // Search Term 550 // Search Term
550 if (bar_text_->parent() != text_layer_) 551 bool bar_text_visible = search_term_opacity > 0.0f;
552 if (bar_text_visible && bar_text_->parent() != text_layer_)
551 text_layer_->AddChild(bar_text_); 553 text_layer_->AddChild(bar_text_);
552 554
553 // Search Context 555 // Search Context
554 ui::ResourceManager::Resource* context_resource = 556 ui::ResourceManager::Resource* context_resource =
555 resource_manager_->GetResource( 557 resource_manager_->GetResource(
556 ui::ANDROID_RESOURCE_TYPE_DYNAMIC, context_resource_id); 558 ui::ANDROID_RESOURCE_TYPE_DYNAMIC, context_resource_id);
557 if (context_resource) { 559 if (context_resource) {
558 search_context_->SetUIResourceId(context_resource->ui_resource->id()); 560 search_context_->SetUIResourceId(context_resource->ui_resource->id());
559 search_context_->SetBounds(context_resource->size); 561 search_context_->SetBounds(context_resource->size);
560 } 562 }
(...skipping 19 matching lines...) Expand all
580 } 582 }
581 583
582 // --------------------------------------------------------------------------- 584 // ---------------------------------------------------------------------------
583 // Calculate Text Layer Size 585 // Calculate Text Layer Size
584 // --------------------------------------------------------------------------- 586 // ---------------------------------------------------------------------------
585 // If space allows, the Term, Context and Caption should occupy a Text 587 // If space allows, the Term, Context and Caption should occupy a Text
586 // section of fixed size. 588 // section of fixed size.
587 // We may not be able to fit these inside the ideal size as the user may have 589 // We may not be able to fit these inside the ideal size as the user may have
588 // their Font Size set to large. 590 // their Font Size set to large.
589 591
592 // The Term might not be visible or initialized yet, so set up main_text with
593 // whichever main bar text seems appropriate.
594 scoped_refptr<cc::UIResourceLayer> main_text =
595 (bar_text_visible ? bar_text_ : search_context_);
596
590 // The search_caption_ may not have had it's resource set by this point, if so 597 // 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. 598 // the bounds will be zero and everything will still work.
592 float term_height = bar_text_->bounds().height(); 599 float term_height = main_text->bounds().height();
593 float caption_height = search_caption_->bounds().height(); 600 float caption_height = search_caption_->bounds().height();
594 601
595 float layer_height = std::max(search_text_layer_min_height, 602 float layer_height = std::max(search_text_layer_min_height,
596 term_height + caption_height + term_caption_spacing); 603 term_height + caption_height + term_caption_spacing);
597 float layer_width = std::max(bar_text_->bounds().width(), 604 float layer_width =
598 search_caption_->bounds().width()); 605 std::max(main_text->bounds().width(), search_caption_->bounds().width());
599 606
600 float layer_top = bar_top + (bar_height - layer_height) / 2; 607 float layer_top = bar_top + (bar_height - layer_height) / 2;
601 text_layer_->SetBounds(gfx::Size(layer_width, layer_height)); 608 text_layer_->SetBounds(gfx::Size(layer_width, layer_height));
602 text_layer_->SetPosition(gfx::PointF(0.f, layer_top)); 609 text_layer_->SetPosition(gfx::PointF(0.f, layer_top));
603 text_layer_->SetMasksToBounds(true); 610 text_layer_->SetMasksToBounds(true);
604 611
605 // --------------------------------------------------------------------------- 612 // ---------------------------------------------------------------------------
606 // Layout Text Layer 613 // Layout Text Layer
607 // --------------------------------------------------------------------------- 614 // ---------------------------------------------------------------------------
608 // ---Top of Search Bar--- <- bar_top 615 // ---Top of Search Bar--- <- bar_top
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 818
812 // Touch Highlight Layer 819 // Touch Highlight Layer
813 touch_highlight_layer_->SetIsDrawable(true); 820 touch_highlight_layer_->SetIsDrawable(true);
814 touch_highlight_layer_->SetBackgroundColor(kTouchHighlightColor); 821 touch_highlight_layer_->SetBackgroundColor(kTouchHighlightColor);
815 } 822 }
816 823
817 ContextualSearchLayer::~ContextualSearchLayer() { 824 ContextualSearchLayer::~ContextualSearchLayer() {
818 } 825 }
819 826
820 } // namespace android 827 } // namespace android
OLDNEW
« no previous file with comments | « chrome/browser/android/compositor/layer/contextual_search_layer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698