[cr147][Android] Changes for custom tab toolbar refactor
Chromium changes: https://chromium.googlesource.com/chromium/src/+/649dad5e5932bddd9a1d9ef3a9f8b0690df8d630 commit 649dad5e5932bddd9a1d9ef3a9f8b0690df8d630 Author: Sinan Sahin <sinansahin@google.com> Date: Tue Feb 10 19:21:23 2026 -0800 [CCT][ToolbarRefactor] Enable by default Bug: 402213312 Change-Id: I7ab5b2d7587b6354df74b63e3406940b4133bb91 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7564736 Reviewed-by: Jinsuk Kim <jinsukkim@chromium.org> Commit-Queue: Sinan Sahin <sinansahin@google.com> Cr-Commit-Position: refs/heads/main@{#1582969}
This commit is contained in:
@@ -191,6 +191,13 @@ public class FullScreenCustomTabActivity extends CustomTabActivity {
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getToolbarLayoutHeightResId() {
|
||||
// Return 0dp so ToolbarPositionController does not push web content down by the
|
||||
// toolbar height. The actual toolbar view is hidden in performPostInflationStartup().
|
||||
return R.dimen.full_screen_custom_tabs_control_container_height;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RootUiCoordinator createRootUiCoordinator() {
|
||||
mBaseCustomTabRootUiCoordinator =
|
||||
|
||||
@@ -379,7 +379,11 @@ public abstract class BraveToolbarLayoutImpl extends ToolbarLayout
|
||||
}
|
||||
}
|
||||
|
||||
if (BraveReflectionUtil.equalTypes(this.getClass(), CustomTabToolbar.class)) {
|
||||
if (BraveReflectionUtil.equalTypes(this.getClass(), CustomTabToolbar.class)
|
||||
&& !ChromeFeatureList.sCctToolbarRefactor.isEnabled()) {
|
||||
// In the old (non-refactored) CCT toolbar, adjust the action_buttons container margin
|
||||
// to account for the shields button. In refactored mode this is handled dynamically in
|
||||
// maybeRepositionCctShieldsButton() via onLayout.
|
||||
LinearLayout customActionButtons = findViewById(R.id.action_buttons);
|
||||
assert customActionButtons != null : "Something has changed in the upstream!";
|
||||
if (customActionButtons != null && mBraveShieldsButton != null) {
|
||||
@@ -387,8 +391,9 @@ public abstract class BraveToolbarLayoutImpl extends ToolbarLayout
|
||||
(ViewGroup.MarginLayoutParams) mBraveShieldsButton.getLayoutParams();
|
||||
ViewGroup.MarginLayoutParams actionButtonsLayout =
|
||||
(ViewGroup.MarginLayoutParams) customActionButtons.getLayoutParams();
|
||||
actionButtonsLayout.setMarginEnd(actionButtonsLayout.getMarginEnd()
|
||||
+ braveShieldsButtonLayout.getMarginEnd());
|
||||
actionButtonsLayout.setMarginEnd(
|
||||
actionButtonsLayout.getMarginEnd()
|
||||
+ braveShieldsButtonLayout.getMarginEnd());
|
||||
customActionButtons.setLayoutParams(actionButtonsLayout);
|
||||
}
|
||||
}
|
||||
@@ -1741,6 +1746,84 @@ public abstract class BraveToolbarLayoutImpl extends ToolbarLayout
|
||||
maybeHideRewardsLayout(MeasureSpec.getSize(widthMeasureSpec));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
||||
super.onLayout(changed, left, top, right, bottom);
|
||||
maybeRepositionCctShieldsButton();
|
||||
}
|
||||
|
||||
private void maybeRepositionCctShieldsButton() {
|
||||
if (!BraveReflectionUtil.equalTypes(this.getClass(), CustomTabToolbar.class)) return;
|
||||
if (!ChromeFeatureList.sCctToolbarRefactor.isEnabled()) return;
|
||||
if (mBraveShieldsButton == null) return;
|
||||
|
||||
int toolbarWidth = getWidth();
|
||||
if (toolbarWidth <= 0) return;
|
||||
|
||||
// After super.onLayout() children have their actual pixel positions. We anchor the shields
|
||||
// button immediately to the left of the menu button (matching the expected visual order:
|
||||
// [...location bar...][custom buttons][shields][menu]).
|
||||
View menuButton = findViewById(R.id.menu_button_wrapper);
|
||||
if (menuButton == null || menuButton.getVisibility() != View.VISIBLE) return;
|
||||
|
||||
int menuLeft = menuButton.getLeft();
|
||||
if (menuLeft <= 0) return;
|
||||
|
||||
int buttonWidth = getResources().getDimensionPixelSize(R.dimen.toolbar_button_width);
|
||||
|
||||
// Shields sits immediately to the left of menu.
|
||||
int targetShieldsMarginEnd = toolbarWidth - menuLeft;
|
||||
int shieldsLeftEdge = menuLeft - buttonWidth;
|
||||
if (shieldsLeftEdge <= 0) return;
|
||||
|
||||
// Any custom action button whose right edge intrudes into shields' space must be shifted
|
||||
// one buttonWidth further from the toolbar end. Using the laid-out right-edge position
|
||||
// as the guard means we never double-shift: a button that was already pushed left will
|
||||
// have right <= shieldsLeftEdge and will not be shifted again.
|
||||
int leftmostLeft = shieldsLeftEdge; // will track the leftmost end-aligned element
|
||||
View actionButtonsView = findViewById(R.id.action_buttons);
|
||||
if (actionButtonsView instanceof ViewGroup) {
|
||||
int containerLeft = actionButtonsView.getLeft(); // 0 for match_parent
|
||||
ViewGroup actionButtons = (ViewGroup) actionButtonsView;
|
||||
for (int i = 0; i < actionButtons.getChildCount(); i++) {
|
||||
View child = actionButtons.getChildAt(i);
|
||||
if (child.getVisibility() != View.VISIBLE) continue;
|
||||
int childLeft = containerLeft + child.getLeft();
|
||||
int childRight = childLeft + child.getWidth();
|
||||
if (childRight > shieldsLeftEdge) {
|
||||
// Button overlaps shields area — shift it one buttonWidth further out.
|
||||
ViewGroup.MarginLayoutParams lp =
|
||||
(ViewGroup.MarginLayoutParams) child.getLayoutParams();
|
||||
lp.setMarginEnd(lp.getMarginEnd() + buttonWidth);
|
||||
child.setLayoutParams(lp);
|
||||
leftmostLeft = Math.min(leftmostLeft, childLeft - buttonWidth);
|
||||
} else {
|
||||
leftmostLeft = Math.min(leftmostLeft, childLeft);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Location bar must leave room for shields + all custom buttons to its right.
|
||||
int targetLocationBarMarginEnd = toolbarWidth - leftmostLeft;
|
||||
|
||||
ViewGroup.MarginLayoutParams shieldsLp =
|
||||
(ViewGroup.MarginLayoutParams) mBraveShieldsButton.getLayoutParams();
|
||||
if (shieldsLp.getMarginEnd() != targetShieldsMarginEnd) {
|
||||
shieldsLp.setMarginEnd(targetShieldsMarginEnd);
|
||||
mBraveShieldsButton.setLayoutParams(shieldsLp);
|
||||
}
|
||||
|
||||
View locationBar = findViewById(R.id.location_bar_frame_layout);
|
||||
if (locationBar != null) {
|
||||
ViewGroup.MarginLayoutParams locationBarLp =
|
||||
(ViewGroup.MarginLayoutParams) locationBar.getLayoutParams();
|
||||
if (locationBarLp.getMarginEnd() != targetLocationBarMarginEnd) {
|
||||
locationBarLp.setMarginEnd(targetLocationBarMarginEnd);
|
||||
locationBar.setLayoutParams(locationBarLp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hides the rewards layout if the toolbar width is less than the minimum tablet width and the
|
||||
* rewards icon should be shown. Uses the same threshold as the existing toolbar button
|
||||
|
||||
Reference in New Issue
Block a user