Commit f8f12625 authored by Jinsuk Kim's avatar Jinsuk Kim Committed by Commit Bot

Android: Add security icon to OverlayPanel-based Preview Tab

https://crrev.com/c/1844341 implemented security requirements to
BottomSheet-based Preview Tab. This CL ports it to OverlayPanel
version, which is required to start stable experiment.

Bug: 968567, 1007499
Change-Id: Id6bdb73a9038c9cf81db89afbd4881417d61d4bb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1859423
Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706344}
parent 0c142fa0
...@@ -3,14 +3,26 @@ ...@@ -3,14 +3,26 @@
Use of this source code is governed by a BSD-style license that can be Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. --> found in the LICENSE file. -->
<!-- Ephemeral Tab caption view where we display 'Open in new tab'. Hidden in <!-- Ephemeral Tab caption view where we display 'Open in new tab'. Hidden in
peeked state, and gets visible only when being expanded to maximized state. --> peeked state, and gets visible only when being expanded to maximized state.
<FrameLayout
In the new layout, we display security level information with URL like in
CCT header. Always visible. -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/ephemeral_tab_caption_view" android:id="@+id/ephemeral_tab_caption_view"
android:orientation="horizontal"
android:gravity="center"
style="@style/ContextualSearchTextViewLayout" > style="@style/ContextualSearchTextViewLayout" >
<org.chromium.ui.widget.ChromeImageView
android:id="@+id/security_icon"
android:layout_width="@dimen/preview_tab_security_icon_size"
android:layout_height="@dimen/preview_tab_security_icon_size"
android:layout_marginStart="4dp"
android:visibility="gone"
app:tint="@color/default_icon_color" />
<TextView <TextView
android:id="@+id/ephemeral_tab_caption" android:id="@+id/ephemeral_tab_caption"
style="@style/ContextualSearchCaptionTextView" /> style="@style/ContextualSearchCaptionTextView" />
</FrameLayout> </LinearLayout>
...@@ -140,6 +140,7 @@ ...@@ -140,6 +140,7 @@
<!-- Preview tab dimensions --> <!-- Preview tab dimensions -->
<dimen name="preview_tab_toolbar_height">70dp</dimen> <dimen name="preview_tab_toolbar_height">70dp</dimen>
<dimen name="preview_tab_favicon_size">24dp</dimen> <dimen name="preview_tab_favicon_size">24dp</dimen>
<dimen name="preview_tab_security_icon_size">16dp</dimen>
<!-- Autofill keyboard accessory dimensions --> <!-- Autofill keyboard accessory dimensions -->
<dimen name="keyboard_accessory_height_with_shadow">56dp</dimen> <dimen name="keyboard_accessory_height_with_shadow">56dp</dimen>
......
...@@ -8,7 +8,6 @@ import android.content.Context; ...@@ -8,7 +8,6 @@ import android.content.Context;
import android.view.ViewGroup; import android.view.ViewGroup;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ChromeFeatureList;
import org.chromium.ui.resources.dynamics.DynamicResourceLoader; import org.chromium.ui.resources.dynamics.DynamicResourceLoader;
/** /**
...@@ -37,7 +36,7 @@ public class EphemeralTabBarControl { ...@@ -37,7 +36,7 @@ public class EphemeralTabBarControl {
public EphemeralTabBarControl(EphemeralTabPanel panel, Context context, ViewGroup container, public EphemeralTabBarControl(EphemeralTabPanel panel, Context context, ViewGroup container,
DynamicResourceLoader loader) { DynamicResourceLoader loader) {
mTitle = new EphemeralTabTitleControl(panel, context, container, loader); mTitle = new EphemeralTabTitleControl(panel, context, container, loader);
mCaption = panel.canPromoteToNewTab() mCaption = EphemeralTabPanel.isNewLayout() || panel.canPromoteToNewTab()
? new EphemeralTabCaptionControl(panel, context, container, loader) ? new EphemeralTabCaptionControl(panel, context, container, loader)
: null; : null;
mTextLayerMinHeight = mTextLayerMinHeight =
...@@ -66,11 +65,14 @@ public class EphemeralTabBarControl { ...@@ -66,11 +65,14 @@ public class EphemeralTabBarControl {
* @param percentage The percentage to the more opened state. * @param percentage The percentage to the more opened state.
*/ */
public void updateForCloseOrPeek(float percentage) { public void updateForCloseOrPeek(float percentage) {
if (ChromeFeatureList.isEnabled(ChromeFeatureList.OVERLAY_NEW_LAYOUT)) return; if (EphemeralTabPanel.isNewLayout()) {
updateForMaximize(SOLID_OPAQUE);
if (percentage == SOLID_OPAQUE) updateForMaximize(SOLID_TRANSPARENT); } else {
// When the panel is completely closed the caption should be hidden. if (percentage == SOLID_OPAQUE) updateForMaximize(SOLID_TRANSPARENT);
if (percentage == SOLID_TRANSPARENT && mCaption != null) mCaption.hide();
// When the panel is completely closed the caption should be hidden.
if (percentage == SOLID_TRANSPARENT && mCaption != null) mCaption.hide();
}
} }
/** /**
...@@ -78,8 +80,6 @@ public class EphemeralTabBarControl { ...@@ -78,8 +80,6 @@ public class EphemeralTabBarControl {
* @param percentage The percentage to the more opened state. * @param percentage The percentage to the more opened state.
*/ */
public void updateForMaximize(float percentage) { public void updateForMaximize(float percentage) {
if (ChromeFeatureList.isEnabled(ChromeFeatureList.OVERLAY_NEW_LAYOUT)) return;
if (mCaption != null) mCaption.updatePanelForMaximization(percentage); if (mCaption != null) mCaption.updatePanelForMaximization(percentage);
} }
...@@ -112,7 +112,7 @@ public class EphemeralTabBarControl { ...@@ -112,7 +112,7 @@ public class EphemeralTabBarControl {
* *
*/ */
public float getCaptionAnimationPercentage() { public float getCaptionAnimationPercentage() {
return mCaption != null ? mCaption.getAnimationPercentage() : 0; return mCaption.getAnimationPercentage();
} }
/** /**
......
...@@ -7,12 +7,15 @@ package org.chromium.chrome.browser.compositor.bottombar.ephemeraltab; ...@@ -7,12 +7,15 @@ package org.chromium.chrome.browser.compositor.bottombar.ephemeraltab;
import android.content.Context; import android.content.Context;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.DrawableRes;
import org.chromium.base.Supplier;
import org.chromium.chrome.R; 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.OverlayPanelTextViewInflater; import org.chromium.chrome.browser.compositor.bottombar.OverlayPanelTextViewInflater;
import org.chromium.components.url_formatter.UrlFormatter;
import org.chromium.ui.resources.dynamics.DynamicResourceLoader; import org.chromium.ui.resources.dynamics.DynamicResourceLoader;
/** /**
...@@ -29,28 +32,32 @@ public class EphemeralTabCaptionControl extends OverlayPanelTextViewInflater { ...@@ -29,28 +32,32 @@ public class EphemeralTabCaptionControl extends OverlayPanelTextViewInflater {
/** The caption visibility. */ /** The caption visibility. */
private boolean mIsVisible; private boolean mIsVisible;
private Supplier<String> mUrl;
/** /**
* The caption animation percentage, which controls how and where to draw. It is * The caption animation percentage, which controls how and where to draw. It is
* 0 when the Contextual Search bar is peeking and 1 when it is maxmized. * 0 when the Contextual Search bar is peeking and 1 when it is maxmized.
*/ */
private float mAnimationPercentage; private float mAnimationPercentage;
private @DrawableRes int mIconId;
private float mIconOpacity;
/** /**
* @param panel The panel. * @param panel The panel.
* @param context The Android Context used to inflate the View. * @param context The Android Context used to inflate the View.
* @param container The container View used to inflate the View. * @param container The container View used to inflate the View.
* @param resourceLoader The resource loader that will handle the snapshot capturing. * @param resourceLoader The resource loader that will handle the snapshot capturing.
*/ */
public EphemeralTabCaptionControl(OverlayPanel panel, Context context, ViewGroup container, public EphemeralTabCaptionControl(EphemeralTabPanel panel, Context context, ViewGroup container,
DynamicResourceLoader resourceLoader) { DynamicResourceLoader resourceLoader) {
super(panel, R.layout.ephemeral_tab_caption_view, R.id.ephemeral_tab_caption_view, context, super(panel, R.layout.ephemeral_tab_caption_view, R.id.ephemeral_tab_caption_view, context,
container, resourceLoader, container, resourceLoader,
(ChromeFeatureList.isEnabled(ChromeFeatureList.OVERLAY_NEW_LAYOUT) (EphemeralTabPanel.isNewLayout() ? R.dimen.overlay_panel_end_buttons_width
? R.dimen.overlay_panel_end_buttons_width : R.dimen.overlay_panel_padded_button_width),
: R.dimen.overlay_panel_padded_button_width), (EphemeralTabPanel.isNewLayout() ? R.dimen.overlay_panel_end_buttons_width
(ChromeFeatureList.isEnabled(ChromeFeatureList.OVERLAY_NEW_LAYOUT) : R.dimen.overlay_panel_padded_button_width));
? R.dimen.overlay_panel_end_buttons_width mUrl = panel::getUrl;
: R.dimen.overlay_panel_padded_button_width));
} }
/** /**
...@@ -65,7 +72,12 @@ public class EphemeralTabCaptionControl extends OverlayPanelTextViewInflater { ...@@ -65,7 +72,12 @@ public class EphemeralTabCaptionControl extends OverlayPanelTextViewInflater {
if (mCaption == null) { if (mCaption == null) {
// |mCaption| gets initialized synchronously in |onFinishInflate|. // |mCaption| gets initialized synchronously in |onFinishInflate|.
inflate(); inflate();
mCaption.setText(R.string.contextmenu_open_in_new_tab); if (EphemeralTabPanel.isNewLayout()) {
mCaption.setText(
UrlFormatter.formatUrlForSecurityDisplayOmitScheme(mUrl.get()));
} else {
mCaption.setText(R.string.contextmenu_open_in_new_tab);
}
} }
invalidate(); invalidate();
mIsVisible = true; mIsVisible = true;
...@@ -75,6 +87,28 @@ public class EphemeralTabCaptionControl extends OverlayPanelTextViewInflater { ...@@ -75,6 +87,28 @@ public class EphemeralTabCaptionControl extends OverlayPanelTextViewInflater {
if (mAnimationPercentage == 0.f) mShowingCaption = false; if (mAnimationPercentage == 0.f) mShowingCaption = false;
} }
/** Sets the security icon. */
public void setSecurityIcon(@DrawableRes int resId) {
mIconId = resId;
ImageView securityIcon = (ImageView) getView().findViewById(R.id.security_icon);
securityIcon.setImageResource(resId);
}
/** @return Security icon resource ID */
public @DrawableRes int getIconId() {
return mIconId;
}
/** Sets the security icon opacity. */
public void setIconOpacity(float opacity) {
mIconOpacity = opacity;
}
/** @return Security icon opacity. */
public float getIconOpacity() {
return mIconOpacity;
}
/** /**
* Hides the caption. * Hides the caption.
*/ */
...@@ -102,7 +136,7 @@ public class EphemeralTabCaptionControl extends OverlayPanelTextViewInflater { ...@@ -102,7 +136,7 @@ public class EphemeralTabCaptionControl extends OverlayPanelTextViewInflater {
* @return The current percentage ranging from 0.0 to 1.0. * @return The current percentage ranging from 0.0 to 1.0.
*/ */
public float getAnimationPercentage() { public float getAnimationPercentage() {
return mAnimationPercentage; return EphemeralTabPanel.isNewLayout() ? 1.f : mAnimationPercentage;
} }
/** /**
...@@ -127,5 +161,8 @@ public class EphemeralTabCaptionControl extends OverlayPanelTextViewInflater { ...@@ -127,5 +161,8 @@ public class EphemeralTabCaptionControl extends OverlayPanelTextViewInflater {
View view = getView(); View view = getView();
mCaption = (TextView) view.findViewById(R.id.ephemeral_tab_caption); mCaption = (TextView) view.findViewById(R.id.ephemeral_tab_caption);
if (EphemeralTabPanel.isNewLayout()) {
view.findViewById(R.id.security_icon).setVisibility(View.VISIBLE);
}
} }
} }
...@@ -163,7 +163,7 @@ public class EphemeralTabCoordinator { ...@@ -163,7 +163,7 @@ public class EphemeralTabCoordinator {
} }
@DrawableRes @DrawableRes
private static int getSecurityIconResource(@ConnectionSecurityLevel int securityLevel) { static int getSecurityIconResource(@ConnectionSecurityLevel int securityLevel) {
switch (securityLevel) { switch (securityLevel) {
case ConnectionSecurityLevel.NONE: case ConnectionSecurityLevel.NONE:
case ConnectionSecurityLevel.WARNING: case ConnectionSecurityLevel.WARNING:
......
...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.compositor.bottombar.ephemeraltab; ...@@ -6,6 +6,7 @@ package org.chromium.chrome.browser.compositor.bottombar.ephemeraltab;
import android.content.Context; import android.content.Context;
import android.graphics.RectF; import android.graphics.RectF;
import android.text.TextUtils;
import android.view.MotionEvent; import android.view.MotionEvent;
import org.chromium.base.SysUtils; import org.chromium.base.SysUtils;
...@@ -25,6 +26,7 @@ import org.chromium.chrome.browser.compositor.layouts.LayoutUpdateHost; ...@@ -25,6 +26,7 @@ import org.chromium.chrome.browser.compositor.layouts.LayoutUpdateHost;
import org.chromium.chrome.browser.compositor.layouts.eventfilter.OverlayPanelEventFilter; import org.chromium.chrome.browser.compositor.layouts.eventfilter.OverlayPanelEventFilter;
import org.chromium.chrome.browser.compositor.scene_layer.EphemeralTabSceneLayer; import org.chromium.chrome.browser.compositor.scene_layer.EphemeralTabSceneLayer;
import org.chromium.chrome.browser.compositor.scene_layer.SceneOverlayLayer; import org.chromium.chrome.browser.compositor.scene_layer.SceneOverlayLayer;
import org.chromium.chrome.browser.ssl.SecurityStateModel;
import org.chromium.chrome.browser.tab.SadTab; import org.chromium.chrome.browser.tab.SadTab;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.tabmodel.TabLaunchType; import org.chromium.chrome.browser.tabmodel.TabLaunchType;
...@@ -32,14 +34,12 @@ import org.chromium.chrome.browser.tabmodel.TabModelSelector; ...@@ -32,14 +34,12 @@ import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabModelObserver; import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabModelObserver;
import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver; import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver;
import org.chromium.chrome.browser.tabmodel.TabSelectionType; import org.chromium.chrome.browser.tabmodel.TabSelectionType;
import org.chromium.components.url_formatter.UrlFormatter;
import org.chromium.content_public.browser.LoadUrlParams; import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
import org.chromium.ui.base.PageTransition; import org.chromium.ui.base.PageTransition;
import org.chromium.ui.resources.ResourceManager; import org.chromium.ui.resources.ResourceManager;
import java.net.MalformedURLException;
import java.net.URL;
/** /**
* The panel containing an ephemeral tab. * The panel containing an ephemeral tab.
* TODO(jinsukkim): Write tests. * TODO(jinsukkim): Write tests.
...@@ -76,10 +76,16 @@ public class EphemeralTabPanel extends OverlayPanel { ...@@ -76,10 +76,16 @@ public class EphemeralTabPanel extends OverlayPanel {
/** Animation effect for favicon display. */ /** Animation effect for favicon display. */
private CompositorAnimator mFaviconAnimation; private CompositorAnimator mFaviconAnimation;
/** Animation effect for security icon display . */
private CompositorAnimator mCaptionAnimation;
private final AnimatorUpdateListener mFadeInAnimatorListener = private final AnimatorUpdateListener mFadeInAnimatorListener =
animator -> mFaviconOpacity = animator.getAnimatedValue(); animator -> mFaviconOpacity = animator.getAnimatedValue();
private final AnimatorUpdateListener mFadeOutAnimatorListener = private final AnimatorUpdateListener mFadeOutAnimatorListener =
animator -> mFaviconOpacity = 1.f - animator.getAnimatedValue(); animator -> mFaviconOpacity = 1.f - animator.getAnimatedValue();
private final AnimatorUpdateListener mSecurityIconAnimationListener = animator
-> getBarControl().getCaptionControl().setIconOpacity(animator.getAnimatedValue());
/** /**
* Checks if this feature (a.k.a. "Preview page/image") is supported. * Checks if this feature (a.k.a. "Preview page/image") is supported.
...@@ -90,6 +96,10 @@ public class EphemeralTabPanel extends OverlayPanel { ...@@ -90,6 +96,10 @@ public class EphemeralTabPanel extends OverlayPanel {
&& !SysUtils.isLowEndDevice(); && !SysUtils.isLowEndDevice();
} }
static boolean isNewLayout() {
return ChromeFeatureList.isEnabled(ChromeFeatureList.OVERLAY_NEW_LAYOUT);
}
/** /**
* @param context The current Android {@link Context}. * @param context The current Android {@link Context}.
* @param updateHost The {@link LayoutUpdateHost} used to request updates in the Layout. * @param updateHost The {@link LayoutUpdateHost} used to request updates in the Layout.
...@@ -125,17 +135,16 @@ public class EphemeralTabPanel extends OverlayPanel { ...@@ -125,17 +135,16 @@ public class EphemeralTabPanel extends OverlayPanel {
private class EphemeralTabPanelContentDelegate extends OverlayContentDelegate { private class EphemeralTabPanelContentDelegate extends OverlayContentDelegate {
@Override @Override
public void onMainFrameLoadStarted(String url, boolean isExternalUrl) { public void onMainFrameLoadStarted(String url, boolean isExternalUrl) {
try { if (TextUtils.equals(mUrl, url)) return;
String newHost = new URL(url).getHost(); mUrl = url;
String curHost = new URL(mUrl).getHost();
if (!newHost.equals(curHost)) { // Resets to default icon if favicon may need updating.
mUrl = url; startFaviconAnimation(false);
// Resets to default icon if favicon may need updating. }
startFaviconAnimation(false);
} @Override
} catch (MalformedURLException e) { public void onSSLStateUpdated() {
assert false : "Malformed URL should not be passed."; if (isNewLayout()) updateCaption();
}
} }
} }
...@@ -257,6 +266,21 @@ public class EphemeralTabPanel extends OverlayPanel { ...@@ -257,6 +266,21 @@ public class EphemeralTabPanel extends OverlayPanel {
mFaviconAnimation.start(); mFaviconAnimation.start();
} }
private void updateCaption() {
if (mCaptionAnimation != null) mCaptionAnimation.cancel();
int securityLevel = SecurityStateModel.getSecurityLevelForWebContents(getWebContents());
EphemeralTabCaptionControl caption = getBarControl().getCaptionControl();
caption.getTextView().setText(UrlFormatter.formatUrlForSecurityDisplayOmitScheme(
getWebContents().getVisibleUrl()));
caption.setSecurityIcon(EphemeralTabCoordinator.getSecurityIconResource(securityLevel));
mCaptionAnimation = new CompositorAnimator(getAnimationHandler());
mCaptionAnimation.setDuration(BASE_ANIMATION_DURATION_MS);
mCaptionAnimation.removeAllListeners();
mCaptionAnimation.addUpdateListener(mSecurityIconAnimationListener);
mCaptionAnimation.start();
}
/** /**
* @return Snaptshot value of the favicon opacity. * @return Snaptshot value of the favicon opacity.
*/ */
...@@ -343,16 +367,12 @@ public class EphemeralTabPanel extends OverlayPanel { ...@@ -343,16 +367,12 @@ public class EphemeralTabPanel extends OverlayPanel {
@Override @Override
protected void updatePanelForCloseOrPeek(float percentage) { protected void updatePanelForCloseOrPeek(float percentage) {
super.updatePanelForCloseOrPeek(percentage); super.updatePanelForCloseOrPeek(percentage);
if (ChromeFeatureList.isEnabled(ChromeFeatureList.OVERLAY_NEW_LAYOUT)) return;
getBarControl().updateForCloseOrPeek(percentage); getBarControl().updateForCloseOrPeek(percentage);
} }
@Override @Override
protected void updatePanelForMaximization(float percentage) { protected void updatePanelForMaximization(float percentage) {
super.updatePanelForMaximization(percentage); super.updatePanelForMaximization(percentage);
if (ChromeFeatureList.isEnabled(ChromeFeatureList.OVERLAY_NEW_LAYOUT)) return;
getBarControl().updateForMaximize(percentage); getBarControl().updateForMaximize(percentage);
} }
......
...@@ -92,12 +92,16 @@ public class EphemeralTabSceneLayer extends SceneOverlayLayer { ...@@ -92,12 +92,16 @@ public class EphemeralTabSceneLayer extends SceneOverlayLayer {
int titleViewId = title.getViewId(); int titleViewId = title.getViewId();
int captionViewId = 0; int captionViewId = 0;
int captionIconId = 0;
float captionIconOpacity = 0.f;
float captionAnimationPercentage = 0.f; float captionAnimationPercentage = 0.f;
boolean captionVisible = false; boolean captionVisible = false;
if (caption != null) { if (caption != null) {
captionViewId = caption.getViewId(); captionViewId = caption.getViewId();
captionAnimationPercentage = caption.getAnimationPercentage(); captionAnimationPercentage = caption.getAnimationPercentage();
captionIconOpacity = caption.getIconOpacity();
captionVisible = caption.getIsVisible(); captionVisible = caption.getIsVisible();
captionIconId = caption.getIconId();
} }
boolean isProgressBarVisible = panel.isProgressBarVisible(); boolean isProgressBarVisible = panel.isProgressBarVisible();
float progressBarHeight = panel.getProgressBarHeight(); float progressBarHeight = panel.getProgressBarHeight();
...@@ -107,18 +111,18 @@ public class EphemeralTabSceneLayer extends SceneOverlayLayer { ...@@ -107,18 +111,18 @@ public class EphemeralTabSceneLayer extends SceneOverlayLayer {
WebContents panelWebContents = panel.getWebContents(); WebContents panelWebContents = panel.getWebContents();
EphemeralTabSceneLayerJni.get().update(mNativePtr, EphemeralTabSceneLayer.this, titleViewId, EphemeralTabSceneLayerJni.get().update(mNativePtr, EphemeralTabSceneLayer.this, titleViewId,
captionViewId, captionAnimationPercentage, bar.getTextLayerMinHeight(), captionViewId, captionIconId, captionIconOpacity, captionAnimationPercentage,
bar.getTitleCaptionSpacing(), captionVisible, R.drawable.progress_bar_background, bar.getTextLayerMinHeight(), bar.getTitleCaptionSpacing(), captionVisible,
R.drawable.progress_bar_foreground, mDpToPx, panel.getBasePageBrightness(), R.drawable.progress_bar_background, R.drawable.progress_bar_foreground, mDpToPx,
panel.getBasePageY() * mDpToPx, panelWebContents, panel.getOffsetX() * mDpToPx, panel.getBasePageBrightness(), panel.getBasePageY() * mDpToPx, panelWebContents,
panel.getOffsetY() * mDpToPx, panel.getWidth() * mDpToPx, panel.getOffsetX() * mDpToPx, panel.getOffsetY() * mDpToPx,
panel.getHeight() * mDpToPx, panel.getBarBackgroundColor(), panel.getWidth() * mDpToPx, panel.getHeight() * mDpToPx,
panel.getBarMarginSide() * mDpToPx, panel.getBarMarginTop() * mDpToPx, panel.getBarBackgroundColor(), panel.getBarMarginSide() * mDpToPx,
panel.getBarHeight() * mDpToPx, panel.isBarBorderVisible(), panel.getBarMarginTop() * mDpToPx, panel.getBarHeight() * mDpToPx,
panel.getBarBorderHeight() * mDpToPx, panel.getBarShadowVisible(), panel.isBarBorderVisible(), panel.getBarBorderHeight() * mDpToPx,
panel.getIconColor(), panel.getDragHandlebarColor(), panel.getFaviconOpacity(), panel.getBarShadowVisible(), panel.getIconColor(), panel.getDragHandlebarColor(),
isProgressBarVisible, progressBarHeight * mDpToPx, progressBarOpacity, panel.getFaviconOpacity(), isProgressBarVisible, progressBarHeight * mDpToPx,
progressBarCompletion, separatorLineColor); progressBarOpacity, progressBarCompletion, separatorLineColor);
} }
@Override @Override
...@@ -137,8 +141,9 @@ public class EphemeralTabSceneLayer extends SceneOverlayLayer { ...@@ -137,8 +141,9 @@ public class EphemeralTabSceneLayer extends SceneOverlayLayer {
@Override @Override
protected void initializeNative() { protected void initializeNative() {
if (mNativePtr == 0) if (mNativePtr == 0) {
mNativePtr = EphemeralTabSceneLayerJni.get().init(EphemeralTabSceneLayer.this); mNativePtr = EphemeralTabSceneLayerJni.get().init(EphemeralTabSceneLayer.this);
}
assert mNativePtr != 0; assert mNativePtr != 0;
} }
...@@ -166,8 +171,9 @@ public class EphemeralTabSceneLayer extends SceneOverlayLayer { ...@@ -166,8 +171,9 @@ public class EphemeralTabSceneLayer extends SceneOverlayLayer {
int barShadowResourceId, int panelIconResourceId, int dragHandlebarResourceId, int barShadowResourceId, int panelIconResourceId, int dragHandlebarResourceId,
int openTabIconResourceId, int closeIconResourceId); int openTabIconResourceId, int closeIconResourceId);
void update(long nativeEphemeralTabSceneLayer, EphemeralTabSceneLayer caller, void update(long nativeEphemeralTabSceneLayer, EphemeralTabSceneLayer caller,
int titleViewId, int captionViewId, float captionAnimationPercentage, int titleViewId, int captionViewId, int captionIconId, float captionIconOpacity,
float textLayerMinHeight, float titleCaptionSpacing, boolean captionVisible, float captionAnimationPercentage, float textLayerMinHeight,
float titleCaptionSpacing, boolean captionVisible,
int progressBarBackgroundResourceId, int progressBarResourceId, float dpToPx, int progressBarBackgroundResourceId, int progressBarResourceId, float dpToPx,
float basePageBrightness, float basePageYOffset, WebContents webContents, float basePageBrightness, float basePageYOffset, WebContents webContents,
float panelX, float panelY, float panelWidth, float panelHeight, float panelX, float panelY, float panelWidth, float panelHeight,
......
...@@ -27,7 +27,7 @@ void DisplayFavicon(scoped_refptr<cc::UIResourceLayer> layer, ...@@ -27,7 +27,7 @@ void DisplayFavicon(scoped_refptr<cc::UIResourceLayer> layer,
const float bar_margin, const float bar_margin,
const base::RepeatingCallback<void()>& favicon_callback) { const base::RepeatingCallback<void()>& favicon_callback) {
const float bounds_width = const float bounds_width =
android::OverlayPanelLayer::kDefaultIconWidthDp * dp_to_px; android::EphemeralTabLayer::kFaviconWidthDp * dp_to_px;
// Dimension to which favicons are resized - half the size of default icon. // Dimension to which favicons are resized - half the size of default icon.
const float icon_size = bounds_width / 2.0f; const float icon_size = bounds_width / 2.0f;
...@@ -58,6 +58,8 @@ void EphemeralTabLayer::SetProperties( ...@@ -58,6 +58,8 @@ void EphemeralTabLayer::SetProperties(
content::WebContents* web_contents, content::WebContents* web_contents,
int title_view_resource_id, int title_view_resource_id,
int caption_view_resource_id, int caption_view_resource_id,
int caption_icon_resource_id,
jfloat caption_icon_opacity,
jfloat caption_animation_percentage, jfloat caption_animation_percentage,
jfloat text_layer_min_height, jfloat text_layer_min_height,
jfloat title_caption_spacing, jfloat title_caption_spacing,
...@@ -111,9 +113,11 @@ void EphemeralTabLayer::SetProperties( ...@@ -111,9 +113,11 @@ void EphemeralTabLayer::SetProperties(
1.0f /* icon opacity */, separator_line_color); 1.0f /* icon opacity */, separator_line_color);
SetupTextLayer(bar_top, bar_height, text_layer_min_height, SetupTextLayer(bar_top, bar_height, text_layer_min_height,
caption_view_resource_id, caption_animation_percentage, caption_view_resource_id, caption_icon_resource_id,
caption_visible, title_view_resource_id, caption_icon_opacity,
title_caption_spacing);
caption_animation_percentage, caption_visible,
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,
...@@ -132,7 +136,9 @@ void EphemeralTabLayer::SetProperties( ...@@ -132,7 +136,9 @@ void EphemeralTabLayer::SetProperties(
void EphemeralTabLayer::SetupTextLayer(float bar_top, void EphemeralTabLayer::SetupTextLayer(float bar_top,
float bar_height, float bar_height,
float text_layer_min_height, float text_layer_min_height,
int caption_resource_id, int caption_view_resource_id,
int caption_icon_resource_id,
float caption_icon_opacity,
float animation_percentage, float animation_percentage,
bool caption_visible, bool caption_visible,
int title_resource_id, int title_resource_id,
...@@ -158,19 +164,24 @@ void EphemeralTabLayer::SetupTextLayer(float bar_top, ...@@ -158,19 +164,24 @@ void EphemeralTabLayer::SetupTextLayer(float bar_top,
if (caption_visible) { if (caption_visible) {
// Grabs the dynamic Search Caption resource so we can get a snapshot. // Grabs the dynamic Search Caption resource so we can get a snapshot.
caption_resource = resource_manager_->GetResource( caption_resource = resource_manager_->GetResource(
ui::ANDROID_RESOURCE_TYPE_DYNAMIC, caption_resource_id); ui::ANDROID_RESOURCE_TYPE_DYNAMIC, caption_view_resource_id);
} }
if (animation_percentage != 0.f) { if (animation_percentage != 0.f) {
if (caption_->parent() != text_layer_) { if (caption_->parent() != text_layer_)
text_layer_->AddChild(caption_); text_layer_->AddChild(caption_);
}
if (security_icon_layer_->parent() != text_layer_)
text_layer_->AddChild(security_icon_layer_);
if (caption_resource) { if (caption_resource) {
caption_->SetUIResourceId(caption_resource->ui_resource()->id()); caption_->SetUIResourceId(caption_resource->ui_resource()->id());
caption_->SetBounds(caption_resource->size()); caption_->SetBounds(caption_resource->size());
} }
} else if (caption_->parent()) { } else {
caption_->RemoveFromParent(); if (caption_->parent())
caption_->RemoveFromParent();
if (security_icon_layer_->parent())
security_icon_layer_->RemoveFromParent();
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -229,6 +240,22 @@ void EphemeralTabLayer::SetupTextLayer(float bar_top, ...@@ -229,6 +240,22 @@ void EphemeralTabLayer::SetupTextLayer(float bar_top,
title_->SetPosition(gfx::PointF(0.f, title_top)); title_->SetPosition(gfx::PointF(0.f, title_top));
caption_->SetPosition(gfx::PointF(0.f, caption_top)); caption_->SetPosition(gfx::PointF(0.f, caption_top));
// Security icon
if (!caption_icon_resource_id)
return;
float icon_x = bar_margin_side_ +
(kFaviconWidthDp + kSecurityIconMarginStartDp) * dp_to_px_;
float icon_y = title_top_end + title_height;
ui::Resource* security_icon_resource =
resource_manager_->GetStaticResourceWithTint(caption_icon_resource_id, 0);
security_icon_layer_->SetUIResourceId(
security_icon_resource->ui_resource()->id());
security_icon_layer_->SetBounds(gfx::ScaleToRoundedSize(
security_icon_resource->size(), kSecurityIconScale));
security_icon_layer_->SetPosition(gfx::PointF(icon_x, icon_y));
security_icon_layer_->SetOpacity(caption_icon_opacity);
} }
void EphemeralTabLayer::OnFaviconUpdated( void EphemeralTabLayer::OnFaviconUpdated(
...@@ -264,11 +291,13 @@ EphemeralTabLayer::EphemeralTabLayer( ...@@ -264,11 +291,13 @@ EphemeralTabLayer::EphemeralTabLayer(
title_(cc::UIResourceLayer::Create()), title_(cc::UIResourceLayer::Create()),
caption_(cc::UIResourceLayer::Create()), caption_(cc::UIResourceLayer::Create()),
favicon_layer_(cc::UIResourceLayer::Create()), favicon_layer_(cc::UIResourceLayer::Create()),
security_icon_layer_(cc::UIResourceLayer::Create()),
text_layer_(cc::UIResourceLayer::Create()) { text_layer_(cc::UIResourceLayer::Create()) {
// Content layer // Content layer
text_layer_->SetIsDrawable(true); text_layer_->SetIsDrawable(true);
title_->SetIsDrawable(true); title_->SetIsDrawable(true);
caption_->SetIsDrawable(true); caption_->SetIsDrawable(true);
security_icon_layer_->SetIsDrawable(true);
AddBarTextLayer(text_layer_); AddBarTextLayer(text_layer_);
text_layer_->AddChild(title_); text_layer_->AddChild(title_);
......
...@@ -34,12 +34,24 @@ namespace android { ...@@ -34,12 +34,24 @@ namespace android {
class EphemeralTabLayer : public OverlayPanelLayer, class EphemeralTabLayer : public OverlayPanelLayer,
public favicon::FaviconDriverObserver { public favicon::FaviconDriverObserver {
public: public:
static constexpr float kFaviconWidthDp =
OverlayPanelLayer::kDefaultIconWidthDp;
// Scale factor used to make the security icon size smaller to fit in the
// header.
static constexpr float kSecurityIconScale = 0.8f;
// Left margin that positions the icon in front of the caption.
static constexpr float kSecurityIconMarginStartDp = 8.f;
static scoped_refptr<EphemeralTabLayer> Create( static scoped_refptr<EphemeralTabLayer> Create(
ui::ResourceManager* resource_manager, ui::ResourceManager* resource_manager,
base::RepeatingCallback<void()>&& favicon_callback); base::RepeatingCallback<void()>&& favicon_callback);
void SetProperties(content::WebContents* web_contents, void SetProperties(content::WebContents* web_contents,
int title_view_resource_id, int title_view_resource_id,
int caption_view_resource_id, int caption_view_resource_id,
int caption_icon_resource_id,
jfloat caption_icon_opacity,
jfloat caption_animation_percentage, jfloat caption_animation_percentage,
jfloat text_layer_min_height, jfloat text_layer_min_height,
jfloat title_caption_spacing, jfloat title_caption_spacing,
...@@ -70,7 +82,9 @@ class EphemeralTabLayer : public OverlayPanelLayer, ...@@ -70,7 +82,9 @@ class EphemeralTabLayer : public OverlayPanelLayer,
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,
int caption_resource_id, int caption_view_resource_id,
int caption_icon_resource_id,
float caption_icon_opacity,
float animation_percentage, float animation_percentage,
bool caption_visible, bool caption_visible,
int context_resource_id, int context_resource_id,
...@@ -101,6 +115,7 @@ class EphemeralTabLayer : public OverlayPanelLayer, ...@@ -101,6 +115,7 @@ class EphemeralTabLayer : public OverlayPanelLayer,
scoped_refptr<cc::UIResourceLayer> title_; scoped_refptr<cc::UIResourceLayer> title_;
scoped_refptr<cc::UIResourceLayer> caption_; scoped_refptr<cc::UIResourceLayer> caption_;
scoped_refptr<cc::UIResourceLayer> favicon_layer_; scoped_refptr<cc::UIResourceLayer> favicon_layer_;
scoped_refptr<cc::UIResourceLayer> security_icon_layer_;
scoped_refptr<cc::UIResourceLayer> text_layer_; scoped_refptr<cc::UIResourceLayer> text_layer_;
std::unique_ptr<base::CancelableTaskTracker> cancelable_task_tracker_; std::unique_ptr<base::CancelableTaskTracker> cancelable_task_tracker_;
}; };
......
...@@ -17,9 +17,6 @@ ...@@ -17,9 +17,6 @@
namespace android { namespace android {
const float OverlayPanelLayer::kDefaultIconWidthDp = 36.0f;
const int OverlayPanelLayer::kInvalidResourceID = -1;
scoped_refptr<cc::Layer> OverlayPanelLayer::GetIconLayer() { scoped_refptr<cc::Layer> OverlayPanelLayer::GetIconLayer() {
if (panel_icon_resource_id_ == kInvalidResourceID) if (panel_icon_resource_id_ == kInvalidResourceID)
return nullptr; return nullptr;
......
...@@ -25,10 +25,10 @@ namespace android { ...@@ -25,10 +25,10 @@ namespace android {
class OverlayPanelLayer : public Layer { class OverlayPanelLayer : public Layer {
public: public:
// Default width for any icon displayed on an OverlayPanel. // Default width for any icon displayed on an OverlayPanel.
static const float kDefaultIconWidthDp; static constexpr float kDefaultIconWidthDp = 36.0f;
// ID for Invalid resource. // ID for Invalid resource.
static const int kInvalidResourceID; static constexpr int kInvalidResourceID = -1;
void SetResourceIds(int bar_text_resource_id, void SetResourceIds(int bar_text_resource_id,
int panel_shadow_resource_id, int panel_shadow_resource_id,
......
...@@ -77,6 +77,8 @@ void EphemeralTabSceneLayer::Update(JNIEnv* env, ...@@ -77,6 +77,8 @@ void EphemeralTabSceneLayer::Update(JNIEnv* env,
const JavaParamRef<jobject>& object, const JavaParamRef<jobject>& object,
jint title_view_resource_id, jint title_view_resource_id,
jint caption_view_resource_id, jint caption_view_resource_id,
jint caption_icon_resource_id,
jfloat caption_icon_opacity,
jfloat caption_animation_percentage, jfloat caption_animation_percentage,
jfloat text_layer_min_height, jfloat text_layer_min_height,
jfloat title_caption_spacing, jfloat title_caption_spacing,
...@@ -127,6 +129,7 @@ void EphemeralTabSceneLayer::Update(JNIEnv* env, ...@@ -127,6 +129,7 @@ void EphemeralTabSceneLayer::Update(JNIEnv* env,
content_container_->SetPosition(gfx::PointF(0.0f, base_page_offset)); content_container_->SetPosition(gfx::PointF(0.0f, base_page_offset));
ephemeral_tab_layer_->SetProperties( ephemeral_tab_layer_->SetProperties(
web_contents, title_view_resource_id, caption_view_resource_id, web_contents, title_view_resource_id, caption_view_resource_id,
caption_icon_resource_id, caption_icon_opacity,
caption_animation_percentage, text_layer_min_height, caption_animation_percentage, text_layer_min_height,
title_caption_spacing, caption_visible, title_caption_spacing, caption_visible,
progress_bar_background_resource_id, progress_bar_resource_id, dp_to_px, progress_bar_background_resource_id, progress_bar_resource_id, dp_to_px,
......
...@@ -45,6 +45,8 @@ class EphemeralTabSceneLayer : public SceneLayer { ...@@ -45,6 +45,8 @@ class EphemeralTabSceneLayer : public SceneLayer {
const base::android::JavaParamRef<jobject>& object, const base::android::JavaParamRef<jobject>& object,
jint title_view_resource_id, jint title_view_resource_id,
jint caption_view_resource_id, jint caption_view_resource_id,
jint caption_icon_resource_id,
jfloat caption_icon_opacity,
jfloat caption_animation_percentage, jfloat caption_animation_percentage,
jfloat text_layer_min_height, jfloat text_layer_min_height,
jfloat term_caption_spacing, jfloat term_caption_spacing,
......
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