Commit 52fe73d0 authored by bttk's avatar bttk Committed by Commit Bot

[ToolbarMVC] Add nested LocationBar interfaces for phone and tablet

Making Toolbar interact with LocationBar only through those interfaces
uncovered which LocationBar* and View methods are used.
Next these interfaces can be replaced by Coordinator objects.

Bug: 1133482
Change-Id: Iececeed429fee66f7adbeb515a328403ef1b1aab
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2444470Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarBrandon Wylie <wylieb@chromium.org>
Reviewed-by: default avatarFilip Gorski <fgorski@chromium.org>
Reviewed-by: default avatarPatrick Noland <pnoland@chromium.org>
Commit-Queue: who/bttk <bttk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#814529}
parent b7edca7e
...@@ -12,6 +12,7 @@ import android.graphics.Rect; ...@@ -12,6 +12,7 @@ import android.graphics.Rect;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.TouchDelegate; import android.view.TouchDelegate;
import android.view.View; import android.view.View;
import android.widget.FrameLayout;
import org.chromium.base.TraceEvent; import org.chromium.base.TraceEvent;
import org.chromium.chrome.R; import org.chromium.chrome.R;
...@@ -23,7 +24,7 @@ import java.util.List; ...@@ -23,7 +24,7 @@ import java.util.List;
/** /**
* A location bar implementation specific for smaller/phone screens. * A location bar implementation specific for smaller/phone screens.
*/ */
public class LocationBarPhone extends LocationBarLayout { public class LocationBarPhone extends LocationBarLayout implements LocationBar.Phone {
private static final int ACTION_BUTTON_TOUCH_OVERFLOW_LEFT = 15; private static final int ACTION_BUTTON_TOUCH_OVERFLOW_LEFT = 15;
private View mFirstVisibleFocusedView; private View mFirstVisibleFocusedView;
...@@ -94,6 +95,7 @@ public class LocationBarPhone extends LocationBarLayout { ...@@ -94,6 +95,7 @@ public class LocationBarPhone extends LocationBarLayout {
* @return Width of child views before the first view that would be visible when location bar is * @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. * focused. The first visible, focused view should be either url bar or status icon.
*/ */
@Override
public int getOffsetOfFirstVisibleFocusedView() { public int getOffsetOfFirstVisibleFocusedView() {
int visibleWidth = 0; int visibleWidth = 0;
for (int i = 0; i < getChildCount(); i++) { for (int i = 0; i < getChildCount(); i++) {
...@@ -112,6 +114,7 @@ public class LocationBarPhone extends LocationBarLayout { ...@@ -112,6 +114,7 @@ public class LocationBarPhone extends LocationBarLayout {
* @param durationMs Duration of fade animation in milliseconds. * @param durationMs Duration of fade animation in milliseconds.
* @param targetAlpha Target alpha value. * @param targetAlpha Target alpha value.
*/ */
@Override
public void populateFadeAnimations( public void populateFadeAnimations(
List<Animator> animators, long startDelayMs, long durationMs, float targetAlpha) { List<Animator> animators, long startDelayMs, long durationMs, float targetAlpha) {
for (int i = 0; i < getChildCount(); i++) { for (int i = 0; i < getChildCount(); i++) {
...@@ -133,6 +136,7 @@ public class LocationBarPhone extends LocationBarLayout { ...@@ -133,6 +136,7 @@ public class LocationBarPhone extends LocationBarLayout {
* animation starting and the unfocus animation starting. * animation starting and the unfocus animation starting.
* @return The offset for the location bar when showing the dse icon. * @return The offset for the location bar when showing the dse icon.
*/ */
@Override
public int getLocationBarOffsetForFocusAnimation(boolean hasFocus) { public int getLocationBarOffsetForFocusAnimation(boolean hasFocus) {
if (mStatusCoordinator == null) return 0; if (mStatusCoordinator == null) return 0;
...@@ -166,6 +170,7 @@ public class LocationBarPhone extends LocationBarLayout { ...@@ -166,6 +170,7 @@ public class LocationBarPhone extends LocationBarLayout {
* animation starting and the unfocus animation starting. * animation starting and the unfocus animation starting.
* @return The X translation for the URL bar, used in the toolbar animation. * @return The X translation for the URL bar, used in the toolbar animation.
*/ */
@Override
public float getUrlBarTranslationXForToolbarAnimation( public float getUrlBarTranslationXForToolbarAnimation(
float urlExpansionPercent, boolean hasFocus) { float urlExpansionPercent, boolean hasFocus) {
// This will be called before status view is ready. // This will be called before status view is ready.
...@@ -277,6 +282,11 @@ public class LocationBarPhone extends LocationBarLayout { ...@@ -277,6 +282,11 @@ public class LocationBarPhone extends LocationBarLayout {
mStatusCoordinator.onUrlAnimationFinished(hasFocus); mStatusCoordinator.onUrlAnimationFinished(hasFocus);
} }
@Override
public FrameLayout.LayoutParams getFrameLayoutParams() {
return (FrameLayout.LayoutParams) getLayoutParams();
}
@Override @Override
protected void updateButtonVisibility() { protected void updateButtonVisibility() {
super.updateButtonVisibility(); super.updateButtonVisibility();
...@@ -328,6 +338,11 @@ public class LocationBarPhone extends LocationBarLayout { ...@@ -328,6 +338,11 @@ public class LocationBarPhone extends LocationBarLayout {
} }
} }
@Override
public View getViewForDrawing() {
return this;
}
/** Update the status visibility according to the current state held in LocationBar. */ /** Update the status visibility according to the current state held in LocationBar. */
private void updateStatusVisibility() { private void updateStatusVisibility() {
boolean incognito = getToolbarDataProvider().isIncognito(); boolean incognito = getToolbarDataProvider().isIncognito();
......
...@@ -29,7 +29,7 @@ import java.util.List; ...@@ -29,7 +29,7 @@ import java.util.List;
/** /**
* Location bar for tablet form factors. * Location bar for tablet form factors.
*/ */
public class LocationBarTablet extends LocationBarLayout { public class LocationBarTablet extends LocationBarLayout implements LocationBar.Tablet {
private static final long MAX_NTP_KEYBOARD_FOCUS_DURATION_MS = 200; private static final long MAX_NTP_KEYBOARD_FOCUS_DURATION_MS = 200;
private static final int ICON_FADE_ANIMATION_DURATION_MS = 150; private static final int ICON_FADE_ANIMATION_DURATION_MS = 150;
...@@ -187,6 +187,7 @@ public class LocationBarTablet extends LocationBarLayout { ...@@ -187,6 +187,7 @@ public class LocationBarTablet extends LocationBarLayout {
* @param shouldShowButtons Whether buttons should be displayed in the URL bar when it's not * @param shouldShowButtons Whether buttons should be displayed in the URL bar when it's not
* focused. * focused.
*/ */
@Override
public void setShouldShowButtonsWhenUnfocused(boolean shouldShowButtons) { public void setShouldShowButtonsWhenUnfocused(boolean shouldShowButtons) {
mShouldShowButtonsWhenUnfocused = shouldShowButtons; mShouldShowButtonsWhenUnfocused = shouldShowButtons;
updateButtonVisibility(); updateButtonVisibility();
...@@ -267,6 +268,7 @@ public class LocationBarTablet extends LocationBarLayout { ...@@ -267,6 +268,7 @@ public class LocationBarTablet extends LocationBarLayout {
* @return An animator to run for the given view when showing buttons in the unfocused location * @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. * bar. This should also be used to create animators for showing toolbar buttons.
*/ */
@Override
public ObjectAnimator createShowButtonAnimator(View button) { public ObjectAnimator createShowButtonAnimator(View button) {
if (button.getVisibility() != View.VISIBLE) { if (button.getVisibility() != View.VISIBLE) {
button.setAlpha(0.f); button.setAlpha(0.f);
...@@ -283,6 +285,7 @@ public class LocationBarTablet extends LocationBarLayout { ...@@ -283,6 +285,7 @@ public class LocationBarTablet extends LocationBarLayout {
* @return An animator to run for the given view when hiding buttons in the unfocused location * @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. * bar. This should also be used to create animators for hiding toolbar buttons.
*/ */
@Override
public ObjectAnimator createHideButtonAnimator(View button) { public ObjectAnimator createHideButtonAnimator(View button) {
ObjectAnimator buttonAnimator = ObjectAnimator.ofFloat(button, View.ALPHA, 0.f); ObjectAnimator buttonAnimator = ObjectAnimator.ofFloat(button, View.ALPHA, 0.f);
buttonAnimator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE); buttonAnimator.setInterpolator(BakedBezierInterpolator.FADE_OUT_CURVE);
...@@ -299,6 +302,7 @@ public class LocationBarTablet extends LocationBarLayout { ...@@ -299,6 +302,7 @@ public class LocationBarTablet extends LocationBarLayout {
* the beginning and end of the animation. * the beginning and end of the animation.
* @return An ArrayList of animators to run. * @return An ArrayList of animators to run.
*/ */
@Override
public List<Animator> getShowButtonsWhenUnfocusedAnimators(int toolbarStartPaddingDifference) { public List<Animator> getShowButtonsWhenUnfocusedAnimators(int toolbarStartPaddingDifference) {
mToolbarStartPaddingDifference = toolbarStartPaddingDifference; mToolbarStartPaddingDifference = toolbarStartPaddingDifference;
...@@ -353,6 +357,7 @@ public class LocationBarTablet extends LocationBarLayout { ...@@ -353,6 +357,7 @@ public class LocationBarTablet extends LocationBarLayout {
* the beginning and end of the animation. * the beginning and end of the animation.
* @return An ArrayList of animators to run. * @return An ArrayList of animators to run.
*/ */
@Override
public List<Animator> getHideButtonsWhenUnfocusedAnimators(int toolbarStartPaddingDifference) { public List<Animator> getHideButtonsWhenUnfocusedAnimators(int toolbarStartPaddingDifference) {
mToolbarStartPaddingDifference = toolbarStartPaddingDifference; mToolbarStartPaddingDifference = toolbarStartPaddingDifference;
......
...@@ -32,7 +32,6 @@ import org.chromium.chrome.browser.download.DownloadUtils; ...@@ -32,7 +32,6 @@ import org.chromium.chrome.browser.download.DownloadUtils;
import org.chromium.chrome.browser.homepage.HomepageManager; import org.chromium.chrome.browser.homepage.HomepageManager;
import org.chromium.chrome.browser.ntp.NewTabPage; import org.chromium.chrome.browser.ntp.NewTabPage;
import org.chromium.chrome.browser.omnibox.LocationBar; import org.chromium.chrome.browser.omnibox.LocationBar;
import org.chromium.chrome.browser.omnibox.LocationBarTablet;
import org.chromium.chrome.browser.preferences.ChromePreferenceKeys; import org.chromium.chrome.browser.preferences.ChromePreferenceKeys;
import org.chromium.chrome.browser.preferences.SharedPreferencesManager; import org.chromium.chrome.browser.preferences.SharedPreferencesManager;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
...@@ -85,7 +84,8 @@ public class ToolbarTablet extends ToolbarLayout ...@@ -85,7 +84,8 @@ public class ToolbarTablet extends ToolbarLayout
private NavigationPopup mNavigationPopup; private NavigationPopup mNavigationPopup;
private Boolean mIsIncognito; private Boolean mIsIncognito;
private LocationBarTablet mLocationBar; private LocationBar mLocationBar;
private LocationBar.Tablet mLocationBarTablet;
private final int mStartPaddingWithButtons; private final int mStartPaddingWithButtons;
private final int mStartPaddingWithoutButtons; private final int mStartPaddingWithoutButtons;
...@@ -110,7 +110,8 @@ public class ToolbarTablet extends ToolbarLayout ...@@ -110,7 +110,8 @@ public class ToolbarTablet extends ToolbarLayout
@Override @Override
public void onFinishInflate() { public void onFinishInflate() {
super.onFinishInflate(); super.onFinishInflate();
mLocationBar = (LocationBarTablet) findViewById(R.id.location_bar); mLocationBar = (LocationBar) findViewById(R.id.location_bar);
mLocationBarTablet = (LocationBar.Tablet) mLocationBar;
mHomeButton = findViewById(R.id.home_button); mHomeButton = findViewById(R.id.home_button);
mBackButton = findViewById(R.id.back_button); mBackButton = findViewById(R.id.back_button);
...@@ -391,7 +392,7 @@ public class ToolbarTablet extends ToolbarLayout ...@@ -391,7 +392,7 @@ public class ToolbarTablet extends ToolbarLayout
setBackgroundColor(color); setBackgroundColor(color);
final int textBoxColor = ToolbarColors.getTextBoxColorForToolbarBackgroundInNonNativePage( final int textBoxColor = ToolbarColors.getTextBoxColorForToolbarBackgroundInNonNativePage(
getResources(), color, isIncognito()); getResources(), color, isIncognito());
mLocationBar.getBackground().setColorFilter(textBoxColor, PorterDuff.Mode.SRC_IN); mLocationBarTablet.getBackground().setColorFilter(textBoxColor, PorterDuff.Mode.SRC_IN);
mLocationBar.updateVisualsForState(); mLocationBar.updateVisualsForState();
} }
...@@ -428,7 +429,7 @@ public class ToolbarTablet extends ToolbarLayout ...@@ -428,7 +429,7 @@ public class ToolbarTablet extends ToolbarLayout
@Override @Override
void updateButtonVisibility() { void updateButtonVisibility() {
mLocationBar.updateButtonVisibility(); mLocationBarTablet.updateButtonVisibility();
} }
@Override @Override
...@@ -616,7 +617,7 @@ public class ToolbarTablet extends ToolbarLayout ...@@ -616,7 +617,7 @@ public class ToolbarTablet extends ToolbarLayout
for (ImageButton button : mToolbarButtons) { for (ImageButton button : mToolbarButtons) {
button.setVisibility(visible ? View.VISIBLE : View.GONE); button.setVisibility(visible ? View.VISIBLE : View.GONE);
} }
mLocationBar.setShouldShowButtonsWhenUnfocused(visible); mLocationBarTablet.setShouldShowButtonsWhenUnfocused(visible);
setStartPaddingBasedOnButtonVisibility(visible); setStartPaddingBasedOnButtonVisibility(visible);
} }
} }
...@@ -657,11 +658,11 @@ public class ToolbarTablet extends ToolbarLayout ...@@ -657,11 +658,11 @@ public class ToolbarTablet extends ToolbarLayout
// Create animators for all of the toolbar buttons. // Create animators for all of the toolbar buttons.
for (ImageButton button : mToolbarButtons) { for (ImageButton button : mToolbarButtons) {
animators.add(mLocationBar.createShowButtonAnimator(button)); animators.add(mLocationBarTablet.createShowButtonAnimator(button));
} }
// Add animators for location bar. // Add animators for location bar.
animators.addAll(mLocationBar.getShowButtonsWhenUnfocusedAnimators( animators.addAll(mLocationBarTablet.getShowButtonsWhenUnfocusedAnimators(
getStartPaddingDifferenceForButtonVisibilityAnimation())); getStartPaddingDifferenceForButtonVisibilityAnimation()));
AnimatorSet set = new AnimatorSet(); AnimatorSet set = new AnimatorSet();
...@@ -692,11 +693,11 @@ public class ToolbarTablet extends ToolbarLayout ...@@ -692,11 +693,11 @@ public class ToolbarTablet extends ToolbarLayout
// Create animators for all of the toolbar buttons. // Create animators for all of the toolbar buttons.
for (ImageButton button : mToolbarButtons) { for (ImageButton button : mToolbarButtons) {
animators.add(mLocationBar.createHideButtonAnimator(button)); animators.add(mLocationBarTablet.createHideButtonAnimator(button));
} }
// Add animators for location bar. // Add animators for location bar.
animators.addAll(mLocationBar.getHideButtonsWhenUnfocusedAnimators( animators.addAll(mLocationBarTablet.getHideButtonsWhenUnfocusedAnimators(
getStartPaddingDifferenceForButtonVisibilityAnimation())); getStartPaddingDifferenceForButtonVisibilityAnimation()));
AnimatorSet set = new AnimatorSet(); AnimatorSet set = new AnimatorSet();
......
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