Commit 12c5add2 authored by bttk's avatar bttk Committed by Commit Bot

[ToolbarMVC] Coordinator - LocationBar API that is not a View

LocationBarCoordinator (LBC) - the public API for location bar.
This class implements LocationBar, but is not a View.

Interfaces LocationBar.Phone and LocationBar.Tablet are now replaced by
LBCPhone and LBCTablet. Interfaces were removed in an effort to reduce
the method count.

Views LBPhone and LBTablet no longer need to be visible outside of
their package. LocationBarLayout can't be hidden, since
SearchActivityLocationBarLayout depends on it.

Bug: 1133482
Change-Id: I5f8bbc3b8cfd6c896aca41482d3c271be957f352
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2446826
Commit-Queue: who/bttk <bttk@chromium.org>
Reviewed-by: default avatarPatrick Noland <pnoland@chromium.org>
Reviewed-by: default avatarBrandon Wylie <wylieb@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarFilip Gorski <fgorski@chromium.org>
Auto-Submit: who/bttk <bttk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816877}
parent 67f514a9
......@@ -1093,6 +1093,9 @@ chrome_java_sources = [
"java/src/org/chromium/chrome/browser/omnibox/ChromeAutocompleteSchemeClassifier.java",
"java/src/org/chromium/chrome/browser/omnibox/KeyboardHideHelper.java",
"java/src/org/chromium/chrome/browser/omnibox/LocationBar.java",
"java/src/org/chromium/chrome/browser/omnibox/LocationBarCoordinator.java",
"java/src/org/chromium/chrome/browser/omnibox/LocationBarCoordinatorPhone.java",
"java/src/org/chromium/chrome/browser/omnibox/LocationBarCoordinatorTablet.java",
"java/src/org/chromium/chrome/browser/omnibox/LocationBarLayout.java",
"java/src/org/chromium/chrome/browser/omnibox/LocationBarPhone.java",
"java/src/org/chromium/chrome/browser/omnibox/LocationBarTablet.java",
......
// Copyright 2020 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.omnibox;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.chromium.base.supplier.ObservableSupplier;
import org.chromium.base.supplier.Supplier;
import org.chromium.chrome.browser.ActivityTabProvider;
import org.chromium.chrome.browser.WindowDelegate;
import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior;
import org.chromium.chrome.browser.lifecycle.Destroyable;
import org.chromium.chrome.browser.ntp.NewTabPage;
import org.chromium.chrome.browser.omnibox.voice.VoiceRecognitionHandler;
import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.browser.share.ShareDelegate;
import org.chromium.chrome.browser.tabmodel.IncognitoStateProvider;
import org.chromium.chrome.browser.toolbar.ToolbarDataProvider;
import org.chromium.chrome.browser.toolbar.top.ToolbarActionModeCallback;
import org.chromium.chrome.browser.ui.native_page.NativePage;
import org.chromium.ui.base.WindowAndroid;
import org.chromium.ui.modaldialog.ModalDialogManager;
import java.util.List;
/**
* The public API of the location bar component. Location bar responsibilities are:
* <ul>
* <li>Display the current URL.
* <li>Display Status.
* <li>Handle omnibox input.
* </ul>
*
* <p>The coordinator creates and owns elements within this component.
*/
public final class LocationBarCoordinator implements LocationBar {
/** Identifies coordinators with methods specific to a device type. */
public interface SubCoordinator extends Destroyable {}
private LocationBarLayout mLocationBarLayout;
@Nullable
private SubCoordinator mSubCoordinator;
/**
* Creates {@link LocationBarCoordinator} and its subcoordinator: {@link
* LocationBarCoordinatorPhone} or {@link LocationBarCoordinatorTablet}, depending on the type
* of {@code locationBarLayout}.
* {@code LocationBarCoordinator} owns the subcoordinator. Destroying the former destroys the
* latter.
*
* @param locationBarLayout Inflated {@link LocationBarPhone} or {@link LocationBarTablet}.
* {@code LocationBarCoordinator} takes ownership and will destroy this object.
* @throws IllegalArgumentException if the view is neither {@link LocationBarPhone} nor {@link
* LocationBarTablet}.
*/
public LocationBarCoordinator(View locationBarLayout) {
mLocationBarLayout = (LocationBarLayout) locationBarLayout;
if (locationBarLayout instanceof LocationBarPhone) {
mSubCoordinator = new LocationBarCoordinatorPhone((LocationBarPhone) locationBarLayout);
} else if (locationBarLayout instanceof LocationBarTablet) {
mSubCoordinator =
new LocationBarCoordinatorTablet((LocationBarTablet) locationBarLayout);
} else {
assert false : "Expected LocationBarPhone or LocationBarTablet, got "
+ locationBarLayout.getClass();
throw new IllegalArgumentException(locationBarLayout.getClass().toString());
}
}
/**
* Returns the {@link LocationBarCoordinatorPhone} for this coordinator.
*
* @throws ClassCastException if this coordinator holds a {@link SubCoordinator} of a different
* type.
*/
@NonNull
public LocationBarCoordinatorPhone getPhoneCoordinator() {
assert mSubCoordinator != null;
return (LocationBarCoordinatorPhone) mSubCoordinator;
}
/**
* Returns the {@link LocationBarCoordinatorTablet} for this coordinator.
*
* @throws ClassCastException if this coordinator holds a {@link SubCoordinator} of a different
* type.
*/
@NonNull
public LocationBarCoordinatorTablet getTabletCoordinator() {
assert mSubCoordinator != null;
return (LocationBarCoordinatorTablet) mSubCoordinator;
}
@Override
public void destroy() {
if (mSubCoordinator != null) {
mSubCoordinator.destroy();
mSubCoordinator = null;
}
if (mLocationBarLayout != null) {
mLocationBarLayout.destroy();
mLocationBarLayout = null;
}
}
@Override
public void onDeferredStartup() {
mLocationBarLayout.onDeferredStartup();
}
@Override
public void onNativeLibraryReady() {
mLocationBarLayout.onNativeLibraryReady();
}
@Override
public void onTabLoadingNTP(NewTabPage ntp) {
mLocationBarLayout.onTabLoadingNTP(ntp);
}
@Override
public void updateVisualsForState() {
mLocationBarLayout.updateVisualsForState();
}
@Override
public void setUrlFocusChangeFraction(float fraction) {
mLocationBarLayout.setUrlFocusChangeFraction(fraction);
}
@Override
public void setUrlToPageUrl() {
mLocationBarLayout.setUrlToPageUrl();
}
@Override
public void setTitleToPageTitle() {
mLocationBarLayout.setTitleToPageTitle();
}
@Override
public void setShowTitle(boolean showTitle) {
mLocationBarLayout.setShowTitle(showTitle);
}
@Override
public void updateLoadingState(boolean updateUrl) {
mLocationBarLayout.updateLoadingState(updateUrl);
}
@Override
public void setToolbarDataProvider(ToolbarDataProvider dataProvider) {
mLocationBarLayout.setToolbarDataProvider(dataProvider);
}
@Override
public void setOverviewModeBehavior(OverviewModeBehavior overviewModeBehavior) {
mLocationBarLayout.setOverviewModeBehavior(overviewModeBehavior);
}
@Override
public ToolbarDataProvider getToolbarDataProvider() {
return mLocationBarLayout.getToolbarDataProvider();
}
@Override
public void initializeControls(WindowDelegate windowDelegate, WindowAndroid windowAndroid,
ActivityTabProvider activityTabProvider,
Supplier<ModalDialogManager> modalDialogManagerSupplier,
Supplier<ShareDelegate> shareDelegateSupplier,
IncognitoStateProvider incognitoStateProvider) {
mLocationBarLayout.initializeControls(windowDelegate, windowAndroid, activityTabProvider,
modalDialogManagerSupplier, shareDelegateSupplier, incognitoStateProvider);
}
@Override
public void showUrlBarCursorWithoutFocusAnimations() {
mLocationBarLayout.showUrlBarCursorWithoutFocusAnimations();
}
@Override
public void selectAll() {
mLocationBarLayout.selectAll();
}
@Override
public void revertChanges() {
mLocationBarLayout.revertChanges();
}
@Override
public void updateStatusIcon() {
mLocationBarLayout.updateStatusIcon();
}
@Override
public View getContainerView() {
return mLocationBarLayout.getContainerView();
}
@Override
public View getSecurityIconView() {
return mLocationBarLayout.getSecurityIconView();
}
@Override
public void updateMicButtonState() {
mLocationBarLayout.updateMicButtonState();
}
@Override
public void setDefaultTextEditActionModeCallback(ToolbarActionModeCallback callback) {
mLocationBarLayout.setDefaultTextEditActionModeCallback(callback);
}
@Override
public void setUnfocusedWidth(int unfocusedWidth) {
mLocationBarLayout.setUnfocusedWidth(unfocusedWidth);
}
@Override
public void setProfileSupplier(ObservableSupplier<Profile> profileSupplier) {
mLocationBarLayout.setProfileSupplier(profileSupplier);
}
@Nullable
@Override
public View getViewForUrlBackFocus() {
return mLocationBarLayout.getViewForUrlBackFocus();
}
@Override
public boolean allowKeyboardLearning() {
return mLocationBarLayout.allowKeyboardLearning();
}
@Override
public void backKeyPressed() {
mLocationBarLayout.backKeyPressed();
}
@Override
public boolean shouldForceLTR() {
return mLocationBarLayout.shouldForceLTR();
}
@Override
public boolean shouldCutCopyVerbatim() {
return mLocationBarLayout.shouldCutCopyVerbatim();
}
@Override
public void gestureDetected(boolean isLongPress) {
mLocationBarLayout.gestureDetected(isLongPress);
}
@Override
public void setUrlBarFocus(boolean shouldBeFocused, @Nullable String pastedText, int reason) {
mLocationBarLayout.setUrlBarFocus(shouldBeFocused, pastedText, reason);
}
@Override
public void performSearchQuery(String query, List<String> searchParams) {
mLocationBarLayout.performSearchQuery(query, searchParams);
}
@Override
public boolean isUrlBarFocused() {
return mLocationBarLayout.isUrlBarFocused();
}
@Override
public boolean isCurrentPage(NativePage nativePage) {
return mLocationBarLayout.isCurrentPage(nativePage);
}
@Override
public VoiceRecognitionHandler getVoiceRecognitionHandler() {
return mLocationBarLayout.getVoiceRecognitionHandler();
}
@Override
public void addUrlFocusChangeListener(UrlFocusChangeListener listener) {
mLocationBarLayout.addUrlFocusChangeListener(listener);
}
@Override
public void removeUrlFocusChangeListener(UrlFocusChangeListener listener) {
mLocationBarLayout.removeUrlFocusChangeListener(listener);
}
}
// Copyright 2020 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.omnibox;
import android.animation.Animator;
import android.view.View;
import android.widget.FrameLayout;
import java.util.List;
/**
* A supplement to {@link LocationBarCoordinator} with methods specific to smaller devices.
*/
public class LocationBarCoordinatorPhone implements LocationBarCoordinator.SubCoordinator {
private LocationBarPhone mLocationBarPhone;
public LocationBarCoordinatorPhone(LocationBarPhone phoneLayout) {
mLocationBarPhone = phoneLayout;
}
@Override
public void destroy() {
mLocationBarPhone = null;
}
/**
* Returns width of child views before the first view that would be visible when location
* bar is focused. The first visible, focused view should be either url bar or status icon.
*/
public int getOffsetOfFirstVisibleFocusedView() {
return mLocationBarPhone.getOffsetOfFirstVisibleFocusedView();
}
/**
* Populates fade animators of status icon for location bar focus change animation.
*
* @param animators The target list to add animators to.
* @param startDelayMs Start delay of fade animation in milliseconds.
* @param durationMs Duration of fade animation in milliseconds.
* @param targetAlpha Target alpha value.
*/
public void populateFadeAnimations(
List<Animator> animators, long startDelayMs, long durationMs, float targetAlpha) {
mLocationBarPhone.populateFadeAnimations(animators, startDelayMs, durationMs, targetAlpha);
}
/**
* Calculates the offset required for the focused LocationBar to appear as it's still
* unfocused so it can animate to a focused state.
*
* @param hasFocus True if the LocationBar has focus, this will be true between the focus
* animation starting and the unfocus animation starting.
* @return The offset for the location bar when showing the DSE/loupe icon.
*/
public int getLocationBarOffsetForFocusAnimation(boolean hasFocus) {
return mLocationBarPhone.getLocationBarOffsetForFocusAnimation(hasFocus);
}
/**
* Function used to position the URL bar inside the location bar during omnibox animation.
*
* @param urlExpansionFraction The current expansion progress, 1 is fully focused and 0 is
* completely unfocused.
* @param hasFocus True if the LocationBar has focus, this will be true between the focus
* animation starting and the unfocus animation starting.
* @return The number of pixels of horizontal translation for the URL bar, used in the
* toolbar animation.
*/
public float getUrlBarTranslationXForToolbarAnimation(
float urlExpansionFraction, boolean hasFocus) {
return mLocationBarPhone.getUrlBarTranslationXForToolbarAnimation(
urlExpansionFraction, hasFocus);
}
/**
* Handles any actions to be performed after all other actions triggered by the URL focus
* change. This will be called after any animations are performed to transition from one
* focus state to the other.
*
* @param hasFocus Whether the URL field has gained focus.
*/
public void finishUrlFocusChange(boolean hasFocus) {
mLocationBarPhone.finishUrlFocusChange(hasFocus);
}
/** Sets whether the url bar should be focusable. */
public void setUrlBarFocusable(boolean focusable) {
mLocationBarPhone.setUrlBarFocusable(focusable);
}
/**
* Returns {@link FrameLayout.LayoutParams} of the LocationBar view.
*
* <p>TODO(1133482): Hide this View interaction if possible.
*
* @see View#getLayoutParams()
*/
public FrameLayout.LayoutParams getFrameLayoutParams() {
return mLocationBarPhone.getFrameLayoutParams();
}
/**
* The opacity of the view.
*
* <p>TODO(1133482): Hide this View interaction if possible.
*
* @see View#getAlpha()
*/
public float getAlpha() {
return mLocationBarPhone.getAlpha();
}
/**
* Bottom position of this view relative to its parent.
*
* <p>TODO(1133482): Hide this View interaction if possible.
*
* @see View#getBottom()
* @return The bottom of this view, in pixels.
*/
public int getBottom() {
return mLocationBarPhone.getBottom();
}
/**
* Returns the resolved layout direction for this view.
*
* <p>TODO(1133482): Hide this View interaction if possible.
*
* @see View#getLayoutDirection()
* @return {@link View#LAYOUT_DIRECTION_LTR}, or {@link View#LAYOUT_DIRECTION_RTL}.
*/
public int getLayoutDirection() {
return mLocationBarPhone.getLayoutDirection();
}
/**
* Returns the end padding of this view.
*
* <p>TODO(1133482): Hide this View interaction if possible.
*
* @see View#getPaddingEnd()
* @return The end padding in pixels.
*/
public int getPaddingEnd() {
return mLocationBarPhone.getPaddingEnd();
}
/**
* Returns the start padding of this view.
*
* <p>TODO(1133482): Hide this View interaction if possible.
*
* @see View#getPaddingStart()
* @return The start padding in pixels.
*/
public int getPaddingStart() {
return mLocationBarPhone.getPaddingStart();
}
/**
* Top position of this view relative to its parent.
*
* <p>TODO(1133482): Hide this View interaction if possible.
*
* @see View#getTop()
* @return The top of this view, in pixels.
*/
public int getTop() {
return mLocationBarPhone.getTop();
}
/**
* The vertical location of this view relative to its top position, in pixels.
*
* <p>TODO(1133482): Hide this View interaction if possible.
*
* @see View#getTranslationY()
*/
public float getTranslationY() {
return mLocationBarPhone.getTranslationY();
}
/**
* Returns the visibility status for this view.
*
* <p>TODO(1133482): Hide this View interaction if possible.
*
* @see View#getVisibility()
*/
public int getVisibility() {
return mLocationBarPhone.getVisibility();
}
/**
* Returns true if this view has focus itself, or is the ancestor of the view that has
* focus.
*
* <p>TODO(1133482): Hide this View interaction if possible.
*
* @see View#hasFocus()
*/
public boolean hasFocus() {
return mLocationBarPhone.hasFocus();
}
/**
* Invalidate the whole view.
*
* <p>TODO(1133482): Hide this View interaction if possible.
*
* @see View#invalidate()
*/
public void invalidate() {
mLocationBarPhone.invalidate();
}
/**
* Sets the opacity of the view.
*
* <p>TODO(1133482): Hide this View interaction if possible.
*
* @see View#setAlpha(float)
*/
public void setAlpha(float alpha) {
mLocationBarPhone.setAlpha(alpha);
}
/**
* Sets the padding.
*
* <p>TODO(1133482): Hide this View interaction if possible.
*
* @see View#setPadding(int, int, int, int)
*/
public void setPadding(int left, int top, int right, int bottom) {
mLocationBarPhone.setPadding(left, top, right, bottom);
}
/**
* Sets the horizontal location of this view relative to its left position.
*
* <p>TODO(1133482): Hide this View interaction if possible.
*
* @see View#setTranslationX(float)
*/
public void setTranslationX(float translationX) {
mLocationBarPhone.setTranslationX(translationX);
}
/**
* Sets the vertical location of this view relative to its top position.
*
* <p>TODO(1133482): Hide this View interaction if possible.
*
* @see View#setTranslationY(float)
*/
public void setTranslationY(float translationY) {
mLocationBarPhone.setTranslationY(translationY);
}
/**
* Returns the LocationBar view for use in drawing.
*
* <p>TODO(1133482): Hide this View interaction if possible.
*
* @see ViewGroup#drawChild(Canvas, View, long)
*/
public View getViewForDrawing() {
return mLocationBarPhone;
}
}
// Copyright 2020 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.omnibox;
import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.graphics.drawable.Drawable;
import android.view.View;
import java.util.List;
/**
* A supplement to {@link LocationBarCoordinator} with methods specific to larger devices.
*/
public class LocationBarCoordinatorTablet implements LocationBarCoordinator.SubCoordinator {
private LocationBarTablet mLocationBarTablet;
public LocationBarCoordinatorTablet(LocationBarTablet tabletLayout) {
mLocationBarTablet = tabletLayout;
}
@Override
public void destroy() {
mLocationBarTablet = null;
}
/**
* @param button The {@link View} of the button to hide.
* @return An animator to run for the given view when hiding buttons in the unfocused
* location bar. This should also be used to create animators for hiding toolbar
* buttons.
*/
public ObjectAnimator createHideButtonAnimator(View button) {
return mLocationBarTablet.createHideButtonAnimator(button);
}
/**
* @param button The {@link View} of the button to show.
* @return An animator to run for the given view when showing buttons in the unfocused
* location bar. This should also be used to create animators for showing toolbar
* buttons.
*/
public ObjectAnimator createShowButtonAnimator(View button) {
return mLocationBarTablet.createShowButtonAnimator(button);
}
/**
* Creates animators for hiding buttons in the unfocused location bar. The buttons fade out
* while width of the location bar gets larger. There are toolbar buttons that also hide at
* the same time, causing the width of the location bar to change.
*
* @param toolbarStartPaddingDifference The difference in the toolbar's start padding
* between the beginning and end of the animation.
* @return A list of animators to run.
*/
public List<Animator> getHideButtonsWhenUnfocusedAnimators(int toolbarStartPaddingDifference) {
return mLocationBarTablet.getHideButtonsWhenUnfocusedAnimators(
toolbarStartPaddingDifference);
}
/**
* Creates animators for showing buttons in the unfocused location bar. The buttons fade in
* while width of the location bar gets smaller. There are toolbar buttons that also show at
* the same time, causing the width of the location bar to change.
*
* @param toolbarStartPaddingDifference The difference in the toolbar's start padding
* between the beginning and end of the animation.
* @return A list of animators to run.
*/
public List<Animator> getShowButtonsWhenUnfocusedAnimators(int toolbarStartPaddingDifference) {
return mLocationBarTablet.getShowButtonsWhenUnfocusedAnimators(
toolbarStartPaddingDifference);
}
/** Sets, whether buttons should be displayed in the URL bar when it's not focused. */
public void setShouldShowButtonsWhenUnfocused(boolean shouldShowButtons) {
mLocationBarTablet.setShouldShowButtonsWhenUnfocused(shouldShowButtons);
}
/** Updates the visibility of the buttons inside the location bar. */
public void updateButtonVisibility() {
mLocationBarTablet.updateButtonVisibility();
}
/**
* Gets the background drawable.
*
* <p>TODO(1133482): Hide this View interaction if possible.
*
* @see View#getBackground()
*/
public Drawable getBackground() {
return mLocationBarTablet.getBackground();
}
}
......@@ -112,7 +112,8 @@ public class LocationBarLayout extends FrameLayout
protected AutocompleteCoordinator mAutocompleteCoordinator;
protected ToolbarDataProvider mToolbarDataProvider;
private ObserverList<UrlFocusChangeListener> mUrlFocusChangeListeners = new ObserverList<>();
private final ObserverList<UrlFocusChangeListener> mUrlFocusChangeListeners =
new ObserverList<>();
private final List<Runnable> mDeferredNativeRunnables = new ArrayList<Runnable>();
......@@ -244,6 +245,8 @@ public class LocationBarLayout extends FrameLayout
@Override
public void destroy() {
mUrlFocusChangeListeners.clear();
if (mAutocompleteCoordinator != null) {
removeUrlFocusChangeListener(mAutocompleteCoordinator);
mAutocompleteCoordinator.destroy();
......
......@@ -24,7 +24,7 @@ import java.util.List;
/**
* A location bar implementation specific for smaller/phone screens.
*/
public class LocationBarPhone extends LocationBarLayout implements LocationBar.Phone {
class LocationBarPhone extends LocationBarLayout {
private static final int ACTION_BUTTON_TOUCH_OVERFLOW_LEFT = 15;
private View mFirstVisibleFocusedView;
......@@ -95,7 +95,6 @@ public class LocationBarPhone extends LocationBarLayout implements LocationBar.P
* @return Width of child views before the first view that would be visible when location bar is
* focused. The first visible, focused view should be either url bar or status icon.
*/
@Override
public int getOffsetOfFirstVisibleFocusedView() {
int visibleWidth = 0;
for (int i = 0; i < getChildCount(); i++) {
......@@ -114,7 +113,6 @@ public class LocationBarPhone extends LocationBarLayout implements LocationBar.P
* @param durationMs Duration of fade animation in milliseconds.
* @param targetAlpha Target alpha value.
*/
@Override
public void populateFadeAnimations(
List<Animator> animators, long startDelayMs, long durationMs, float targetAlpha) {
for (int i = 0; i < getChildCount(); i++) {
......@@ -136,7 +134,6 @@ public class LocationBarPhone extends LocationBarLayout implements LocationBar.P
* animation starting and the unfocus animation starting.
* @return The offset for the location bar when showing the dse icon.
*/
@Override
public int getLocationBarOffsetForFocusAnimation(boolean hasFocus) {
if (mStatusCoordinator == null) return 0;
......@@ -170,7 +167,6 @@ public class LocationBarPhone extends LocationBarLayout implements LocationBar.P
* animation starting and the unfocus animation starting.
* @return The X translation for the URL bar, used in the toolbar animation.
*/
@Override
public float getUrlBarTranslationXForToolbarAnimation(
float urlExpansionPercent, boolean hasFocus) {
// This will be called before status view is ready.
......@@ -282,7 +278,6 @@ public class LocationBarPhone extends LocationBarLayout implements LocationBar.P
mStatusCoordinator.onUrlAnimationFinished(hasFocus);
}
@Override
public FrameLayout.LayoutParams getFrameLayoutParams() {
return (FrameLayout.LayoutParams) getLayoutParams();
}
......@@ -338,11 +333,6 @@ public class LocationBarPhone extends LocationBarLayout implements LocationBar.P
}
}
@Override
public View getViewForDrawing() {
return this;
}
/** Update the status visibility according to the current state held in LocationBar. */
private void updateStatusVisibility() {
boolean incognito = getToolbarDataProvider().isIncognito();
......
......@@ -29,7 +29,7 @@ import java.util.List;
/**
* Location bar for tablet form factors.
*/
public class LocationBarTablet extends LocationBarLayout implements LocationBar.Tablet {
class LocationBarTablet extends LocationBarLayout {
private static final long MAX_NTP_KEYBOARD_FOCUS_DURATION_MS = 200;
private static final int ICON_FADE_ANIMATION_DURATION_MS = 150;
......@@ -187,7 +187,6 @@ public class LocationBarTablet extends LocationBarLayout implements LocationBar.
* @param shouldShowButtons Whether buttons should be displayed in the URL bar when it's not
* focused.
*/
@Override
public void setShouldShowButtonsWhenUnfocused(boolean shouldShowButtons) {
mShouldShowButtonsWhenUnfocused = shouldShowButtons;
updateButtonVisibility();
......@@ -268,7 +267,6 @@ public class LocationBarTablet extends LocationBarLayout implements LocationBar.
* @return An animator to run for the given view when showing buttons in the unfocused location
* bar. This should also be used to create animators for showing toolbar buttons.
*/
@Override
public ObjectAnimator createShowButtonAnimator(View button) {
if (button.getVisibility() != View.VISIBLE) {
button.setAlpha(0.f);
......@@ -285,7 +283,6 @@ public class LocationBarTablet extends LocationBarLayout implements LocationBar.
* @return An animator to run for the given view when hiding buttons in the unfocused location
* bar. This should also be used to create animators for hiding toolbar buttons.
*/
@Override
public ObjectAnimator createHideButtonAnimator(View button) {
ObjectAnimator buttonAnimator = ObjectAnimator.ofFloat(button, View.ALPHA, 0.f);
buttonAnimator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE);
......@@ -302,7 +299,6 @@ public class LocationBarTablet extends LocationBarLayout implements LocationBar.
* the beginning and end of the animation.
* @return An ArrayList of animators to run.
*/
@Override
public List<Animator> getShowButtonsWhenUnfocusedAnimators(int toolbarStartPaddingDifference) {
mToolbarStartPaddingDifference = toolbarStartPaddingDifference;
......@@ -357,7 +353,6 @@ public class LocationBarTablet extends LocationBarLayout implements LocationBar.
* the beginning and end of the animation.
* @return An ArrayList of animators to run.
*/
@Override
public List<Animator> getHideButtonsWhenUnfocusedAnimators(int toolbarStartPaddingDifference) {
mToolbarStartPaddingDifference = toolbarStartPaddingDifference;
......
......@@ -901,10 +901,6 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve
mBottomControlsCoordinator = null;
}
if (mLocationBar != null) {
mLocationBar.removeUrlFocusChangeListener(this);
}
mToolbar.removeUrlExpansionObserver(mActivity.getStatusBarColorController());
mToolbar.destroy();
......@@ -921,10 +917,6 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve
mHandler.removeCallbacksAndMessages(null); // Cancel delayed tasks.
mBrowserControlsSizer.removeObserver(mBrowserControlsObserver);
mFullscreenManager.removeObserver(mFullscreenObserver);
if (mLocationBar != null) {
mLocationBar.removeUrlFocusChangeListener(mLocationBarFocusHandler);
mLocationBarFocusHandler = null;
}
if (mTabThemeColorProvider != null) mTabThemeColorProvider.removeThemeColorObserver(this);
if (mAppThemeColorProvider != null) {
......
......@@ -153,8 +153,6 @@ public abstract class ToolbarLayout
mThemeColorProvider.removeThemeColorObserver(this);
mThemeColorProvider = null;
}
getLocationBar().destroy();
}
/**
......@@ -377,6 +375,7 @@ public abstract class ToolbarLayout
/**
* @return The {@link ProgressBar} this layout uses.
*/
@Nullable
protected ToolbarProgressBar getProgressBar() {
return mProgressBar;
}
......@@ -486,6 +485,7 @@ public abstract class ToolbarLayout
* @return The name of the publisher of the content if it can be reliably extracted, or null
* otherwise.
*/
@Nullable
protected String getContentPublisher() {
return null;
}
......
......@@ -32,6 +32,7 @@ import org.chromium.chrome.browser.download.DownloadUtils;
import org.chromium.chrome.browser.homepage.HomepageManager;
import org.chromium.chrome.browser.ntp.NewTabPage;
import org.chromium.chrome.browser.omnibox.LocationBar;
import org.chromium.chrome.browser.omnibox.LocationBarCoordinator;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.chrome.browser.profiles.Profile;
......@@ -84,8 +85,7 @@ public class ToolbarTablet extends ToolbarLayout
private NavigationPopup mNavigationPopup;
private Boolean mIsIncognito;
private LocationBar mLocationBar;
private LocationBar.Tablet mLocationBarTablet;
private LocationBarCoordinator mLocationBar;
private final int mStartPaddingWithButtons;
private final int mStartPaddingWithoutButtons;
......@@ -110,9 +110,7 @@ public class ToolbarTablet extends ToolbarLayout
@Override
public void onFinishInflate() {
super.onFinishInflate();
mLocationBar = (LocationBar) findViewById(R.id.location_bar);
mLocationBarTablet = (LocationBar.Tablet) mLocationBar;
mLocationBar = new LocationBarCoordinator(findViewById(R.id.location_bar));
mHomeButton = findViewById(R.id.home_button);
mBackButton = findViewById(R.id.back_button);
mForwardButton = findViewById(R.id.forward_button);
......@@ -151,8 +149,15 @@ public class ToolbarTablet extends ToolbarLayout
@Override
void destroy() {
if (mHomeButton != null) {
mHomeButton.destroy();
mHomeButton = null;
}
if (mLocationBar != null) {
mLocationBar.destroy();
mLocationBar = null;
}
super.destroy();
mHomeButton.destroy();
}
/**
......@@ -392,7 +397,8 @@ public class ToolbarTablet extends ToolbarLayout
setBackgroundColor(color);
final int textBoxColor = ToolbarColors.getTextBoxColorForToolbarBackgroundInNonNativePage(
getResources(), color, isIncognito());
mLocationBarTablet.getBackground().setColorFilter(textBoxColor, PorterDuff.Mode.SRC_IN);
mLocationBar.getTabletCoordinator().getBackground().setColorFilter(
textBoxColor, PorterDuff.Mode.SRC_IN);
mLocationBar.updateVisualsForState();
}
......@@ -429,7 +435,7 @@ public class ToolbarTablet extends ToolbarLayout
@Override
void updateButtonVisibility() {
mLocationBarTablet.updateButtonVisibility();
mLocationBar.getTabletCoordinator().updateButtonVisibility();
}
@Override
......@@ -617,7 +623,7 @@ public class ToolbarTablet extends ToolbarLayout
for (ImageButton button : mToolbarButtons) {
button.setVisibility(visible ? View.VISIBLE : View.GONE);
}
mLocationBarTablet.setShouldShowButtonsWhenUnfocused(visible);
mLocationBar.getTabletCoordinator().setShouldShowButtonsWhenUnfocused(visible);
setStartPaddingBasedOnButtonVisibility(visible);
}
}
......@@ -658,11 +664,11 @@ public class ToolbarTablet extends ToolbarLayout
// Create animators for all of the toolbar buttons.
for (ImageButton button : mToolbarButtons) {
animators.add(mLocationBarTablet.createShowButtonAnimator(button));
animators.add(mLocationBar.getTabletCoordinator().createShowButtonAnimator(button));
}
// Add animators for location bar.
animators.addAll(mLocationBarTablet.getShowButtonsWhenUnfocusedAnimators(
animators.addAll(mLocationBar.getTabletCoordinator().getShowButtonsWhenUnfocusedAnimators(
getStartPaddingDifferenceForButtonVisibilityAnimation()));
AnimatorSet set = new AnimatorSet();
......@@ -693,11 +699,11 @@ public class ToolbarTablet extends ToolbarLayout
// Create animators for all of the toolbar buttons.
for (ImageButton button : mToolbarButtons) {
animators.add(mLocationBarTablet.createHideButtonAnimator(button));
animators.add(mLocationBar.getTabletCoordinator().createHideButtonAnimator(button));
}
// Add animators for location bar.
animators.addAll(mLocationBarTablet.getHideButtonsWhenUnfocusedAnimators(
animators.addAll(mLocationBar.getTabletCoordinator().getHideButtonsWhenUnfocusedAnimators(
getStartPaddingDifferenceForButtonVisibilityAnimation()));
AnimatorSet set = new AnimatorSet();
......
......@@ -302,6 +302,7 @@ public class TopToolbarCoordinator implements Toolbar {
return mMenuButtonCoordinator.getMenuButton();
}
@Nullable
@Override
public ToolbarProgressBar 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