Commit 88f73151 authored by Jinsuk Kim's avatar Jinsuk Kim Committed by Commit Bot

Android: Fix gesture navigation in dark mode

Tab uses themed application context when creating the content view for
rendered pages' WebContents. Views in gesture navigation should not
use this context to create UI since dark mode is not enabled in the
context. This CL lets the feature use activity context to deal with
dark mode properly.

Bug: 1010576, 1009393
Change-Id: I5373b7244767a35516138cb8d735be80a53df1b0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1855148
Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705340}
parent fec93868
......@@ -2267,7 +2267,7 @@ public class ChromeTabbedActivity extends ChromeActivity implements ScreenshotMo
return;
}
mNavigationSheet = NavigationSheet.create(
getWindow().getDecorView().findViewById(android.R.id.content),
getWindow().getDecorView().findViewById(android.R.id.content), this,
this::getBottomSheetController, new TabbedSheetDelegate(tab));
mNavigationSheet.startAndExpand(/* forward=*/false, /* animate=*/true);
getBottomSheet().addObserver(new EmptyBottomSheetObserver() {
......
......@@ -243,7 +243,8 @@ public class SwipeRefreshHandler extends TabWebContentsUserData
if (mNavigationDelegate.isNavigationEnabled(mContainerView)) {
if (mNavigationHandler == null) {
mActionDelegate = mNavigationDelegate.createActionDelegate();
mNavigationHandler = new NavigationHandler(mContainerView, mNavigationDelegate,
mNavigationHandler = new NavigationHandler(mContainerView, mTab.getContext(),
mNavigationDelegate,
NavigationGlowFactory.forRenderedPage(
mContainerView, mTab.getWebContents()));
}
......
......@@ -71,7 +71,7 @@ public class HistoryNavigationLayout extends FrameLayout {
if (mNavigationHandler == null) {
mDetector = new GestureDetector(getContext(), new SideNavGestureListener());
mNavigationHandler = new NavigationHandler(
this, mDelegate, NavigationGlowFactory.forJavaLayer(this));
this, getContext(), mDelegate, NavigationGlowFactory.forJavaLayer(this));
}
} else {
mDetector = null;
......
......@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.gesturenav;
import android.content.Context;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
......@@ -44,6 +45,7 @@ public class NavigationHandler {
}
private final ViewGroup mParentView;
private final Context mContext;
private final Supplier<NavigationGlow> mGlowEffectSupplier;
private final HistoryNavigationDelegate mDelegate;
......@@ -88,9 +90,10 @@ public class NavigationHandler {
boolean willBackExitApp();
}
public NavigationHandler(ViewGroup parentView, HistoryNavigationDelegate delegate,
Supplier<NavigationGlow> glowEffectSupplier) {
public NavigationHandler(ViewGroup parentView, Context context,
HistoryNavigationDelegate delegate, Supplier<NavigationGlow> glowEffectSupplier) {
mParentView = parentView;
mContext = context;
mDelegate = delegate;
mActionDelegate = delegate.createActionDelegate();
mGlowEffectSupplier = glowEffectSupplier;
......@@ -98,7 +101,7 @@ public class NavigationHandler {
}
private void createLayout() {
mSideSlideLayout = new SideSlideLayout(mParentView.getContext());
mSideSlideLayout = new SideSlideLayout(mContext);
mSideSlideLayout.setLayoutParams(
new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
mSideSlideLayout.setOnNavigationListener((forward) -> {
......@@ -117,8 +120,8 @@ public class NavigationHandler {
});
mNavigationSheet = NavigationSheet.isEnabled()
? NavigationSheet.create(mParentView, mDelegate.getBottomSheetController(),
mDelegate.createSheetDelegate())
? NavigationSheet.create(mParentView, mContext,
mDelegate.getBottomSheetController(), mDelegate.createSheetDelegate())
: NavigationSheet.DUMMY;
}
......
......@@ -4,6 +4,7 @@
package org.chromium.chrome.browser.gesturenav;
import android.content.Context;
import android.view.View;
import org.chromium.base.Supplier;
......@@ -44,14 +45,15 @@ public interface NavigationSheet {
/**
* Create {@link NavigationSheet} object.
* @param rootView Root view whose dimension is used for the sheet.
* @param context {@link Context} used to retrieve resources.
* @param bottomSheetController {@link BottomSheetController} object.
* @param delegate Delegate used by navigation sheet to perform actions.
* @return NavigationSheet object.
*/
public static NavigationSheet create(View rootView,
public static NavigationSheet create(View rootView, Context context,
Supplier<BottomSheetController> bottomSheetController,
NavigationSheet.Delegate delegate) {
return new NavigationSheetCoordinator(rootView, bottomSheetController, delegate);
return new NavigationSheetCoordinator(rootView, context, bottomSheetController, delegate);
}
/**
......
......@@ -114,12 +114,11 @@ class NavigationSheetCoordinator implements BottomSheetContent, NavigationSheet
/**
* Construct a new NavigationSheet.
*/
NavigationSheetCoordinator(
View parent, Supplier<BottomSheetController> bottomSheetController, Delegate delegate) {
NavigationSheetCoordinator(View parent, Context context,
Supplier<BottomSheetController> bottomSheetController, Delegate delegate) {
mParentView = parent;
mBottomSheetController = bottomSheetController;
mDelegate = delegate;
Context context = parent.getContext();
mLayoutInflater = LayoutInflater.from(context);
mToolbarView = mLayoutInflater.inflate(R.layout.navigation_sheet_toolbar, null);
mMediator = new NavigationSheetMediator(context, mModelList, (position, index) -> {
......
......@@ -196,7 +196,8 @@ public class NavigationSheetTest {
private NavigationSheet showPopup(NavigationController controller) throws ExecutionException {
return TestThreadUtils.runOnUiThreadBlocking(() -> {
Tab tab = mActivityTestRule.getActivity().getActivityTabProvider().get();
NavigationSheet navigationSheet = NavigationSheet.create(tab.getContentView(),
NavigationSheet navigationSheet =
NavigationSheet.create(tab.getContentView(), mActivityTestRule.getActivity(),
mActivityTestRule.getActivity()::getBottomSheetController,
new TestSheetDelegate(controller));
navigationSheet.startAndExpand(false, false);
......
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