Commit 739cd817 authored by Donn Denman's avatar Donn Denman Committed by Commit Bot

[Overlay][TTS] Move vertical center of content in Bar

Moves the vertical centering of the text and other content such as icons
in the Bar by centering them the space below the Drag handle instead of
the whole Bar height.

BUG=1013333

Change-Id: Ib02b3d434e4f8ed2e4065b8f42219f0372c3f14b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1854362
Auto-Submit: Donn Denman <donnd@chromium.org>
Commit-Queue: Matthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarJinsuk Kim <jinsukkim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708205}
parent fc69c6f5
...@@ -130,11 +130,22 @@ void ContextualSearchLayer::SetProperties( ...@@ -130,11 +130,22 @@ void ContextualSearchLayer::SetProperties(
search_bar_border_height, search_bar_shadow_visible, icon_color, search_bar_border_height, search_bar_shadow_visible, icon_color,
drag_handlebar_color, close_icon_opacity, separator_line_color); drag_handlebar_color, close_icon_opacity, separator_line_color);
// -----------------------------------------------------------------
// Content setup, to center in space below drag handle (when present).
// -----------------------------------------------------------------
bool is_rtl = l10n_util::IsLayoutRtl(); bool is_rtl = l10n_util::IsLayoutRtl();
int content_height = search_bar_height;
int content_top = search_bar_top;
bool is_overlay_new_layout =
rounded_bar_top_resource_id != kInvalidResourceID;
if (is_overlay_new_layout) {
content_top += search_bar_margin_top;
content_height -= search_bar_margin_top;
}
// --------------------------------------------------------------------------- // -----------------------------------------------------------------
// Bar Banner // Bar Banner -- obsolete. TODO(donnd): remove.
// --------------------------------------------------------------------------- // -----------------------------------------------------------------
if (search_bar_banner_visible) { if (search_bar_banner_visible) {
// Grabs the Bar Banner resource. // Grabs the Bar Banner resource.
ui::Resource* bar_banner_text_resource = resource_manager_->GetResource( ui::Resource* bar_banner_text_resource = resource_manager_->GetResource(
...@@ -223,15 +234,15 @@ void ContextualSearchLayer::SetProperties( ...@@ -223,15 +234,15 @@ void ContextualSearchLayer::SetProperties(
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Search Term, Context and Search Caption // Search Term, Context and Search Caption
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
int text_layer_height = SetupTextLayer( int text_layer_height =
search_bar_top, search_bar_height, search_text_layer_min_height, SetupTextLayer(content_top, content_height, search_text_layer_min_height,
search_caption_resource_id, search_caption_visible, search_caption_resource_id, search_caption_visible,
search_caption_animation_percentage, search_term_opacity, search_caption_animation_percentage, search_term_opacity,
search_context_resource_id, search_context_opacity, search_context_resource_id, search_context_opacity,
search_term_caption_spacing); search_term_caption_spacing);
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Arrow Icon // Arrow Icon. Deprecated -- old layout only.
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Grabs the arrow icon resource. // Grabs the arrow icon resource.
ui::Resource* arrow_icon_resource = ui::Resource* arrow_icon_resource =
...@@ -320,7 +331,7 @@ void ContextualSearchLayer::SetProperties( ...@@ -320,7 +331,7 @@ void ContextualSearchLayer::SetProperties(
progress_bar_opacity, progress_bar_completion, search_panel_width); progress_bar_opacity, progress_bar_completion, search_panel_width);
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Divider Line separator // Divider Line separator. Deprecated -- old layout only.
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
if (divider_line_visibility_percentage > 0.f) { if (divider_line_visibility_percentage > 0.f) {
if (divider_line_->parent() != layer_) if (divider_line_->parent() != layer_)
...@@ -349,13 +360,12 @@ void ContextualSearchLayer::SetProperties( ...@@ -349,13 +360,12 @@ void ContextualSearchLayer::SetProperties(
if (touch_highlight_visible) { if (touch_highlight_visible) {
if (touch_highlight_layer_->parent() != layer_) if (touch_highlight_layer_->parent() != layer_)
layer_->AddChild(touch_highlight_layer_); layer_->AddChild(touch_highlight_layer_);
bool is_overlay_new_layout = // In the new layout don't highlight the whole bar due to rounded corners.
rounded_bar_top_resource_id != kInvalidResourceID;
int highlight_height = int highlight_height =
is_overlay_new_layout ? text_layer_height : search_bar_height; is_overlay_new_layout ? text_layer_height : search_bar_height;
int highlight_top = search_bar_top; int highlight_top = content_top;
highlight_top += highlight_top +=
is_overlay_new_layout ? (search_bar_height - text_layer_height) / 2 : 0; is_overlay_new_layout ? (content_height - text_layer_height) / 2 : 0;
gfx::Size background_size(touch_highlight_width, highlight_height); gfx::Size background_size(touch_highlight_width, highlight_height);
touch_highlight_layer_->SetBounds(background_size); touch_highlight_layer_->SetBounds(background_size);
touch_highlight_layer_->SetPosition( touch_highlight_layer_->SetPosition(
...@@ -466,8 +476,8 @@ void ContextualSearchLayer::SetCustomImageProperties( ...@@ -466,8 +476,8 @@ void ContextualSearchLayer::SetCustomImageProperties(
gfx::PointF(side_margin, custom_image_y_offset)); gfx::PointF(side_margin, custom_image_y_offset));
} }
int ContextualSearchLayer::SetupTextLayer(float bar_top, int ContextualSearchLayer::SetupTextLayer(float content_top,
float bar_height, float content_height,
float search_text_layer_min_height, float search_text_layer_min_height,
int caption_resource_id, int caption_resource_id,
bool caption_visible, bool caption_visible,
...@@ -538,7 +548,7 @@ int ContextualSearchLayer::SetupTextLayer(float bar_top, ...@@ -538,7 +548,7 @@ int ContextualSearchLayer::SetupTextLayer(float bar_top,
float layer_width = float layer_width =
std::max(main_text->bounds().width(), search_caption_->bounds().width()); std::max(main_text->bounds().width(), search_caption_->bounds().width());
float layer_top = bar_top + (bar_height - layer_height) / 2; float layer_top = content_top + (content_height - layer_height) / 2;
text_layer_->SetBounds(gfx::Size(layer_width, layer_height)); text_layer_->SetBounds(gfx::Size(layer_width, layer_height));
text_layer_->SetPosition(gfx::PointF(0.f, layer_top)); text_layer_->SetPosition(gfx::PointF(0.f, layer_top));
text_layer_->SetMasksToBounds(true); text_layer_->SetMasksToBounds(true);
......
...@@ -86,7 +86,8 @@ void EphemeralTabLayer::SetProperties( ...@@ -86,7 +86,8 @@ void EphemeralTabLayer::SetProperties(
float progress_bar_height, float progress_bar_height,
float progress_bar_opacity, float progress_bar_opacity,
int progress_bar_completion, int progress_bar_completion,
int separator_line_color) { int separator_line_color,
bool is_new_layout) {
if (web_contents_ != web_contents) { if (web_contents_ != web_contents) {
web_contents_ = web_contents; web_contents_ = web_contents;
if (web_contents_) { if (web_contents_) {
...@@ -112,12 +113,18 @@ void EphemeralTabLayer::SetProperties( ...@@ -112,12 +113,18 @@ void EphemeralTabLayer::SetProperties(
bar_shadow_visible, icon_color, drag_handlebar_color, bar_shadow_visible, icon_color, drag_handlebar_color,
1.0f /* icon opacity */, separator_line_color); 1.0f /* icon opacity */, separator_line_color);
SetupTextLayer(bar_top, bar_height, text_layer_min_height, // Content setup, to center in space below drag handle (when present).
int content_top = bar_top;
int content_height = bar_height;
if (is_new_layout) {
content_top += bar_margin_top;
content_height -= bar_margin_top;
}
SetupTextLayer(content_top, content_height, text_layer_min_height,
caption_view_resource_id, caption_icon_resource_id, caption_view_resource_id, caption_icon_resource_id,
caption_icon_opacity, caption_icon_opacity, caption_animation_percentage,
caption_visible, title_view_resource_id,
caption_animation_percentage, caption_visible, title_caption_spacing);
title_view_resource_id, title_caption_spacing);
OverlayPanelLayer::SetProgressBar( OverlayPanelLayer::SetProgressBar(
progress_bar_background_resource_id, progress_bar_resource_id, progress_bar_background_resource_id, progress_bar_resource_id,
...@@ -133,8 +140,8 @@ void EphemeralTabLayer::SetProperties( ...@@ -133,8 +140,8 @@ void EphemeralTabLayer::SetProperties(
panel_icon_->SetOpacity(1 - favicon_opacity); panel_icon_->SetOpacity(1 - favicon_opacity);
} }
void EphemeralTabLayer::SetupTextLayer(float bar_top, void EphemeralTabLayer::SetupTextLayer(float content_top,
float bar_height, float content_height,
float text_layer_min_height, float text_layer_min_height,
int caption_view_resource_id, int caption_view_resource_id,
int caption_icon_resource_id, int caption_icon_resource_id,
...@@ -196,7 +203,7 @@ void EphemeralTabLayer::SetupTextLayer(float bar_top, ...@@ -196,7 +203,7 @@ void EphemeralTabLayer::SetupTextLayer(float bar_top,
float layer_width = float layer_width =
std::max(title_->bounds().width(), caption_->bounds().width()); std::max(title_->bounds().width(), caption_->bounds().width());
float layer_top = bar_top + (bar_height - layer_height) / 2; float layer_top = content_top + (content_height - layer_height) / 2;
text_layer_->SetBounds(gfx::Size(layer_width, layer_height)); text_layer_->SetBounds(gfx::Size(layer_width, layer_height));
text_layer_->SetPosition(gfx::PointF(0.f, layer_top)); text_layer_->SetPosition(gfx::PointF(0.f, layer_top));
text_layer_->SetMasksToBounds(true); text_layer_->SetMasksToBounds(true);
......
...@@ -78,7 +78,8 @@ class EphemeralTabLayer : public OverlayPanelLayer, ...@@ -78,7 +78,8 @@ class EphemeralTabLayer : public OverlayPanelLayer,
float progress_bar_height, float progress_bar_height,
float progress_bar_opacity, float progress_bar_opacity,
int progress_bar_completion, int progress_bar_completion,
int separator_line_color); int separator_line_color,
bool is_new_layout);
void SetupTextLayer(float bar_top, void SetupTextLayer(float bar_top,
float bar_height, float bar_height,
float text_layer_min_height, float text_layer_min_height,
......
...@@ -115,7 +115,17 @@ void OverlayPanelLayer::SetProperties( ...@@ -115,7 +115,17 @@ void OverlayPanelLayer::SetProperties(
panel_shadow_->SetPosition(shadow_position); panel_shadow_->SetPosition(shadow_position);
} }
// ---------------------------------------------------------------------------
// Content setup, to center in space below drag handle (when present).
// ---------------------------------------------------------------------------
int content_top_y = bar_top_y;
int content_height = bar_height;
int rounded_top_adjust = 0; int rounded_top_adjust = 0;
if (rounded_bar_top_resource_id_ != kInvalidResourceID) {
content_top_y += bar_margin_top;
content_height -= bar_margin_top;
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Rounded Bar Top // Rounded Bar Top
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -172,9 +182,10 @@ void OverlayPanelLayer::SetProperties( ...@@ -172,9 +182,10 @@ void OverlayPanelLayer::SetProperties(
ui::ANDROID_RESOURCE_TYPE_DYNAMIC, bar_text_resource_id_); ui::ANDROID_RESOURCE_TYPE_DYNAMIC, bar_text_resource_id_);
if (bar_text_resource) { if (bar_text_resource) {
// Centers the text vertically in the Search Bar. // Centers the text vertically in the section of the Search Bar below the
float bar_padding_top = // drag handle.
bar_top_y + bar_height / 2 - bar_text_resource->size().height() / 2; float bar_padding_top = content_top_y + content_height / 2 -
bar_text_resource->size().height() / 2;
bar_text_->SetUIResourceId(bar_text_resource->ui_resource()->id()); bar_text_->SetUIResourceId(bar_text_resource->ui_resource()->id());
bar_text_->SetBounds(bar_text_resource->size()); bar_text_->SetBounds(bar_text_resource->size());
bar_text_->SetPosition(gfx::PointF(0.f, bar_padding_top)); bar_text_->SetPosition(gfx::PointF(0.f, bar_padding_top));
...@@ -202,7 +213,7 @@ void OverlayPanelLayer::SetProperties( ...@@ -202,7 +213,7 @@ void OverlayPanelLayer::SetProperties(
// Centers the Icon vertically in the bar. // Centers the Icon vertically in the bar.
float icon_y = float icon_y =
bar_top_y + bar_height / 2 - icon_layer->bounds().height() / 2; content_top_y + content_height / 2 - icon_layer->bounds().height() / 2;
icon_layer->SetPosition(gfx::PointF(icon_x, icon_y)); icon_layer->SetPosition(gfx::PointF(icon_x, icon_y));
} }
...@@ -252,8 +263,8 @@ void OverlayPanelLayer::SetProperties( ...@@ -252,8 +263,8 @@ void OverlayPanelLayer::SetProperties(
} }
// Centers the Close Icon vertically in the bar. // Centers the Close Icon vertically in the bar.
float close_icon_top = float close_icon_top = content_top_y + content_height / 2 -
bar_top_y + bar_height / 2 - close_icon_resource->size().height() / 2; close_icon_resource->size().height() / 2;
close_icon_->SetUIResourceId(close_icon_resource->ui_resource()->id()); close_icon_->SetUIResourceId(close_icon_resource->ui_resource()->id());
close_icon_->SetBounds(close_icon_resource->size()); close_icon_->SetBounds(close_icon_resource->size());
close_icon_->SetPosition(gfx::PointF(close_icon_left, close_icon_top)); close_icon_->SetPosition(gfx::PointF(close_icon_left, close_icon_top));
...@@ -268,7 +279,7 @@ void OverlayPanelLayer::SetProperties( ...@@ -268,7 +279,7 @@ void OverlayPanelLayer::SetProperties(
resource_manager_->GetStaticResourceWithTint(open_tab_icon_resource_id_, resource_manager_->GetStaticResourceWithTint(open_tab_icon_resource_id_,
icon_tint); icon_tint);
// Positions the icon at the end of the bar. // Positions the icon at the end of the bar.
float open_tab_top = bar_top_y + bar_height / 2 - float open_tab_top = content_top_y + content_height / 2 -
open_tab_icon_resource->size().height() / 2; open_tab_icon_resource->size().height() / 2;
float open_tab_left; float open_tab_left;
float spacing_between_icons = 2 * bar_margin_side; float spacing_between_icons = 2 * bar_margin_side;
...@@ -287,7 +298,7 @@ void OverlayPanelLayer::SetProperties( ...@@ -287,7 +298,7 @@ void OverlayPanelLayer::SetProperties(
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Content // Overlay Web Content
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
content_container_->SetPosition( content_container_->SetPosition(
gfx::PointF(0.f, content_offset_y)); gfx::PointF(0.f, content_offset_y));
......
...@@ -31,7 +31,8 @@ EphemeralTabSceneLayer::EphemeralTabSceneLayer(JNIEnv* env, ...@@ -31,7 +31,8 @@ EphemeralTabSceneLayer::EphemeralTabSceneLayer(JNIEnv* env,
const JavaRef<jobject>& jobj) const JavaRef<jobject>& jobj)
: SceneLayer(env, jobj), : SceneLayer(env, jobj),
base_page_brightness_(1.0f), base_page_brightness_(1.0f),
content_container_(cc::Layer::Create()) { content_container_(cc::Layer::Create()),
is_new_layout_(false) {
// Responsible for moving the base page without modifying the layer itself. // Responsible for moving the base page without modifying the layer itself.
content_container_->SetIsDrawable(true); content_container_->SetIsDrawable(true);
content_container_->SetPosition(gfx::PointF(0.0f, 0.0f)); content_container_->SetPosition(gfx::PointF(0.0f, 0.0f));
...@@ -66,6 +67,7 @@ void EphemeralTabSceneLayer::SetResourceIds(JNIEnv* env, ...@@ -66,6 +67,7 @@ void EphemeralTabSceneLayer::SetResourceIds(JNIEnv* env,
jint drag_handlebar_resource_id, jint drag_handlebar_resource_id,
jint open_tab_icon_resource_id, jint open_tab_icon_resource_id,
jint close_icon_resource_id) { jint close_icon_resource_id) {
is_new_layout_ = rounded_bar_top_resource_id > 0;
ephemeral_tab_layer_->SetResourceIds( ephemeral_tab_layer_->SetResourceIds(
text_resource_id, panel_shadow_resource_id, rounded_bar_top_resource_id, text_resource_id, panel_shadow_resource_id, rounded_bar_top_resource_id,
bar_shadow_resource_id, panel_icon_resource_id, bar_shadow_resource_id, panel_icon_resource_id,
...@@ -138,7 +140,7 @@ void EphemeralTabSceneLayer::Update(JNIEnv* env, ...@@ -138,7 +140,7 @@ void EphemeralTabSceneLayer::Update(JNIEnv* env,
bar_border_visible, bar_border_height, bar_shadow_visible, icon_color, bar_border_visible, bar_border_height, bar_shadow_visible, icon_color,
drag_handlebar_color, favicon_opacity, progress_bar_visible, drag_handlebar_color, favicon_opacity, progress_bar_visible,
progress_bar_height, progress_bar_opacity, progress_bar_completion, progress_bar_height, progress_bar_opacity, progress_bar_completion,
separator_line_color); separator_line_color, is_new_layout_);
// Make the layer visible if it is not already. // Make the layer visible if it is not already.
ephemeral_tab_layer_->layer()->SetHideLayerAndSubtree(false); ephemeral_tab_layer_->layer()->SetHideLayerAndSubtree(false);
} }
......
...@@ -90,6 +90,7 @@ class EphemeralTabSceneLayer : public SceneLayer { ...@@ -90,6 +90,7 @@ class EphemeralTabSceneLayer : public SceneLayer {
scoped_refptr<EphemeralTabLayer> ephemeral_tab_layer_; scoped_refptr<EphemeralTabLayer> ephemeral_tab_layer_;
scoped_refptr<cc::SolidColorLayer> color_overlay_; scoped_refptr<cc::SolidColorLayer> color_overlay_;
scoped_refptr<cc::Layer> content_container_; scoped_refptr<cc::Layer> content_container_;
bool is_new_layout_;
DISALLOW_COPY_AND_ASSIGN(EphemeralTabSceneLayer); DISALLOW_COPY_AND_ASSIGN(EphemeralTabSceneLayer);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment