Commit 7915ff17 authored by bttk's avatar bttk Committed by Commit Bot

[ToolbarMVC] Remove unnecessary LocationBar methods

These methods are only called on LocationBarCoordinator and have no
effect on CustomTabToolbar.

Change-Id: I4af4c32d8aadfdade5d5c4c04faa31c90abe63dd
Bug: 1133482
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2464085Reviewed-by: default avatarPeter Conn <peconn@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@{#817520}
parent facc74dc
...@@ -49,9 +49,7 @@ import org.chromium.chrome.R; ...@@ -49,9 +49,7 @@ import org.chromium.chrome.R;
import org.chromium.chrome.browser.ActivityTabProvider; import org.chromium.chrome.browser.ActivityTabProvider;
import org.chromium.chrome.browser.WindowDelegate; import org.chromium.chrome.browser.WindowDelegate;
import org.chromium.chrome.browser.app.ChromeActivity; import org.chromium.chrome.browser.app.ChromeActivity;
import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior;
import org.chromium.chrome.browser.native_page.NativePageFactory; import org.chromium.chrome.browser.native_page.NativePageFactory;
import org.chromium.chrome.browser.ntp.NewTabPage;
import org.chromium.chrome.browser.offlinepages.OfflinePageUtils; import org.chromium.chrome.browser.offlinepages.OfflinePageUtils;
import org.chromium.chrome.browser.omnibox.LocationBar; import org.chromium.chrome.browser.omnibox.LocationBar;
import org.chromium.chrome.browser.omnibox.UrlBar; import org.chromium.chrome.browser.omnibox.UrlBar;
...@@ -864,18 +862,9 @@ public class CustomTabToolbar extends ToolbarLayout implements View.OnLongClickL ...@@ -864,18 +862,9 @@ public class CustomTabToolbar extends ToolbarLayout implements View.OnLongClickL
@Override @Override
public void updateMicButtonState() {} public void updateMicButtonState() {}
@Override
public void onTabLoadingNTP(NewTabPage ntp) {}
@Override @Override
public void setProfileSupplier(ObservableSupplier<Profile> profileSupplier) {} public void setProfileSupplier(ObservableSupplier<Profile> profileSupplier) {}
@Override
public void setUnfocusedWidth(int unfocusedWidth) {}
@Override
public void setOverviewModeBehavior(OverviewModeBehavior overviewModeBehavior) {}
// Implements FakeBoxDelegate. // Implements FakeBoxDelegate.
@Override @Override
public boolean isUrlBarFocused() { public boolean isUrlBarFocused() {
...@@ -889,9 +878,6 @@ public class CustomTabToolbar extends ToolbarLayout implements View.OnLongClickL ...@@ -889,9 +878,6 @@ public class CustomTabToolbar extends ToolbarLayout implements View.OnLongClickL
public void setUrlBarFocus(boolean shouldBeFocused, @Nullable String pastedText, public void setUrlBarFocus(boolean shouldBeFocused, @Nullable String pastedText,
@LocationBar.OmniboxFocusReason int reason) {} @LocationBar.OmniboxFocusReason int reason) {}
@Override
public void setUrlFocusChangeFraction(float fraction) {}
@Override @Override
public boolean isCurrentPage(NativePage nativePage) { public boolean isCurrentPage(NativePage nativePage) {
return false; return false;
......
...@@ -15,7 +15,6 @@ import org.chromium.base.supplier.ObservableSupplier; ...@@ -15,7 +15,6 @@ import org.chromium.base.supplier.ObservableSupplier;
import org.chromium.base.supplier.Supplier; import org.chromium.base.supplier.Supplier;
import org.chromium.chrome.browser.ActivityTabProvider; import org.chromium.chrome.browser.ActivityTabProvider;
import org.chromium.chrome.browser.WindowDelegate; 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.lifecycle.Destroyable;
import org.chromium.chrome.browser.ntp.FakeboxDelegate; import org.chromium.chrome.browser.ntp.FakeboxDelegate;
import org.chromium.chrome.browser.ntp.NewTabPage; import org.chromium.chrome.browser.ntp.NewTabPage;
...@@ -66,20 +65,14 @@ public interface LocationBar extends UrlBarDelegate, FakeboxDelegate, Destroyabl ...@@ -66,20 +65,14 @@ public interface LocationBar extends UrlBarDelegate, FakeboxDelegate, Destroyabl
int NUM_ENTRIES = 14; int NUM_ENTRIES = 14;
} }
/** /** Handle all necessary tasks that can be delayed until initialization completes. */
* Handle all necessary tasks that can be delayed until initialization completes.
*/
default void onDeferredStartup() {} default void onDeferredStartup() {}
/** /** Handles native dependent initialization for this class. */
* Handles native dependent initialization for this class.
*/
void onNativeLibraryReady(); void onNativeLibraryReady();
/** /** Triggered when the current tab has changed to a {@link NewTabPage}. */
* Triggered when the current tab has changed to a {@link NewTabPage}. default void onTabLoadingNTP(NewTabPage ntp){};
*/
void onTabLoadingNTP(NewTabPage ntp);
/** /**
* Call to force the UI to update the state of various buttons based on whether or not the * Call to force the UI to update the state of various buttons based on whether or not the
...@@ -87,13 +80,6 @@ public interface LocationBar extends UrlBarDelegate, FakeboxDelegate, Destroyabl ...@@ -87,13 +80,6 @@ public interface LocationBar extends UrlBarDelegate, FakeboxDelegate, Destroyabl
*/ */
void updateVisualsForState(); void updateVisualsForState();
/**
* Updates progress of current the URL focus change animation.
*
* @param fraction 1.0 is 100% focused, 0 is completely unfocused.
*/
void setUrlFocusChangeFraction(float fraction);
/** /**
* Sets the displayed URL to be the URL of the page currently showing. * Sets the displayed URL to be the URL of the page currently showing.
* *
...@@ -103,40 +89,32 @@ public interface LocationBar extends UrlBarDelegate, FakeboxDelegate, Destroyabl ...@@ -103,40 +89,32 @@ public interface LocationBar extends UrlBarDelegate, FakeboxDelegate, Destroyabl
*/ */
void setUrlToPageUrl(); void setUrlToPageUrl();
/** /** Sets the displayed title to the page title. */
* Sets the displayed title to the page title.
*/
void setTitleToPageTitle(); void setTitleToPageTitle();
/** /**
* Sets whether the location bar should have a layout showing a title. * Sets whether the location bar should have a layout showing a title.
*
* @param showTitle Whether the title should be shown. * @param showTitle Whether the title should be shown.
*/ */
void setShowTitle(boolean showTitle); void setShowTitle(boolean showTitle);
/** /**
* Update the visuals based on a loading state change. * Update the visuals based on a loading state change.
*
* @param updateUrl Whether to update the URL as a result of the this call. * @param updateUrl Whether to update the URL as a result of the this call.
*/ */
void updateLoadingState(boolean updateUrl); void updateLoadingState(boolean updateUrl);
/** /** Sets the {@link ToolbarDataProvider} to be used for accessing {@link Toolbar} state. */
* Sets the {@link ToolbarDataProvider} to be used for accessing {@link Toolbar} state.
*/
void setToolbarDataProvider(ToolbarDataProvider model); void setToolbarDataProvider(ToolbarDataProvider model);
/** /** Gets the {@link ToolbarDataProvider} to be used for accessing {@link Toolbar} state. */
* Sets the {@link OverviewModeBehavior}.
*/
void setOverviewModeBehavior(OverviewModeBehavior overviewModeBehavior);
/**
* Gets the {@link ToolbarDataProvider} to be used for accessing {@link Toolbar} state.
*/
ToolbarDataProvider getToolbarDataProvider(); ToolbarDataProvider getToolbarDataProvider();
/** /**
* Initialize controls that will act as hooks to various functions. * Initialize controls that will act as hooks to various functions.
*
* @param windowDelegate {@link WindowDelegate} that will provide {@link Window} related info. * @param windowDelegate {@link WindowDelegate} that will provide {@link Window} related info.
* @param windowAndroid {@link WindowAndroid} that is used by the owning {@link Activity}. * @param windowAndroid {@link WindowAndroid} that is used by the owning {@link Activity}.
* @param activityTabProvider An {@link ActivityTabProvider} to access the activity's current * @param activityTabProvider An {@link ActivityTabProvider} to access the activity's current
...@@ -155,14 +133,12 @@ public interface LocationBar extends UrlBarDelegate, FakeboxDelegate, Destroyabl ...@@ -155,14 +133,12 @@ public interface LocationBar extends UrlBarDelegate, FakeboxDelegate, Destroyabl
/** /**
* Triggers the cursor to be visible in the UrlBar without triggering any of the focus animation * Triggers the cursor to be visible in the UrlBar without triggering any of the focus animation
* logic. * logic.
* <p> *
* Only applies to devices with a hardware keyboard attached. * <p>Only applies to devices with a hardware keyboard attached.
*/ */
void showUrlBarCursorWithoutFocusAnimations(); void showUrlBarCursorWithoutFocusAnimations();
/** /** Selects all of the editable text in the {@link UrlBar}. */
* Selects all of the editable text in the UrlBar.
*/
void selectAll(); void selectAll();
/** /**
...@@ -171,14 +147,10 @@ public interface LocationBar extends UrlBarDelegate, FakeboxDelegate, Destroyabl ...@@ -171,14 +147,10 @@ public interface LocationBar extends UrlBarDelegate, FakeboxDelegate, Destroyabl
*/ */
void revertChanges(); void revertChanges();
/** /** Updates the security icon displayed in the LocationBar. */
* Updates the security icon displayed in the LocationBar.
*/
void updateStatusIcon(); void updateStatusIcon();
/** /** Returns {@link ViewGroup} that this container holds. */
* @return The {@link ViewGroup} that this container holds.
*/
View getContainerView(); View getContainerView();
/** /**
...@@ -189,34 +161,16 @@ public interface LocationBar extends UrlBarDelegate, FakeboxDelegate, Destroyabl ...@@ -189,34 +161,16 @@ public interface LocationBar extends UrlBarDelegate, FakeboxDelegate, Destroyabl
*/ */
View getSecurityIconView(); View getSecurityIconView();
/** /** Updates the state of the mic button if there is one. */
* Updates the state of the mic button if there is one.
*/
void updateMicButtonState(); void updateMicButtonState();
/** /** Sets the callback to be used by default for text editing action bar. */
* Sets the callback to be used by default for text editing action bar.
* @param callback The callback to use.
*/
void setDefaultTextEditActionModeCallback(ToolbarActionModeCallback callback); void setDefaultTextEditActionModeCallback(ToolbarActionModeCallback callback);
/**
* Called to set the width of the location bar when the url bar is not focused.
*
* Immediately after the animation to transition the URL bar from focused to unfocused finishes,
* the layout width returned from #getMeasuredWidth() can differ from the final unfocused width
* (e.g. this value) until the next layout pass is complete.
*
* This value may be used to determine whether optional child views should be visible in the
* unfocused location bar.
*
* @param unfocusedWidth The unfocused location bar width.
*/
void setUnfocusedWidth(int unfocusedWidth);
/** /**
* Sets the (observable) supplier of the active profile. This supplier will notify observers of * Sets the (observable) supplier of the active profile. This supplier will notify observers of
* changes to the active profile, e.g. when selecting an incognito tab model. * changes to the active profile, e.g. when selecting an incognito tab model.
*
* @param profileSupplier The supplier of the active profile. * @param profileSupplier The supplier of the active profile.
*/ */
void setProfileSupplier(ObservableSupplier<Profile> profileSupplier); void setProfileSupplier(ObservableSupplier<Profile> profileSupplier);
......
...@@ -73,30 +73,6 @@ public final class LocationBarCoordinator implements LocationBar { ...@@ -73,30 +73,6 @@ public final class LocationBarCoordinator implements LocationBar {
} }
} }
/**
* 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 @Override
public void destroy() { public void destroy() {
if (mSubCoordinator != null) { if (mSubCoordinator != null) {
...@@ -129,11 +105,6 @@ public final class LocationBarCoordinator implements LocationBar { ...@@ -129,11 +105,6 @@ public final class LocationBarCoordinator implements LocationBar {
mLocationBarLayout.updateVisualsForState(); mLocationBarLayout.updateVisualsForState();
} }
@Override
public void setUrlFocusChangeFraction(float fraction) {
mLocationBarLayout.setUrlFocusChangeFraction(fraction);
}
@Override @Override
public void setUrlToPageUrl() { public void setUrlToPageUrl() {
mLocationBarLayout.setUrlToPageUrl(); mLocationBarLayout.setUrlToPageUrl();
...@@ -159,11 +130,6 @@ public final class LocationBarCoordinator implements LocationBar { ...@@ -159,11 +130,6 @@ public final class LocationBarCoordinator implements LocationBar {
mLocationBarLayout.setToolbarDataProvider(dataProvider); mLocationBarLayout.setToolbarDataProvider(dataProvider);
} }
@Override
public void setOverviewModeBehavior(OverviewModeBehavior overviewModeBehavior) {
mLocationBarLayout.setOverviewModeBehavior(overviewModeBehavior);
}
@Override @Override
public ToolbarDataProvider getToolbarDataProvider() { public ToolbarDataProvider getToolbarDataProvider() {
return mLocationBarLayout.getToolbarDataProvider(); return mLocationBarLayout.getToolbarDataProvider();
...@@ -219,11 +185,6 @@ public final class LocationBarCoordinator implements LocationBar { ...@@ -219,11 +185,6 @@ public final class LocationBarCoordinator implements LocationBar {
mLocationBarLayout.setDefaultTextEditActionModeCallback(callback); mLocationBarLayout.setDefaultTextEditActionModeCallback(callback);
} }
@Override
public void setUnfocusedWidth(int unfocusedWidth) {
mLocationBarLayout.setUnfocusedWidth(unfocusedWidth);
}
@Override @Override
public void setProfileSupplier(ObservableSupplier<Profile> profileSupplier) { public void setProfileSupplier(ObservableSupplier<Profile> profileSupplier) {
mLocationBarLayout.setProfileSupplier(profileSupplier); mLocationBarLayout.setProfileSupplier(profileSupplier);
...@@ -294,4 +255,58 @@ public final class LocationBarCoordinator implements LocationBar { ...@@ -294,4 +255,58 @@ public final class LocationBarCoordinator implements LocationBar {
public void removeUrlFocusChangeListener(UrlFocusChangeListener listener) { public void removeUrlFocusChangeListener(UrlFocusChangeListener listener) {
mLocationBarLayout.removeUrlFocusChangeListener(listener); mLocationBarLayout.removeUrlFocusChangeListener(listener);
} }
/**
* 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;
}
/** Sets the {@link OverviewModeBehavior}. */
public void setOverviewModeBehavior(OverviewModeBehavior overviewModeBehavior) {
mLocationBarLayout.setOverviewModeBehavior(overviewModeBehavior);
}
/**
* Updates progress of current the URL focus change animation.
*
* @param fraction 1.0 is 100% focused, 0 is completely unfocused.
*/
public void setUrlFocusChangeFraction(float fraction) {
mLocationBarLayout.setUrlFocusChangeFraction(fraction);
}
/**
* Called to set the width of the location bar when the url bar is not focused.
*
* <p>Immediately after the animation to transition the URL bar from focused to unfocused
* finishes, the layout width returned from #getMeasuredWidth() can differ from the final
* unfocused width (e.g. this value) until the next layout pass is complete.
*
* <p>This value may be used to determine whether optional child views should be visible in the
* unfocused location bar.
*
* @param unfocusedWidth The unfocused location bar width.
*/
public void setUnfocusedWidth(int unfocusedWidth) {
mLocationBarLayout.setUnfocusedWidth(unfocusedWidth);
}
} }
...@@ -346,24 +346,11 @@ public class LocationBarLayout extends FrameLayout ...@@ -346,24 +346,11 @@ public class LocationBarLayout extends FrameLayout
mStatusCoordinator.setModalDialogManagerSupplier(modalDialogManagerSupplier); mStatusCoordinator.setModalDialogManagerSupplier(modalDialogManagerSupplier);
} }
/**
* @param focusable Whether the url bar should be focusable.
*/
public void setUrlBarFocusable(boolean focusable) {
if (mUrlCoordinator == null) return;
mUrlCoordinator.setAllowFocus(focusable);
}
@Override @Override
public AutocompleteCoordinator getAutocompleteCoordinator() { public AutocompleteCoordinator getAutocompleteCoordinator() {
return mAutocompleteCoordinator; return mAutocompleteCoordinator;
} }
@Override
public void setOverviewModeBehavior(OverviewModeBehavior overviewModeBehavior) {
mAutocompleteCoordinator.setOverviewModeBehavior(overviewModeBehavior);
}
@Override @Override
public void onDeferredStartup() { public void onDeferredStartup() {
mAutocompleteCoordinator.prefetchZeroSuggestResults(); mAutocompleteCoordinator.prefetchZeroSuggestResults();
...@@ -402,61 +389,6 @@ public class LocationBarLayout extends FrameLayout ...@@ -402,61 +389,6 @@ public class LocationBarLayout extends FrameLayout
setProfile(mProfileSupplier.get()); setProfile(mProfileSupplier.get());
} }
@Override
@CallSuper
public void setUrlFocusChangeFraction(float fraction) {
mUrlFocusChangeFraction = fraction;
}
private void registerTemplateUrlObserver() {
final TemplateUrlService templateUrlService = TemplateUrlServiceFactory.get();
assert mTemplateUrlObserver == null;
mTemplateUrlObserver = new TemplateUrlServiceObserver() {
private TemplateUrl mSearchEngine =
templateUrlService.getDefaultSearchEngineTemplateUrl();
@Override
public void onTemplateURLServiceChanged() {
TemplateUrl searchEngine = templateUrlService.getDefaultSearchEngineTemplateUrl();
if ((mSearchEngine == null && searchEngine == null)
|| (mSearchEngine != null && mSearchEngine.equals(searchEngine))) {
return;
}
mSearchEngine = searchEngine;
updateSearchEngineStatusIcon(SearchEngineLogoUtils.shouldShowSearchEngineLogo(
mToolbarDataProvider.isIncognito()),
TemplateUrlServiceFactory.get().isDefaultSearchEngineGoogle(),
SearchEngineLogoUtils.getSearchLogoUrl());
}
};
templateUrlService.addObserver(mTemplateUrlObserver);
// Force an update once to populate initial data.
updateSearchEngineStatusIcon(SearchEngineLogoUtils.shouldShowSearchEngineLogo(
mToolbarDataProvider.isIncognito()),
TemplateUrlServiceFactory.get().isDefaultSearchEngineGoogle(),
SearchEngineLogoUtils.getSearchLogoUrl());
}
/**
* Evaluate state and update child components' animations.
*
* This call and all overrides should invoke `notifyShouldAnimateIconChanges(boolean)` with a
* computed boolean value toggling animation support in child components.
*/
protected void updateShouldAnimateIconChanges() {
notifyShouldAnimateIconChanges(mUrlHasFocus);
}
/**
* Toggle child components animations.
* @param shouldAnimate Boolean flag indicating whether animations should be enabled.
*/
protected void notifyShouldAnimateIconChanges(boolean shouldAnimate) {
mStatusCoordinator.setShouldAnimateIconChanges(shouldAnimate);
}
@Override @Override
public void setProfileSupplier(ObservableSupplier<Profile> profileSupplier) { public void setProfileSupplier(ObservableSupplier<Profile> profileSupplier) {
assert profileSupplier != null; assert profileSupplier != null;
...@@ -466,28 +398,6 @@ public class LocationBarLayout extends FrameLayout ...@@ -466,28 +398,6 @@ public class LocationBarLayout extends FrameLayout
mProfileSupplier.addObserver(mProfileSupplierObserver); mProfileSupplier.addObserver(mProfileSupplierObserver);
} }
/**
* Updates the profile used by this LocationBar, for, e.g. determining incognito status or
* generating autocomplete suggestions..
* @param profile The profile to be used.
*/
private void setProfile(Profile profile) {
if (profile == null || !mNativeInitialized) return;
mAutocompleteCoordinator.setAutocompleteProfile(profile);
mOmniboxPrerender.initializeForProfile(profile);
setShowIconsWhenUrlFocused(
SearchEngineLogoUtils.shouldShowSearchEngineLogo(profile.isOffTheRecord()));
}
/** Focuses the current page. */
private void focusCurrentTab() {
if (mToolbarDataProvider.hasTab()) {
View view = getCurrentTab().getView();
if (view != null) view.requestFocus();
}
}
@Override @Override
public void clearOmniboxFocus() { public void clearOmniboxFocus() {
setUrlBarFocus(false, null, LocationBar.OmniboxFocusReason.UNFOCUS); setUrlBarFocus(false, null, LocationBar.OmniboxFocusReason.UNFOCUS);
...@@ -514,132 +424,6 @@ public class LocationBarLayout extends FrameLayout ...@@ -514,132 +424,6 @@ public class LocationBarLayout extends FrameLayout
} }
} }
/**
* @return Whether the URL focus change is taking place, e.g. a focus animation is running on
* a phone device.
*/
public boolean isUrlFocusChangeInProgress() {
return mUrlFocusChangeInProgress;
}
/**
* Specify whether location bar should present icons when focused.
* @param showIcon True if we should show the icons when the url is focused.
*/
protected void setShowIconsWhenUrlFocused(boolean showIcon) {}
/**
* @param inProgress Whether a URL focus change is taking place.
*/
protected void setUrlFocusChangeInProgress(boolean inProgress) {
mUrlFocusChangeInProgress = inProgress;
if (!inProgress) {
updateButtonVisibility();
// The accessibility bounding box is not properly updated when focusing the Omnibox
// from the NTP fakebox. Clearing/re-requesting focus triggers the bounding box to
// be recalculated.
if (didFocusUrlFromFakebox() && mUrlHasFocus
&& ChromeAccessibilityUtil.get().isAccessibilityEnabled()) {
String existingText = mUrlCoordinator.getTextWithoutAutocomplete();
mUrlBar.clearFocus();
mUrlBar.requestFocus();
// Existing text (e.g. if the user pasted via the fakebox) from the fake box
// should be restored after toggling the focus.
if (!TextUtils.isEmpty(existingText)) {
mUrlCoordinator.setUrlBarData(UrlBarData.forNonUrlText(existingText),
UrlBar.ScrollType.NO_SCROLL,
UrlBarCoordinator.SelectionState.SELECT_END);
forceOnTextChanged();
}
}
for (UrlFocusChangeListener listener : mUrlFocusChangeListeners) {
listener.onUrlAnimationFinished(mUrlHasFocus);
}
}
}
/**
* Triggered when the URL input field has gained or lost focus.
* @param hasFocus Whether the URL field has gained focus.
*/
protected void onUrlFocusChange(boolean hasFocus) {
mUrlHasFocus = hasFocus;
updateButtonVisibility();
updateShouldAnimateIconChanges();
if (mUrlHasFocus) {
mKeyboardShouldShow = false;
if (mNativeInitialized) RecordUserAction.record("FocusLocation");
UrlBarData urlBarData = mToolbarDataProvider.getUrlBarData();
if (urlBarData.editingText != null) {
setUrlBarText(urlBarData, UrlBar.ScrollType.NO_SCROLL, SelectionState.SELECT_ALL);
}
// Explicitly tell InputMethodManager that the url bar is focused before any callbacks
// so that it updates the active view accordingly. Otherwise, it may fail to update
// the correct active view if ViewGroup.addView() or ViewGroup.removeView() is called
// to update a view that accepts text input.
InputMethodManager imm = (InputMethodManager) mUrlBar.getContext().getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.viewClicked(mUrlBar);
} else {
mUrlFocusedFromFakebox = false;
mUrlFocusedFromQueryTiles = false;
mUrlFocusedWithoutAnimations = false;
// Focus change caused by a close-tab may result in an invalid current tab.
if (mToolbarDataProvider.hasTab()) {
setUrlToPageUrl();
}
// Moving focus away from UrlBar(EditText) to a non-editable focus holder, such as
// ToolbarPhone, won't automatically hide keyboard app, but restart it with TYPE_NULL,
// which will result in a visual glitch. Also, currently, we do not allow moving focus
// directly from omnibox to web content's form field. Therefore, we hide keyboard on
// focus blur indiscriminately here. Note that hiding keyboard may lower FPS of other
// animation effects, but we found it tolerable in an experiment.
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(
Context.INPUT_METHOD_SERVICE);
if (imm.isActive(mUrlBar)) imm.hideSoftInputFromWindow(getWindowToken(), 0, null);
}
if (mToolbarDataProvider.isUsingBrandColor()) updateVisualsForState();
mStatusCoordinator.onUrlFocusChange(mUrlHasFocus);
if (!mUrlFocusedWithoutAnimations) handleUrlFocusAnimation(mUrlHasFocus);
if (mUrlHasFocus && mToolbarDataProvider.hasTab() && !mToolbarDataProvider.isIncognito()) {
if (mNativeInitialized
&& TemplateUrlServiceFactory.get().isDefaultSearchEngineGoogle()) {
GeolocationHeader.primeLocationForGeoHeader();
} else {
mDeferredNativeRunnables.add(new Runnable() {
@Override
public void run() {
if (TemplateUrlServiceFactory.get().isDefaultSearchEngineGoogle()) {
GeolocationHeader.primeLocationForGeoHeader();
}
}
});
}
}
}
/**
* Handle and run any necessary animations that are triggered off focusing the UrlBar.
* @param hasFocus Whether focus was gained.
*/
protected void handleUrlFocusAnimation(boolean hasFocus) {
removeCallbacks(mKeyboardResizeModeTask);
if (hasFocus) mUrlFocusedWithoutAnimations = false;
for (UrlFocusChangeListener listener : mUrlFocusChangeListeners) {
listener.onUrlFocusChange(hasFocus);
}
}
@Override @Override
public void onUrlTextChanged() { public void onUrlTextChanged() {
updateButtonVisibility(); updateButtonVisibility();
...@@ -700,123 +484,10 @@ public class LocationBarLayout extends FrameLayout ...@@ -700,123 +484,10 @@ public class LocationBarLayout extends FrameLayout
setUrlToPageUrl(); setUrlToPageUrl();
} }
/** @Override
* @return The margin to be applied to the URL bar based on the buttons currently visible next public void setKeyboardVisibility(boolean shouldShow) {
* to it, used to avoid text overlapping the buttons and vice versa. mKeyboardShouldShow = shouldShow;
*/ setKeyboardVisibilityInternal(false);
private int getUrlContainerMarginEnd() {
int urlContainerMarginEnd = 0;
for (View childView : getUrlContainerViewsForMargin()) {
ViewGroup.MarginLayoutParams childLayoutParams =
(ViewGroup.MarginLayoutParams) childView.getLayoutParams();
urlContainerMarginEnd += childLayoutParams.width
+ MarginLayoutParamsCompat.getMarginStart(childLayoutParams)
+ MarginLayoutParamsCompat.getMarginEnd(childLayoutParams);
}
if (mUrlActionContainer != null && mUrlActionContainer.getVisibility() == View.VISIBLE) {
ViewGroup.MarginLayoutParams urlActionContainerLayoutParams =
(ViewGroup.MarginLayoutParams) mUrlActionContainer.getLayoutParams();
urlContainerMarginEnd +=
MarginLayoutParamsCompat.getMarginStart(urlActionContainerLayoutParams)
+ MarginLayoutParamsCompat.getMarginEnd(urlActionContainerLayoutParams);
}
return urlContainerMarginEnd;
}
/**
* Updates the layout params for the location bar start aligned views.
*/
protected void updateLayoutParams() {
int startMargin = 0;
for (int i = 0; i < getChildCount(); i++) {
View childView = getChildAt(i);
if (childView.getVisibility() != GONE) {
LayoutParams childLayoutParams = (LayoutParams) childView.getLayoutParams();
if (MarginLayoutParamsCompat.getMarginStart(childLayoutParams) != startMargin) {
MarginLayoutParamsCompat.setMarginStart(childLayoutParams, startMargin);
childView.setLayoutParams(childLayoutParams);
}
if (childView == mUrlBar) break;
int widthMeasureSpec;
int heightMeasureSpec;
if (childLayoutParams.width == LayoutParams.WRAP_CONTENT) {
widthMeasureSpec =
MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.AT_MOST);
} else if (childLayoutParams.width == LayoutParams.MATCH_PARENT) {
widthMeasureSpec =
MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.EXACTLY);
} else {
widthMeasureSpec = MeasureSpec.makeMeasureSpec(
childLayoutParams.width, MeasureSpec.EXACTLY);
}
if (childLayoutParams.height == LayoutParams.WRAP_CONTENT) {
heightMeasureSpec =
MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.AT_MOST);
} else if (childLayoutParams.height == LayoutParams.MATCH_PARENT) {
heightMeasureSpec =
MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY);
} else {
heightMeasureSpec = MeasureSpec.makeMeasureSpec(
childLayoutParams.height, MeasureSpec.EXACTLY);
}
childView.measure(widthMeasureSpec, heightMeasureSpec);
startMargin += childView.getMeasuredWidth();
}
}
int urlContainerMarginEnd = getUrlContainerMarginEnd();
LayoutParams urlLayoutParams = (LayoutParams) mUrlBar.getLayoutParams();
if (MarginLayoutParamsCompat.getMarginEnd(urlLayoutParams) != urlContainerMarginEnd) {
// Include the space which the URL bar will be translated post-layout into the
// end-margin so the URL bar doesn't overlap with the URL actions container.
if (SearchEngineLogoUtils.shouldShowSearchEngineLogo(
mToolbarDataProvider.isIncognito())) {
urlContainerMarginEnd += mStatusCoordinator.getEndPaddingPixelSizeOnFocusDelta();
}
MarginLayoutParamsCompat.setMarginEnd(urlLayoutParams, urlContainerMarginEnd);
mUrlBar.setLayoutParams(urlLayoutParams);
}
}
/**
* Gets the list of views that need to be taken into account for adding margin to the end of the
* URL bar.
*
* @return A {@link List} of the views to be taken into account for URL bar margin to avoid
* overlapping text and buttons.
*/
protected List<View> getUrlContainerViewsForMargin() {
List<View> outList = new ArrayList<View>();
if (mUrlActionContainer == null) return outList;
for (int i = 0; i < mUrlActionContainer.getChildCount(); i++) {
View childView = mUrlActionContainer.getChildAt(i);
if (childView.getVisibility() != GONE) outList.add(childView);
}
return outList;
}
/**
* @return Whether the delete button should be shown.
*/
protected boolean shouldShowDeleteButton() {
// Show the delete button at the end when the bar has focus and has some text.
boolean hasText = !TextUtils.isEmpty(mUrlCoordinator.getTextWithAutocomplete());
return hasText && (mUrlBar.hasFocus() || mUrlFocusChangeInProgress);
}
/**
* Updates the display of the delete URL content button.
*/
protected void updateDeleteButtonVisibility() {
mDeleteButton.setVisibility(shouldShowDeleteButton() ? VISIBLE : GONE);
}
@Override
public void setKeyboardVisibility(boolean shouldShow) {
mKeyboardShouldShow = shouldShow;
setKeyboardVisibilityInternal(false);
} }
@Override @Override
...@@ -946,157 +617,6 @@ public class LocationBarLayout extends FrameLayout ...@@ -946,157 +617,6 @@ public class LocationBarLayout extends FrameLayout
: LocationBar.OmniboxFocusReason.OMNIBOX_TAP); : LocationBar.OmniboxFocusReason.OMNIBOX_TAP);
} }
/**
* @return Returns the original url of the page.
*/
public String getOriginalUrl() {
return mOriginalUrl;
}
/**
* Sets the displayed URL to be the URL of the page currently showing.
*
* <p>The URL is converted to the most user friendly format (removing HTTP:// for example).
*
* <p>If the current tab is null, the URL text will be cleared.
*/
@Override
public void setUrlToPageUrl() {
String currentUrl = mToolbarDataProvider.getCurrentUrl();
// If the URL is currently focused, do not replace the text they have entered with the URL.
// Once they stop editing the URL, the current tab's URL will automatically be filled in.
if (mUrlBar.hasFocus()) {
if (mUrlFocusedWithoutAnimations && !NewTabPage.isNTPUrl(currentUrl)) {
// If we did not run the focus animations, then the user has not typed any text.
// So, clear the focus and accept whatever URL the page is currently attempting to
// display. If the NTP is showing, the current page's URL should not be displayed.
setUrlBarFocus(false, null, LocationBar.OmniboxFocusReason.UNFOCUS);
} else {
return;
}
}
mOriginalUrl = currentUrl;
@ScrollType
int scrollType = mToolbarDataProvider.getDisplaySearchTerms() != null
? UrlBar.ScrollType.SCROLL_TO_BEGINNING
: UrlBar.ScrollType.SCROLL_TO_TLD;
setUrlBarText(mToolbarDataProvider.getUrlBarData(), scrollType, SelectionState.SELECT_ALL);
if (!mToolbarDataProvider.hasTab()) return;
// Profile may be null if switching to a tab that has not yet been initialized.
Profile profile = mToolbarDataProvider.getProfile();
if (profile != null && mOmniboxPrerender != null) mOmniboxPrerender.clear(profile);
}
/**
* Changes the text on the url bar. The text update will be applied regardless of the current
* focus state (comparing to {@link #setUrlToPageUrl()} which only applies text updates when
* not focused).
*
* @param urlBarData The contents of the URL bar, both for editing and displaying.
* @param scrollType Specifies how the text should be scrolled in the unfocused state.
* @param selectionState Specifies how the text should be selected in the focused state.
* @return Whether the URL was changed as a result of this call.
*/
private boolean setUrlBarText(
UrlBarData urlBarData, @ScrollType int scrollType, @SelectionState int selectionState) {
return mUrlCoordinator.setUrlBarData(urlBarData, scrollType, selectionState);
}
/**
* Clear any text in the URL bar.
* @return Whether this changed the existing text.
*/
private boolean setUrlBarTextEmpty() {
boolean textChanged = mUrlCoordinator.setUrlBarData(
UrlBarData.EMPTY, UrlBar.ScrollType.SCROLL_TO_BEGINNING, SelectionState.SELECT_ALL);
forceOnTextChanged();
return textChanged;
}
@Override
public void setOmniboxEditingText(String text) {
mUrlCoordinator.setUrlBarData(UrlBarData.forNonUrlText(text), UrlBar.ScrollType.NO_SCROLL,
UrlBarCoordinator.SelectionState.SELECT_END);
updateButtonVisibility();
}
@Override
public void loadUrlFromVoice(String url) {
loadUrl(url, PageTransition.TYPED, 0);
}
/**
* Load the url given with the given transition. Exposed for child classes to overwrite as
* necessary.
*/
@Override
public void loadUrl(String url, @PageTransition int transition, long inputStart) {
loadUrlWithPostData(url, transition, inputStart, null, null);
}
@Override
public void loadUrlWithPostData(String url, @PageTransition int transition, long inputStart,
@Nullable String postDataType, @Nullable byte[] postData) {
Tab currentTab = getCurrentTab();
// The code of the rest of this class ensures that this can't be called until the native
// side is initialized
assert mNativeInitialized : "Loading URL before native side initialized";
// TODO(crbug.com/1085812): Should be taking a fulll loaded LoadUrlParams.
if (ReturnToChromeExperimentsUtil.willHandleLoadUrlWithPostDataFromStartSurface(
url, transition, postDataType, postData, mToolbarDataProvider.isIncognito())) {
return;
}
if (currentTab != null
&& (currentTab.isNativePage() || NewTabPage.isNTPUrl(currentTab.getUrlString()))) {
NewTabPageUma.recordOmniboxNavigation(url, transition);
// Passing in an empty string should not do anything unless the user is at the NTP.
// Since the NTP has no url, pressing enter while clicking on the URL bar should refresh
// the page as it does when you click and press enter on any other site.
if (url.isEmpty()) url = currentTab.getUrlString();
}
// Loads the |url| in a new tab or the current ContentView and gives focus to the
// ContentView.
if (currentTab != null && !url.isEmpty()) {
LoadUrlParams loadUrlParams = new LoadUrlParams(url);
loadUrlParams.setVerbatimHeaders(GeolocationHeader.getGeoHeader(url, currentTab));
loadUrlParams.setTransitionType(transition | PageTransition.FROM_ADDRESS_BAR);
if (inputStart != 0) {
loadUrlParams.setInputStartTimestamp(inputStart);
}
if (!TextUtils.isEmpty(postDataType)) {
StringBuilder headers = new StringBuilder();
String prevHeader = loadUrlParams.getVerbatimHeaders();
if (prevHeader != null && !prevHeader.isEmpty()) {
headers.append(prevHeader);
headers.append("\r\n");
}
loadUrlParams.setExtraHeaders(new HashMap<String, String>() {
{ put("Content-Type", postDataType); }
});
headers.append(loadUrlParams.getExtraHttpRequestHeadersString());
loadUrlParams.setVerbatimHeaders(headers.toString());
}
if (postData != null && postData.length != 0) {
loadUrlParams.setPostData(ResourceRequestBody.createFromBytes(postData));
}
currentTab.loadUrl(loadUrlParams);
RecordUserAction.record("MobileOmniboxUse");
}
LocaleManager.getInstance().recordLocaleBasedSearchMetrics(false, url, transition);
focusCurrentTab();
}
/** /**
* Update the location bar visuals based on a loading state change. * Update the location bar visuals based on a loading state change.
* @param updateUrl Whether to update the URL as a result of this call. * @param updateUrl Whether to update the URL as a result of this call.
...@@ -1107,13 +627,6 @@ public class LocationBarLayout extends FrameLayout ...@@ -1107,13 +627,6 @@ public class LocationBarLayout extends FrameLayout
mStatusCoordinator.updateStatusIcon(); mStatusCoordinator.updateStatusIcon();
} }
/** @return The current active {@link Tab}. */
@Nullable
private Tab getCurrentTab() {
if (mToolbarDataProvider == null) return null;
return mToolbarDataProvider.getTab();
}
@Override @Override
public View getViewForUrlBackFocus() { public View getViewForUrlBackFocus() {
Tab tab = getCurrentTab(); Tab tab = getCurrentTab();
...@@ -1127,17 +640,6 @@ public class LocationBarLayout extends FrameLayout ...@@ -1127,17 +640,6 @@ public class LocationBarLayout extends FrameLayout
return !mToolbarDataProvider.isIncognito(); return !mToolbarDataProvider.isIncognito();
} }
@Override
public void setUnfocusedWidth(int unfocusedWidth) {
mStatusCoordinator.setUnfocusedLocationBarWidth(unfocusedWidth);
}
protected void updateSearchEngineStatusIcon(boolean shouldShowSearchEngineLogo,
boolean isSearchEngineGoogle, String searchEngineUrl) {
mStatusCoordinator.updateSearchEngineStatusIcon(
shouldShowSearchEngineLogo, isSearchEngineGoogle, searchEngineUrl);
}
@Override @Override
public void setUrlBarFocus( public void setUrlBarFocus(
boolean shouldBeFocused, @Nullable String pastedText, @OmniboxFocusReason int reason) { boolean shouldBeFocused, @Nullable String pastedText, @OmniboxFocusReason int reason) {
...@@ -1207,44 +709,8 @@ public class LocationBarLayout extends FrameLayout ...@@ -1207,44 +709,8 @@ public class LocationBarLayout extends FrameLayout
} }
/** /**
* Call to update the visibility of the buttons inside the location bar. * Call to force the UI to update the state of various buttons based on whether or not the
*/ * current tab is incognito.
protected void updateButtonVisibility() {
updateDeleteButtonVisibility();
}
/**
* Call to notify the location bar that the state of the voice search microphone button may
* need to be updated.
*/
@Override
public void updateMicButtonState() {
mVoiceSearchEnabled = mVoiceRecognitionHandler.isVoiceSearchEnabled();
updateButtonVisibility();
}
/**
* Updates the display of the mic button.
*/
protected void updateMicButtonVisibility() {
boolean visible = !shouldShowDeleteButton();
boolean showMicButton = mVoiceSearchEnabled && visible
&& (mUrlBar.hasFocus() || mUrlFocusChangeInProgress || mUrlFocusChangeFraction > 0f
|| mShouldShowMicButtonWhenUnfocused);
mMicButton.setVisibility(showMicButton ? VISIBLE : GONE);
}
/**
* Value determines if mic button should be shown when location bar is not focused. By default
* mic button is not shown. It is only shown for SearchActivityLocationBarLayout.
*/
protected void setShouldShowMicButtonWhenUnfocused(boolean shouldShowMicButtonWhenUnfocused) {
mShouldShowMicButtonWhenUnfocused = shouldShowMicButtonWhenUnfocused;
}
/**
* Call to force the UI to update the state of various buttons based on whether or not the
* current tab is incognito.
*/ */
@Override @Override
public void updateVisualsForState() { public void updateVisualsForState() {
...@@ -1311,22 +777,6 @@ public class LocationBarLayout extends FrameLayout ...@@ -1311,22 +777,6 @@ public class LocationBarLayout extends FrameLayout
return mWindowAndroid; return mWindowAndroid;
} }
@VisibleForTesting
public StatusCoordinator getStatusCoordinatorForTesting() {
return mStatusCoordinator;
}
private void forceOnTextChanged() {
String textWithoutAutocomplete = mUrlCoordinator.getTextWithoutAutocomplete();
String textWithAutocomplete = mUrlCoordinator.getTextWithAutocomplete();
mAutocompleteCoordinator.onTextChanged(textWithoutAutocomplete, textWithAutocomplete);
}
private void recordOmniboxFocusReason(@OmniboxFocusReason int reason) {
RecordHistogram.recordEnumeratedHistogram(
"Android.OmniboxFocusReason", reason, OmniboxFocusReason.NUM_ENTRIES);
}
@Override @Override
public void onAssistantVoiceSearchServiceChanged() { public void onAssistantVoiceSearchServiceChanged() {
Drawable drawable = mAssistantVoiceSearchService.getCurrentMicDrawable(); Drawable drawable = mAssistantVoiceSearchService.getCurrentMicDrawable();
...@@ -1341,6 +791,553 @@ public class LocationBarLayout extends FrameLayout ...@@ -1341,6 +791,553 @@ public class LocationBarLayout extends FrameLayout
ApiCompatibilityUtils.setImageTintList(mMicButton, colorStateList); ApiCompatibilityUtils.setImageTintList(mMicButton, colorStateList);
} }
/**
* Call to notify the location bar that the state of the voice search microphone button may
* need to be updated.
*/
@Override
public void updateMicButtonState() {
mVoiceSearchEnabled = mVoiceRecognitionHandler.isVoiceSearchEnabled();
updateButtonVisibility();
}
/**
* Sets the displayed URL to be the URL of the page currently showing.
*
* <p>The URL is converted to the most user friendly format (removing HTTP:// for example).
*
* <p>If the current tab is null, the URL text will be cleared.
*/
@Override
public void setUrlToPageUrl() {
String currentUrl = mToolbarDataProvider.getCurrentUrl();
// If the URL is currently focused, do not replace the text they have entered with the URL.
// Once they stop editing the URL, the current tab's URL will automatically be filled in.
if (mUrlBar.hasFocus()) {
if (mUrlFocusedWithoutAnimations && !NewTabPage.isNTPUrl(currentUrl)) {
// If we did not run the focus animations, then the user has not typed any text.
// So, clear the focus and accept whatever URL the page is currently attempting to
// display. If the NTP is showing, the current page's URL should not be displayed.
setUrlBarFocus(false, null, LocationBar.OmniboxFocusReason.UNFOCUS);
} else {
return;
}
}
mOriginalUrl = currentUrl;
@ScrollType
int scrollType = mToolbarDataProvider.getDisplaySearchTerms() != null
? UrlBar.ScrollType.SCROLL_TO_BEGINNING
: UrlBar.ScrollType.SCROLL_TO_TLD;
setUrlBarText(mToolbarDataProvider.getUrlBarData(), scrollType, SelectionState.SELECT_ALL);
if (!mToolbarDataProvider.hasTab()) return;
// Profile may be null if switching to a tab that has not yet been initialized.
Profile profile = mToolbarDataProvider.getProfile();
if (profile != null && mOmniboxPrerender != null) mOmniboxPrerender.clear(profile);
}
@Override
public void setOmniboxEditingText(String text) {
mUrlCoordinator.setUrlBarData(UrlBarData.forNonUrlText(text), UrlBar.ScrollType.NO_SCROLL,
UrlBarCoordinator.SelectionState.SELECT_END);
updateButtonVisibility();
}
@Override
public void loadUrlFromVoice(String url) {
loadUrl(url, PageTransition.TYPED, 0);
}
/**
* Load the url given with the given transition. Exposed for child classes to overwrite as
* necessary.
*/
@Override
public void loadUrl(String url, @PageTransition int transition, long inputStart) {
loadUrlWithPostData(url, transition, inputStart, null, null);
}
@Override
public void loadUrlWithPostData(String url, @PageTransition int transition, long inputStart,
@Nullable String postDataType, @Nullable byte[] postData) {
Tab currentTab = getCurrentTab();
// The code of the rest of this class ensures that this can't be called until the native
// side is initialized
assert mNativeInitialized : "Loading URL before native side initialized";
// TODO(crbug.com/1085812): Should be taking a fulll loaded LoadUrlParams.
if (ReturnToChromeExperimentsUtil.willHandleLoadUrlWithPostDataFromStartSurface(
url, transition, postDataType, postData, mToolbarDataProvider.isIncognito())) {
return;
}
if (currentTab != null
&& (currentTab.isNativePage() || NewTabPage.isNTPUrl(currentTab.getUrlString()))) {
NewTabPageUma.recordOmniboxNavigation(url, transition);
// Passing in an empty string should not do anything unless the user is at the NTP.
// Since the NTP has no url, pressing enter while clicking on the URL bar should refresh
// the page as it does when you click and press enter on any other site.
if (url.isEmpty()) url = currentTab.getUrlString();
}
// Loads the |url| in a new tab or the current ContentView and gives focus to the
// ContentView.
if (currentTab != null && !url.isEmpty()) {
LoadUrlParams loadUrlParams = new LoadUrlParams(url);
loadUrlParams.setVerbatimHeaders(GeolocationHeader.getGeoHeader(url, currentTab));
loadUrlParams.setTransitionType(transition | PageTransition.FROM_ADDRESS_BAR);
if (inputStart != 0) {
loadUrlParams.setInputStartTimestamp(inputStart);
}
if (!TextUtils.isEmpty(postDataType)) {
StringBuilder headers = new StringBuilder();
String prevHeader = loadUrlParams.getVerbatimHeaders();
if (prevHeader != null && !prevHeader.isEmpty()) {
headers.append(prevHeader);
headers.append("\r\n");
}
loadUrlParams.setExtraHeaders(new HashMap<String, String>() {
{ put("Content-Type", postDataType); }
});
headers.append(loadUrlParams.getExtraHttpRequestHeadersString());
loadUrlParams.setVerbatimHeaders(headers.toString());
}
if (postData != null && postData.length != 0) {
loadUrlParams.setPostData(ResourceRequestBody.createFromBytes(postData));
}
currentTab.loadUrl(loadUrlParams);
RecordUserAction.record("MobileOmniboxUse");
}
LocaleManager.getInstance().recordLocaleBasedSearchMetrics(false, url, transition);
focusCurrentTab();
}
/**
* @param focusable Whether the url bar should be focusable.
*/
public void setUrlBarFocusable(boolean focusable) {
if (mUrlCoordinator == null) return;
mUrlCoordinator.setAllowFocus(focusable);
}
public void setOverviewModeBehavior(OverviewModeBehavior overviewModeBehavior) {
mAutocompleteCoordinator.setOverviewModeBehavior(overviewModeBehavior);
}
@CallSuper
public void setUrlFocusChangeFraction(float fraction) {
mUrlFocusChangeFraction = fraction;
}
private void registerTemplateUrlObserver() {
final TemplateUrlService templateUrlService = TemplateUrlServiceFactory.get();
assert mTemplateUrlObserver == null;
mTemplateUrlObserver = new TemplateUrlServiceObserver() {
private TemplateUrl mSearchEngine =
templateUrlService.getDefaultSearchEngineTemplateUrl();
@Override
public void onTemplateURLServiceChanged() {
TemplateUrl searchEngine = templateUrlService.getDefaultSearchEngineTemplateUrl();
if ((mSearchEngine == null && searchEngine == null)
|| (mSearchEngine != null && mSearchEngine.equals(searchEngine))) {
return;
}
mSearchEngine = searchEngine;
updateSearchEngineStatusIcon(SearchEngineLogoUtils.shouldShowSearchEngineLogo(
mToolbarDataProvider.isIncognito()),
TemplateUrlServiceFactory.get().isDefaultSearchEngineGoogle(),
SearchEngineLogoUtils.getSearchLogoUrl());
}
};
templateUrlService.addObserver(mTemplateUrlObserver);
// Force an update once to populate initial data.
updateSearchEngineStatusIcon(SearchEngineLogoUtils.shouldShowSearchEngineLogo(
mToolbarDataProvider.isIncognito()),
TemplateUrlServiceFactory.get().isDefaultSearchEngineGoogle(),
SearchEngineLogoUtils.getSearchLogoUrl());
}
/**
* Evaluate state and update child components' animations.
*
* This call and all overrides should invoke `notifyShouldAnimateIconChanges(boolean)` with a
* computed boolean value toggling animation support in child components.
*/
protected void updateShouldAnimateIconChanges() {
notifyShouldAnimateIconChanges(mUrlHasFocus);
}
/**
* Toggle child components animations.
* @param shouldAnimate Boolean flag indicating whether animations should be enabled.
*/
protected void notifyShouldAnimateIconChanges(boolean shouldAnimate) {
mStatusCoordinator.setShouldAnimateIconChanges(shouldAnimate);
}
/**
* Updates the profile used by this LocationBar, for, e.g. determining incognito status or
* generating autocomplete suggestions..
* @param profile The profile to be used.
*/
private void setProfile(Profile profile) {
if (profile == null || !mNativeInitialized) return;
mAutocompleteCoordinator.setAutocompleteProfile(profile);
mOmniboxPrerender.initializeForProfile(profile);
setShowIconsWhenUrlFocused(
SearchEngineLogoUtils.shouldShowSearchEngineLogo(profile.isOffTheRecord()));
}
/** Focuses the current page. */
private void focusCurrentTab() {
if (mToolbarDataProvider.hasTab()) {
View view = getCurrentTab().getView();
if (view != null) view.requestFocus();
}
}
/**
* @return Whether the URL focus change is taking place, e.g. a focus animation is running on
* a phone device.
*/
public boolean isUrlFocusChangeInProgress() {
return mUrlFocusChangeInProgress;
}
/**
* Specify whether location bar should present icons when focused.
* @param showIcon True if we should show the icons when the url is focused.
*/
protected void setShowIconsWhenUrlFocused(boolean showIcon) {}
/**
* @param inProgress Whether a URL focus change is taking place.
*/
protected void setUrlFocusChangeInProgress(boolean inProgress) {
mUrlFocusChangeInProgress = inProgress;
if (!inProgress) {
updateButtonVisibility();
// The accessibility bounding box is not properly updated when focusing the Omnibox
// from the NTP fakebox. Clearing/re-requesting focus triggers the bounding box to
// be recalculated.
if (didFocusUrlFromFakebox() && mUrlHasFocus
&& ChromeAccessibilityUtil.get().isAccessibilityEnabled()) {
String existingText = mUrlCoordinator.getTextWithoutAutocomplete();
mUrlBar.clearFocus();
mUrlBar.requestFocus();
// Existing text (e.g. if the user pasted via the fakebox) from the fake box
// should be restored after toggling the focus.
if (!TextUtils.isEmpty(existingText)) {
mUrlCoordinator.setUrlBarData(UrlBarData.forNonUrlText(existingText),
UrlBar.ScrollType.NO_SCROLL,
UrlBarCoordinator.SelectionState.SELECT_END);
forceOnTextChanged();
}
}
for (UrlFocusChangeListener listener : mUrlFocusChangeListeners) {
listener.onUrlAnimationFinished(mUrlHasFocus);
}
}
}
/**
* Triggered when the URL input field has gained or lost focus.
* @param hasFocus Whether the URL field has gained focus.
*/
protected void onUrlFocusChange(boolean hasFocus) {
mUrlHasFocus = hasFocus;
updateButtonVisibility();
updateShouldAnimateIconChanges();
if (mUrlHasFocus) {
mKeyboardShouldShow = false;
if (mNativeInitialized) RecordUserAction.record("FocusLocation");
UrlBarData urlBarData = mToolbarDataProvider.getUrlBarData();
if (urlBarData.editingText != null) {
setUrlBarText(urlBarData, UrlBar.ScrollType.NO_SCROLL, SelectionState.SELECT_ALL);
}
// Explicitly tell InputMethodManager that the url bar is focused before any callbacks
// so that it updates the active view accordingly. Otherwise, it may fail to update
// the correct active view if ViewGroup.addView() or ViewGroup.removeView() is called
// to update a view that accepts text input.
InputMethodManager imm = (InputMethodManager) mUrlBar.getContext().getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.viewClicked(mUrlBar);
} else {
mUrlFocusedFromFakebox = false;
mUrlFocusedFromQueryTiles = false;
mUrlFocusedWithoutAnimations = false;
// Focus change caused by a close-tab may result in an invalid current tab.
if (mToolbarDataProvider.hasTab()) {
setUrlToPageUrl();
}
// Moving focus away from UrlBar(EditText) to a non-editable focus holder, such as
// ToolbarPhone, won't automatically hide keyboard app, but restart it with TYPE_NULL,
// which will result in a visual glitch. Also, currently, we do not allow moving focus
// directly from omnibox to web content's form field. Therefore, we hide keyboard on
// focus blur indiscriminately here. Note that hiding keyboard may lower FPS of other
// animation effects, but we found it tolerable in an experiment.
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(
Context.INPUT_METHOD_SERVICE);
if (imm.isActive(mUrlBar)) imm.hideSoftInputFromWindow(getWindowToken(), 0, null);
}
if (mToolbarDataProvider.isUsingBrandColor()) updateVisualsForState();
mStatusCoordinator.onUrlFocusChange(mUrlHasFocus);
if (!mUrlFocusedWithoutAnimations) handleUrlFocusAnimation(mUrlHasFocus);
if (mUrlHasFocus && mToolbarDataProvider.hasTab() && !mToolbarDataProvider.isIncognito()) {
if (mNativeInitialized
&& TemplateUrlServiceFactory.get().isDefaultSearchEngineGoogle()) {
GeolocationHeader.primeLocationForGeoHeader();
} else {
mDeferredNativeRunnables.add(new Runnable() {
@Override
public void run() {
if (TemplateUrlServiceFactory.get().isDefaultSearchEngineGoogle()) {
GeolocationHeader.primeLocationForGeoHeader();
}
}
});
}
}
}
/**
* Handle and run any necessary animations that are triggered off focusing the UrlBar.
* @param hasFocus Whether focus was gained.
*/
protected void handleUrlFocusAnimation(boolean hasFocus) {
removeCallbacks(mKeyboardResizeModeTask);
if (hasFocus) mUrlFocusedWithoutAnimations = false;
for (UrlFocusChangeListener listener : mUrlFocusChangeListeners) {
listener.onUrlFocusChange(hasFocus);
}
}
/**
* @return The margin to be applied to the URL bar based on the buttons currently visible next
* to it, used to avoid text overlapping the buttons and vice versa.
*/
private int getUrlContainerMarginEnd() {
int urlContainerMarginEnd = 0;
for (View childView : getUrlContainerViewsForMargin()) {
ViewGroup.MarginLayoutParams childLayoutParams =
(ViewGroup.MarginLayoutParams) childView.getLayoutParams();
urlContainerMarginEnd += childLayoutParams.width
+ MarginLayoutParamsCompat.getMarginStart(childLayoutParams)
+ MarginLayoutParamsCompat.getMarginEnd(childLayoutParams);
}
if (mUrlActionContainer != null && mUrlActionContainer.getVisibility() == View.VISIBLE) {
ViewGroup.MarginLayoutParams urlActionContainerLayoutParams =
(ViewGroup.MarginLayoutParams) mUrlActionContainer.getLayoutParams();
urlContainerMarginEnd +=
MarginLayoutParamsCompat.getMarginStart(urlActionContainerLayoutParams)
+ MarginLayoutParamsCompat.getMarginEnd(urlActionContainerLayoutParams);
}
return urlContainerMarginEnd;
}
/**
* Updates the layout params for the location bar start aligned views.
*/
protected void updateLayoutParams() {
int startMargin = 0;
for (int i = 0; i < getChildCount(); i++) {
View childView = getChildAt(i);
if (childView.getVisibility() != GONE) {
LayoutParams childLayoutParams = (LayoutParams) childView.getLayoutParams();
if (MarginLayoutParamsCompat.getMarginStart(childLayoutParams) != startMargin) {
MarginLayoutParamsCompat.setMarginStart(childLayoutParams, startMargin);
childView.setLayoutParams(childLayoutParams);
}
if (childView == mUrlBar) break;
int widthMeasureSpec;
int heightMeasureSpec;
if (childLayoutParams.width == LayoutParams.WRAP_CONTENT) {
widthMeasureSpec =
MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.AT_MOST);
} else if (childLayoutParams.width == LayoutParams.MATCH_PARENT) {
widthMeasureSpec =
MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.EXACTLY);
} else {
widthMeasureSpec = MeasureSpec.makeMeasureSpec(
childLayoutParams.width, MeasureSpec.EXACTLY);
}
if (childLayoutParams.height == LayoutParams.WRAP_CONTENT) {
heightMeasureSpec =
MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.AT_MOST);
} else if (childLayoutParams.height == LayoutParams.MATCH_PARENT) {
heightMeasureSpec =
MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.EXACTLY);
} else {
heightMeasureSpec = MeasureSpec.makeMeasureSpec(
childLayoutParams.height, MeasureSpec.EXACTLY);
}
childView.measure(widthMeasureSpec, heightMeasureSpec);
startMargin += childView.getMeasuredWidth();
}
}
int urlContainerMarginEnd = getUrlContainerMarginEnd();
LayoutParams urlLayoutParams = (LayoutParams) mUrlBar.getLayoutParams();
if (MarginLayoutParamsCompat.getMarginEnd(urlLayoutParams) != urlContainerMarginEnd) {
// Include the space which the URL bar will be translated post-layout into the
// end-margin so the URL bar doesn't overlap with the URL actions container.
if (SearchEngineLogoUtils.shouldShowSearchEngineLogo(
mToolbarDataProvider.isIncognito())) {
urlContainerMarginEnd += mStatusCoordinator.getEndPaddingPixelSizeOnFocusDelta();
}
MarginLayoutParamsCompat.setMarginEnd(urlLayoutParams, urlContainerMarginEnd);
mUrlBar.setLayoutParams(urlLayoutParams);
}
}
/**
* Gets the list of views that need to be taken into account for adding margin to the end of the
* URL bar.
*
* @return A {@link List} of the views to be taken into account for URL bar margin to avoid
* overlapping text and buttons.
*/
protected List<View> getUrlContainerViewsForMargin() {
List<View> outList = new ArrayList<View>();
if (mUrlActionContainer == null) return outList;
for (int i = 0; i < mUrlActionContainer.getChildCount(); i++) {
View childView = mUrlActionContainer.getChildAt(i);
if (childView.getVisibility() != GONE) outList.add(childView);
}
return outList;
}
/**
* @return Whether the delete button should be shown.
*/
protected boolean shouldShowDeleteButton() {
// Show the delete button at the end when the bar has focus and has some text.
boolean hasText = !TextUtils.isEmpty(mUrlCoordinator.getTextWithAutocomplete());
return hasText && (mUrlBar.hasFocus() || mUrlFocusChangeInProgress);
}
/**
* Updates the display of the delete URL content button.
*/
protected void updateDeleteButtonVisibility() {
mDeleteButton.setVisibility(shouldShowDeleteButton() ? VISIBLE : GONE);
}
/**
* @return Returns the original url of the page.
*/
public String getOriginalUrl() {
return mOriginalUrl;
}
/**
* Changes the text on the url bar. The text update will be applied regardless of the current
* focus state (comparing to {@link #setUrlToPageUrl()} which only applies text updates when
* not focused).
*
* @param urlBarData The contents of the URL bar, both for editing and displaying.
* @param scrollType Specifies how the text should be scrolled in the unfocused state.
* @param selectionState Specifies how the text should be selected in the focused state.
* @return Whether the URL was changed as a result of this call.
*/
private boolean setUrlBarText(
UrlBarData urlBarData, @ScrollType int scrollType, @SelectionState int selectionState) {
return mUrlCoordinator.setUrlBarData(urlBarData, scrollType, selectionState);
}
/**
* Clear any text in the URL bar.
* @return Whether this changed the existing text.
*/
private boolean setUrlBarTextEmpty() {
boolean textChanged = mUrlCoordinator.setUrlBarData(
UrlBarData.EMPTY, UrlBar.ScrollType.SCROLL_TO_BEGINNING, SelectionState.SELECT_ALL);
forceOnTextChanged();
return textChanged;
}
/** @return The current active {@link Tab}. */
@Nullable
private Tab getCurrentTab() {
if (mToolbarDataProvider == null) return null;
return mToolbarDataProvider.getTab();
}
public void setUnfocusedWidth(int unfocusedWidth) {
mStatusCoordinator.setUnfocusedLocationBarWidth(unfocusedWidth);
}
protected void updateSearchEngineStatusIcon(boolean shouldShowSearchEngineLogo,
boolean isSearchEngineGoogle, String searchEngineUrl) {
mStatusCoordinator.updateSearchEngineStatusIcon(
shouldShowSearchEngineLogo, isSearchEngineGoogle, searchEngineUrl);
}
/**
* Call to update the visibility of the buttons inside the location bar.
*/
protected void updateButtonVisibility() {
updateDeleteButtonVisibility();
}
/**
* Updates the display of the mic button.
*/
protected void updateMicButtonVisibility() {
boolean visible = !shouldShowDeleteButton();
boolean showMicButton = mVoiceSearchEnabled && visible
&& (mUrlBar.hasFocus() || mUrlFocusChangeInProgress || mUrlFocusChangeFraction > 0f
|| mShouldShowMicButtonWhenUnfocused);
mMicButton.setVisibility(showMicButton ? VISIBLE : GONE);
}
/**
* Value determines if mic button should be shown when location bar is not focused. By default
* mic button is not shown. It is only shown for SearchActivityLocationBarLayout.
*/
protected void setShouldShowMicButtonWhenUnfocused(boolean shouldShowMicButtonWhenUnfocused) {
mShouldShowMicButtonWhenUnfocused = shouldShowMicButtonWhenUnfocused;
}
@VisibleForTesting
public StatusCoordinator getStatusCoordinatorForTesting() {
return mStatusCoordinator;
}
private void forceOnTextChanged() {
String textWithoutAutocomplete = mUrlCoordinator.getTextWithoutAutocomplete();
String textWithAutocomplete = mUrlCoordinator.getTextWithAutocomplete();
mAutocompleteCoordinator.onTextChanged(textWithoutAutocomplete, textWithAutocomplete);
}
private void recordOmniboxFocusReason(@OmniboxFocusReason int reason) {
RecordHistogram.recordEnumeratedHistogram(
"Android.OmniboxFocusReason", reason, OmniboxFocusReason.NUM_ENTRIES);
}
/** /**
* Handles any actions to be performed after all other actions triggered by the URL focus * 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 * change. This will be called after any animations are performed to transition from one
......
...@@ -91,6 +91,120 @@ class LocationBarPhone extends LocationBarLayout { ...@@ -91,6 +91,120 @@ class LocationBarPhone extends LocationBarLayout {
setShowIconsWhenUrlFocused(shouldShowSearchEngineLogo); setShowIconsWhenUrlFocused(shouldShowSearchEngineLogo);
} }
/**
* Updates progress of current the URL focus change animation.
*
* @param fraction 1.0 is 100% focused, 0 is completely unfocused.
*/
@Override
public void setUrlFocusChangeFraction(float fraction) {
super.setUrlFocusChangeFraction(fraction);
if (fraction > 0f) {
mUrlActionContainer.setVisibility(VISIBLE);
} else if (fraction == 0f && !isUrlFocusChangeInProgress()) {
// If a URL focus change is in progress, then it will handle setting the visibility
// correctly after it completes. If done here, it would cause the URL to jump due
// to a badly timed layout call.
mUrlActionContainer.setVisibility(GONE);
}
updateButtonVisibility();
mStatusCoordinator.setUrlFocusChangePercent(fraction);
}
@Override
public void onUrlFocusChange(boolean hasFocus) {
if (hasFocus) {
// Remove the focus of this view once the URL field has taken focus as this view no
// longer needs it.
setFocusable(false);
setFocusableInTouchMode(false);
}
setUrlFocusChangeInProgress(true);
updateShouldAnimateIconChanges();
super.onUrlFocusChange(hasFocus);
}
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
boolean needsCanvasRestore = false;
if (child == mUrlBar && mUrlActionContainer.getVisibility() == VISIBLE) {
canvas.save();
// Clip the URL bar contents to ensure they do not draw under the URL actions during
// focus animations. Based on the RTL state of the location bar, the url actions
// container can be on the left or right side, so clip accordingly.
if (mUrlBar.getLeft() < mUrlActionContainer.getLeft()) {
canvas.clipRect(0, 0, (int) mUrlActionContainer.getX(), getBottom());
} else {
canvas.clipRect(mUrlActionContainer.getX() + mUrlActionContainer.getWidth(), 0,
getWidth(), getBottom());
}
needsCanvasRestore = true;
}
boolean retVal = super.drawChild(canvas, child, drawingTime);
if (needsCanvasRestore) {
canvas.restore();
}
return retVal;
}
@Override
public void finishUrlFocusChange(boolean hasFocus) {
super.finishUrlFocusChange(hasFocus);
if (!hasFocus) {
mUrlActionContainer.setVisibility(GONE);
}
mStatusCoordinator.onUrlAnimationFinished(hasFocus);
}
@Override
protected void updateButtonVisibility() {
super.updateButtonVisibility();
updateMicButtonVisibility();
}
@Override
public void updateShouldAnimateIconChanges() {
notifyShouldAnimateIconChanges(isUrlBarFocused() || isUrlFocusChangeInProgress());
}
@Override
public void setShowIconsWhenUrlFocused(boolean showIcon) {
super.setShowIconsWhenUrlFocused(showIcon);
mFirstVisibleFocusedView = showIcon ? mStatusView : mUrlBar;
mStatusCoordinator.setShowIconsWhenUrlFocused(showIcon);
}
@Override
public void updateVisualsForState() {
super.updateVisualsForState();
boolean isIncognito = getToolbarDataProvider().isIncognito();
setShowIconsWhenUrlFocused(SearchEngineLogoUtils.shouldShowSearchEngineLogo(isIncognito));
updateStatusVisibility();
}
@Override
public void onTabLoadingNTP(NewTabPage ntp) {
super.onTabLoadingNTP(ntp);
updateStatusVisibility();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
try (TraceEvent e = TraceEvent.scoped("LocationBarPhone.onMeasure")) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
try (TraceEvent e = TraceEvent.scoped("LocationBarPhone.onLayout")) {
super.onLayout(changed, left, top, right, bottom);
}
}
/** /**
* @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.
...@@ -126,6 +240,17 @@ class LocationBarPhone extends LocationBarLayout { ...@@ -126,6 +240,17 @@ class LocationBarPhone extends LocationBarLayout {
} }
} }
/**
* 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 (FrameLayout.LayoutParams) getLayoutParams();
}
/** /**
* Calculates the offset required for the focused LocationBar to appear as it's still unfocused * Calculates the offset required for the focused LocationBar to appear as it's still unfocused
* so it can animate to a focused state. * so it can animate to a focused state.
...@@ -210,129 +335,11 @@ class LocationBarPhone extends LocationBarLayout { ...@@ -210,129 +335,11 @@ class LocationBarPhone extends LocationBarLayout {
return isRtl ? -translation : translation; return isRtl ? -translation : translation;
} }
/**
* Updates progress of current the URL focus change animation.
*
* @param fraction 1.0 is 100% focused, 0 is completely unfocused.
*/
@Override
public void setUrlFocusChangeFraction(float fraction) {
super.setUrlFocusChangeFraction(fraction);
if (fraction > 0f) {
mUrlActionContainer.setVisibility(VISIBLE);
} else if (fraction == 0f && !isUrlFocusChangeInProgress()) {
// If a URL focus change is in progress, then it will handle setting the visibility
// correctly after it completes. If done here, it would cause the URL to jump due
// to a badly timed layout call.
mUrlActionContainer.setVisibility(GONE);
}
updateButtonVisibility();
mStatusCoordinator.setUrlFocusChangePercent(fraction);
}
@Override
public void onUrlFocusChange(boolean hasFocus) {
if (hasFocus) {
// Remove the focus of this view once the URL field has taken focus as this view no
// longer needs it.
setFocusable(false);
setFocusableInTouchMode(false);
}
setUrlFocusChangeInProgress(true);
updateShouldAnimateIconChanges();
super.onUrlFocusChange(hasFocus);
}
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
boolean needsCanvasRestore = false;
if (child == mUrlBar && mUrlActionContainer.getVisibility() == VISIBLE) {
canvas.save();
// Clip the URL bar contents to ensure they do not draw under the URL actions during
// focus animations. Based on the RTL state of the location bar, the url actions
// container can be on the left or right side, so clip accordingly.
if (mUrlBar.getLeft() < mUrlActionContainer.getLeft()) {
canvas.clipRect(0, 0, (int) mUrlActionContainer.getX(), getBottom());
} else {
canvas.clipRect(mUrlActionContainer.getX() + mUrlActionContainer.getWidth(), 0,
getWidth(), getBottom());
}
needsCanvasRestore = true;
}
boolean retVal = super.drawChild(canvas, child, drawingTime);
if (needsCanvasRestore) {
canvas.restore();
}
return retVal;
}
@Override
public void finishUrlFocusChange(boolean hasFocus) {
super.finishUrlFocusChange(hasFocus);
if (!hasFocus) {
mUrlActionContainer.setVisibility(GONE);
}
mStatusCoordinator.onUrlAnimationFinished(hasFocus);
}
public FrameLayout.LayoutParams getFrameLayoutParams() {
return (FrameLayout.LayoutParams) getLayoutParams();
}
@Override
protected void updateButtonVisibility() {
super.updateButtonVisibility();
updateMicButtonVisibility();
}
@Override
public void updateShouldAnimateIconChanges() {
notifyShouldAnimateIconChanges(isUrlBarFocused() || isUrlFocusChangeInProgress());
}
@Override
public void setShowIconsWhenUrlFocused(boolean showIcon) {
super.setShowIconsWhenUrlFocused(showIcon);
mFirstVisibleFocusedView = showIcon ? mStatusView : mUrlBar;
mStatusCoordinator.setShowIconsWhenUrlFocused(showIcon);
}
private int getAdditionalOffsetForNTP() { private int getAdditionalOffsetForNTP() {
return getResources().getDimensionPixelSize(R.dimen.sei_search_box_lateral_padding) return getResources().getDimensionPixelSize(R.dimen.sei_search_box_lateral_padding)
- getResources().getDimensionPixelSize(R.dimen.sei_location_bar_lateral_padding); - getResources().getDimensionPixelSize(R.dimen.sei_location_bar_lateral_padding);
} }
@Override
public void updateVisualsForState() {
super.updateVisualsForState();
boolean isIncognito = getToolbarDataProvider().isIncognito();
setShowIconsWhenUrlFocused(SearchEngineLogoUtils.shouldShowSearchEngineLogo(isIncognito));
updateStatusVisibility();
}
@Override
public void onTabLoadingNTP(NewTabPage ntp) {
super.onTabLoadingNTP(ntp);
updateStatusVisibility();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
try (TraceEvent e = TraceEvent.scoped("LocationBarPhone.onMeasure")) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
try (TraceEvent e = TraceEvent.scoped("LocationBarPhone.onLayout")) {
super.onLayout(changed, left, top, right, bottom);
}
}
/** 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();
......
...@@ -141,11 +141,6 @@ class LocationBarTablet extends LocationBarLayout { ...@@ -141,11 +141,6 @@ class LocationBarTablet extends LocationBarLayout {
return selectedTarget.onTouchEvent(event); return selectedTarget.onTouchEvent(event);
} }
// Returns amount by which to adjust to move value inside the given range.
private static float distanceToRange(float min, float max, float value) {
return value < min ? (min - value) : value > max ? (max - value) : 0;
}
@Override @Override
public void handleUrlFocusAnimation(final boolean hasFocus) { public void handleUrlFocusAnimation(final boolean hasFocus) {
super.handleUrlFocusAnimation(hasFocus); super.handleUrlFocusAnimation(hasFocus);
...@@ -183,15 +178,6 @@ class LocationBarTablet extends LocationBarLayout { ...@@ -183,15 +178,6 @@ class LocationBarTablet extends LocationBarLayout {
mUrlFocusChangeAnimator.start(); mUrlFocusChangeAnimator.start();
} }
/**
* @param shouldShowButtons Whether buttons should be displayed in the URL bar when it's not
* focused.
*/
public void setShouldShowButtonsWhenUnfocused(boolean shouldShowButtons) {
mShouldShowButtonsWhenUnfocused = shouldShowButtons;
updateButtonVisibility();
}
/** /**
* Updates progress of current the URL focus change animation. * Updates progress of current the URL focus change animation.
* *
...@@ -262,6 +248,15 @@ class LocationBarTablet extends LocationBarLayout { ...@@ -262,6 +248,15 @@ class LocationBarTablet extends LocationBarLayout {
} }
} }
/**
* @param shouldShowButtons Whether buttons should be displayed in the URL bar when it's not
* focused.
*/
public void setShouldShowButtonsWhenUnfocused(boolean shouldShowButtons) {
mShouldShowButtonsWhenUnfocused = shouldShowButtons;
updateButtonVisibility();
}
/** /**
* @param button The {@link View} of the button to show. * @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 * @return An animator to run for the given view when showing buttons in the unfocused location
...@@ -403,6 +398,11 @@ class LocationBarTablet extends LocationBarLayout { ...@@ -403,6 +398,11 @@ class LocationBarTablet extends LocationBarLayout {
return animators; return animators;
} }
/** Returns amount by which to adjust to move value inside the given range. */
private static float distanceToRange(float min, float max, float value) {
return value < min ? (min - value) : value > max ? (max - value) : 0;
}
/** /**
* Resets the alpha and translation X for all views affected by the animations for showing or * Resets the alpha and translation X for all views affected by the animations for showing or
* hiding buttons. * hiding buttons.
......
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