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