Commit e2b68be2 authored by bttk's avatar bttk Committed by Commit Bot

[ToolbarMVC] LocationBar no longer implements FakeboxDelegate

Classes implementing LocationBar now explicitly implement
FakeboxDelegate as well and provide it with the
LocationBar.getFakeboxDelegate() method.

Bug: 1139481
Change-Id: I34a1a1400db34460a3f577b83b6efd4dd07a4cd1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2482463
Commit-Queue: who/bttk <bttk@chromium.org>
Reviewed-by: default avatarPatrick Noland <pnoland@chromium.org>
Reviewed-by: default avatarFilip Gorski <fgorski@chromium.org>
Reviewed-by: default avatarBrandon Wylie <wylieb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#821371}
parent 613390d9
...@@ -46,14 +46,13 @@ import org.chromium.base.task.PostTask; ...@@ -46,14 +46,13 @@ import org.chromium.base.task.PostTask;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.app.ChromeActivity; import org.chromium.chrome.browser.app.ChromeActivity;
import org.chromium.chrome.browser.native_page.NativePageFactory; import org.chromium.chrome.browser.native_page.NativePageFactory;
import org.chromium.chrome.browser.ntp.FakeboxDelegate;
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.OmniboxFocusReason;
import org.chromium.chrome.browser.omnibox.UrlBar; import org.chromium.chrome.browser.omnibox.UrlBar;
import org.chromium.chrome.browser.omnibox.UrlBarCoordinator; import org.chromium.chrome.browser.omnibox.UrlBarCoordinator;
import org.chromium.chrome.browser.omnibox.UrlBarCoordinator.SelectionState; import org.chromium.chrome.browser.omnibox.UrlBarCoordinator.SelectionState;
import org.chromium.chrome.browser.omnibox.UrlBarData; import org.chromium.chrome.browser.omnibox.UrlBarData;
import org.chromium.chrome.browser.omnibox.voice.VoiceRecognitionHandler;
import org.chromium.chrome.browser.page_info.ChromePageInfoControllerDelegate; import org.chromium.chrome.browser.page_info.ChromePageInfoControllerDelegate;
import org.chromium.chrome.browser.page_info.ChromePermissionParamsListBuilderDelegate; import org.chromium.chrome.browser.page_info.ChromePermissionParamsListBuilderDelegate;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
...@@ -63,7 +62,6 @@ import org.chromium.chrome.browser.toolbar.ToolbarDataProvider; ...@@ -63,7 +62,6 @@ import org.chromium.chrome.browser.toolbar.ToolbarDataProvider;
import org.chromium.chrome.browser.toolbar.top.ToolbarActionModeCallback; import org.chromium.chrome.browser.toolbar.top.ToolbarActionModeCallback;
import org.chromium.chrome.browser.toolbar.top.ToolbarLayout; import org.chromium.chrome.browser.toolbar.top.ToolbarLayout;
import org.chromium.chrome.browser.toolbar.top.ToolbarPhone; import org.chromium.chrome.browser.toolbar.top.ToolbarPhone;
import org.chromium.chrome.browser.ui.native_page.NativePage;
import org.chromium.components.browser_ui.styles.ChromeColors; import org.chromium.components.browser_ui.styles.ChromeColors;
import org.chromium.components.browser_ui.widget.TintedDrawable; import org.chromium.components.browser_ui.widget.TintedDrawable;
import org.chromium.components.page_info.PageInfoController; import org.chromium.components.page_info.PageInfoController;
...@@ -859,27 +857,9 @@ public class CustomTabToolbar extends ToolbarLayout implements View.OnLongClickL ...@@ -859,27 +857,9 @@ public class CustomTabToolbar extends ToolbarLayout implements View.OnLongClickL
@Override @Override
public void updateMicButtonState() {} public void updateMicButtonState() {}
// Implements FakeBoxDelegate.
@Override
public boolean isUrlBarFocused() {
return false;
}
@Override
public void performSearchQuery(String query, List<String> searchParams) {}
@Override
public void setUrlBarFocus(boolean shouldBeFocused, @Nullable String pastedText,
@OmniboxFocusReason int reason) {}
@Override
public boolean isCurrentPage(NativePage nativePage) {
return false;
}
@Nullable @Nullable
@Override @Override
public VoiceRecognitionHandler getVoiceRecognitionHandler() { public FakeboxDelegate getFakeboxDelegate() {
return null; return null;
} }
} }
......
...@@ -7,6 +7,8 @@ package org.chromium.chrome.browser.omnibox; ...@@ -7,6 +7,8 @@ package org.chromium.chrome.browser.omnibox;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import androidx.annotation.Nullable;
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;
...@@ -16,8 +18,7 @@ import org.chromium.chrome.browser.tab.Tab; ...@@ -16,8 +18,7 @@ import org.chromium.chrome.browser.tab.Tab;
/** /**
* Container that holds the {@link UrlBar} and SSL state related with the current {@link Tab}. * Container that holds the {@link UrlBar} and SSL state related with the current {@link Tab}.
*/ */
public interface LocationBar extends UrlBarDelegate, FakeboxDelegate, Destroyable { public interface LocationBar extends UrlBarDelegate, Destroyable {
/** 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() {}
...@@ -93,4 +94,11 @@ public interface LocationBar extends UrlBarDelegate, FakeboxDelegate, Destroyabl ...@@ -93,4 +94,11 @@ public interface LocationBar extends UrlBarDelegate, FakeboxDelegate, Destroyabl
/** 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();
/**
* Returns a (@link FakeboxDelegate}.
*
* <p>TODO(crbug.com/1140287): Inject FakeboxDelegate where needed and remove this method.
*/
@Nullable
FakeboxDelegate getFakeboxDelegate();
} }
...@@ -15,6 +15,7 @@ import org.chromium.chrome.browser.ActivityTabProvider; ...@@ -15,6 +15,7 @@ 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.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.NewTabPage; import org.chromium.chrome.browser.ntp.NewTabPage;
import org.chromium.chrome.browser.omnibox.voice.VoiceRecognitionHandler; import org.chromium.chrome.browser.omnibox.voice.VoiceRecognitionHandler;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
...@@ -38,7 +39,7 @@ import java.util.List; ...@@ -38,7 +39,7 @@ import java.util.List;
* *
* <p>The coordinator creates and owns elements within this component. * <p>The coordinator creates and owns elements within this component.
*/ */
public final class LocationBarCoordinator implements LocationBar { public final class LocationBarCoordinator implements LocationBar, FakeboxDelegate {
/** Identifies coordinators with methods specific to a device type. */ /** Identifies coordinators with methods specific to a device type. */
public interface SubCoordinator extends Destroyable {} public interface SubCoordinator extends Destroyable {}
...@@ -260,6 +261,11 @@ public final class LocationBarCoordinator implements LocationBar { ...@@ -260,6 +261,11 @@ public final class LocationBarCoordinator implements LocationBar {
mLocationBarLayout.removeUrlFocusChangeListener(listener); mLocationBarLayout.removeUrlFocusChangeListener(listener);
} }
@Override
public FakeboxDelegate getFakeboxDelegate() {
return this;
}
/** /**
* Returns the {@link LocationBarCoordinatorPhone} for this coordinator. * Returns the {@link LocationBarCoordinatorPhone} for this coordinator.
* *
......
...@@ -369,7 +369,7 @@ public class TabbedRootUiCoordinator extends RootUiCoordinator { ...@@ -369,7 +369,7 @@ public class TabbedRootUiCoordinator extends RootUiCoordinator {
} }
ObservableSupplierImpl<Boolean> isUrlBarFocusedSupplier = new ObservableSupplierImpl<>(); ObservableSupplierImpl<Boolean> isUrlBarFocusedSupplier = new ObservableSupplierImpl<>();
isUrlBarFocusedSupplier.set(mToolbarManager.getFakeboxDelegate().isUrlBarFocused()); isUrlBarFocusedSupplier.set(mToolbarManager.isUrlBarFocused());
mUrlFocusChangeListener = new UrlFocusChangeListener() { mUrlFocusChangeListener = new UrlFocusChangeListener() {
@Override @Override
public void onUrlFocusChange(boolean hasFocus) { public void onUrlFocusChange(boolean hasFocus) {
...@@ -389,7 +389,9 @@ public class TabbedRootUiCoordinator extends RootUiCoordinator { ...@@ -389,7 +389,9 @@ public class TabbedRootUiCoordinator extends RootUiCoordinator {
}; };
mOfflineIndicatorController = new OfflineIndicatorControllerV2(mActivity, mOfflineIndicatorController = new OfflineIndicatorControllerV2(mActivity,
mStatusIndicatorCoordinator, isUrlBarFocusedSupplier, mCanAnimateBrowserControls); mStatusIndicatorCoordinator, isUrlBarFocusedSupplier, mCanAnimateBrowserControls);
mToolbarManager.getFakeboxDelegate().addUrlFocusChangeListener(mUrlFocusChangeListener); if (mToolbarManager.getFakeboxDelegate() != null) {
mToolbarManager.getFakeboxDelegate().addUrlFocusChangeListener(mUrlFocusChangeListener);
}
} }
@Override @Override
......
...@@ -379,14 +379,18 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve ...@@ -379,14 +379,18 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve
mLocationBar = locationBarCoordinator; mLocationBar = locationBarCoordinator;
} }
mLocationBar.addUrlFocusChangeListener(this); if (mLocationBar.getFakeboxDelegate() != null) {
mLocationBar.getFakeboxDelegate().addUrlFocusChangeListener(this);
}
Runnable clickDelegate = Runnable clickDelegate =
() -> setUrlBarFocus(false, OmniboxFocusReason.UNFOCUS); () -> setUrlBarFocus(false, OmniboxFocusReason.UNFOCUS);
View scrimTarget = mActivity.getCompositorViewHolder(); View scrimTarget = mActivity.getCompositorViewHolder();
mLocationBarFocusHandler = new LocationBarFocusScrimHandler(scrimCoordinator, mLocationBarFocusHandler = new LocationBarFocusScrimHandler(scrimCoordinator,
tabObscuringHandler, activity, activity.getNightModeStateProvider(), tabObscuringHandler, activity, activity.getNightModeStateProvider(),
mLocationBarModel, clickDelegate, scrimTarget); mLocationBarModel, clickDelegate, scrimTarget);
mLocationBar.addUrlFocusChangeListener(mLocationBarFocusHandler); if (mLocationBar.getFakeboxDelegate() != null) {
mLocationBar.getFakeboxDelegate().addUrlFocusChangeListener(mLocationBarFocusHandler);
}
mProgressBarCoordinator = mProgressBarCoordinator =
new LoadProgressCoordinator(mActivityTabProvider, mToolbar.getProgressBar()); new LoadProgressCoordinator(mActivityTabProvider, mToolbar.getProgressBar());
...@@ -736,7 +740,10 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve ...@@ -736,7 +740,10 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve
* @return Whether the UrlBar currently has focus. * @return Whether the UrlBar currently has focus.
*/ */
public boolean isUrlBarFocused() { public boolean isUrlBarFocused() {
return mLocationBar.isUrlBarFocused(); if (mLocationBar.getFakeboxDelegate() == null) {
return false;
}
return mLocationBar.getFakeboxDelegate().isUrlBarFocused();
} }
/** /**
...@@ -1205,8 +1212,9 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve ...@@ -1205,8 +1212,9 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve
*/ */
public void setUrlBarFocus(boolean focused, @OmniboxFocusReason int reason) { public void setUrlBarFocus(boolean focused, @OmniboxFocusReason int reason) {
if (!mInitializedWithNative) return; if (!mInitializedWithNative) return;
boolean wasFocused = mLocationBar.isUrlBarFocused(); if (mLocationBar.getFakeboxDelegate() == null) return;
mLocationBar.setUrlBarFocus(focused, null, reason); boolean wasFocused = mLocationBar.getFakeboxDelegate().isUrlBarFocused();
mLocationBar.getFakeboxDelegate().setUrlBarFocus(focused, null, reason);
if (wasFocused && focused) { if (wasFocused && focused) {
mLocationBar.selectAll(); mLocationBar.selectAll();
} }
...@@ -1382,9 +1390,10 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve ...@@ -1382,9 +1390,10 @@ public class ToolbarManager implements UrlFocusChangeListener, ThemeColorObserve
/** /**
* @return The {@link FakeboxDelegate}. * @return The {@link FakeboxDelegate}.
*/ */
@Nullable
public FakeboxDelegate getFakeboxDelegate() { public FakeboxDelegate getFakeboxDelegate() {
// TODO(crbug.com/1000295): Split fakebox component out of ntp package. // TODO(crbug.com/1000295): Split fakebox component out of ntp package.
return mLocationBar; return mLocationBar.getFakeboxDelegate();
} }
private boolean shouldShowCursorInLocationBar() { private boolean shouldShowCursorInLocationBar() {
......
...@@ -792,9 +792,7 @@ public abstract class ToolbarLayout ...@@ -792,9 +792,7 @@ public abstract class ToolbarLayout
* @return Whether or not the current Tab did go back. * @return Whether or not the current Tab did go back.
*/ */
boolean back() { boolean back() {
if (getLocationBar() != null) { maybeUnfocusUrlBar();
getLocationBar().setUrlBarFocus(false, null, OmniboxFocusReason.UNFOCUS);
}
return mToolbarTabController != null && mToolbarTabController.back(); return mToolbarTabController != null && mToolbarTabController.back();
} }
...@@ -803,9 +801,7 @@ public abstract class ToolbarLayout ...@@ -803,9 +801,7 @@ public abstract class ToolbarLayout
* @return Whether or not the current Tab did go forward. * @return Whether or not the current Tab did go forward.
*/ */
boolean forward() { boolean forward() {
if (getLocationBar() != null) { maybeUnfocusUrlBar();
getLocationBar().setUrlBarFocus(false, null, OmniboxFocusReason.UNFOCUS);
}
return mToolbarTabController != null ? mToolbarTabController.forward() : false; return mToolbarTabController != null ? mToolbarTabController.forward() : false;
} }
...@@ -816,9 +812,7 @@ public abstract class ToolbarLayout ...@@ -816,9 +812,7 @@ public abstract class ToolbarLayout
* <p>The buttons of the toolbar will be updated as a result of making this call. * <p>The buttons of the toolbar will be updated as a result of making this call.
*/ */
void stopOrReloadCurrentTab() { void stopOrReloadCurrentTab() {
if (getLocationBar() != null) { maybeUnfocusUrlBar();
getLocationBar().setUrlBarFocus(false, null, OmniboxFocusReason.UNFOCUS);
}
if (mToolbarTabController != null) mToolbarTabController.stopOrReloadCurrentTab(); if (mToolbarTabController != null) mToolbarTabController.stopOrReloadCurrentTab();
} }
...@@ -826,12 +820,17 @@ public abstract class ToolbarLayout ...@@ -826,12 +820,17 @@ public abstract class ToolbarLayout
* Opens hompage in the current tab. * Opens hompage in the current tab.
*/ */
void openHomepage() { void openHomepage() {
if (getLocationBar() != null) { maybeUnfocusUrlBar();
getLocationBar().setUrlBarFocus(false, null, OmniboxFocusReason.UNFOCUS);
}
if (mToolbarTabController != null) mToolbarTabController.openHomepage(); if (mToolbarTabController != null) mToolbarTabController.openHomepage();
} }
private void maybeUnfocusUrlBar() {
if (getLocationBar() != null && getLocationBar().getFakeboxDelegate() != null) {
getLocationBar().getFakeboxDelegate().setUrlBarFocus(
false, null, OmniboxFocusReason.UNFOCUS);
}
}
/** /**
* Update the optional toolbar button, showing it if currently hidden. * Update the optional toolbar button, showing it if currently hidden.
* @param buttonData Display data for the button, e.g. the Drawable and content description. * @param buttonData Display data for the button, e.g. the Drawable and content description.
......
...@@ -120,6 +120,7 @@ public class ChromeTabModalPresenterTest { ...@@ -120,6 +120,7 @@ public class ChromeTabModalPresenterTest {
mActivity.getToolbarManager() mActivity.getToolbarManager()
.getToolbarLayoutForTesting() .getToolbarLayoutForTesting()
.getLocationBar() .getLocationBar()
.getFakeboxDelegate()
.addUrlFocusChangeListener(mTestObserver); .addUrlFocusChangeListener(mTestObserver);
mTabModalPresenter = mTabModalPresenter =
(ChromeTabModalPresenter) mManager.getPresenterForTest(ModalDialogType.TAB); (ChromeTabModalPresenter) mManager.getPresenterForTest(ModalDialogType.TAB);
......
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