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

Toolbar: Do not use ChromeActivity in ActionBar

ToolbarManager injects the necessary objects through ViewShifting-
ActionBarDelegate to remove the dependendency on ChromeActivity
in the class.

Bug: 1127732
Change-Id: Ief8e4a5f12d2488389e02c4fbe5af0e353f3d8de
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2430566Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#819212}
parent 83e87751
...@@ -254,7 +254,8 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve ...@@ -254,7 +254,8 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve
mActivity = activity; mActivity = activity;
mBrowserControlsSizer = controlsSizer; mBrowserControlsSizer = controlsSizer;
mFullscreenManager = fullscreenManager; mFullscreenManager = fullscreenManager;
mActionBarDelegate = new ViewShiftingActionBarDelegate(activity, controlContainer); mActionBarDelegate = new ViewShiftingActionBarDelegate(activity.getSupportActionBar(),
controlContainer, activity.findViewById(R.id.action_bar_black_background));
mShareDelegateSupplier = shareDelegateSupplier; mShareDelegateSupplier = shareDelegateSupplier;
mCanAnimateNativeBrowserControls = canAnimateNativeBrowserControls; mCanAnimateNativeBrowserControls = canAnimateNativeBrowserControls;
mScrimCoordinator = scrimCoordinator; mScrimCoordinator = scrimCoordinator;
......
...@@ -9,26 +9,29 @@ import android.view.ViewGroup; ...@@ -9,26 +9,29 @@ import android.view.ViewGroup;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.app.ChromeActivity;
/** /**
* An {@link ActionModeController.ActionBarDelegate} that shifts a view as the action bar appears. * An {@link ActionModeController.ActionBarDelegate} that shifts a view as the action bar appears.
*/ */
public class ViewShiftingActionBarDelegate implements ActionModeController.ActionBarDelegate { public class ViewShiftingActionBarDelegate implements ActionModeController.ActionBarDelegate {
/** The action bar which this delegate works for. */
private final ActionBar mActionBar;
/** The view that will be shifted as the action bar appears. */ /** The view that will be shifted as the action bar appears. */
private final View mShiftingView; private final View mShiftingView;
/** A handle to a {@link ChromeActivity}. */ /** Action bar background view. */
private final ChromeActivity mActivity; private final View mBackgroundView;
/** /**
* @param activity A handle to the {@link ChromeActivity}. * @param actionBar The {@link ActionBar} in use.
* @param shiftingView The view that will shift when the action bar appears. * @param shiftingView The view that will shift when the action bar appears.
* @param backgroundView Background view for shadow effect.
*/ */
public ViewShiftingActionBarDelegate(ChromeActivity activity, View shiftingView) { public ViewShiftingActionBarDelegate(
mActivity = activity; ActionBar actionBar, View shiftingView, View backgroundView) {
mActionBar = actionBar;
mShiftingView = shiftingView; mShiftingView = shiftingView;
mBackgroundView = backgroundView;
} }
@Override @Override
...@@ -48,13 +51,13 @@ public class ViewShiftingActionBarDelegate implements ActionModeController.Actio ...@@ -48,13 +51,13 @@ public class ViewShiftingActionBarDelegate implements ActionModeController.Actio
@Override @Override
public ActionBar getSupportActionBar() { public ActionBar getSupportActionBar() {
return mActivity.getSupportActionBar(); return mActionBar;
} }
@Override @Override
public void setActionBarBackgroundVisibility(boolean visible) { public void setActionBarBackgroundVisibility(boolean visible) {
int visibility = visible ? View.VISIBLE : View.GONE; int visibility = visible ? View.VISIBLE : View.GONE;
mActivity.findViewById(R.id.action_bar_black_background).setVisibility(visibility); mBackgroundView.setVisibility(visibility);
// TODO(tedchoc): Add support for changing the color based on the brand color. // TODO(tedchoc): Add support for changing the color based on the brand color.
} }
} }
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