Commit 3504586e authored by Matthew Jones's avatar Matthew Jones Committed by Commit Bot

Handle interaction between Contextual Search and bottom toolbar

The contextual search manager is passed into the bottom toolbar's
init function allowing us to attach an observer to it. This allows
us to show and hide the bottom toolbar's android view which was
previously obscuring contextual search.

Bug: 854230
Change-Id: Ieefbc233bacfb90d31f0110ed3f96957b10f069a
Reviewed-on: https://chromium-review.googlesource.com/1106552
Commit-Queue: Matthew Jones <mdjones@chromium.org>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarPedro Amaral <amaralp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#569329}
parent c59e0e37
...@@ -13,6 +13,7 @@ import android.view.ViewStub; ...@@ -13,6 +13,7 @@ import android.view.ViewStub;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.compositor.layouts.LayoutManager; import org.chromium.chrome.browser.compositor.layouts.LayoutManager;
import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior; import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior;
import org.chromium.chrome.browser.contextualsearch.ContextualSearchManager;
import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager; import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager;
import org.chromium.chrome.browser.modelutil.PropertyKey; import org.chromium.chrome.browser.modelutil.PropertyKey;
import org.chromium.chrome.browser.modelutil.PropertyModelChangeProcessor; import org.chromium.chrome.browser.modelutil.PropertyModelChangeProcessor;
...@@ -77,17 +78,21 @@ public class BottomToolbarCoordinator { ...@@ -77,17 +78,21 @@ public class BottomToolbarCoordinator {
* @param tabModelSelector A {@link TabModelSelector} that the tab switcher button uses to * @param tabModelSelector A {@link TabModelSelector} that the tab switcher button uses to
* keep its tab count updated. * keep its tab count updated.
* @param overviewModeBehavior The overview mode manager. * @param overviewModeBehavior The overview mode manager.
* @param contextualSearchManager The manager for Contextual Search to handle interactions when
* that feature is visible.
*/ */
public void initializeWithNative(ResourceManager resourceManager, LayoutManager layoutManager, public void initializeWithNative(ResourceManager resourceManager, LayoutManager layoutManager,
OnClickListener tabSwitcherListener, OnClickListener searchAcceleratorListener, OnClickListener tabSwitcherListener, OnClickListener searchAcceleratorListener,
OnClickListener homeButtonListener, OnTouchListener menuButtonListener, OnClickListener homeButtonListener, OnTouchListener menuButtonListener,
TabModelSelector tabModelSelector, OverviewModeBehavior overviewModeBehavior) { TabModelSelector tabModelSelector, OverviewModeBehavior overviewModeBehavior,
ContextualSearchManager contextualSearchManager) {
mMediator.setButtonListeners( mMediator.setButtonListeners(
searchAcceleratorListener, homeButtonListener, menuButtonListener); searchAcceleratorListener, homeButtonListener, menuButtonListener);
mMediator.setLayoutManager(layoutManager); mMediator.setLayoutManager(layoutManager);
mMediator.setResourceManager(resourceManager); mMediator.setResourceManager(resourceManager);
mMediator.setOverviewModeBehavior(overviewModeBehavior); mMediator.setOverviewModeBehavior(overviewModeBehavior);
mMediator.setToolbarSwipeHandler(layoutManager.getToolbarSwipeHandler()); mMediator.setToolbarSwipeHandler(layoutManager.getToolbarSwipeHandler());
mMediator.setContextualSearchManager(contextualSearchManager);
mTabSwitcherButtonCoordinator.setTabSwitcherListener(tabSwitcherListener); mTabSwitcherButtonCoordinator.setTabSwitcherListener(tabSwitcherListener);
mTabSwitcherButtonCoordinator.setTabModelSelector(tabModelSelector); mTabSwitcherButtonCoordinator.setTabModelSelector(tabModelSelector);
......
...@@ -13,16 +13,22 @@ import org.chromium.chrome.browser.compositor.layouts.LayoutManager; ...@@ -13,16 +13,22 @@ import org.chromium.chrome.browser.compositor.layouts.LayoutManager;
import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior; import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior;
import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior.OverviewModeObserver; import org.chromium.chrome.browser.compositor.layouts.OverviewModeBehavior.OverviewModeObserver;
import org.chromium.chrome.browser.compositor.layouts.eventfilter.EdgeSwipeHandler; import org.chromium.chrome.browser.compositor.layouts.eventfilter.EdgeSwipeHandler;
import org.chromium.chrome.browser.contextualsearch.ContextualSearchManager;
import org.chromium.chrome.browser.contextualsearch.ContextualSearchObserver;
import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager; import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager;
import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager.FullscreenListener; import org.chromium.chrome.browser.fullscreen.ChromeFullscreenManager.FullscreenListener;
import org.chromium.chrome.browser.gsa.GSAContextDisplaySelection;
import org.chromium.ui.resources.ResourceManager; import org.chromium.ui.resources.ResourceManager;
import javax.annotation.Nullable;
/** /**
* This class is responsible for reacting to events from the outside world, interacting with other * This class is responsible for reacting to events from the outside world, interacting with other
* coordinators, running most of the business logic associated with the bottom toolbar, and updating * coordinators, running most of the business logic associated with the bottom toolbar, and updating
* the model accordingly. * the model accordingly.
*/ */
class BottomToolbarMediator implements FullscreenListener, OverviewModeObserver { class BottomToolbarMediator
implements FullscreenListener, OverviewModeObserver, ContextualSearchObserver {
/** The model for the bottom toolbar that holds all of its state. */ /** The model for the bottom toolbar that holds all of its state. */
private BottomToolbarModel mModel; private BottomToolbarModel mModel;
...@@ -32,6 +38,9 @@ class BottomToolbarMediator implements FullscreenListener, OverviewModeObserver ...@@ -32,6 +38,9 @@ class BottomToolbarMediator implements FullscreenListener, OverviewModeObserver
/** The overview mode manager. */ /** The overview mode manager. */
private OverviewModeBehavior mOverviewModeBehavior; private OverviewModeBehavior mOverviewModeBehavior;
/** The manager for Contextual Search to observe appearance/disappearance of the feature. */
private ContextualSearchManager mContextualSearchManger;
/** /**
* Build a new mediator that handles events from outside the bottom toolbar. * Build a new mediator that handles events from outside the bottom toolbar.
* @param model The {@link BottomToolbarModel} that holds all the state for the bottom toolbar. * @param model The {@link BottomToolbarModel} that holds all the state for the bottom toolbar.
...@@ -64,6 +73,7 @@ class BottomToolbarMediator implements FullscreenListener, OverviewModeObserver ...@@ -64,6 +73,7 @@ class BottomToolbarMediator implements FullscreenListener, OverviewModeObserver
public void destroy() { public void destroy() {
mFullscreenManager.removeListener(this); mFullscreenManager.removeListener(this);
mOverviewModeBehavior.removeOverviewModeObserver(this); mOverviewModeBehavior.removeOverviewModeObserver(this);
if (mContextualSearchManger != null) mContextualSearchManger.removeObserver(this);
} }
@Override @Override
...@@ -101,6 +111,19 @@ class BottomToolbarMediator implements FullscreenListener, OverviewModeObserver ...@@ -101,6 +111,19 @@ class BottomToolbarMediator implements FullscreenListener, OverviewModeObserver
@Override @Override
public void onOverviewModeFinishedHiding() {} public void onOverviewModeFinishedHiding() {}
@Override
public void onShowContextualSearch(@Nullable GSAContextDisplaySelection selectionContext) {
mModel.setValue(BottomToolbarModel.ANDROID_VIEW_VISIBLE, false);
}
@Override
public void onHideContextualSearch() {
// If the scroll offset for the toolbar is non-zero, it needs to remain hidden after
// contextual search is hidden.
if (mModel.getValue(BottomToolbarModel.Y_OFFSET) != 0) return;
mModel.setValue(BottomToolbarModel.ANDROID_VIEW_VISIBLE, true);
}
public void setButtonListeners(OnClickListener searchAcceleratorListener, public void setButtonListeners(OnClickListener searchAcceleratorListener,
OnClickListener homeButtonListener, OnTouchListener menuButtonListener) { OnClickListener homeButtonListener, OnTouchListener menuButtonListener) {
mModel.setValue(BottomToolbarModel.SEARCH_ACCELERATOR_LISTENER, searchAcceleratorListener); mModel.setValue(BottomToolbarModel.SEARCH_ACCELERATOR_LISTENER, searchAcceleratorListener);
...@@ -128,4 +151,10 @@ class BottomToolbarMediator implements FullscreenListener, OverviewModeObserver ...@@ -128,4 +151,10 @@ class BottomToolbarMediator implements FullscreenListener, OverviewModeObserver
public boolean isShowingAppMenuUpdateBadge() { public boolean isShowingAppMenuUpdateBadge() {
return mModel.getValue(BottomToolbarModel.UPDATE_BADGE_VISIBLE); return mModel.getValue(BottomToolbarModel.UPDATE_BADGE_VISIBLE);
} }
public void setContextualSearchManager(ContextualSearchManager contextualSearchManager) {
mContextualSearchManger = contextualSearchManager;
if (mContextualSearchManger == null) return;
mContextualSearchManger.addObserver(this);
}
} }
...@@ -714,7 +714,8 @@ public class ToolbarManager implements ToolbarTabController, UrlFocusChangeListe ...@@ -714,7 +714,8 @@ public class ToolbarManager implements ToolbarTabController, UrlFocusChangeListe
mActivity.getCompositorViewHolder().getResourceManager(), mActivity.getCompositorViewHolder().getResourceManager(),
mActivity.getCompositorViewHolder().getLayoutManager(), tabSwitcherClickHandler, mActivity.getCompositorViewHolder().getLayoutManager(), tabSwitcherClickHandler,
searchAcceleratorListener, homeButtonListener, mAppMenuButtonHelper, searchAcceleratorListener, homeButtonListener, mAppMenuButtonHelper,
mTabModelSelector, mOverviewModeBehavior); mTabModelSelector, mOverviewModeBehavior,
mActivity.getContextualSearchManager());
} }
onNativeLibraryReady(); onNativeLibraryReady();
......
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