Commit 391aef74 authored by Donn Denman's avatar Donn Denman Committed by Commit Bot

[Overlay][TTS] Add side shadows to the new Overlay

Adds side-shadow assets to the Overlay in the new layout that already
has rounded corners.  These assets just add a shadow, so there are
no dark versions needed, and we just have one side (using code to
flip it for the other side).

Binary-Size: +2K for the side shadow assets.

BUG=1005975

Change-Id: I31ebf657b2e9f49822c5aeb525b655c91d9b81aa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1895924
Commit-Queue: Donn Denman <donnd@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarJinsuk Kim <jinsukkim@chromium.org>
Auto-Submit: Donn Denman <donnd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713660}
parent 04c4b1b3
......@@ -17,6 +17,7 @@ import org.chromium.base.ApplicationStatus;
import org.chromium.base.ApplicationStatus.ActivityStateListener;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.compositor.LayerTitleCache;
import org.chromium.chrome.browser.compositor.bottombar.OverlayPanelManager.PanelPriority;
import org.chromium.chrome.browser.compositor.layouts.LayoutUpdateHost;
......@@ -364,6 +365,12 @@ public class OverlayPanel extends OverlayPanelAnimation implements ActivityState
return mPanelShown;
}
/** @return Whether we're using the new Overlay layout feature. */
public static boolean isNewLayout() {
return ChromeFeatureList.isInitialized()
&& ChromeFeatureList.isEnabled(ChromeFeatureList.OVERLAY_NEW_LAYOUT);
}
// ============================================================================================
// ActivityStateListener
// ============================================================================================
......
......@@ -16,7 +16,6 @@ import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeActivity;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.PanelState;
import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.StateChangeReason;
import org.chromium.chrome.browser.util.MathUtils;
......@@ -151,8 +150,8 @@ abstract class OverlayPanelBase {
mProgressBarHeight = PROGRESS_BAR_HEIGHT_DP;
mBarBorderHeight = BAR_BORDER_HEIGHT_DP;
int bar_height_dimen = isNewLayout() ? R.dimen.overlay_panel_bar_height
: R.dimen.overlay_panel_bar_height_legacy;
int bar_height_dimen = OverlayPanel.isNewLayout() ? R.dimen.overlay_panel_bar_height
: R.dimen.overlay_panel_bar_height_legacy;
mBarHeight = mContext.getResources().getDimension(bar_height_dimen) * mPxToDp;
final Resources resources = mContext.getResources();
......@@ -164,7 +163,7 @@ abstract class OverlayPanelBase {
mButtonPaddingDps =
(int) (mPxToDp * resources.getDimension(R.dimen.overlay_panel_button_padding));
mBarShadowVisible = true;
mPanelShadowVisible = !isNewLayout();
mPanelShadowVisible = true;
}
// ============================================================================================
......@@ -355,12 +354,6 @@ abstract class OverlayPanelBase {
return Math.round(mMaximumHeight / mPxToDp);
}
/** @return Whether we're using the new Overlay layout feature. */
private boolean isNewLayout() {
return ChromeFeatureList.isInitialized()
&& ChromeFeatureList.isEnabled(ChromeFeatureList.OVERLAY_NEW_LAYOUT);
}
/** @return The offset for the page content in DPs. */
protected float getLayoutOffsetYDps() {
return mLayoutYOffset * mPxToDp;
......@@ -513,7 +506,7 @@ abstract class OverlayPanelBase {
* @return The opacity of the arrow icon.
*/
public float getArrowIconOpacity() {
return isNewLayout() ? ARROW_ICON_OPACITY_TRANSPARENT : mArrowIconOpacity;
return OverlayPanel.isNewLayout() ? ARROW_ICON_OPACITY_TRANSPARENT : mArrowIconOpacity;
}
/**
......
......@@ -8,6 +8,7 @@ import android.content.Context;
import android.view.ViewGroup;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel;
import org.chromium.ui.resources.dynamics.DynamicResourceLoader;
/**
......@@ -36,7 +37,7 @@ public class EphemeralTabBarControl {
public EphemeralTabBarControl(EphemeralTabPanel panel, Context context, ViewGroup container,
DynamicResourceLoader loader) {
mTitle = new EphemeralTabTitleControl(panel, context, container, loader);
mCaption = EphemeralTabPanel.isNewLayout() || panel.canPromoteToNewTab()
mCaption = OverlayPanel.isNewLayout() || panel.canPromoteToNewTab()
? new EphemeralTabCaptionControl(panel, context, container, loader)
: null;
mTextLayerMinHeight =
......@@ -65,7 +66,7 @@ public class EphemeralTabBarControl {
* @param percentage The percentage to the more opened state.
*/
public void updateForCloseOrPeek(float percentage) {
if (EphemeralTabPanel.isNewLayout()) {
if (OverlayPanel.isNewLayout()) {
updateForMaximize(SOLID_OPAQUE);
} else {
if (percentage == SOLID_OPAQUE) updateForMaximize(SOLID_TRANSPARENT);
......
......@@ -14,6 +14,7 @@ import androidx.annotation.DrawableRes;
import org.chromium.base.Supplier;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel;
import org.chromium.chrome.browser.compositor.bottombar.OverlayPanelTextViewInflater;
import org.chromium.components.url_formatter.UrlFormatter;
import org.chromium.ui.resources.dynamics.DynamicResourceLoader;
......@@ -56,10 +57,10 @@ public class EphemeralTabCaptionControl extends OverlayPanelTextViewInflater {
DynamicResourceLoader resourceLoader) {
super(panel, R.layout.ephemeral_tab_caption_view, R.id.ephemeral_tab_caption_view, context,
container, resourceLoader,
(EphemeralTabPanel.isNewLayout() ? R.dimen.overlay_panel_end_buttons_width
: R.dimen.overlay_panel_padded_button_width),
(EphemeralTabPanel.isNewLayout() ? R.dimen.overlay_panel_end_buttons_width
: R.dimen.overlay_panel_padded_button_width));
(OverlayPanel.isNewLayout() ? R.dimen.overlay_panel_end_buttons_width
: R.dimen.overlay_panel_padded_button_width),
(OverlayPanel.isNewLayout() ? R.dimen.overlay_panel_end_buttons_width
: R.dimen.overlay_panel_padded_button_width));
mUrl = panel::getUrl;
mIconMargin = context.getResources().getDimensionPixelSize(
R.dimen.preview_tab_security_icon_size);
......@@ -77,7 +78,7 @@ public class EphemeralTabCaptionControl extends OverlayPanelTextViewInflater {
if (mCaption == null) {
// |mCaption| gets initialized synchronously in |onFinishInflate|.
inflate();
if (EphemeralTabPanel.isNewLayout()) {
if (OverlayPanel.isNewLayout()) {
mCaption.setText(
UrlFormatter.formatUrlForSecurityDisplayOmitScheme(mUrl.get()));
} else {
......@@ -139,7 +140,7 @@ public class EphemeralTabCaptionControl extends OverlayPanelTextViewInflater {
* @return The current percentage ranging from 0.0 to 1.0.
*/
public float getAnimationPercentage() {
return EphemeralTabPanel.isNewLayout() ? 1.f : mAnimationPercentage;
return OverlayPanel.isNewLayout() ? 1.f : mAnimationPercentage;
}
/**
......@@ -167,7 +168,7 @@ public class EphemeralTabCaptionControl extends OverlayPanelTextViewInflater {
View view = getView();
mCaption = (TextView) view.findViewById(R.id.ephemeral_tab_caption);
if (EphemeralTabPanel.isNewLayout()) {
if (OverlayPanel.isNewLayout()) {
((MarginLayoutParams) mCaption.getLayoutParams()).leftMargin = mIconMargin;
}
}
......
......@@ -97,10 +97,6 @@ public class EphemeralTabPanel extends OverlayPanel {
&& !SysUtils.isLowEndDevice();
}
static boolean isNewLayout() {
return ChromeFeatureList.isEnabled(ChromeFeatureList.OVERLAY_NEW_LAYOUT);
}
/**
* @param context The current Android {@link Context}.
* @param updateHost The {@link LayoutUpdateHost} used to request updates in the Layout.
......
......@@ -8,7 +8,7 @@ import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel;
import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.ContextualSearchBarBannerControl;
import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.ContextualSearchBarControl;
import org.chromium.chrome.browser.compositor.bottombar.contextualsearch.ContextualSearchImageControl;
......@@ -65,13 +65,11 @@ public class ContextualSearchSceneLayer extends SceneOverlayLayer {
int searchTermViewId = searchBarControl.getSearchTermViewId();
int searchCaptionViewId = searchBarControl.getCaptionViewId();
int openNewTabIconId = (ChromeFeatureList.isEnabled(ChromeFeatureList.OVERLAY_NEW_LAYOUT)
&& panel.canPromoteToNewTab())
int openNewTabIconId = OverlayPanel.isNewLayout() && panel.canPromoteToNewTab()
? R.drawable.open_in_new_tab
: INVALID_RESOURCE_ID;
int dragHandlebarId = ChromeFeatureList.isEnabled(ChromeFeatureList.OVERLAY_NEW_LAYOUT)
? R.drawable.drag_handlebar
: INVALID_RESOURCE_ID;
int dragHandlebarId =
OverlayPanel.isNewLayout() ? R.drawable.drag_handlebar : INVALID_RESOURCE_ID;
int searchPromoViewId = promoControl.getViewId();
boolean searchPromoVisible = promoControl.isVisible();
......@@ -143,14 +141,16 @@ public class ContextualSearchSceneLayer extends SceneOverlayLayer {
WebContents panelWebContents = panel.getWebContents();
int roundedBarTopResourceId =
ChromeFeatureList.isEnabled(ChromeFeatureList.OVERLAY_NEW_LAYOUT)
? R.drawable.top_round
: INVALID_RESOURCE_ID;
OverlayPanel.isNewLayout() ? R.drawable.top_round : INVALID_RESOURCE_ID;
int separatorLineColor = panel.getSeparatorLineColor();
// The panel shadow goes all the way around in the old layout, but in the new layout
// the top_round resource also includes the shadow so we only need a side shadow.
// In either case there's just one shadow-only resource needed.
int panelShadowResourceId = panel.getPanelShadowVisible()
? R.drawable.contextual_search_bar_background
? (OverlayPanel.isNewLayout() ? R.drawable.overlay_side_shadow
: R.drawable.contextual_search_bar_background)
: INVALID_RESOURCE_ID;
int closeIconResourceId = ChromeFeatureList.isEnabled(ChromeFeatureList.OVERLAY_NEW_LAYOUT)
int closeIconResourceId = OverlayPanel.isNewLayout()
? INVALID_RESOURCE_ID
: ContextualSearchPanel.CLOSE_ICON_DRAWABLE_ID;
......
......@@ -10,7 +10,7 @@ import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace;
import org.chromium.base.annotations.NativeMethods;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel;
import org.chromium.chrome.browser.compositor.bottombar.ephemeraltab.EphemeralTabBarControl;
import org.chromium.chrome.browser.compositor.bottombar.ephemeraltab.EphemeralTabCaptionControl;
import org.chromium.chrome.browser.compositor.bottombar.ephemeraltab.EphemeralTabPanel;
......@@ -70,18 +70,19 @@ public class EphemeralTabSceneLayer extends SceneOverlayLayer {
EphemeralTabSceneLayerJni.get().createEphemeralTabLayer(mNativePtr,
EphemeralTabSceneLayer.this, resourceManager,
() -> panel.startFaviconAnimation(true));
int openInTabIconId = (ChromeFeatureList.isEnabled(ChromeFeatureList.OVERLAY_NEW_LAYOUT)
&& panel.canPromoteToNewTab())
int openInTabIconId = (OverlayPanel.isNewLayout() && panel.canPromoteToNewTab())
? R.drawable.open_in_new_tab
: INVALID_RESOURCE_ID;
int dragHandlebarId = ChromeFeatureList.isEnabled(ChromeFeatureList.OVERLAY_NEW_LAYOUT)
? R.drawable.drag_handlebar
: INVALID_RESOURCE_ID;
int roundedBarTopId = ChromeFeatureList.isEnabled(ChromeFeatureList.OVERLAY_NEW_LAYOUT)
? R.drawable.top_round
: INVALID_RESOURCE_ID;
int dragHandlebarId =
OverlayPanel.isNewLayout() ? R.drawable.drag_handlebar : INVALID_RESOURCE_ID;
int roundedBarTopId =
OverlayPanel.isNewLayout() ? R.drawable.top_round : INVALID_RESOURCE_ID;
// The panel shadow goes all the way around in the old layout, but in the new layout
// the top_round resource also includes the shadow so we only need a side shadow.
// In either case there's just one shadow-only resource needed.
int panelShadowResourceId = panel.getPanelShadowVisible()
? R.drawable.contextual_search_bar_background
? (OverlayPanel.isNewLayout() ? R.drawable.overlay_side_shadow
: R.drawable.contextual_search_bar_background)
: INVALID_RESOURCE_ID;
EphemeralTabSceneLayerJni.get().setResourceIds(mNativePtr, EphemeralTabSceneLayer.this,
title.getViewId(), panelShadowResourceId, roundedBarTopId,
......
......@@ -83,10 +83,48 @@ void OverlayPanelLayer::SetProperties(
// Round values to avoid pixel gap between layers.
bar_height = floor(bar_height);
// ---------------------------------------------------------------------------
// Content setup, to center in space below drag handle (when present).
// ---------------------------------------------------------------------------
float bar_top_y = bar_offset_y;
float bar_bottom = bar_top_y + bar_height;
bool is_rtl = l10n_util::IsLayoutRtl();
bool is_new_layout = rounded_bar_top_resource_id_ != kInvalidResourceID;
int content_top_y = bar_top_y;
int content_height = bar_height;
int rounded_top_adjust = 0;
int rounded_shadow_top = 0;
gfx::Size rounded_bar_top_size;
gfx::PointF rounded_bar_top_position;
ui::NinePatchResource* rounded_bar_top_resource = nullptr;
if (is_new_layout) {
content_top_y += bar_margin_top;
content_height -= bar_margin_top;
rounded_bar_top_resource =
ui::NinePatchResource::From(resource_manager_->GetResource(
ui::ANDROID_RESOURCE_TYPE_STATIC, rounded_bar_top_resource_id_));
rounded_bar_top_size =
gfx::Size(rounded_bar_top_resource->size().width() -
rounded_bar_top_resource->padding().width(),
rounded_bar_top_resource->size().height() -
rounded_bar_top_resource->padding().height());
// TODO(donnd): fix correctly.
const int vertical_fudge_factor = 2; // Create an overlap to avoid a seam.
rounded_top_adjust = rounded_bar_top_size.height() - vertical_fudge_factor;
// This is the position of the side-shadows vertically.
// TODO(donnd): fix this so it's pixel perfect.
rounded_shadow_top = rounded_top_adjust;
rounded_bar_top_position =
gfx::PointF(-rounded_bar_top_resource->padding().x(),
bar_top_y - rounded_top_adjust);
}
// ---------------------------------------------------------------------------
// Panel Shadow
......@@ -94,6 +132,8 @@ void OverlayPanelLayer::SetProperties(
if (panel_shadow_resource_id_ != kInvalidResourceID) {
if (panel_shadow_->parent() != layer_) {
layer_->AddChild(panel_shadow_);
if (is_new_layout)
layer_->AddChild(panel_shadow_right_);
}
ui::NinePatchResource* panel_shadow_resource =
ui::NinePatchResource::From(resource_manager_->GetResource(
......@@ -102,56 +142,61 @@ void OverlayPanelLayer::SetProperties(
gfx::Size shadow_res_size = panel_shadow_resource->size();
gfx::Rect shadow_res_padding = panel_shadow_resource->padding();
gfx::Size shadow_bounds(panel_width + shadow_res_size.width() -
shadow_res_padding.size().width(),
panel_height + shadow_res_size.height() -
shadow_res_padding.size().height());
panel_shadow_->SetUIResourceId(panel_shadow_resource->ui_resource()->id());
panel_shadow_->SetBorder(panel_shadow_resource->Border(shadow_bounds));
panel_shadow_->SetAperture(panel_shadow_resource->aperture());
panel_shadow_->SetBounds(shadow_bounds);
gfx::PointF shadow_position(-shadow_res_padding.origin().x(),
-shadow_res_padding.origin().y());
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;
if (rounded_bar_top_resource_id_ != kInvalidResourceID) {
content_top_y += bar_margin_top;
content_height -= bar_margin_top;
if (is_new_layout) {
DCHECK(rounded_bar_top_resource);
gfx::Size shadow_bounds(shadow_res_size.width(),
panel_height + shadow_res_size.height());
panel_shadow_->SetBounds(shadow_bounds);
panel_shadow_->SetBorder(panel_shadow_resource->Border(shadow_bounds));
// Position the top of the side shadow to the match the top of the
// rounded_bar_top shadow (which is indicated by its top padding).
// TODO(donnd): revisit side-shadow asset and positioning as discussed
// in https://crbug.com/1005975.
gfx::PointF shadow_position(-shadow_res_padding.size().width(),
bar_top_y - rounded_shadow_top);
panel_shadow_->SetPosition(shadow_position);
// Do the right hand side as a mirror of the left shadow.
panel_shadow_right_->SetUIResourceId(
panel_shadow_resource->ui_resource()->id());
panel_shadow_right_->SetAperture(panel_shadow_resource->aperture());
panel_shadow_right_->SetBounds(shadow_bounds);
panel_shadow_right_->SetBorder(
panel_shadow_resource->Border(shadow_bounds));
gfx::PointF right_shadow_position(
panel_width + shadow_res_padding.size().width(),
bar_top_y - rounded_shadow_top);
panel_shadow_right_->SetPosition(right_shadow_position);
// Flip it from the left side to the right side.
gfx::Transform flip_right_transform;
flip_right_transform.RotateAboutYAxis(180.0);
panel_shadow_right_->SetTransform(flip_right_transform);
} else {
gfx::Size shadow_bounds(panel_width + shadow_res_size.width() -
shadow_res_padding.size().width(),
panel_height + shadow_res_size.height() -
shadow_res_padding.size().height());
panel_shadow_->SetBounds(shadow_bounds);
panel_shadow_->SetBorder(panel_shadow_resource->Border(shadow_bounds));
gfx::PointF shadow_position(-shadow_res_padding.origin().x(),
-shadow_res_padding.origin().y());
panel_shadow_->SetPosition(shadow_position);
}
}
// ---------------------------------------------------------------------------
// Rounded Bar Top
// ---------------------------------------------------------------------------
if (rounded_bar_top_resource_id_ != kInvalidResourceID) {
if (is_new_layout) {
DCHECK(rounded_bar_top_resource_id_ != kInvalidResourceID);
rounded_bar_top_->SetIsDrawable(true);
ui::NinePatchResource* rounded_bar_top_resource =
ui::NinePatchResource::From(resource_manager_->GetResource(
ui::ANDROID_RESOURCE_TYPE_STATIC, rounded_bar_top_resource_id_));
DCHECK(rounded_bar_top_resource);
const gfx::Size rounded_bar_top_size(
rounded_bar_top_resource->size().width() -
rounded_bar_top_resource->padding().width(),
rounded_bar_top_resource->size().height() -
rounded_bar_top_resource->padding().height());
// TODO(donnd): fix correctly.
const int vertical_fudge_factor = 2; // Create an overlap to avoid a seam.
rounded_top_adjust = rounded_bar_top_size.height() - vertical_fudge_factor;
gfx::PointF rounded_bar_top_position(
-rounded_bar_top_resource->padding().x(),
bar_top_y - rounded_top_adjust);
gfx::Size bounds(panel_width - rounded_bar_top_size.width(),
rounded_bar_top_resource->size().height());
......@@ -426,6 +471,7 @@ OverlayPanelLayer::OverlayPanelLayer(ui::ResourceManager* resource_manager)
: resource_manager_(resource_manager),
layer_(cc::Layer::Create()),
panel_shadow_(cc::NinePatchLayer::Create()),
panel_shadow_right_(cc::NinePatchLayer::Create()),
rounded_bar_top_(cc::NinePatchLayer::Create()),
bar_background_(cc::SolidColorLayer::Create()),
bar_text_(cc::UIResourceLayer::Create()),
......@@ -444,10 +490,15 @@ OverlayPanelLayer::OverlayPanelLayer(ui::ResourceManager* resource_manager)
layer_->SetMasksToBounds(false);
layer_->SetIsDrawable(true);
// Panel Shadow
// Panel Shadow -- shadow on the left side of the panel, or the whole panel
// when not using the new layout.
panel_shadow_->SetIsDrawable(true);
panel_shadow_->SetFillCenter(false);
// Panel Shadow Right -- shadow on the right side of the panel.
panel_shadow_right_->SetIsDrawable(true);
panel_shadow_right_->SetFillCenter(false);
// Rounded Bar Top
// Puts the layer near the bottom -- we'll decide if it's actually drawable
// later.
......
......@@ -82,6 +82,7 @@ class OverlayPanelLayer : public Layer {
scoped_refptr<cc::Layer> layer_;
scoped_refptr<cc::NinePatchLayer> panel_shadow_;
scoped_refptr<cc::NinePatchLayer> panel_shadow_right_;
scoped_refptr<cc::NinePatchLayer> rounded_bar_top_;
scoped_refptr<cc::SolidColorLayer> bar_background_;
scoped_refptr<cc::UIResourceLayer> bar_text_;
......
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