Skip to content

Commit

Permalink
Android: Fix gesture navigation in dark mode
Browse files Browse the repository at this point in the history
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.

TBR=twellington@chromium.org
(cherry picked from commit 88f7315)

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: Theresa  <twellington@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#705340}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1858543
Reviewed-by: Jinsuk Kim <jinsukkim@chromium.org>
Cr-Commit-Position: refs/branch-heads/3904@{#742}
Cr-Branched-From: 675968a-refs/heads/master@{#693954}
  • Loading branch information
JinsukKim committed Oct 13, 2019
1 parent 216591c commit 5e8bb5e
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2256,7 +2256,7 @@ private void showFullHistoryOnNavigationSheet(Tab tab) {
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ private void updateNavigationHandler() {
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()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void updateNavigationHandler() {
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package org.chromium.chrome.browser.gesturenav;

import android.content.Context;
import android.support.annotation.IntDef;
import android.view.GestureDetector;
import android.view.MotionEvent;
Expand Down Expand Up @@ -43,6 +44,7 @@ public class NavigationHandler {
}

private final ViewGroup mParentView;
private final Context mContext;
private final Supplier<NavigationGlow> mGlowEffectSupplier;

private final HistoryNavigationDelegate mDelegate;
Expand Down Expand Up @@ -87,17 +89,18 @@ public interface ActionDelegate {
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;
mEdgeWidthPx = EDGE_WIDTH_DP * parentView.getResources().getDisplayMetrics().density;
}

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) -> {
Expand All @@ -116,8 +119,8 @@ private void createLayout() {
});

mNavigationSheet = NavigationSheet.isEnabled()
? NavigationSheet.create(mParentView, mDelegate.getBottomSheetController(),
mDelegate.createSheetDelegate())
? NavigationSheet.create(mParentView, mContext,
mDelegate.getBottomSheetController(), mDelegate.createSheetDelegate())
: NavigationSheet.DUMMY;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package org.chromium.chrome.browser.gesturenav;

import android.content.Context;
import android.view.View;

import org.chromium.base.Supplier;
Expand Down Expand Up @@ -38,14 +39,15 @@ interface Delegate {
/**
* 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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,11 @@ public static void bind(PropertyModel model, View view, PropertyKey propertyKey)
/**
* 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) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,10 @@ public void testItemSelection() throws ExecutionException {
private NavigationSheet showPopup(NavigationController controller) throws ExecutionException {
return TestThreadUtils.runOnUiThreadBlocking(() -> {
Tab tab = mActivityTestRule.getActivity().getActivityTabProvider().get();
NavigationSheet navigationSheet = NavigationSheet.create(tab.getContentView(),
mActivityTestRule.getActivity()::getBottomSheetController,
new TestSheetDelegate(controller));
NavigationSheet navigationSheet =
NavigationSheet.create(tab.getContentView(), mActivityTestRule.getActivity(),
mActivityTestRule.getActivity()::getBottomSheetController,
new TestSheetDelegate(controller));
navigationSheet.startAndExpand(false, false);
return navigationSheet;
});
Expand Down

0 comments on commit 5e8bb5e

Please sign in to comment.