Commit 04d29c8b authored by Theresa's avatar Theresa Committed by Commit Bot

Create TopToolbarCoordinator and sever ToolManager/ToolbarLayout

Creates a new TopToolbarCoordinator to sit between ToolbarManager and
ToolbarLayout. TopToolbarCoordinator implements the Toolbar interface
and acts as the public message channel to other UI components.

The API surface in TopToolbarCoordinator is quite large currently.
Future CLs will attempt to slim the API surface.

BUG=897294

Change-Id: Ic16df5946f3373ecbea4a1f3e908c05086b2dbc1
Reviewed-on: https://chromium-review.googlesource.com/c/1336081
Commit-Queue: Theresa <twellington@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608488}
parent 90cad79a
......@@ -848,27 +848,11 @@ public class ChromeTabbedActivity
mLocaleManager.showSearchEnginePromoIfNeeded(ChromeTabbedActivity.this, null);
};
OnClickListener bookmarkClickHandler = v -> addOrEditBookmark(getActivityTab());
OnClickListener incognitoClickHandler = v -> {
Layout activeLayout = mLayoutManager.getActiveLayout();
if (!activeLayout.shouldAllowIncognitoSwitching()) return;
if (activeLayout instanceof StackLayout) {
// Without this call, tapping the incognito toggle immediately after closing a
// non-incognito tab will not work properly, because the tab closure will bring
// us back to normal mode. We need to handle the tab closure here before running
// the animation.
((StackLayout) activeLayout).commitOutstandingModelState(LayoutManager.time());
}
if (mTabModelSelectorImpl != null) {
mTabModelSelectorImpl.selectModel(!mTabModelSelectorImpl.isIncognitoSelected());
}
};
getToolbarManager().initializeWithNative(mTabModelSelectorImpl,
getFullscreenManager().getBrowserVisibilityDelegate(), getFindToolbarManager(),
mLayoutManager, mLayoutManager, tabSwitcherClickHandler, newTabClickHandler,
bookmarkClickHandler, null, incognitoClickHandler);
bookmarkClickHandler, null);
mLayoutManager.setToolbarManager(getToolbarManager());
......
......@@ -594,7 +594,7 @@ public class CustomTabActivity extends ChromeActivity<CustomTabActivityComponent
recordClientConnectionStatus();
finishAndClose(false);
}
}, null);
});
mBrowserSessionContentHandler = new BrowserSessionContentHandler() {
@Override
......@@ -1485,7 +1485,7 @@ public class CustomTabActivity extends ChromeActivity<CustomTabActivityComponent
// The media viewer has no default menu items, so if there are also no custom items, we
// should hide the menu button altogether.
if (mIntentDataProvider.getMenuTitles().isEmpty()) {
getToolbarManager().getToolbarLayout().disableMenuButton();
getToolbarManager().getToolbar().disableMenuButton();
}
}
}
......
......@@ -66,7 +66,6 @@ import org.chromium.chrome.browser.omaha.UpdateMenuItemHelper;
import org.chromium.chrome.browser.omnibox.LocationBar;
import org.chromium.chrome.browser.omnibox.UrlFocusChangeListener;
import org.chromium.chrome.browser.partnercustomizations.HomepageManager;
import org.chromium.chrome.browser.partnercustomizations.HomepageManager.HomepageStateListener;
import org.chromium.chrome.browser.preferences.PrefServiceBridge;
import org.chromium.chrome.browser.previews.PreviewsAndroidBridge;
import org.chromium.chrome.browser.previews.PreviewsUma;
......@@ -94,6 +93,7 @@ import org.chromium.chrome.browser.toolbar.top.Toolbar;
import org.chromium.chrome.browser.toolbar.top.ToolbarActionModeCallback;
import org.chromium.chrome.browser.toolbar.top.ToolbarControlContainer;
import org.chromium.chrome.browser.toolbar.top.ToolbarLayout;
import org.chromium.chrome.browser.toolbar.top.TopToolbarCoordinator;
import org.chromium.chrome.browser.toolbar.top.ViewShiftingActionBarDelegate;
import org.chromium.chrome.browser.translate.TranslateBridge;
import org.chromium.chrome.browser.util.ColorUtils;
......@@ -174,8 +174,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
private final AsyncViewProvider<ToolbarLayout> mToolbarProvider;
private final IncognitoStateProvider mIncognitoStateProvider;
private final TabCountProvider mTabCountProvider;
@Nullable
private ToolbarLayout mToolbar;
private TopToolbarCoordinator mToolbar;
private final ToolbarControlContainer mControlContainer;
private BottomToolbarCoordinator mBottomToolbarCoordinator;
......@@ -223,15 +222,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
private TextBubble mTextBubble;
private HomepageStateListener mHomepageStateListener = new HomepageStateListener() {
@Override
public void onHomepageStateUpdated() {
mToolbarProvider.whenLoaded(
(toolbar) -> toolbar.onHomeButtonUpdate(HomepageManager.isHomepageEnabled()
|| FeatureUtilities.isNewTabPageButtonEnabled()));
}
};
private boolean mToolbarInflationComplete;
private boolean mInitializedWithNative;
private boolean mShouldUpdateToolbarPrimaryColor = true;
......@@ -312,8 +303,9 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
mTabCountProvider = new TabCountProvider();
mToolbarProvider = AsyncViewProvider.of(controlContainer, R.id.toolbar_stub, R.id.toolbar);
mToolbar = new TopToolbarCoordinator(controlContainer, mToolbarProvider);
mToolbarProvider.whenLoaded((toolbar)
-> onToolbarInflationComplete(toolbar, menuHandler,
-> onToolbarInflationComplete(menuHandler,
appMenuPropertiesDelegate, invalidator));
}
......@@ -331,9 +323,10 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
}
}
private void onToolbarInflationComplete(ToolbarLayout toolbar, final AppMenuHandler menuHandler,
private void onToolbarInflationComplete(final AppMenuHandler menuHandler,
AppMenuPropertiesDelegate appMenuPropertiesDelegate, Invalidator invalidator) {
mToolbar = toolbar;
mToolbarInflationComplete = true;
mActionModeController = new ActionModeController(mActivity, mActionBarDelegate);
mActionModeController.setCustomSelectionActionModeCallback(mToolbarActionModeCallback);
......@@ -348,8 +341,8 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
};
setMenuDelegatePhone(menuDelegate);
toolbar.setPaintInvalidator(invalidator);
mActionModeController.setTabStripHeight(toolbar.getTabStripHeight());
mToolbar.setPaintInvalidator(invalidator);
mActionModeController.setTabStripHeight(mToolbar.getTabStripHeight());
mLocationBar = mToolbar.getLocationBar();
mLocationBar.setToolbarDataProvider(mLocationBarModel);
mLocationBar.addUrlFocusChangeListener(this);
......@@ -360,12 +353,10 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
mLocationBar.addUrlFocusChangeListener(mLocationBarFocusObserver);
setMenuHandler(menuHandler);
toolbar.initialize(mLocationBarModel, this, mAppMenuButtonHelper);
mToolbar.initialize(mLocationBarModel, this, mAppMenuButtonHelper);
mAppMenuPropertiesDelegate = appMenuPropertiesDelegate;
HomepageManager.getInstance().addListener(mHomepageStateListener);
mOmniboxStartupMetrics = new OmniboxStartupMetrics(mActivity);
mTabModelSelectorObserver = new EmptyTabModelSelectorObserver() {
......@@ -755,7 +746,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
* @return Whether the UrlBar currently has focus.
*/
public boolean isUrlBarFocused() {
return getToolbarLayout().getLocationBar().isUrlBarFocused();
return mLocationBar == null ? false : mLocationBar.isUrlBarFocused();
}
/**
......@@ -842,11 +833,11 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
@StringRes int stringId, @StringRes int accessibilityStringId,
Integer highlightItemId) {
ViewRectProvider rectProvider = new ViewRectProvider(getMenuButton());
int yInsetPx = mToolbar.getContext().getResources().getDimensionPixelOffset(
int yInsetPx = mActivity.getResources().getDimensionPixelOffset(
R.dimen.text_bubble_menu_anchor_y_inset);
rectProvider.setInsetPx(0, 0, 0, yInsetPx);
mTextBubble = new TextBubble(mToolbar.getContext(), getMenuButton(), stringId,
accessibilityStringId, rectProvider);
mTextBubble = new TextBubble(
mActivity, getMenuButton(), stringId, accessibilityStringId, rectProvider);
mTextBubble.setDismissOnTouchInteraction(true);
mTextBubble.addOnDismissListener(() -> {
mHandler.postDelayed(() -> {
......@@ -864,7 +855,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
* @param featureName The associated feature name.
*/
public void showDownloadPageTextBubble(final Tab tab, String featureName) {
if (tab == null || mToolbar == null) return;
if (tab == null || !mToolbarInflationComplete) return;
// TODO(shaktisahu): Find out if the download menu button is enabled (crbug/712438).
ChromeActivity activity = tab.getActivity();
......@@ -897,7 +888,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
* @param featureName The associated feature name.
*/
public void showTranslateMenuButtonTextBubble(final Tab tab, String featureName) {
if (tab == null || mToolbar == null) return;
if (tab == null || !mToolbarInflationComplete) return;
ChromeActivity activity = tab.getActivity();
if (!mAppMenuPropertiesDelegate.isTranslateMenuItemVisible(tab)) return;
......@@ -929,21 +920,15 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
FindToolbarManager findToolbarManager, OverviewModeBehavior overviewModeBehavior,
LayoutManager layoutManager, OnClickListener tabSwitcherClickHandler,
OnClickListener newTabClickHandler, OnClickListener bookmarkClickHandler,
OnClickListener customTabsBackClickHandler, OnClickListener incognitoClickHandler) {
OnClickListener customTabsBackClickHandler) {
assert !mInitializedWithNative;
mToolbarProvider.whenLoaded((toolbar) -> {
mTabModelSelector = tabModelSelector;
toolbar.setTabModelSelector(mTabModelSelector);
toolbar.getLocationBar().updateVisualsForState();
toolbar.getLocationBar().setUrlToPageUrl();
toolbar.setBrowserControlsVisibilityDelegate(controlsVisibilityDelegate);
toolbar.setOnTabSwitcherClickHandler(tabSwitcherClickHandler);
toolbar.setOnNewTabClickHandler(newTabClickHandler);
toolbar.setBookmarkClickHandler(bookmarkClickHandler);
toolbar.setCustomTabCloseClickHandler(customTabsBackClickHandler);
toolbar.setIncognitoClickHandler(incognitoClickHandler);
toolbar.setLayoutUpdateHost(layoutManager);
mToolbar.initializeWithNative(tabModelSelector, controlsVisibilityDelegate,
layoutManager, tabSwitcherClickHandler, newTabClickHandler,
bookmarkClickHandler, customTabsBackClickHandler);
toolbar.addOnAttachStateChangeListener(new OnAttachStateChangeListener() {
@Override
......@@ -1008,7 +993,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
* TODO(amaralp): Only the top or bottom menu should be visible.
*/
public void showAppMenuUpdateBadge() {
mToolbarProvider.whenLoaded((toolbar) -> toolbar.showAppMenuUpdateBadge());
mToolbar.showAppMenuUpdateBadge();
if (mBottomToolbarCoordinator != null) {
mBottomToolbarCoordinator.showAppMenuUpdateBadge();
}
......@@ -1019,7 +1004,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
* TODO(amaralp): Only the top or bottom menu should be visible.
*/
public void removeAppMenuUpdateBadge(boolean animate) {
mToolbarProvider.whenLoaded((toolbar) -> toolbar.removeAppMenuUpdateBadge(animate));
mToolbar.removeAppMenuUpdateBadge(animate);
if (mBottomToolbarCoordinator != null) {
mBottomToolbarCoordinator.removeAppMenuUpdateBadge();
}
......@@ -1034,7 +1019,6 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
&& mBottomToolbarCoordinator.isShowingAppMenuUpdateBadge()) {
return true;
}
if (mToolbar == null) return false;
return mToolbar.isShowingAppMenuUpdateBadge();
}
......@@ -1046,24 +1030,20 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
*/
public void enableExperimentalButton(OnClickListener onClickListener,
@DrawableRes int drawableResId, @StringRes int contentDescriptionResId) {
mToolbarProvider.whenLoaded((toolbar) -> {
toolbar.enableExperimentalButton(
onClickListener, drawableResId, contentDescriptionResId);
});
mToolbar.enableExperimentalButton(onClickListener, drawableResId, contentDescriptionResId);
}
/**
* Disable the experimental toolbar button.
*/
public void disableExperimentalButton() {
mToolbarProvider.whenLoaded((t) -> t.disableExperimentalButton());
mToolbar.disableExperimentalButton();
}
/**
* @return The experimental toolbar button if it exists.
*/
public @Nullable View getExperimentalButtonView() {
if (mToolbar == null) return null;
return mToolbar.getExperimentalButtonView();
}
......@@ -1074,11 +1054,6 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
return mBookmarkBridge;
}
/** Return the location bar model for testing purposes. */
public LocationBarModel getLocationBarModelForTesting() {
return mLocationBarModel;
}
/**
* @return The toolbar interface that this manager handles.
*/
......@@ -1087,14 +1062,6 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
return mToolbar;
}
/**
* @return The {@link ToolbarLayout} that constitutes the toolbar.
*/
@VisibleForTesting
public ToolbarLayout getToolbarLayout() {
return mToolbar;
}
/**
* @return The callback for toolbar action mode controller.
*/
......@@ -1112,12 +1079,11 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
/**
* @return The view containing the pop up menu button.
*/
public View getMenuButton() {
public @Nullable View getMenuButton() {
if (mBottomToolbarCoordinator != null) {
return mBottomToolbarCoordinator.getMenuButtonWrapper().getImageButton();
}
if (mToolbar != null) return mToolbar.getMenuButton();
return null;
return mToolbar.getMenuButton();
}
/**
......@@ -1127,8 +1093,8 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
* @return The view containing the security icon.
*/
public View getSecurityIconView() {
if (mToolbar == null || mToolbar.getLocationBar() == null) return null;
return mToolbar.getLocationBar().getSecurityIconView();
if (mLocationBar == null) return null;
return mLocationBar.getSecurityIconView();
}
/**
......@@ -1140,8 +1106,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
*/
public void addCustomActionButton(
Drawable drawable, String description, OnClickListener listener) {
mToolbarProvider.whenLoaded(
(t) -> t.addCustomActionButton(drawable, description, listener));
mToolbar.addCustomActionButton(drawable, description, listener);
}
/**
......@@ -1153,8 +1118,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
* @see #addCustomActionButton
*/
public void updateCustomActionButton(int index, Drawable drawable, String description) {
mToolbarProvider.whenLoaded(
(t) -> t.updateCustomActionButton(index, drawable, description));
mToolbar.updateCustomActionButton(index, drawable, description);
}
/**
......@@ -1162,7 +1126,6 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
*/
public void destroy() {
if (mInitializedWithNative) {
HomepageManager.getInstance().removeListener(mHomepageStateListener);
mFindToolbarManager.removeObserver(mFindToolbarObserver);
}
if (mTabModelSelector != null) {
......@@ -1200,12 +1163,10 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
mOmniboxStartupMetrics = null;
}
if (mToolbarProvider != null) {
mToolbarProvider.destroy((toolbar) -> {
toolbar.getLocationBar().removeUrlFocusChangeListener(this);
toolbar.destroy();
});
if (mLocationBar != null) {
mLocationBar.removeUrlFocusChangeListener(this);
}
mToolbar.destroy();
if (mTabObserver != null) {
Tab currentTab = mLocationBarModel.getTab();
......@@ -1237,7 +1198,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
* @param enabled Whether accessibility is enabled.
*/
public void onAccessibilityStatusChanged(boolean enabled) {
mToolbarProvider.whenLoaded((toolbar) -> toolbar.onAccessibilityStatusChanged(enabled));
mToolbar.onAccessibilityStatusChanged(enabled);
}
private void registerTemplateUrlObserver() {
......@@ -1264,7 +1225,6 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
private void onNativeLibraryReady() {
mNativeLibraryReady = true;
mToolbar.onNativeLibraryReady();
final TemplateUrlService templateUrlService = TemplateUrlService.getInstance();
TemplateUrlService.LoadListener mTemplateServiceLoadListener =
......@@ -1364,10 +1324,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
return mBottomToolbarCoordinator.getMenuButtonWrapper();
}
if (mToolbar == null) return null;
View menuButtonWrapper = mToolbar.getMenuButtonWrapper();
if (menuButtonWrapper instanceof MenuButton) return (MenuButton) menuButtonWrapper;
return null;
return mToolbar.getMenuButtonWrapper();
}
/**
......@@ -1457,7 +1414,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
*/
@Override
public void onUrlFocusChange(boolean hasFocus) {
assert mToolbar != null;
assert mToolbarInflationComplete;
mToolbar.onUrlFocusChange(hasFocus);
......@@ -1489,7 +1446,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
mCurrentThemeColor = color;
mLocationBarModel.setPrimaryColor(color);
mToolbarProvider.whenLoaded((toolbar) -> toolbar.onPrimaryColorChanged(shouldAnimate));
mToolbar.onPrimaryColorChanged(shouldAnimate);
}
/**
......@@ -1528,7 +1485,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
* {@code null}.
*/
public void setCloseButtonDrawable(Drawable drawable) {
mToolbarProvider.whenLoaded((toolbar) -> toolbar.setCloseButtonImageResource(drawable));
mToolbar.setCloseButtonImageResource(drawable);
}
/**
......@@ -1536,22 +1493,21 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
* @param showTitle Whether a title should be shown.
*/
public void setShowTitle(boolean showTitle) {
mToolbarProvider.whenLoaded((toolbar) -> toolbar.getLocationBar().setShowTitle(showTitle));
mToolbar.setShowTitle(showTitle);
}
/**
* @see ToolbarLayout#setUrlBarHidden(boolean)
*/
public void setUrlBarHidden(boolean hidden) {
mToolbarProvider.whenLoaded((toolbar) -> toolbar.setUrlBarHidden(hidden));
mToolbar.setUrlBarHidden(hidden);
}
/**
* @see ToolbarLayout#getContentPublisher()
*/
public String getContentPublisher() {
if (mToolbar != null) return mToolbar.getContentPublisher();
return null;
return mToolbar.getContentPublisher();
}
/**
......@@ -1575,7 +1531,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
* change the focus state of the location bar.
*/
public void revertLocationBarChanges() {
if (mToolbar == null) return;
if (mLocationBar == null) return;
mLocationBar.revertChanges();
}
......@@ -1609,12 +1565,19 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
if (isInitialized()) mToolbar.finishAnimations();
}
/**
* See {@link LocationBar#updateVisualsForState()}
*/
public void updateLocationBarVisualsForState() {
mLocationBar.updateVisualsForState();
}
/**
* Updates the current button states and calls appropriate abstract visibility methods, giving
* inheriting classes the chance to update the button visuals as well.
*/
private void updateButtonStatus() {
assert mToolbar != null;
assert mToolbarInflationComplete;
Tab currentTab = mLocationBarModel.getTab();
boolean tabCrashed = currentTab != null && SadTab.isShowing(currentTab);
......@@ -1629,7 +1592,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
}
private void updateBookmarkButtonStatus() {
assert mToolbar != null;
assert mToolbarInflationComplete;
Tab currentTab = mLocationBarModel.getTab();
boolean isBookmarked = currentTab != null
&& currentTab.getBookmarkId() != Tab.INVALID_BOOKMARK_ID;
......@@ -1639,7 +1602,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
}
private void updateReloadState(boolean tabCrashed) {
assert mToolbar != null;
assert mToolbarInflationComplete;
Tab currentTab = mLocationBarModel.getTab();
boolean isLoading = false;
if (!tabCrashed) {
......@@ -1653,7 +1616,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
* Triggered when the selected tab has changed.
*/
private void refreshSelectedTab() {
assert mToolbar != null;
assert mToolbarInflationComplete;
Tab tab = null;
if (mPreselectedTabId != Tab.INVALID_TAB_ID) {
tab = mTabModelSelector.getTabById(mPreselectedTabId);
......@@ -1683,7 +1646,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
if (tab != null) tab.addObserver(mTabObserver);
}
int defaultPrimaryColor =
ColorUtils.getDefaultThemeColor(mToolbar.getResources(), isIncognito);
ColorUtils.getDefaultThemeColor(mActivity.getResources(), isIncognito);
int primaryColor =
tab != null ? TabThemeColorHelper.getColor(tab) : defaultPrimaryColor;
updatePrimaryColor(primaryColor, false);
......@@ -1727,7 +1690,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
}
private void updateCurrentTabDisplayStatus() {
assert mToolbar != null;
assert mLocationBar != null;
Tab tab = mLocationBarModel.getTab();
mLocationBar.setUrlToPageUrl();
......@@ -1754,13 +1717,13 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
}
private void updateTabLoadingState(boolean updateUrl) {
assert mToolbar != null;
assert mLocationBar != null;
mLocationBar.updateLoadingState(updateUrl);
if (updateUrl) updateButtonStatus();
}
private void updateLoadProgress(int progress) {
assert mToolbar != null;
assert mToolbarInflationComplete;
// If it's a native page, progress bar is already hidden or being hidden, so don't update
// the value.
// TODO(kkimlabs): Investigate back/forward navigation with native page & web content and
......@@ -1776,7 +1739,7 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
}
private void finishLoadProgress(boolean delayed) {
assert mToolbar != null;
assert mToolbarInflationComplete;
mLoadProgressSimulator.cancel();
mToolbar.finishLoadProgress(delayed);
}
......@@ -1785,15 +1748,16 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
* Only start showing the progress bar if it is not already started.
*/
private void startLoadProgress() {
assert mToolbar != null;
assert mToolbarInflationComplete;
if (mToolbar.isProgressStarted()) return;
mToolbar.startLoadProgress();
}
/**
* @param enabled Whether the progress bar is enabled.
*/
public void setProgressBarEnabled(boolean enabled) {
mToolbarProvider.whenLoaded((toolbar)
-> toolbar.getProgressBar().setVisibility(
enabled ? View.VISIBLE : View.GONE));
mToolbar.setProgressBarEnabled(enabled);
}
private boolean shouldShowCursorInLocationBar() {
......@@ -1855,4 +1819,18 @@ public class ToolbarManager implements ScrimObserver, ToolbarTabController, UrlF
mHandler.removeMessages(MSG_ID_UPDATE_PROGRESS);
}
}
/** Return the location bar model for testing purposes. */
@VisibleForTesting
public LocationBarModel getLocationBarModelForTesting() {
return mLocationBarModel;
}
/**
* @return The {@link ToolbarLayout} that constitutes the toolbar.
*/
@VisibleForTesting
public ToolbarLayout getToolbarLayoutForTesting() {
return mToolbar.getToolbarLayoutForTesting();
}
}
......@@ -185,8 +185,8 @@ public class CustomTabToolbar
}
@Override
public void initialize(ToolbarDataProvider toolbarDataProvider,
ToolbarTabController tabController, AppMenuButtonHelper appMenuButtonHelper) {
void initialize(ToolbarDataProvider toolbarDataProvider, ToolbarTabController tabController,
AppMenuButtonHelper appMenuButtonHelper) {
super.initialize(toolbarDataProvider, tabController, appMenuButtonHelper);
updateVisualsForState();
}
......@@ -205,19 +205,18 @@ public class CustomTabToolbar
}
@Override
public void setCloseButtonImageResource(Drawable drawable) {
void setCloseButtonImageResource(Drawable drawable) {
mCloseButton.setVisibility(drawable != null ? View.VISIBLE : View.GONE);
mCloseButton.setImageDrawable(drawable);
}
@Override
public void setCustomTabCloseClickHandler(OnClickListener listener) {
void setCustomTabCloseClickHandler(OnClickListener listener) {
mCloseButton.setOnClickListener(listener);
}
@Override
public void addCustomActionButton(
Drawable drawable, String description, OnClickListener listener) {
void addCustomActionButton(Drawable drawable, String description, OnClickListener listener) {
ImageButton button = (ImageButton) LayoutInflater.from(getContext())
.inflate(R.layout.custom_tabs_toolbar_button, null);
button.setOnLongClickListener(this);
......@@ -231,7 +230,7 @@ public class CustomTabToolbar
}
@Override
public void updateCustomActionButton(int index, Drawable drawable, String description) {
void updateCustomActionButton(int index, Drawable drawable, String description) {
ImageButton button = (ImageButton) mCustomActionButtons.getChildAt(
mCustomActionButtons.getChildCount() - 1 - index);
assert button != null;
......@@ -270,7 +269,7 @@ public class CustomTabToolbar
}
@Override
public int getTabStripHeight() {
int getTabStripHeight() {
return 0;
}
......@@ -341,7 +340,7 @@ public class CustomTabToolbar
}
@Override
public String getContentPublisher() {
String getContentPublisher() {
Tab tab = getToolbarDataProvider().getTab();
if (tab == null) return null;
......@@ -376,7 +375,7 @@ public class CustomTabToolbar
}
@Override
public void onNavigatedToDifferentPage() {
void onNavigatedToDifferentPage() {
super.onNavigatedToDifferentPage();
setTitleToPageTitle();
if (mState == STATE_TITLE_ONLY) {
......@@ -567,7 +566,7 @@ public class CustomTabToolbar
* for the current tab changing.
*/
@Override
public void onPrimaryColorChanged(boolean shouldAnimate) {
void onPrimaryColorChanged(boolean shouldAnimate) {
if (mBrandColorTransitionActive) mBrandColorTransitionAnimation.cancel();
final ColorDrawable background = getBackground();
......@@ -708,7 +707,7 @@ public class CustomTabToolbar
}
@Override
public boolean useLightDrawables() {
boolean useLightDrawables() {
return !mUseDarkColors;
}
......@@ -784,27 +783,27 @@ public class CustomTabToolbar
public void setAutocompleteProfile(Profile profile) {}
@Override
public void showAppMenuUpdateBadge() {}
void showAppMenuUpdateBadge() {}
@Override
public boolean isShowingAppMenuUpdateBadge() {
boolean isShowingAppMenuUpdateBadge() {
return false;
}
@Override
public void removeAppMenuUpdateBadge(boolean animate) {}
void removeAppMenuUpdateBadge(boolean animate) {}
@Override
public void setAppMenuUpdateBadgeToVisible(boolean animate) {}
void setAppMenuUpdateBadgeToVisible(boolean animate) {}
@Override
public View getMenuButtonWrapper() {
View getMenuButtonWrapper() {
// This class has no menu button wrapper, so return the menu button instead.
return getMenuButton();
}
@Override
public void disableMenuButton() {
void disableMenuButton() {
super.disableMenuButton();
// In addition to removing the menu button, we also need to remove the margin on the custom
// action button.
......@@ -818,10 +817,10 @@ public class CustomTabToolbar
// Temporary fix to override ToolbarLayout's highlight-related methods
@Override
public void setMenuButtonHighlight(boolean highlight) {}
void setMenuButtonHighlight(boolean highlight) {}
@Override
public void setMenuButtonHighlightDrawable(boolean highlighting) {}
void setMenuButtonHighlightDrawable(boolean highlighting) {}
@Override
public int getUrlContainerMarginEnd() {
......
......@@ -6,12 +6,14 @@ package org.chromium.chrome.browser.toolbar.top;
import android.graphics.Rect;
import android.view.View;
import android.widget.ProgressBar;
import org.chromium.chrome.browser.compositor.layouts.LayoutUpdateHost;
import org.chromium.chrome.browser.widget.ToolbarProgressBar;
/**
* An interface for outside packages to interact with ToolbarLayout. Other than for testing purposes
* this interface should be used rather than {@link ToolbarLayout} and extending classes.
* An interface for outside packages to interact with the top toolbar. Other than for testing
* purposes this interface should be used rather than {@link TopToolbarCoordinator} or
* {@link ToolbarLayout} and extending classes.
*/
public interface Toolbar {
/**
......@@ -62,13 +64,6 @@ public interface Toolbar {
*/
boolean setForceTextureCapture(boolean forceTextureCapture);
/**
* Sets the {@link LayoutUpdateHost} for use in requesting an update when the toolbar texture
* needs to be recaptured.
* @param layoutUpdateHost The {@link LayoutUpdateHost} for requesting updates.
*/
void setLayoutUpdateHost(LayoutUpdateHost layoutUpdateHost);
/**
* Sets whether or not the menu button should be highlighted.
* @param highlight Whether or not the menu button should be highlighted.
......@@ -98,8 +93,25 @@ public interface Toolbar {
void removeAppMenuUpdateBadge(boolean animate);
/**
* Returns the height of the tab strip, iff the toolbar has one.
* Returns the height of the tab strip, iff the toolbar has one. Returns 0 for toolbars that do
* not have a tabstrip.
* @return height of the tab strip in px.
*/
int getTabStripHeight();
/**
* Disable the menu button. This removes the view from the hierarchy and nulls the related
* instance vars.
*/
void disableMenuButton();
/**
* @return The {@link ProgressBar} this layout uses.
*/
ToolbarProgressBar getProgressBar();
/**
* @return The primary color to use for the background drawable.
*/
int getPrimaryColor();
}
......@@ -25,7 +25,6 @@ import org.chromium.chrome.browser.widget.ClipDrawableProgressBar.DrawingInfo;
import org.chromium.chrome.browser.widget.ControlContainer;
import org.chromium.chrome.browser.widget.ToolbarProgressBar;
import org.chromium.chrome.browser.widget.ViewResourceFrameLayout;
import org.chromium.ui.AsyncViewProvider;
import org.chromium.ui.AsyncViewStub;
import org.chromium.ui.KeyboardVisibilityDelegate;
import org.chromium.ui.base.DeviceFormFactor;
......@@ -72,14 +71,14 @@ public class ToolbarControlContainer extends OptimizedFrameLayout implements Con
public void getProgressBarDrawingInfo(DrawingInfo drawingInfoOut) {
if (mToolbar == null) return;
// TODO(yusufo): Avoid casting to the layout without making the interface bigger.
ToolbarProgressBar progressBar = ((ToolbarLayout) mToolbar).getProgressBar();
ToolbarProgressBar progressBar = mToolbar.getProgressBar();
if (progressBar != null) progressBar.getDrawingInfo(drawingInfoOut);
}
@Override
public int getToolbarBackgroundColor() {
if (mToolbar == null) return 0;
return ((ToolbarLayout) mToolbar).getToolbarDataProvider().getPrimaryColor();
return mToolbar.getPrimaryColor();
}
@Override
......@@ -101,29 +100,32 @@ public class ToolbarControlContainer extends OptimizedFrameLayout implements Con
!DeviceFormFactor.isNonMultiDisplayContextOnTablet(getContext())
&& FeatureUtilities.shouldInflateToolbarOnBackgroundThread());
toolbarStub.inflate();
AsyncViewProvider<ToolbarLayout> toolbarProvider =
AsyncViewProvider.of(toolbarStub, R.id.toolbar);
toolbarProvider.whenLoaded(this ::onToolbarInflationComplete);
} else {
ViewStub toolbarStub = (ViewStub) viewStub;
toolbarStub.setLayoutResource(toolbarLayoutId);
toolbarStub.inflate();
onToolbarInflationComplete(findViewById(R.id.toolbar));
}
}
}
private void onToolbarInflationComplete(ToolbarLayout toolbar) {
/**
* @param toolbar The toolbar contained inside this control container. Should be called
* after inflation is complete.
*/
public void setToolbar(Toolbar toolbar) {
mToolbar = toolbar;
mToolbarContainer.setToolbar(mToolbar);
if (mToolbar instanceof ToolbarTablet) {
View toolbarView = findViewById(R.id.toolbar);
assert toolbarView != null;
if (toolbarView instanceof ToolbarTablet) {
// On tablet, draw a fake tab strip and toolbar until the compositor is
// ready to draw the real tab strip. (On phone, the toolbar is made entirely
// of Android views, which are already initialized.)
setBackgroundResource(R.drawable.toolbar_background);
}
assert mToolbar != null;
}
@Override
......
......@@ -57,7 +57,7 @@ import org.chromium.ui.UiUtils;
* interaction that are not from Views inside Toolbar hierarchy all interactions should be done
* through {@link Toolbar} rather than using this class directly.
*/
public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
public abstract class ToolbarLayout extends FrameLayout {
private Invalidator mInvalidator;
private final int[] mTempPosition = new int[2];
......@@ -117,12 +117,36 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
});
}
/**
* Initialize the external dependencies required for view interaction.
* @param toolbarDataProvider The provider for toolbar data.
* @param tabController The controller that handles interactions with the tab.
* @param appMenuButtonHelper The helper for managing menu button interactions.
*/
void initialize(ToolbarDataProvider toolbarDataProvider, ToolbarTabController tabController,
AppMenuButtonHelper appMenuButtonHelper) {
mToolbarDataProvider = toolbarDataProvider;
mToolbarTabController = tabController;
mAppMenuButtonHelper = appMenuButtonHelper;
if (mMenuButton != null) {
mMenuButton.setOnTouchListener(mAppMenuButtonHelper);
mMenuButton.setAccessibilityDelegate(mAppMenuButtonHelper);
}
}
/**
* Cleans up any code as necessary.
*/
void destroy() {}
/**
* Get the top margin of the progress bar relative to the toolbar layout. This is used to set
* the position of the progress bar (either top or bottom of the toolbar).
* @return The top margin of the progress bar.
*/
protected int getProgressBarTopMargin() {
int getProgressBarTopMargin() {
return getHeight()
- getResources().getDimensionPixelSize(R.dimen.toolbar_progress_bar_height);
}
......@@ -131,14 +155,14 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
* Set the height that the progress bar should be.
* @return The progress bar height in px.
*/
protected int getProgressBarHeight() {
int getProgressBarHeight() {
return getResources().getDimensionPixelSize(R.dimen.toolbar_progress_bar_height);
}
/**
* @return A progress bar for Chrome to use.
*/
protected ToolbarProgressBar createProgressBar() {
ToolbarProgressBar createProgressBar() {
return new ToolbarProgressBar(
getContext(), getProgressBarHeight(), getProgressBarTopMargin(), false);
}
......@@ -147,7 +171,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
* Disable the menu button. This removes the view from the hierarchy and nulls the related
* instance vars.
*/
public void disableMenuButton() {
void disableMenuButton() {
UiUtils.removeViewFromParent(getMenuButtonWrapper());
mMenuButtonWrapper = null;
mMenuButton = null;
......@@ -260,36 +284,17 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
* @param view {@link View} to fetch the layout params for.
* @return {@link LayoutParams} the given {@link View} is currently using.
*/
protected FrameLayout.LayoutParams getFrameLayoutParams(View view) {
FrameLayout.LayoutParams getFrameLayoutParams(View view) {
return ((FrameLayout.LayoutParams) view.getLayoutParams());
}
/**
* Initialize the external dependencies required for view interaction.
* @param toolbarDataProvider The provider for toolbar data.
* @param tabController The controller that handles interactions with the tab.
* @param appMenuButtonHelper The helper for managing menu button interactions.
*/
public void initialize(ToolbarDataProvider toolbarDataProvider,
ToolbarTabController tabController, AppMenuButtonHelper appMenuButtonHelper) {
mToolbarDataProvider = toolbarDataProvider;
mToolbarTabController = tabController;
mAppMenuButtonHelper = appMenuButtonHelper;
if (mMenuButton != null) {
mMenuButton.setOnTouchListener(mAppMenuButtonHelper);
mMenuButton.setAccessibilityDelegate(mAppMenuButtonHelper);
}
}
/** Notified that the menu was shown. */
public void onMenuShown() {}
void onMenuShown() {}
/**
* This function handles native dependent initialization for this class
* This function handles native dependent initialization for this class.
*/
public void onNativeLibraryReady() {
void onNativeLibraryReady() {
mNativeLibraryReady = true;
if (mProgressBar.getParent() != null) mProgressBar.initializeAnimation();
}
......@@ -303,48 +308,46 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
/**
* @return The view containing the menu button and menu button badge.
*/
public View getMenuButtonWrapper() {
View getMenuButtonWrapper() {
return mMenuButtonWrapper;
}
/**
* @return The {@link ImageButton} containing the menu button.
*/
public ImageButton getMenuButton() {
ImageButton getMenuButton() {
return mMenuButton;
}
/**
* @return The view containing the menu badge.
*/
protected View getMenuBadge() {
View getMenuBadge() {
return mMenuBadge;
}
/**
* @return The {@link ProgressBar} this layout uses.
*/
@VisibleForTesting
public ToolbarProgressBar getProgressBar() {
ToolbarProgressBar getProgressBar() {
return mProgressBar;
}
@Override
public void getPositionRelativeToContainer(View containerView, int[] position) {
void getPositionRelativeToContainer(View containerView, int[] position) {
ViewUtils.getRelativeDrawPosition(containerView, this, position);
}
/**
* @return The helper for menu button UI interactions.
*/
protected AppMenuButtonHelper getMenuButtonHelper() {
AppMenuButtonHelper getMenuButtonHelper() {
return mAppMenuButtonHelper;
}
/**
* @return Whether or not the native library is loaded and ready.
*/
protected boolean isNativeLibraryReady() {
boolean isNativeLibraryReady() {
return mNativeLibraryReady;
}
......@@ -357,7 +360,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
/**
* Add the toolbar's progress bar to the view hierarchy.
*/
protected void addProgressBarToHierarchy() {
void addProgressBarToHierarchy() {
ViewGroup controlContainer = (ViewGroup) getRootView().findViewById(R.id.control_container);
int progressBarPosition =
UiUtils.insertAfter(controlContainer, mProgressBar, (View) getParent());
......@@ -379,7 +382,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
* {@link Invalidator} a chance to defer the actual invalidate to sync drawing.
* @param invalidator An {@link Invalidator} instance.
*/
public void setPaintInvalidator(Invalidator invalidator) {
void setPaintInvalidator(Invalidator invalidator) {
mInvalidator = invalidator;
}
......@@ -388,7 +391,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
* {@link #setPaintInvalidator(Invalidator)} to decide when to actually invalidate.
* @param client A {@link Invalidator.Client} instance that wants to be invalidated.
*/
protected void triggerPaintInvalidate(Invalidator.Client client) {
void triggerPaintInvalidate(Invalidator.Client client) {
if (mInvalidator == null) {
client.doInvalidate();
} else {
......@@ -401,89 +404,78 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
* {@link org.chromium.chrome.browser.widget.findinpage.FindToolbar} state changes.
* @param showing Whether or not the {@code FindToolbar} will be showing.
*/
public void handleFindLocationBarStateChange(boolean showing) {
void handleFindLocationBarStateChange(boolean showing) {
mFindInPageToolbarShowing = showing;
}
/**
* Cleans up any code as necessary.
*/
public void destroy() {}
/**
* Sets the delegate to handle visibility of browser controls.
*/
public void setBrowserControlsVisibilityDelegate(
void setBrowserControlsVisibilityDelegate(
BrowserStateBrowserControlsVisibilityDelegate controlsVisibilityDelegate) {}
/**
* Sets the OnClickListener that will be notified when the TabSwitcher button is pressed.
* @param listener The callback that will be notified when the TabSwitcher button is pressed.
*/
public void setOnTabSwitcherClickHandler(OnClickListener listener) {}
void setOnTabSwitcherClickHandler(OnClickListener listener) {}
/**
* Sets the OnClickListener that will be notified when the New Tab button is pressed.
* @param listener The callback that will be notified when the New Tab button is pressed.
*/
public void setOnNewTabClickHandler(OnClickListener listener) {}
void setOnNewTabClickHandler(OnClickListener listener) {}
/**
* Sets the OnClickListener that will be notified when the bookmark button is pressed.
* @param listener The callback that will be notified when the bookmark button is pressed.
*/
public void setBookmarkClickHandler(OnClickListener listener) {}
void setBookmarkClickHandler(OnClickListener listener) {}
/**
* Sets the OnClickListener to notify when the close button is pressed in a custom tab.
* @param listener The callback that will be notified when the close button is pressed.
*/
public void setCustomTabCloseClickHandler(OnClickListener listener) {}
/**
* Sets the OnClickListener to notify when the incognito button is pressed.
* @param listener The callback that will be notifed when the incognito button is pressed.
*/
public void setIncognitoClickHandler(OnClickListener listener) {}
void setCustomTabCloseClickHandler(OnClickListener listener) {}
/**
* Sets whether the urlbar should be hidden on first page load.
*/
public void setUrlBarHidden(boolean hide) {}
void setUrlBarHidden(boolean hide) {}
/**
* @return The name of the publisher of the content if it can be reliably extracted, or null
* otherwise.
*/
public String getContentPublisher() {
String getContentPublisher() {
return null;
}
/**
* Tells the Toolbar to update what buttons it is currently displaying.
*/
public void updateButtonVisibility() {}
void updateButtonVisibility() {}
/**
* Gives inheriting classes the chance to update the visibility of the
* back button.
* @param canGoBack Whether or not the current tab has any history to go back to.
*/
public void updateBackButtonVisibility(boolean canGoBack) {}
void updateBackButtonVisibility(boolean canGoBack) {}
/**
* Gives inheriting classes the chance to update the visibility of the
* forward button.
* @param canGoForward Whether or not the current tab has any history to go forward to.
*/
public void updateForwardButtonVisibility(boolean canGoForward) {}
void updateForwardButtonVisibility(boolean canGoForward) {}
/**
* Gives inheriting classes the chance to update the visibility of the
* reload button.
* @param isReloading Whether or not the current tab is loading.
*/
public void updateReloadButtonVisibility(boolean isReloading) {}
void updateReloadButtonVisibility(boolean isReloading) {}
/**
* Gives inheriting classes the chance to update the visual status of the
......@@ -491,26 +483,26 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
* @param isBookmarked Whether or not the current tab is already bookmarked.
* @param editingAllowed Whether or not bookmarks can be modified (added, edited, or removed).
*/
public void updateBookmarkButton(boolean isBookmarked, boolean editingAllowed) {}
void updateBookmarkButton(boolean isBookmarked, boolean editingAllowed) {}
/**
* Gives inheriting classes the chance to respond to accessibility state changes.
* @param enabled Whether or not accessibility is enabled.
*/
public void onAccessibilityStatusChanged(boolean enabled) {}
void onAccessibilityStatusChanged(boolean enabled) {}
/**
* Gives inheriting classes the chance to do the necessary UI operations after Chrome is
* restored to a previously saved state.
*/
public void onStateRestored() {}
void onStateRestored() {}
/**
* Gives inheriting classes the chance to update home button UI if home button preference is
* changed.
* @param homeButtonEnabled Whether or not home button is enabled in preference.
*/
public void onHomeButtonUpdate(boolean homeButtonEnabled) {}
void onHomeButtonUpdate(boolean homeButtonEnabled) {}
/**
* Triggered when the current tab or model has changed.
......@@ -519,7 +511,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
* tabs but no normal tabs will still allow you to select the normal model), this should
* not guarantee that the model's current tab is non-null.
*/
public void onTabOrModelChanged() {
void onTabOrModelChanged() {
NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab();
if (ntp != null) {
getLocationBar().onTabLoadingNTP(ntp);
......@@ -532,13 +524,13 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
* For extending classes to override and carry out the changes related with the primary color
* for the current tab changing.
*/
public void onPrimaryColorChanged(boolean shouldAnimate) {}
void onPrimaryColorChanged(boolean shouldAnimate) {}
/**
* Sets the icon drawable that the close button in the toolbar (if any) should show, or hides
* it if {@code drawable} is {@code null}.
*/
public void setCloseButtonImageResource(@Nullable Drawable drawable) {}
void setCloseButtonImageResource(@Nullable Drawable drawable) {}
/**
* Adds a custom action button to the toolbar layout, if it is supported.
......@@ -546,8 +538,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
* @param description The content description for the button.
* @param listener The {@link OnClickListener} to use for clicks to the button.
*/
public void addCustomActionButton(
Drawable drawable, String description, OnClickListener listener) {
void addCustomActionButton(Drawable drawable, String description, OnClickListener listener) {
// This method should only be called for subclasses that override it.
assert false;
}
......@@ -559,7 +550,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
* @param drawable The icon for the button.
* @param description The content description for the button.
*/
public void updateCustomActionButton(int index, Drawable drawable, String description) {
void updateCustomActionButton(int index, Drawable drawable, String description) {
// This method should only be called for subclasses that override it.
assert false;
}
......@@ -567,36 +558,32 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
/**
* @return The height of the tab strip. Return 0 for toolbars that do not have a tabstrip.
*/
@Override
public int getTabStripHeight() {
int getTabStripHeight() {
return getResources().getDimensionPixelSize(R.dimen.tab_strip_height);
}
/**
* Triggered when the content view for the specified tab has changed.
*/
public void onTabContentViewChanged() {
void onTabContentViewChanged() {
NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab();
if (ntp != null) getLocationBar().onTabLoadingNTP(ntp);
}
@Override
public boolean isReadyForTextureCapture() {
boolean isReadyForTextureCapture() {
return true;
}
@Override
public boolean setForceTextureCapture(boolean forceTextureCapture) {
boolean setForceTextureCapture(boolean forceTextureCapture) {
return false;
}
@Override
public void setLayoutUpdateHost(LayoutUpdateHost layoutUpdateHost) {}
void setLayoutUpdateHost(LayoutUpdateHost layoutUpdateHost) {}
/**
* @param attached Whether or not the web content is attached to the view heirarchy.
*/
public void setContentAttached(boolean attached) {}
void setContentAttached(boolean attached) {}
/**
* Gives inheriting classes the chance to show or hide the TabSwitcher mode of this toolbar.
......@@ -606,26 +593,26 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
* finished (which can be detected by a call to
* {@link #onTabSwitcherTransitionFinished()}).
*/
public void setTabSwitcherMode(
void setTabSwitcherMode(
boolean inTabSwitcherMode, boolean showToolbar, boolean delayAnimation) {}
/**
* Gives inheriting classes the chance to update their state when the TabSwitcher transition has
* finished.
*/
public void onTabSwitcherTransitionFinished() {}
void onTabSwitcherTransitionFinished() {}
/**
* Gives inheriting classes the chance to observe tab count changes.
* @param tabCountProvider The {@link TabCountProvider} subclasses can observe.
*/
public void setTabCountProvider(TabCountProvider tabCountProvider) {}
void setTabCountProvider(TabCountProvider tabCountProvider) {}
/**
* Gives inheriting classes the chance to update themselves based on default search engine
* changes.
*/
public void onDefaultSearchEngineChanged() {}
void onDefaultSearchEngineChanged() {}
@Override
public boolean onGenericMotionEvent(MotionEvent event) {
......@@ -642,8 +629,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
return super.onGenericMotionEvent(event);
}
@Override
public void getLocationBarContentRect(Rect outRect) {
void getLocationBarContentRect(Rect outRect) {
View container = getLocationBar().getContainerView();
outRect.set(container.getPaddingLeft(), container.getPaddingTop(),
container.getWidth() - container.getPaddingRight(),
......@@ -652,11 +638,9 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
outRect.offset(mTempPosition[0], mTempPosition[1]);
}
@Override
public void setTextureCaptureMode(boolean textureMode) {}
void setTextureCaptureMode(boolean textureMode) {}
@Override
public boolean shouldIgnoreSwipeGesture() {
boolean shouldIgnoreSwipeGesture() {
return mUrlHasFocus
|| (mAppMenuButtonHelper != null && mAppMenuButtonHelper.isAppMenuActive())
|| mFindInPageToolbarShowing;
......@@ -665,7 +649,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
/**
* @return Whether or not the url bar has focus.
*/
protected boolean urlHasFocus() {
boolean urlHasFocus() {
return mUrlHasFocus;
}
......@@ -673,7 +657,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
* Triggered when the URL input field has gained or lost focus.
* @param hasFocus Whether the URL field has gained focus.
*/
public void onUrlFocusChange(boolean hasFocus) {
void onUrlFocusChange(boolean hasFocus) {
mUrlHasFocus = hasFocus;
}
......@@ -687,19 +671,19 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
/**
* Returns the elapsed realtime in ms of the time at which first draw for the toolbar occurred.
*/
public long getFirstDrawTime() {
long getFirstDrawTime() {
return mFirstDrawTimeMs;
}
/**
* Notified when a navigation to a different page has occurred.
*/
public void onNavigatedToDifferentPage() {}
void onNavigatedToDifferentPage() {}
/**
* Starts load progress.
*/
public void startLoadProgress() {
void startLoadProgress() {
mProgressBar.start();
}
......@@ -707,7 +691,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
* Sets load progress.
* @param progress The load progress between 0 and 1.
*/
public void setLoadProgress(float progress) {
void setLoadProgress(float progress) {
mProgressBar.setProgress(progress);
}
......@@ -716,26 +700,26 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
* @param delayed Whether hiding progress bar should be delayed to give enough time for user to
* recognize the last state.
*/
public void finishLoadProgress(boolean delayed) {
void finishLoadProgress(boolean delayed) {
mProgressBar.finish(delayed);
}
/**
* @return True if the progress bar is started.
*/
public boolean isProgressStarted() {
boolean isProgressStarted() {
return mProgressBar.isStarted();
}
/**
* Finish any toolbar animations.
*/
public void finishAnimations() {}
void finishAnimations() {}
/**
* @return The current View showing in the Tab.
*/
protected View getCurrentTabView() {
View getCurrentTabView() {
Tab tab = mToolbarDataProvider.getTab();
if (tab != null) {
return tab.getView();
......@@ -746,25 +730,26 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
/**
* @return Whether or not the toolbar is incognito.
*/
protected boolean isIncognito() {
boolean isIncognito() {
return mToolbarDataProvider.isIncognito();
}
/**
* @return {@link LocationBar} object this {@link ToolbarLayout} contains.
*/
@VisibleForTesting
public abstract LocationBar getLocationBar();
/**
* @return Whether or not this toolbar should use light or dark assets based on the theme.
*/
public abstract boolean useLightDrawables();
abstract boolean useLightDrawables();
/**
* Navigates the current Tab back.
* @return Whether or not the current Tab did go back.
*/
protected boolean back() {
boolean back() {
if (getLocationBar() != null) getLocationBar().setUrlBarFocus(false);
return mToolbarTabController != null ? mToolbarTabController.back() : false;
}
......@@ -773,7 +758,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
* Navigates the current Tab forward.
* @return Whether or not the current Tab did go forward.
*/
protected boolean forward() {
boolean forward() {
if (getLocationBar() != null) getLocationBar().setUrlBarFocus(false);
return mToolbarTabController != null ? mToolbarTabController.forward() : false;
}
......@@ -784,7 +769,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
*
* <p>The buttons of the toolbar will be updated as a result of making this call.
*/
protected void stopOrReloadCurrentTab() {
void stopOrReloadCurrentTab() {
if (getLocationBar() != null) getLocationBar().setUrlBarFocus(false);
if (mToolbarTabController != null) mToolbarTabController.stopOrReloadCurrentTab();
}
......@@ -792,7 +777,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
/**
* Opens hompage in the current tab.
*/
protected void openHomepage() {
void openHomepage() {
if (getLocationBar() != null) getLocationBar().setUrlBarFocus(false);
if (mToolbarTabController != null) mToolbarTabController.openHomepage();
}
......@@ -800,29 +785,25 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
/**
* Opens the Memex UI in the current tab.
*/
protected void openMemexUI() {
void openMemexUI() {
if (mToolbarTabController != null) mToolbarTabController.openMemexUI();
}
@Override
public void setMenuButtonHighlight(boolean highlight) {
void setMenuButtonHighlight(boolean highlight) {
mHighlightingMenu = highlight;
setMenuButtonHighlightDrawable(mHighlightingMenu);
}
@Override
public void showAppMenuUpdateBadge() {
void showAppMenuUpdateBadge() {
mShowMenuBadge = true;
mMenuButtonWrapper.updateImageResources();
}
@Override
public boolean isShowingAppMenuUpdateBadge() {
boolean isShowingAppMenuUpdateBadge() {
return mShowMenuBadge;
}
@Override
public void removeAppMenuUpdateBadge(boolean animate) {
void removeAppMenuUpdateBadge(boolean animate) {
if (mMenuBadge == null) return;
boolean wasShowingMenuBadge = mShowMenuBadge;
mShowMenuBadge = false;
......@@ -869,26 +850,27 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
* @param drawableResId The resource id of the drawable to display for the button.
* @param contentDescriptionResId The resource id of the content description for the button.
*/
public void enableExperimentalButton(OnClickListener onClickListener,
@DrawableRes int drawableResId, @StringRes int contentDescriptionResId) {}
void enableExperimentalButton(OnClickListener onClickListener, @DrawableRes int drawableResId,
@StringRes int contentDescriptionResId) {}
/**
* @return The experimental toolbar button if it exists.
*/
public @Nullable View getExperimentalButtonView() {
@Nullable
View getExperimentalButtonView() {
return null;
}
/**
* Disable the experimental toolbar button.
*/
public void disableExperimentalButton() {}
void disableExperimentalButton() {}
/**
* Sets the update badge visibility to VISIBLE and sets the menu button image to the badged
* bitmap.
*/
protected void setAppMenuUpdateBadgeToVisible(boolean animate) {
void setAppMenuUpdateBadgeToVisible(boolean animate) {
if (mMenuBadge == null || mMenuButton == null || mMenuButtonWrapper == null) return;
setMenuButtonContentDescription(true);
if (!animate || mIsMenuBadgeAnimationRunning) {
......@@ -923,7 +905,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
mMenuBadgeAnimatorSet.start();
}
protected void cancelAppMenuUpdateBadgeAnimation() {
void cancelAppMenuUpdateBadgeAnimation() {
if (mIsMenuBadgeAnimationRunning && mMenuBadgeAnimatorSet != null) {
mMenuBadgeAnimatorSet.cancel();
}
......@@ -933,7 +915,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
* Sets the update menu badge drawable to the light or dark asset.
* @param useLightDrawable Whether the light drawable should be used.
*/
protected void setAppMenuUpdateBadgeDrawable(boolean useLightDrawable) {
void setAppMenuUpdateBadgeDrawable(boolean useLightDrawable) {
if (mMenuButtonWrapper == null) return;
mMenuButtonWrapper.setUseLightDrawables(useLightDrawable);
}
......@@ -943,7 +925,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
* or not we are using light or dark assets.
* @param highlighting Whether or not the menu button should be highlighted.
*/
protected void setMenuButtonHighlightDrawable(boolean highlighting) {
void setMenuButtonHighlightDrawable(boolean highlighting) {
// Return if onFinishInflate didn't finish
if (mMenuButtonWrapper == null || mMenuButton == null) return;
......@@ -966,7 +948,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
* Sets the content description for the menu button.
* @param isUpdateBadgeVisible Whether the update menu badge is visible
*/
protected void setMenuButtonContentDescription(boolean isUpdateBadgeVisible) {
void setMenuButtonContentDescription(boolean isUpdateBadgeVisible) {
if (mMenuButtonWrapper == null) return;
mMenuButtonWrapper.updateContentDescription(isUpdateBadgeVisible);
}
......@@ -975,7 +957,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
* Sets the current TabModelSelector so the toolbar can pass it into buttons that need access to
* it.
*/
public void setTabModelSelector(TabModelSelector selector) {}
void setTabModelSelector(TabModelSelector selector) {}
/**
* Sets the icon drawable for the ntp button if the ntp button feature is enabled.
......@@ -983,7 +965,7 @@ public abstract class ToolbarLayout extends FrameLayout implements Toolbar {
* #onNativeLibraryReady() & once in #onFinishInflate() (see https://crbug.com/862887).
* @param ntpButton The button that needs to be changed.
*/
protected void changeIconToNTPIcon(ImageButton ntpButton) {
void changeIconToNTPIcon(ImageButton ntpButton) {
if (FeatureUtilities.isNewTabPageButtonEnabled())
ntpButton.setImageResource(R.drawable.ic_home);
}
......
......@@ -502,7 +502,7 @@ public class ToolbarPhone
* Sets up click and key listeners once we have native library available to handle clicks.
*/
@Override
public void onNativeLibraryReady() {
void onNativeLibraryReady() {
super.onNativeLibraryReady();
getLocationBar().onNativeLibraryReady();
......@@ -2607,18 +2607,18 @@ public class ToolbarPhone
}
@Override
public boolean useLightDrawables() {
boolean useLightDrawables() {
return mUseLightToolbarDrawables;
}
@Override
public void setMenuButtonHighlightDrawable(boolean highlighting) {
void setMenuButtonHighlightDrawable(boolean highlighting) {
highlighting &= !isTabSwitcherAnimationRunning();
super.setMenuButtonHighlightDrawable(highlighting);
}
@Override
public void setTabModelSelector(TabModelSelector selector) {
void setTabModelSelector(TabModelSelector selector) {
mTabModelSelector = selector;
if (mIncognitoToggleTabLayout != null) {
mIncognitoToggleTabLayout.setTabModelSelector(mTabModelSelector);
......@@ -2626,7 +2626,7 @@ public class ToolbarPhone
}
@Override
public void showAppMenuUpdateBadge() {
void showAppMenuUpdateBadge() {
if (getMenuBadge() == null) return;
super.showAppMenuUpdateBadge();
......@@ -2649,7 +2649,7 @@ public class ToolbarPhone
}
@Override
public void removeAppMenuUpdateBadge(boolean animate) {
void removeAppMenuUpdateBadge(boolean animate) {
if (getMenuBadge() == null) return;
super.removeAppMenuUpdateBadge(animate);
......@@ -2661,7 +2661,7 @@ public class ToolbarPhone
}
@Override
public void enableExperimentalButton(
void enableExperimentalButton(
OnClickListener onClickListener, int drawableResId, int contentDescriptionResId) {
if (mExperimentalButton == null) {
ViewStub viewStub = findViewById(R.id.experimental_button_stub);
......@@ -2701,12 +2701,12 @@ public class ToolbarPhone
}
@Override
public View getExperimentalButtonView() {
View getExperimentalButtonView() {
return mExperimentalButton;
}
@Override
public void disableExperimentalButton() {
void disableExperimentalButton() {
if (mExperimentalButton == null || mExperimentalButton.getVisibility() == View.GONE) {
return;
}
......
......@@ -376,12 +376,12 @@ public class ToolbarTablet extends ToolbarLayout
}
@Override
public boolean isReadyForTextureCapture() {
boolean isReadyForTextureCapture() {
return !urlHasFocus();
}
@Override
public void onTabOrModelChanged() {
void onTabOrModelChanged() {
super.onTabOrModelChanged();
boolean incognito = isIncognito();
if (mUseLightColorAssets == null || mUseLightColorAssets != incognito) {
......@@ -443,13 +443,13 @@ public class ToolbarTablet extends ToolbarLayout
}
@Override
public void onTabContentViewChanged() {
void onTabContentViewChanged() {
super.onTabContentViewChanged();
updateNtp();
}
@Override
public void updateButtonVisibility() {
void updateButtonVisibility() {
if (FeatureUtilities.isNewTabPageButtonEnabled()) {
mHomeButton.setVisibility(isIncognito() ? GONE : VISIBLE);
}
......@@ -457,21 +457,21 @@ public class ToolbarTablet extends ToolbarLayout
}
@Override
public void updateBackButtonVisibility(boolean canGoBack) {
void updateBackButtonVisibility(boolean canGoBack) {
boolean enableButton = canGoBack && !mIsInTabSwitcherMode;
mBackButton.setEnabled(enableButton);
mBackButton.setFocusable(enableButton);
}
@Override
public void updateForwardButtonVisibility(boolean canGoForward) {
void updateForwardButtonVisibility(boolean canGoForward) {
boolean enableButton = canGoForward && !mIsInTabSwitcherMode;
mForwardButton.setEnabled(enableButton);
mForwardButton.setFocusable(enableButton);
}
@Override
public void updateReloadButtonVisibility(boolean isReloading) {
void updateReloadButtonVisibility(boolean isReloading) {
if (isReloading) {
mReloadButton.getDrawable().setLevel(
getResources().getInteger(R.integer.reload_button_level_stop));
......@@ -489,7 +489,7 @@ public class ToolbarTablet extends ToolbarLayout
}
@Override
public void updateBookmarkButton(boolean isBookmarked, boolean editingAllowed) {
void updateBookmarkButton(boolean isBookmarked, boolean editingAllowed) {
if (isBookmarked) {
mBookmarkButton.setImageResource(R.drawable.btn_star_filled);
// Non-incognito mode shows a blue filled star.
......@@ -509,7 +509,7 @@ public class ToolbarTablet extends ToolbarLayout
}
@Override
public void setTabSwitcherMode(
void setTabSwitcherMode(
boolean inTabSwitcherMode, boolean showToolbar, boolean delayAnimation) {
if (mShowTabStack && inTabSwitcherMode) {
mIsInTabSwitcherMode = true;
......@@ -541,12 +541,12 @@ public class ToolbarTablet extends ToolbarLayout
}
@Override
public void setTabCountProvider(TabCountProvider tabCountProvider) {
void setTabCountProvider(TabCountProvider tabCountProvider) {
tabCountProvider.addObserver(this);
}
@Override
public void onAccessibilityStatusChanged(boolean enabled) {
void onAccessibilityStatusChanged(boolean enabled) {
// If Memex is enabled, don't allow the accessibility tab switcher button to be disabled.
if (!enabled && ChromeFeatureList.isInitialized()
&& ChromeFeatureList.isEnabled(ChromeFeatureList.CHROME_MEMEX)) {
......@@ -557,17 +557,17 @@ public class ToolbarTablet extends ToolbarLayout
}
@Override
public void setBookmarkClickHandler(OnClickListener listener) {
void setBookmarkClickHandler(OnClickListener listener) {
mBookmarkListener = listener;
}
@Override
public void setOnTabSwitcherClickHandler(OnClickListener listener) {
void setOnTabSwitcherClickHandler(OnClickListener listener) {
mTabSwitcherListener = listener;
}
@Override
public void onHomeButtonUpdate(boolean homeButtonEnabled) {
void onHomeButtonUpdate(boolean homeButtonEnabled) {
mHomeButton.setVisibility(homeButtonEnabled ? VISIBLE : GONE);
}
......@@ -577,12 +577,12 @@ public class ToolbarTablet extends ToolbarLayout
}
@Override
public boolean useLightDrawables() {
boolean useLightDrawables() {
return mUseLightColorAssets != null && mUseLightColorAssets;
}
@Override
public void showAppMenuUpdateBadge() {
void showAppMenuUpdateBadge() {
super.showAppMenuUpdateBadge();
if (!mIsInTabSwitcherMode) {
if (mUseLightColorAssets != null && mUseLightColorAssets) {
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package org.chromium.chrome.browser.toolbar.top;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.annotation.DrawableRes;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.appmenu.AppMenuButtonHelper;
import org.chromium.chrome.browser.compositor.Invalidator;
import org.chromium.chrome.browser.compositor.layouts.LayoutManager;
import org.chromium.chrome.browser.fullscreen.BrowserStateBrowserControlsVisibilityDelegate;
import org.chromium.chrome.browser.omnibox.LocationBar;
import org.chromium.chrome.browser.partnercustomizations.HomepageManager;
import org.chromium.chrome.browser.tabmodel.TabModelSelector;
import org.chromium.chrome.browser.toolbar.MenuButton;
import org.chromium.chrome.browser.toolbar.TabCountProvider;
import org.chromium.chrome.browser.toolbar.ToolbarDataProvider;
import org.chromium.chrome.browser.toolbar.ToolbarTabController;
import org.chromium.chrome.browser.util.FeatureUtilities;
import org.chromium.chrome.browser.widget.ToolbarProgressBar;
import org.chromium.ui.AsyncViewProvider;
/**
* A coordinator for the top toolbar component.
*/
public class TopToolbarCoordinator implements Toolbar {
private final AsyncViewProvider<ToolbarLayout> mToolbarProvider;
private @Nullable ToolbarLayout mToolbarLayout;
private HomepageManager.HomepageStateListener mHomepageStateListener =
new HomepageManager.HomepageStateListener() {
@Override
public void onHomepageStateUpdated() {
mToolbarProvider.whenLoaded(
(toolbar)
-> mToolbarLayout.onHomeButtonUpdate(
HomepageManager.isHomepageEnabled()
|| FeatureUtilities.isNewTabPageButtonEnabled()));
}
};
/**
* Creates a new {@link TopToolbarCoordinator}.
* @param controlContainer The {@link ToolbarControlContainer} for the containing activity.
* @param toolbarProvider The {@link AsyncViewProvider} for the {@link ToolbarLayout}.
*/
public TopToolbarCoordinator(ToolbarControlContainer controlContainer,
AsyncViewProvider<ToolbarLayout> toolbarProvider) {
mToolbarProvider = toolbarProvider;
mToolbarProvider.whenLoaded((toolbar) -> {
mToolbarLayout = toolbar;
controlContainer.setToolbar(this);
HomepageManager.getInstance().addListener(mHomepageStateListener);
});
}
/**
* Initialize the external dependencies required for view interaction.
* @param toolbarDataProvider The provider for toolbar data.
* @param tabController The controller that handles interactions with the tab.
* @param appMenuButtonHelper The helper for managing menu button interactions.
*/
public void initialize(ToolbarDataProvider toolbarDataProvider,
ToolbarTabController tabController, AppMenuButtonHelper appMenuButtonHelper) {
mToolbarLayout.initialize(toolbarDataProvider, tabController, appMenuButtonHelper);
}
/**
* Initialize the coordinator with the components that have native initialization dependencies.
* <p>
* Calling this must occur after the native library have completely loaded.
*
* @param tabModelSelector The selector that handles tab management.
* @param controlsVisibilityDelegate The delegate to handle visibility of browser controls.
* @param layoutManager A {@link LayoutManager} instance used to watch for scene changes.
* @param tabSwitcherClickHandler The click handler for the tab switcher button.
* @param newTabClickHandler The click handler for the new tab button.
* @param bookmarkClickHandler The click handler for the bookmarks button.
* @param customTabsBackClickHandler The click handler for the custom tabs back button.
*/
public void initializeWithNative(TabModelSelector tabModelSelector,
BrowserStateBrowserControlsVisibilityDelegate controlsVisibilityDelegate,
LayoutManager layoutManager, OnClickListener tabSwitcherClickHandler,
OnClickListener newTabClickHandler, OnClickListener bookmarkClickHandler,
OnClickListener customTabsBackClickHandler) {
mToolbarLayout.setTabModelSelector(tabModelSelector);
getLocationBar().updateVisualsForState();
getLocationBar().setUrlToPageUrl();
mToolbarLayout.setBrowserControlsVisibilityDelegate(controlsVisibilityDelegate);
mToolbarLayout.setOnTabSwitcherClickHandler(tabSwitcherClickHandler);
mToolbarLayout.setOnNewTabClickHandler(newTabClickHandler);
mToolbarLayout.setBookmarkClickHandler(bookmarkClickHandler);
mToolbarLayout.setCustomTabCloseClickHandler(customTabsBackClickHandler);
mToolbarLayout.setLayoutUpdateHost(layoutManager);
mToolbarLayout.onNativeLibraryReady();
}
/**
* Cleans up any code as necessary.
*/
public void destroy() {
if (mToolbarLayout != null) {
HomepageManager.getInstance().removeListener(mHomepageStateListener);
mToolbarProvider.destroy((toolbar) -> mToolbarLayout.destroy());
}
}
@Override
public void disableMenuButton() {
mToolbarLayout.disableMenuButton();
}
/** Notified that the menu was shown. */
public void onMenuShown() {
mToolbarLayout.onMenuShown();
}
/**
* @return The view containing the menu button and menu button badge.
*/
public MenuButton getMenuButtonWrapper() {
if (mToolbarLayout == null) return null;
View menuButtonWrapper = mToolbarLayout.getMenuButtonWrapper();
if (menuButtonWrapper instanceof MenuButton) return (MenuButton) menuButtonWrapper;
return null;
}
/**
* @return The {@link ImageButton} containing the menu button.
*/
public @Nullable ImageButton getMenuButton() {
return mToolbarLayout == null ? null : mToolbarLayout.getMenuButton();
}
@Override
public ToolbarProgressBar getProgressBar() {
return mToolbarLayout.getProgressBar();
}
@Override
public int getPrimaryColor() {
return mToolbarLayout.getToolbarDataProvider().getPrimaryColor();
}
@Override
public void getPositionRelativeToContainer(View containerView, int[] position) {
mToolbarLayout.getPositionRelativeToContainer(containerView, position);
}
/**
* Sets the {@link Invalidator} that will be called when the toolbar attempts to invalidate the
* drawing surface. This will give the object that registers as the host for the
* {@link Invalidator} a chance to defer the actual invalidate to sync drawing.
* @param invalidator An {@link Invalidator} instance.
*/
public void setPaintInvalidator(Invalidator invalidator) {
mToolbarLayout.setPaintInvalidator(invalidator);
}
/**
* Gives inheriting classes the chance to respond to
* {@link org.chromium.chrome.browser.widget.findinpage.FindToolbar} state changes.
* @param showing Whether or not the {@code FindToolbar} will be showing.
*/
public void handleFindLocationBarStateChange(boolean showing) {
mToolbarLayout.handleFindLocationBarStateChange(showing);
}
/**
* Sets whether the urlbar should be hidden on first page load.
*/
public void setUrlBarHidden(boolean hidden) {
mToolbarProvider.whenLoaded((toolbar) -> mToolbarLayout.setUrlBarHidden(hidden));
}
/**
* @return The name of the publisher of the content if it can be reliably extracted, or null
* otherwise.
*/
public String getContentPublisher() {
return mToolbarLayout == null ? null : mToolbarLayout.getContentPublisher();
}
/**
* Tells the Toolbar to update what buttons it is currently displaying.
*/
public void updateButtonVisibility() {
mToolbarLayout.updateButtonVisibility();
}
/**
* Gives inheriting classes the chance to update the visibility of the
* back button.
* @param canGoBack Whether or not the current tab has any history to go back to.
*/
public void updateBackButtonVisibility(boolean canGoBack) {
mToolbarLayout.updateBackButtonVisibility(canGoBack);
}
/**
* Gives inheriting classes the chance to update the visibility of the
* forward button.
* @param canGoForward Whether or not the current tab has any history to go forward to.
*/
public void updateForwardButtonVisibility(boolean canGoForward) {
mToolbarLayout.updateForwardButtonVisibility(canGoForward);
}
/**
* Gives inheriting classes the chance to update the visibility of the
* reload button.
* @param isReloading Whether or not the current tab is loading.
*/
public void updateReloadButtonVisibility(boolean isReloading) {
mToolbarLayout.updateReloadButtonVisibility(isReloading);
}
/**
* Gives inheriting classes the chance to update the visual status of the
* bookmark button.
* @param isBookmarked Whether or not the current tab is already bookmarked.
* @param editingAllowed Whether or not bookmarks can be modified (added, edited, or removed).
*/
public void updateBookmarkButton(boolean isBookmarked, boolean editingAllowed) {
mToolbarLayout.updateBookmarkButton(isBookmarked, editingAllowed);
}
/**
* Gives inheriting classes the chance to respond to accessibility state changes.
* @param enabled Whether or not accessibility is enabled.
*/
public void onAccessibilityStatusChanged(boolean enabled) {
mToolbarProvider.whenLoaded(
(toolbar) -> mToolbarLayout.onAccessibilityStatusChanged(enabled));
}
/**
* Gives inheriting classes the chance to do the necessary UI operations after Chrome is
* restored to a previously saved state.
*/
public void onStateRestored() {
mToolbarLayout.onStateRestored();
}
/**
* Triggered when the current tab or model has changed.
* <p>
* As there are cases where you can select a model with no tabs (i.e. having incognito
* tabs but no normal tabs will still allow you to select the normal model), this should
* not guarantee that the model's current tab is non-null.
*/
public void onTabOrModelChanged() {
mToolbarLayout.onTabOrModelChanged();
}
/**
* For extending classes to override and carry out the changes related with the primary color
* for the current tab changing.
*/
public void onPrimaryColorChanged(boolean shouldAnimate) {
mToolbarProvider.whenLoaded(
(toolbar) -> mToolbarLayout.onPrimaryColorChanged(shouldAnimate));
}
/**
* Sets whether a title should be shown within the Toolbar.
* @param showTitle Whether a title should be shown.
*/
public void setShowTitle(boolean showTitle) {
mToolbarProvider.whenLoaded((toolbar) -> getLocationBar().setShowTitle(showTitle));
}
/**
* Sets the icon drawable that the close button in the toolbar (if any) should show, or hides
* it if {@code drawable} is {@code null}.
*/
public void setCloseButtonImageResource(@Nullable Drawable drawable) {
mToolbarProvider.whenLoaded(
(toolbar) -> mToolbarLayout.setCloseButtonImageResource(drawable));
}
/**
* Adds a custom action button to the toolbar layout, if it is supported.
* @param drawable The icon for the button.
* @param description The content description for the button.
* @param listener The {@link View.OnClickListener} to use for clicks to the button.
*/
public void addCustomActionButton(
Drawable drawable, String description, View.OnClickListener listener) {
mToolbarProvider.whenLoaded(
(toolbar) -> mToolbarLayout.addCustomActionButton(drawable, description, listener));
}
/**
* Updates the visual appearance of a custom action button in the toolbar layout,
* if it is supported.
* @param index The index of the button.
* @param drawable The icon for the button.
* @param description The content description for the button.
*/
public void updateCustomActionButton(int index, Drawable drawable, String description) {
mToolbarProvider.whenLoaded(
(toolbar) -> mToolbarLayout.updateCustomActionButton(index, drawable, description));
}
@Override
public int getTabStripHeight() {
return mToolbarLayout.getTabStripHeight();
}
/**
* Triggered when the content view for the specified tab has changed.
*/
public void onTabContentViewChanged() {
mToolbarLayout.onTabContentViewChanged();
}
@Override
public boolean isReadyForTextureCapture() {
return mToolbarLayout.isReadyForTextureCapture();
}
@Override
public boolean setForceTextureCapture(boolean forceTextureCapture) {
return mToolbarLayout.setForceTextureCapture(forceTextureCapture);
}
/**
* @param attached Whether or not the web content is attached to the view heirarchy.
*/
public void setContentAttached(boolean attached) {
mToolbarLayout.setContentAttached(attached);
}
/**
* Gives inheriting classes the chance to show or hide the TabSwitcher mode of this toolbar.
* @param inTabSwitcherMode Whether or not TabSwitcher mode should be shown or hidden.
* @param showToolbar Whether or not to show the normal toolbar while animating.
* @param delayAnimation Whether or not to delay the animation until after the transition has
* finished (which can be detected by a call to
* {@link #onTabSwitcherTransitionFinished()}).
*/
public void setTabSwitcherMode(
boolean inTabSwitcherMode, boolean showToolbar, boolean delayAnimation) {
mToolbarLayout.setTabSwitcherMode(inTabSwitcherMode, showToolbar, delayAnimation);
}
/**
* Gives inheriting classes the chance to update their state when the TabSwitcher transition has
* finished.
*/
public void onTabSwitcherTransitionFinished() {
mToolbarLayout.onTabSwitcherTransitionFinished();
}
/**
* Gives inheriting classes the chance to observe tab count changes.
* @param tabCountProvider The {@link TabCountProvider} subclasses can observe.
*/
public void setTabCountProvider(TabCountProvider tabCountProvider) {
mToolbarLayout.setTabCountProvider(tabCountProvider);
}
/**
* Gives inheriting classes the chance to update themselves based on default search engine
* changes.
*/
public void onDefaultSearchEngineChanged() {
mToolbarLayout.onDefaultSearchEngineChanged();
}
@Override
public void getLocationBarContentRect(Rect outRect) {
mToolbarLayout.getLocationBarContentRect(outRect);
}
@Override
public void setTextureCaptureMode(boolean textureMode) {
mToolbarLayout.setTextureCaptureMode(textureMode);
}
@Override
public boolean shouldIgnoreSwipeGesture() {
return mToolbarLayout.shouldIgnoreSwipeGesture();
}
/**
* Triggered when the URL input field has gained or lost focus.
* @param hasFocus Whether the URL field has gained focus.
*/
public void onUrlFocusChange(boolean hasFocus) {
mToolbarLayout.onUrlFocusChange(hasFocus);
}
/**
* Returns the elapsed realtime in ms of the time at which first draw for the toolbar occurred.
*/
public long getFirstDrawTime() {
return mToolbarLayout.getFirstDrawTime();
}
/**
* Notified when a navigation to a different page has occurred.
*/
public void onNavigatedToDifferentPage() {
mToolbarLayout.onNavigatedToDifferentPage();
}
/**
* @param enabled Whether the progress bar is enabled.
*/
public void setProgressBarEnabled(boolean enabled) {
mToolbarProvider.whenLoaded(
(toolbar) -> getProgressBar().setVisibility(enabled ? View.VISIBLE : View.GONE));
}
/**
* Starts load progress.
*/
public void startLoadProgress() {
mToolbarLayout.startLoadProgress();
}
/**
* Sets load progress.
* @param progress The load progress between 0 and 1.
*/
public void setLoadProgress(float progress) {
mToolbarLayout.setLoadProgress(progress);
}
/**
* Finishes load progress.
* @param delayed Whether hiding progress bar should be delayed to give enough time for user to
* recognize the last state.
*/
public void finishLoadProgress(boolean delayed) {
mToolbarLayout.finishLoadProgress(delayed);
}
/**
* @return True if the progress bar is started.
*/
public boolean isProgressStarted() {
return mToolbarLayout.isProgressStarted();
}
/**
* Finish any toolbar animations.
*/
public void finishAnimations() {
mToolbarLayout.finishAnimations();
}
/**
* @return {@link LocationBar} object this {@link ToolbarLayout} contains.
*/
public LocationBar getLocationBar() {
return mToolbarLayout.getLocationBar();
}
@Override
public void setMenuButtonHighlight(boolean highlight) {
mToolbarLayout.setMenuButtonHighlight(highlight);
}
@Override
public void showAppMenuUpdateBadge() {
mToolbarProvider.whenLoaded((toolbar) -> mToolbarLayout.showAppMenuUpdateBadge());
}
@Override
public boolean isShowingAppMenuUpdateBadge() {
return mToolbarLayout == null ? false : mToolbarLayout.isShowingAppMenuUpdateBadge();
}
@Override
public void removeAppMenuUpdateBadge(boolean animate) {
mToolbarProvider.whenLoaded((toolbar) -> mToolbarLayout.removeAppMenuUpdateBadge(animate));
}
/**
* Enable the experimental toolbar button.
* @param onClickListener The {@link View.OnClickListener} to be called when the button is
* clicked.
* @param drawableResId The resource id of the drawable to display for the button.
* @param contentDescriptionResId The resource id of the content description for the button.
*/
public void enableExperimentalButton(View.OnClickListener onClickListener,
@DrawableRes int drawableResId, @StringRes int contentDescriptionResId) {
mToolbarProvider.whenLoaded((toolbar) -> {
mToolbarLayout.enableExperimentalButton(
onClickListener, drawableResId, contentDescriptionResId);
});
}
/**
* @return The experimental toolbar button if it exists.
*/
public @Nullable View getExperimentalButtonView() {
return mToolbarLayout == null ? null : mToolbarLayout.getExperimentalButtonView();
}
/**
* Disable the experimental toolbar button.
*/
public void disableExperimentalButton() {
mToolbarProvider.whenLoaded((toolbarLayout) -> mToolbarLayout.disableExperimentalButton());
}
@Override
public int getHeight() {
return mToolbarLayout.getHeight();
}
/**
* @return The {@link ToolbarLayout} that constitutes the toolbar.
*/
@VisibleForTesting
public ToolbarLayout getToolbarLayoutForTesting() {
return mToolbarLayout;
}
}
......@@ -294,7 +294,7 @@ public class WebappActivity extends SingleTabActivity {
(ToolbarControlContainer) findViewById(R.id.control_container));
getToolbarManager().initializeWithNative(getTabModelSelector(),
getFullscreenManager().getBrowserVisibilityDelegate(), getFindToolbarManager(),
null, layoutDriver, null, null, null, view -> onToolbarCloseButtonClicked(), null);
null, layoutDriver, null, null, null, view -> onToolbarCloseButtonClicked());
getToolbarManager().setShowTitle(true);
getToolbarManager().setCloseButtonDrawable(null); // Hides close button.
......@@ -717,7 +717,7 @@ public class WebappActivity extends SingleTabActivity {
getToolbarManager().setCloseButtonDrawable(
TintedDrawable.constructTintedDrawable(this, R.drawable.btn_close));
// Applies light or dark tint to icons depending on the theme color.
getToolbarManager().getToolbarLayout().getLocationBar().updateVisualsForState();
getToolbarManager().updateLocationBarVisualsForState();
} else {
getToolbarManager().setCloseButtonDrawable(null);
}
......
......@@ -1608,6 +1608,7 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/toolbar/top/ToolbarLayout.java",
"java/src/org/chromium/chrome/browser/toolbar/top/ToolbarPhone.java",
"java/src/org/chromium/chrome/browser/toolbar/top/ToolbarTablet.java",
"java/src/org/chromium/chrome/browser/toolbar/top/TopToolbarCoordinator.java",
"java/src/org/chromium/chrome/browser/toolbar/top/ViewShiftingActionBarDelegate.java",
"java/src/org/chromium/chrome/browser/tracing/TracingController.java",
"java/src/org/chromium/chrome/browser/tracing/TracingNotificationManager.java",
......
......@@ -311,7 +311,9 @@ public class NavigationPopupTest {
return ThreadUtils.runOnUiThreadBlocking(() -> {
NavigationPopup popup = new NavigationPopup(mProfile, mActivityTestRule.getActivity(),
controller, NavigationPopup.Type.TABLET_FORWARD);
popup.show(mActivityTestRule.getActivity().getToolbarManager().getToolbarLayout());
popup.show(mActivityTestRule.getActivity()
.getToolbarManager()
.getToolbarLayoutForTesting());
return popup.getPopupForTesting();
});
}
......
......@@ -687,6 +687,6 @@ public class ContextualSuggestionsTest {
}
private ToolbarPhone getToolbarPhone(ChromeActivity activity) {
return (ToolbarPhone) activity.getToolbarManager().getToolbarLayout();
return (ToolbarPhone) activity.getToolbarManager().getToolbarLayoutForTesting();
}
}
......@@ -84,8 +84,10 @@ public class ModalDialogManagerTest {
mModalDialogViews = new ModalDialogView[MAX_DIALOGS];
for (int i = 0; i < MAX_DIALOGS; i++) mModalDialogViews[i] = createDialog(i);
mTestObserver = new TestObserver();
mActivity.getToolbarManager().getToolbarLayout().getLocationBar().addUrlFocusChangeListener(
mTestObserver);
mActivity.getToolbarManager()
.getToolbarLayoutForTesting()
.getLocationBar()
.addUrlFocusChangeListener(mTestObserver);
TabModalPresenter presenter =
(TabModalPresenter) mManager.getPresenterForTest(ModalDialogType.TAB);
presenter.disableAnimationForTest();
......
......@@ -44,7 +44,7 @@ public class WebappDisplayModeTest {
public void testStandalone() throws Exception {
WebappActivity activity = startActivity(WebDisplayMode.STANDALONE);
Assert.assertFalse(activity.getToolbarManager().getToolbarLayout().isShown());
Assert.assertFalse(activity.getToolbarManager().getToolbarLayoutForTesting().isShown());
Assert.assertFalse(isFullscreen(activity));
}
......@@ -55,7 +55,7 @@ public class WebappDisplayModeTest {
public void testFullScreen() throws Exception {
WebappActivity activity = startActivity(WebDisplayMode.FULLSCREEN);
Assert.assertFalse(activity.getToolbarManager().getToolbarLayout().isShown());
Assert.assertFalse(activity.getToolbarManager().getToolbarLayoutForTesting().isShown());
Assert.assertTrue(isFullscreen(activity));
}
......@@ -66,7 +66,7 @@ public class WebappDisplayModeTest {
WebappActivity activity = startActivity(WebDisplayMode.MINIMAL_UI);
Assert.assertFalse(isFullscreen(activity));
Assert.assertTrue(activity.getToolbarManager().getToolbarLayout().isShown());
Assert.assertTrue(activity.getToolbarManager().getToolbarLayoutForTesting().isShown());
Assert.assertEquals(Color.CYAN, activity.getToolbarManager().getPrimaryColor());
Assert.assertEquals("Web App title should be displayed on the title bar",
......
......@@ -361,8 +361,11 @@ public class WebappNavigationTest {
WebappActivityTestRule.assertToolbarShowState(activity, true);
// Navigate back to in-scope through a close button.
ThreadUtils.runOnUiThreadBlocking(() -> activity.getToolbarManager()
.getToolbarLayout().findViewById(R.id.close_button).callOnClick());
ThreadUtils.runOnUiThreadBlocking(()
-> activity.getToolbarManager()
.getToolbarLayoutForTesting()
.findViewById(R.id.close_button)
.callOnClick());
// We should end up on most recent in-scope URL.
ChromeTabUtils.waitForTabPageLoaded(tab, otherInScopeUrl);
......@@ -398,10 +401,11 @@ public class WebappNavigationTest {
// Close the Minimal UI.
WebappActivityTestRule.assertToolbarShowState(activity, true);
ThreadUtils.runOnUiThreadBlocking(() -> activity.getToolbarManager()
.getToolbarLayout()
.findViewById(R.id.close_button)
.callOnClick());
ThreadUtils.runOnUiThreadBlocking(()
-> activity.getToolbarManager()
.getToolbarLayoutForTesting()
.findViewById(R.id.close_button)
.callOnClick());
// The WebappActivity should be navigated to the page prior to the redirect.
ChromeTabUtils.waitForTabPageLoaded(activity.getActivityTab(), initialInScopeUrl);
......
......@@ -60,10 +60,8 @@ public class ToolbarProgressBarTest {
@Before
public void setUp() throws InterruptedException, TimeoutException {
mActivityTestRule.startMainActivityOnBlankPage();
mProgressBar = mActivityTestRule.getActivity()
.getToolbarManager()
.getToolbarLayout()
.getProgressBar();
mProgressBar =
mActivityTestRule.getActivity().getToolbarManager().getToolbar().getProgressBar();
mProgressBar.resetStartCountForTesting();
......
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