Commit f35263f6 authored by Patrick Noland's avatar Patrick Noland Committed by Commit Bot

[ToolbarMVC] Remove ToolbarLayout#getMenuButton

As a consequence of removing getMenuButton, this CL also reduces direct usage of MenuButton in ToolbarPhone/ToolbarTablet, although a few exceptions (getNextFocusForward, animations) remain.

Bug: 1086676
Change-Id: Ic1f13733b48a06b34d9ec2484ca2971f79f2f19f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2412702Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Commit-Queue: Patrick Noland <pnoland@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807638}
parent 9d10a275
...@@ -761,7 +761,7 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve ...@@ -761,7 +761,7 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve
@Override @Override
public @Nullable View getMenuButtonView() { public @Nullable View getMenuButtonView() {
return mToolbar.getMenuButton(); return mMenuButtonCoordinator.getMenuButton().getImageButton();
} }
/** /**
......
...@@ -20,11 +20,9 @@ import android.view.View; ...@@ -20,11 +20,9 @@ import android.view.View;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView; import android.widget.ImageView;
import androidx.annotation.DrawableRes; import androidx.annotation.DrawableRes;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.core.view.ViewCompat; import androidx.core.view.ViewCompat;
import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.ThemeColorProvider; import org.chromium.chrome.browser.ThemeColorProvider;
...@@ -83,6 +81,12 @@ public class MenuButton extends FrameLayout implements TintObserver { ...@@ -83,6 +81,12 @@ public class MenuButton extends FrameLayout implements TintObserver {
return mMenuImageButton; return mMenuImageButton;
} }
@Override
public void setOnKeyListener(OnKeyListener onKeyListener) {
if (mMenuImageButton == null) return;
mMenuImageButton.setOnKeyListener(onKeyListener);
}
/** /**
* Sets the update badge to visible. * Sets the update badge to visible.
* *
......
...@@ -6,11 +6,10 @@ package org.chromium.chrome.browser.toolbar.menu_button; ...@@ -6,11 +6,10 @@ package org.chromium.chrome.browser.toolbar.menu_button;
import android.app.Activity; import android.app.Activity;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.view.View.OnKeyListener;
import androidx.annotation.IdRes; import androidx.annotation.IdRes;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import org.chromium.base.ApiCompatibilityUtils; import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.metrics.RecordUserAction; import org.chromium.base.metrics.RecordUserAction;
...@@ -133,6 +132,22 @@ public class MenuButtonCoordinator implements AppMenuObserver { ...@@ -133,6 +132,22 @@ public class MenuButtonCoordinator implements AppMenuObserver {
mMenuButton.setThemeColorProvider(mThemeColorProvider); mMenuButton.setThemeColorProvider(mThemeColorProvider);
} }
/**
* Handle the key press event on the menu button.
* @return Whether the app menu was shown as a result of this action.
*/
public boolean onEnterKeyPress() {
if (mAppMenuButtonHelper == null || mMenuButton == null) return false;
return mAppMenuButtonHelper.onEnterKeyPress(mMenuButton.getImageButton());
}
/**
* @return Whether the menu button is present and visible.
*/
public boolean isShown() {
return mMenuButton != null && mMenuButton.isShown();
}
/** /**
* Get the underlying MenuButton view. Present for legacy reasons only; don't add new usages. * Get the underlying MenuButton view. Present for legacy reasons only; don't add new usages.
*/ */
...@@ -161,6 +176,15 @@ public class MenuButtonCoordinator implements AppMenuObserver { ...@@ -161,6 +176,15 @@ public class MenuButtonCoordinator implements AppMenuObserver {
mMenuButton.setClickable(isClickable); mMenuButton.setClickable(isClickable);
} }
/**
* Sets the on key listener for the underlying menu button.
* @param onKeyListener Listener for key events.
*/
public void setOnKeyListener(OnKeyListener onKeyListener) {
if (mMenuButton == null) return;
mMenuButton.setOnKeyListener(onKeyListener);
}
public void destroy() { public void destroy() {
if (mAppMenuButtonHelper != null) { if (mAppMenuButtonHelper != null) {
mAppMenuHandler.removeObserver(this); mAppMenuHandler.removeObserver(this);
......
...@@ -16,14 +16,11 @@ import android.view.MotionEvent; ...@@ -16,14 +16,11 @@ import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import androidx.annotation.CallSuper; import androidx.annotation.CallSuper;
import androidx.annotation.ColorRes; import androidx.annotation.ColorRes;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import org.chromium.base.ObserverList; import org.chromium.base.ObserverList;
import org.chromium.base.TraceEvent; import org.chromium.base.TraceEvent;
import org.chromium.chrome.R; import org.chromium.chrome.R;
...@@ -359,14 +356,6 @@ public abstract class ToolbarLayout ...@@ -359,14 +356,6 @@ public abstract class ToolbarLayout
mMenuButtonCoordinator = menuButtonCoordinator; mMenuButtonCoordinator = menuButtonCoordinator;
} }
/**
* @return The {@link ImageButton} containing the menu button.
*/
ImageButton getMenuButton() {
if (mMenuButtonCoordinator.getMenuButton() == null) return null;
return mMenuButtonCoordinator.getMenuButton().getImageButton();
}
/** /**
* @return The {@link ProgressBar} this layout uses. * @return The {@link ProgressBar} this layout uses.
*/ */
......
...@@ -436,9 +436,8 @@ public class ToolbarPhone extends ToolbarLayout implements Invalidator.Client, O ...@@ -436,9 +436,8 @@ public class ToolbarPhone extends ToolbarLayout implements Invalidator.Client, O
mToggleTabStackButton.setOnKeyListener(new KeyboardNavigationListener() { mToggleTabStackButton.setOnKeyListener(new KeyboardNavigationListener() {
@Override @Override
public View getNextFocusForward() { public View getNextFocusForward() {
final ImageButton menuButton = getMenuButton(); if (getMenuButtonCoordinator().isShown()) {
if (menuButton != null && menuButton.isShown()) { return getMenuButtonCoordinator().getMenuButton();
return menuButton;
} else { } else {
return getCurrentTabView(); return getCurrentTabView();
} }
...@@ -466,24 +465,23 @@ public class ToolbarPhone extends ToolbarLayout implements Invalidator.Client, O ...@@ -466,24 +465,23 @@ public class ToolbarPhone extends ToolbarLayout implements Invalidator.Client, O
mHomeButton.setOnClickListener(this); mHomeButton.setOnClickListener(this);
} }
if (getMenuButton() != null) { getMenuButtonCoordinator().setOnKeyListener(new KeyboardNavigationListener() {
getMenuButton().setOnKeyListener(new KeyboardNavigationListener() { @Override
@Override public View getNextFocusForward() {
public View getNextFocusForward() { return getCurrentTabView();
return getCurrentTabView(); }
}
@Override @Override
public View getNextFocusBackward() { public View getNextFocusBackward() {
return mToggleTabStackButton; return mToggleTabStackButton;
} }
@Override
protected boolean handleEnterKeyPress() {
return getMenuButtonCoordinator().onEnterKeyPress();
}
});
@Override
protected boolean handleEnterKeyPress() {
return getMenuButtonHelper().onEnterKeyPress(getMenuButton());
}
});
}
onHomeButtonUpdate(HomepageManager.isHomepageEnabled()); onHomeButtonUpdate(HomepageManager.isHomepageEnabled());
updateVisualsForLocationBarState(); updateVisualsForLocationBarState();
...@@ -1880,9 +1878,7 @@ public class ToolbarPhone extends ToolbarLayout implements Invalidator.Client, O ...@@ -1880,9 +1878,7 @@ public class ToolbarPhone extends ToolbarLayout implements Invalidator.Client, O
mToggleTabStackButton.setVisibility(isGone ? GONE : VISIBLE); mToggleTabStackButton.setVisibility(isGone ? GONE : VISIBLE);
} }
if (getMenuButton() != null) { getMenuButtonCoordinator().setVisibility(inTabSwitcherMode ? GONE : VISIBLE);
getMenuButton().setVisibility(inTabSwitcherMode ? GONE : VISIBLE);
}
triggerUrlFocusAnimation(inTabSwitcherMode && !urlHasFocus()); triggerUrlFocusAnimation(inTabSwitcherMode && !urlHasFocus());
...@@ -2600,9 +2596,7 @@ public class ToolbarPhone extends ToolbarLayout implements Invalidator.Client, O ...@@ -2600,9 +2596,7 @@ public class ToolbarPhone extends ToolbarLayout implements Invalidator.Client, O
* buttons besides the optional button. * buttons besides the optional button.
*/ */
private boolean isMenuButtonPresent() { private boolean isMenuButtonPresent() {
final ImageButton menuButton = getMenuButton(); return getMenuButtonCoordinator().isShown();
if (menuButton == null) return false;
return menuButton.isShown();
} }
private void requestLayoutHostUpdateForOptionalButton() { private void requestLayoutHostUpdateForOptionalButton() {
......
...@@ -248,7 +248,7 @@ public class ToolbarTablet extends ToolbarLayout ...@@ -248,7 +248,7 @@ public class ToolbarTablet extends ToolbarLayout
mBookmarkButton.setOnClickListener(this); mBookmarkButton.setOnClickListener(this);
mBookmarkButton.setOnLongClickListener(this); mBookmarkButton.setOnLongClickListener(this);
getMenuButton().setOnKeyListener(new KeyboardNavigationListener() { getMenuButtonCoordinator().setOnKeyListener(new KeyboardNavigationListener() {
@Override @Override
public View getNextFocusForward() { public View getNextFocusForward() {
return getCurrentTabView(); return getCurrentTabView();
...@@ -261,7 +261,7 @@ public class ToolbarTablet extends ToolbarLayout ...@@ -261,7 +261,7 @@ public class ToolbarTablet extends ToolbarLayout
@Override @Override
protected boolean handleEnterKeyPress() { protected boolean handleEnterKeyPress() {
return getMenuButtonHelper().onEnterKeyPress(getMenuButton()); return getMenuButtonCoordinator().onEnterKeyPress();
} }
}); });
if (HomepageManager.isHomepageEnabled()) { if (HomepageManager.isHomepageEnabled()) {
......
...@@ -10,7 +10,6 @@ import android.graphics.drawable.Drawable; ...@@ -10,7 +10,6 @@ import android.graphics.drawable.Drawable;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener; import android.view.View.OnLongClickListener;
import android.widget.ImageButton;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
...@@ -266,13 +265,6 @@ public class TopToolbarCoordinator implements Toolbar { ...@@ -266,13 +265,6 @@ public class TopToolbarCoordinator implements Toolbar {
return mMenuButtonCoordinator.getMenuButton(); return mMenuButtonCoordinator.getMenuButton();
} }
/**
* @return The {@link ImageButton} containing the menu button.
*/
public @Nullable ImageButton getMenuButton() {
return mToolbarLayout.getMenuButton();
}
@Override @Override
public ToolbarProgressBar getProgressBar() { public ToolbarProgressBar getProgressBar() {
return mToolbarLayout.getProgressBar(); return mToolbarLayout.getProgressBar();
......
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