Skip to content

Commit

Permalink
Remove unneeded params from Toolbar[Scene]Layer
Browse files Browse the repository at this point in the history
This patch removes the 'toolbar textbox aplha' param from the native
methods since it is always 1 and the 'view height' param since it is
unused. The visibility param in the SceneLayer has also been removed
as it is handled by one of the SceneOverlay interface methods.

Bug: 1100332
Change-Id: Ia43c405ede070bc4d2ac3b95e00f7b35ac94628c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2278168
Commit-Queue: Matthew Jones <mdjones@chromium.org>
Reviewed-by: Mei Liang <meiliang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#785769}
  • Loading branch information
iotitan authored and Commit Bot committed Jul 7, 2020
1 parent 3193cbf commit 389eefc
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,11 @@ public void init(TabModelSelector selector, TabCreatorManager creator,
ContextualSearchManagementDelegate contextualSearchDelegate,
DynamicResourceLoader dynamicResourceLoader) {
LayoutRenderHost renderHost = mHost.getLayoutRenderHost();
mToolbarOverlay = new ToolbarSceneLayer(
mContext, this, renderHost, controlContainer, () -> mCurrentTab);
mToolbarOverlay = new ToolbarSceneLayer(mContext, this, renderHost, controlContainer,
() -> mCurrentTab, getFullscreenManager(),
() -> getActiveLayout() != null
? getActiveLayout().getViewportMode()
: Layout.ViewportMode.USE_PREVIOUS_BROWSER_CONTROLS_STATE);

// Initialize Layouts
mStaticLayout.onFinishNativeInitialization();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ public void pushLayers(Context context, RectF viewport, RectF contentViewport, L

int defaultThemeColor = ChromeColors.getDefaultThemeColor(res, useIncognitoColors);

// In the modern design, the text box is always drawn opaque in the compositor.
float textBoxAlpha = 1.f;

int closeButtonColor = useIncognitoColors
? Color.WHITE
: ApiCompatibilityUtils.getColor(res, R.color.default_icon_color_secondary);
Expand All @@ -126,7 +123,7 @@ public void pushLayers(Context context, RectF viewport, RectF contentViewport, L
t.isCloseButtonOnRight(), t.getRenderX() * dpToPx, t.getRenderY() * dpToPx,
t.getScaledContentWidth() * dpToPx, t.getScaledContentHeight() * dpToPx,
t.getOriginalContentWidth() * dpToPx, t.getOriginalContentHeight() * dpToPx,
contentViewport.height(), t.getClippedX() * dpToPx, t.getClippedY() * dpToPx,
t.getClippedX() * dpToPx, t.getClippedY() * dpToPx,
Math.min(t.getClippedWidth(), t.getScaledContentWidth()) * dpToPx,
Math.min(t.getClippedHeight(), t.getScaledContentHeight()) * dpToPx,
t.getTiltXPivotOffset() * dpToPx, t.getTiltYPivotOffset() * dpToPx,
Expand All @@ -138,7 +135,7 @@ public void pushLayers(Context context, RectF viewport, RectF contentViewport, L
t.getBrightness(), t.showToolbar(), defaultThemeColor,
t.getToolbarBackgroundColor(), closeButtonColor, t.anonymizeToolbar(),
t.isTitleNeeded(), urlBarBackgroundId, t.getTextBoxBackgroundColor(),
textBoxAlpha, t.getToolbarAlpha(), fullscreenManager.getContentOffset(),
t.getToolbarAlpha(), fullscreenManager.getContentOffset(),
t.getSideBorderScale(), t.insetBorderVertical());
}
TabListSceneLayerJni.get().finishBuildingFrame(mNativePtr, TabListSceneLayer.this);
Expand Down Expand Up @@ -203,17 +200,16 @@ void putTabLayer(long nativeTabListSceneLayer, TabListSceneLayer caller, int sel
int backLogoResourceId, int borderResourceId, int borderInnerShadowResourceId,
boolean canUseLiveLayer, int tabBackgroundColor, int backLogoColor,
boolean incognito, boolean isPortrait, float x, float y, float width, float height,
float contentWidth, float contentHeight, float visibleContentHeight, float shadowX,
float shadowY, float shadowWidth, float shadowHeight, float pivotX, float pivotY,
float rotationX, float rotationY, float alpha, float borderAlpha,
float borderInnerShadowAlpha, float contourAlpha, float shadowAlpha,
float closeAlpha, float closeBtnWidth, float closeBtnAssetSize,
float staticToViewBlend, float borderScale, float saturation, float brightness,
boolean showToolbar, int defaultThemeColor, int toolbarBackgroundColor,
int closeButtonColor, boolean anonymizeToolbar, boolean showTabTitle,
int toolbarTextBoxResource, int toolbarTextBoxBackgroundColor,
float toolbarTextBoxAlpha, float toolbarAlpha, float contentOffset,
float sideBorderScale, boolean insetVerticalBorder);
float contentWidth, float contentHeight, float shadowX, float shadowY,
float shadowWidth, float shadowHeight, float pivotX, float pivotY, float rotationX,
float rotationY, float alpha, float borderAlpha, float borderInnerShadowAlpha,
float contourAlpha, float shadowAlpha, float closeAlpha, float closeBtnWidth,
float closeBtnAssetSize, float staticToViewBlend, float borderScale,
float saturation, float brightness, boolean showToolbar, int defaultThemeColor,
int toolbarBackgroundColor, int closeButtonColor, boolean anonymizeToolbar,
boolean showTabTitle, int toolbarTextBoxResource, int toolbarTextBoxBackgroundColor,
float toolbarTextBoxAlpha, float contentOffset, float sideBorderScale,
boolean insetVerticalBorder);

void putBackgroundLayer(long nativeTabListSceneLayer, TabListSceneLayer caller,
int resourceId, float alpha, int topOffset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ public class ToolbarSceneLayer extends SceneOverlayLayer implements SceneOverlay
/** Provides current tab. */
private final Supplier<Tab> mCurrentTab;

/** Access to the current state of the browser controls. */
private final BrowserControlsStateProvider mBrowserControlsStateProvider;

/** A means of accessing the current viewport mode. */
private final Supplier<Integer> mViewportModeSupplier;

/**
* @param context An Android context to use.
* @param provider A LayoutProvider for accessing the current layout.
Expand All @@ -64,46 +70,42 @@ public class ToolbarSceneLayer extends SceneOverlayLayer implements SceneOverlay
* @param currentTab A supplier for the current tab.
*/
public ToolbarSceneLayer(Context context, LayoutProvider provider, LayoutRenderHost renderHost,
ControlContainer toolbarContainer, Supplier<Tab> currentTab) {
ControlContainer toolbarContainer, Supplier<Tab> currentTab,
BrowserControlsStateProvider browserControlsStateProvider,
Supplier<Integer> viewportModeSupplier) {
mContext = context;
mLayoutProvider = provider;
mRenderHost = renderHost;
mToolbarContainer = toolbarContainer;
mCurrentTab = currentTab;
mBrowserControlsStateProvider = browserControlsStateProvider;
mViewportModeSupplier = viewportModeSupplier;
}

/**
* Update the toolbar and progress bar layers.
*
* @param browserControlsBackgroundColor The background color of the browser controls.
* @param browserControlsUrlBarAlpha The alpha of the URL bar.
* @param browserControlsStateProvider A BrowserControlsStateProvider instance.
* @param resourceManager A ResourceManager for loading static resources.
* @param forceHideAndroidBrowserControls True if the Android browser controls are being hidden.
* @param viewportMode The sizing mode of the viewport being drawn in.
* @param isTablet If the device is a tablet.
* @param windowHeight The height of the window.
*/
private void update(int browserControlsBackgroundColor, float browserControlsUrlBarAlpha,
BrowserControlsStateProvider browserControlsStateProvider,
ResourceManager resourceManager, boolean forceHideAndroidBrowserControls,
@ViewportMode int viewportMode, boolean isTablet, float windowHeight) {
private void update(int browserControlsBackgroundColor, ResourceManager resourceManager,
boolean forceHideAndroidBrowserControls, @ViewportMode int viewportMode,
boolean isTablet) {
if (!DeviceClassManager.enableFullscreen()) return;

if (browserControlsStateProvider == null) return;
if (mBrowserControlsStateProvider == null) return;
if (!isTablet && mToolbarContainer != null) {
if (mProgressBarDrawingInfo == null) mProgressBarDrawingInfo = new DrawingInfo();
mToolbarContainer.getProgressBarDrawingInfo(mProgressBarDrawingInfo);
} else {
assert mProgressBarDrawingInfo == null;
}

// Texture is always used unless it is completely off-screen.
boolean useTexture =
!BrowserControlsUtils.areBrowserControlsOffScreen(browserControlsStateProvider)
&& viewportMode != ViewportMode.ALWAYS_FULLSCREEN;
boolean drawControlsAsTexture =
BrowserControlsUtils.drawControlsAsTexture(browserControlsStateProvider);
BrowserControlsUtils.drawControlsAsTexture(mBrowserControlsStateProvider);
boolean showShadow = drawControlsAsTexture || forceHideAndroidBrowserControls;

int textBoxColor = ToolbarColors.getTextBoxColorForToolbarBackground(
Expand All @@ -117,8 +119,7 @@ private void update(int browserControlsBackgroundColor, float browserControlsUrl
// positioned at the bottom of the top controls regardless of the total height.
ToolbarSceneLayerJni.get().updateToolbarLayer(mNativePtr, ToolbarSceneLayer.this,
resourceManager, R.id.control_container, browserControlsBackgroundColor,
textBoxResourceId, browserControlsUrlBarAlpha, textBoxColor,
browserControlsStateProvider.getContentOffset(), windowHeight, useTexture,
textBoxResourceId, textBoxColor, mBrowserControlsStateProvider.getContentOffset(),
showShadow);

if (mProgressBarDrawingInfo == null) return;
Expand Down Expand Up @@ -165,23 +166,19 @@ public SceneOverlayLayer getUpdatedSceneOverlayTree(RectF viewport, RectF visibl
boolean forceHideBrowserControlsAndroidView =
mLayoutProvider.getActiveLayout().forceHideBrowserControlsAndroidView();
@ViewportMode
int viewportMode = mLayoutProvider.getActiveLayout().getViewportMode();

// In Chrome modern design, the url bar is always opaque since it is drawn in the
// compositor.
float alpha = 1;
int viewportMode = mViewportModeSupplier.get();

update(mRenderHost.getBrowserControlsBackgroundColor(mContext.getResources()), alpha,
mLayoutProvider.getFullscreenManager(), resourceManager,
forceHideBrowserControlsAndroidView, viewportMode,
DeviceFormFactor.isNonMultiDisplayContextOnTablet(mContext), viewport.height());
update(mRenderHost.getBrowserControlsBackgroundColor(mContext.getResources()),
resourceManager, forceHideBrowserControlsAndroidView, viewportMode,
DeviceFormFactor.isNonMultiDisplayContextOnTablet(mContext));

return this;
}

@Override
public boolean isSceneOverlayTreeShowing() {
return true;
return !BrowserControlsUtils.areBrowserControlsOffScreen(mBrowserControlsStateProvider)
&& mViewportModeSupplier.get() != ViewportMode.ALWAYS_FULLSCREEN;
}

@Override
Expand Down Expand Up @@ -238,8 +235,7 @@ void setContentTree(
long nativeToolbarSceneLayer, ToolbarSceneLayer caller, SceneLayer contentTree);
void updateToolbarLayer(long nativeToolbarSceneLayer, ToolbarSceneLayer caller,
ResourceManager resourceManager, int resourceId, int toolbarBackgroundColor,
int urlBarResourceId, float urlBarAlpha, int urlBarColor, float contentOffset,
float viewHeight, boolean visible, boolean showShadow);
int urlBarResourceId, int urlBarColor, float contentOffset, boolean showShadow);
void updateProgressBar(long nativeToolbarSceneLayer, ToolbarSceneLayer caller,
int progressBarX, int progressBarY, int progressBarWidth, int progressBarHeight,
int progressBarColor, int progressBarBackgroundX, int progressBarBackgroundY,
Expand Down
4 changes: 1 addition & 3 deletions chrome/browser/android/compositor/layer/tab_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ void TabLayer::SetProperties(int id,
float content_width,
float content_height,
float view_width,
float view_height,
bool show_toolbar,
int default_theme_color,
int toolbar_background_color,
Expand All @@ -141,7 +140,6 @@ void TabLayer::SetProperties(int id,
bool show_tab_title,
int toolbar_textbox_resource_id,
int toolbar_textbox_background_color,
float toolbar_textbox_alpha,
float toolbar_alpha,
float content_offset,
float side_border_scale,
Expand Down Expand Up @@ -230,7 +228,7 @@ void TabLayer::SetProperties(int id,
toolbar_layer_->PushResource(
toolbar_resource_id, toolbar_background_color, anonymize_toolbar,
toolbar_textbox_background_color, toolbar_textbox_resource_id,
toolbar_textbox_alpha, view_height, content_offset, false, false);
content_offset, false, false);
toolbar_layer_->UpdateProgressBar(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

float toolbar_impact_height = 0;
Expand Down
2 changes: 0 additions & 2 deletions chrome/browser/android/compositor/layer/tab_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ class TabLayer : public Layer {
float content_width,
float content_height,
float view_width,
float view_height,
bool show_toolbar,
int default_theme_color,
int toolbar_background_color,
Expand All @@ -95,7 +94,6 @@ class TabLayer : public Layer {
bool show_tab_title,
int toolbar_textbox_resource_id,
int toolbar_textbox_background_color,
float toolbar_textbox_alpha,
float toolbar_alpha,
float toolbar_y_offset,
float side_border_scale,
Expand Down
6 changes: 1 addition & 5 deletions chrome/browser/android/compositor/layer/toolbar_layer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ void ToolbarLayer::PushResource(int toolbar_resource_id,
bool anonymize,
int toolbar_textbox_background_color,
int url_bar_background_resource_id,
float url_bar_alpha,
float window_height,
float content_offset,
bool show_debug,
bool clip_shadow) {
Expand All @@ -57,8 +55,7 @@ void ToolbarLayer::PushResource(int toolbar_resource_id,
gfx::PointF(resource->toolbar_rect().origin()));
toolbar_background_layer_->SetBackgroundColor(toolbar_background_color);

bool url_bar_visible =
(resource->location_bar_content_rect().width() != 0) && url_bar_alpha > 0;
bool url_bar_visible = resource->location_bar_content_rect().width() != 0;
url_bar_background_layer_->SetHideLayerAndSubtree(!url_bar_visible);
if (url_bar_visible) {
ui::NinePatchResource* url_bar_background_resource;
Expand All @@ -79,7 +76,6 @@ void ToolbarLayer::PushResource(int toolbar_resource_id,
url_bar_background_resource->aperture());
url_bar_background_layer_->SetUIResourceId(
url_bar_background_resource->ui_resource()->id());
url_bar_background_layer_->SetOpacity(url_bar_alpha);
}

bitmap_layer_->SetUIResourceId(resource->ui_resource()->id());
Expand Down
2 changes: 0 additions & 2 deletions chrome/browser/android/compositor/layer/toolbar_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class ToolbarLayer : public Layer {
bool anonymize,
int toolbar_textbox_background_color,
int url_bar_background_resource_id,
float url_bar_alpha,
float window_height,
float y_offset,
bool show_debug,
bool clip_shadow);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ void TabListSceneLayer::PutTabLayer(
jfloat height,
jfloat content_width,
jfloat content_height,
jfloat visible_content_height,
jfloat shadow_x,
jfloat shadow_y,
jfloat shadow_width,
Expand Down Expand Up @@ -142,7 +141,6 @@ void TabListSceneLayer::PutTabLayer(
jboolean show_tab_title,
jint toolbar_textbox_resource_id,
jint toolbar_textbox_background_color,
jfloat toolbar_textbox_alpha,
jfloat toolbar_alpha,
jfloat content_offset,
jfloat side_border_scale,
Expand Down Expand Up @@ -184,12 +182,11 @@ void TabListSceneLayer::PutTabLayer(
alpha, border_alpha, border_inner_shadow_alpha, contour_alpha,
shadow_alpha, close_alpha, border_scale, saturation, brightness,
close_btn_width, close_btn_asset_size, static_to_view_blend,
content_width, content_height, content_width, visible_content_height,
show_toolbar, default_theme_color, toolbar_background_color,
close_button_color, anonymize_toolbar, show_tab_title,
toolbar_textbox_resource_id, toolbar_textbox_background_color,
toolbar_textbox_alpha, toolbar_alpha, content_offset, side_border_scale,
inset_border);
content_width, content_height, content_width, show_toolbar,
default_theme_color, toolbar_background_color, close_button_color,
anonymize_toolbar, show_tab_title, toolbar_textbox_resource_id,
toolbar_textbox_background_color, toolbar_alpha, content_offset,
side_border_scale, inset_border);
}

gfx::RectF self(own_tree_->position(), gfx::SizeF(own_tree_->bounds()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class TabListSceneLayer : public SceneLayer {
jfloat width,
jfloat height,
jfloat content_width,
jfloat content_height,
jfloat visible_content_height,
jfloat shadow_x,
jfloat shadow_y,
Expand Down Expand Up @@ -102,7 +101,6 @@ class TabListSceneLayer : public SceneLayer {
jboolean show_tab_title,
jint toolbar_textbox_resource_id,
jint toolbar_textbox_background_color,
jfloat toolbar_textbox_alpha,
jfloat toolbar_alpha,
jfloat toolbar_y_offset,
jfloat side_border_scale,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@ void ToolbarSceneLayer::UpdateToolbarLayer(
jint toolbar_resource_id,
jint toolbar_background_color,
jint url_bar_resource_id,
jfloat url_bar_alpha,
jint url_bar_color,
jfloat content_offset,
jfloat view_height,
bool visible,
bool show_shadow) {
// If the toolbar layer has not been created yet, create it.
if (!toolbar_layer_) {
Expand All @@ -51,13 +48,9 @@ void ToolbarSceneLayer::UpdateToolbarLayer(
layer_->AddChild(toolbar_layer_->layer());
}

toolbar_layer_->layer()->SetHideLayerAndSubtree(!visible);
if (visible) {
toolbar_layer_->PushResource(toolbar_resource_id, toolbar_background_color,
false, url_bar_color, url_bar_resource_id,
url_bar_alpha, view_height, content_offset,
false, !show_shadow);
}
toolbar_layer_->PushResource(toolbar_resource_id, toolbar_background_color,
false, url_bar_color, url_bar_resource_id,
content_offset, false, !show_shadow);
}

void ToolbarSceneLayer::UpdateProgressBar(JNIEnv* env,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@ class ToolbarSceneLayer : public SceneLayer {
jint toolbar_resource_id,
jint toolbar_background_color,
jint url_bar_resource_id,
jfloat url_bar_alpha,
jint url_bar_color,
jfloat y_offset,
jfloat view_height,
bool visible,
bool show_shadow);

// Update the progress bar.
Expand Down

0 comments on commit 389eefc

Please sign in to comment.