Commit b6235dfb authored by Ted Choc's avatar Ted Choc Committed by Commit Bot

Add a drop shadow for bottom anchored elements.

Uses that drop shadow for the navigation popup used for long press.

Fixes a small bug where the "Show all history" item in the
navigation popup was showing chrome://history because it was
using the wrong constructor param ordering (added a test).

BUG=800033

Change-Id: I84f60d0e7d67e86aa473b435ee63ededc5ee09f7
Reviewed-on: https://chromium-review.googlesource.com/1217362
Commit-Queue: Ted Choc <tedchoc@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Cr-Commit-Position: refs/heads/master@{#590124}
parent 55dcc199
...@@ -2070,9 +2070,8 @@ public class ChromeTabbedActivity ...@@ -2070,9 +2070,8 @@ public class ChromeTabbedActivity
Tab tab = getActivityTab(); Tab tab = getActivityTab();
if (tab == null || tab.getWebContents() == null || !tab.isUserInteractable()) return; if (tab == null || tab.getWebContents() == null || !tab.isUserInteractable()) return;
mNavigationPopup = new NavigationPopup( mNavigationPopup = new NavigationPopup(tab.getProfile(), this,
tab.getProfile(), this, tab.getWebContents().getNavigationController(), false); tab.getWebContents().getNavigationController(), false, true);
mNavigationPopup.reverseHistoryOrder();
mNavigationPopup.setWidth( mNavigationPopup.setWidth(
getResources().getDimensionPixelSize(R.dimen.navigation_popup_width)); getResources().getDimensionPixelSize(R.dimen.navigation_popup_width));
mNavigationPopup.setAnchorView(findViewById(R.id.navigation_popup_anchor_stub)); mNavigationPopup.setAnchorView(findViewById(R.id.navigation_popup_anchor_stub));
......
...@@ -73,22 +73,28 @@ public class NavigationPopup extends ListPopupWindow implements AdapterView.OnIt ...@@ -73,22 +73,28 @@ public class NavigationPopup extends ListPopupWindow implements AdapterView.OnIt
* @param context The context used for building the popup. * @param context The context used for building the popup.
* @param navigationController The controller which takes care of page navigations. * @param navigationController The controller which takes care of page navigations.
* @param isForward Whether to request forward navigation entries. * @param isForward Whether to request forward navigation entries.
* @param anchorToBottom Whether the popup is anchored to the bottom of the screen.
*/ */
public NavigationPopup(Profile profile, Context context, public NavigationPopup(Profile profile, Context context,
NavigationController navigationController, boolean isForward) { NavigationController navigationController, boolean isForward, boolean anchorToBottom) {
super(context, null, android.R.attr.popupMenuStyle); super(context, null, android.R.attr.popupMenuStyle);
mProfile = profile; mProfile = profile;
mContext = context; mContext = context;
mNavigationController = navigationController; mNavigationController = navigationController;
mHistory = mNavigationController.getDirectedNavigationHistory( mHistory = mNavigationController.getDirectedNavigationHistory(
isForward, MAXIMUM_HISTORY_ITEMS); isForward, MAXIMUM_HISTORY_ITEMS);
mHistory.addEntry(new NavigationEntry(FULL_HISTORY_ENTRY_INDEX, UrlConstants.HISTORY_URL, mHistory.addEntry(new NavigationEntry(FULL_HISTORY_ENTRY_INDEX, UrlConstants.HISTORY_URL,
null, null, mContext.getResources().getString(R.string.show_full_history), null, null, null, null, mContext.getResources().getString(R.string.show_full_history),
null, 0)); null, 0));
setBackgroundDrawable( setBackgroundDrawable(ApiCompatibilityUtils.getDrawable(mContext.getResources(),
ApiCompatibilityUtils.getDrawable(mContext.getResources(), R.drawable.popup_bg)); anchorToBottom ? R.drawable.popup_bg_bottom : R.drawable.popup_bg));
// By default ListPopupWindow uses the top & bottom padding of the background to determine
// the vertical offset applied to the window. This causes the popup to be shifted up
// by the top padding, and thus we forcibly need to specify a vertical offset of 0 to
// prevent that.
if (anchorToBottom) setVerticalOffset(0);
if (ChromeFeatureList.isInitialized() if (ChromeFeatureList.isInitialized()
&& ChromeFeatureList.isEnabled(ChromeFeatureList.LONG_PRESS_BACK_NEW_DESIGN)) { && ChromeFeatureList.isEnabled(ChromeFeatureList.LONG_PRESS_BACK_NEW_DESIGN)) {
...@@ -96,6 +102,7 @@ public class NavigationPopup extends ListPopupWindow implements AdapterView.OnIt ...@@ -96,6 +102,7 @@ public class NavigationPopup extends ListPopupWindow implements AdapterView.OnIt
} else { } else {
mAdapter = new NavigationAdapter(); mAdapter = new NavigationAdapter();
} }
if (anchorToBottom) mAdapter.reverseOrder();
setModal(true); setModal(true);
setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED); setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED);
...@@ -136,14 +143,6 @@ public class NavigationPopup extends ListPopupWindow implements AdapterView.OnIt ...@@ -136,14 +143,6 @@ public class NavigationPopup extends ListPopupWindow implements AdapterView.OnIt
}); });
} }
/**
* Reverses the history order for visual purposes only. This does not pull from the beginning of
* the navigation history, but only reverses the list that would have normally been retrieved.
*/
public void reverseHistoryOrder() {
mAdapter.reverseOrder();
}
private void initialize() { private void initialize() {
ThreadUtils.assertOnUiThread(); ThreadUtils.assertOnUiThread();
mInitialized = true; mInitialized = true;
......
...@@ -298,7 +298,7 @@ public class ToolbarTablet ...@@ -298,7 +298,7 @@ public class ToolbarTablet
Tab tab = getToolbarDataProvider().getTab(); Tab tab = getToolbarDataProvider().getTab();
if (tab == null || tab.getWebContents() == null) return; if (tab == null || tab.getWebContents() == null) return;
mNavigationPopup = new NavigationPopup(tab.getProfile(), getContext(), mNavigationPopup = new NavigationPopup(tab.getProfile(), getContext(),
tab.getWebContents().getNavigationController(), isForward); tab.getWebContents().getNavigationController(), isForward, false);
mNavigationPopup.setAnchorView(anchorView); mNavigationPopup.setAnchorView(anchorView);
......
...@@ -7,6 +7,9 @@ package org.chromium.chrome.browser; ...@@ -7,6 +7,9 @@ package org.chromium.chrome.browser;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.support.test.filters.MediumTest; import android.support.test.filters.MediumTest;
import android.support.test.filters.SmallTest; import android.support.test.filters.SmallTest;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
...@@ -19,6 +22,7 @@ import org.chromium.base.test.util.CommandLineFlags; ...@@ -19,6 +22,7 @@ import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Feature; import org.chromium.base.test.util.Feature;
import org.chromium.base.test.util.RetryOnFailure; import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.base.test.util.UrlUtils; import org.chromium.base.test.util.UrlUtils;
import org.chromium.chrome.R;
import org.chromium.chrome.browser.profiles.Profile; import org.chromium.chrome.browser.profiles.Profile;
import org.chromium.chrome.test.ChromeActivityTestRule; import org.chromium.chrome.test.ChromeActivityTestRule;
import org.chromium.chrome.test.ChromeJUnit4ClassRunner; import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
...@@ -29,7 +33,7 @@ import org.chromium.content_public.browser.NavigationHistory; ...@@ -29,7 +33,7 @@ import org.chromium.content_public.browser.NavigationHistory;
import org.chromium.content_public.browser.test.util.Criteria; import org.chromium.content_public.browser.test.util.Criteria;
import org.chromium.content_public.browser.test.util.CriteriaHelper; import org.chromium.content_public.browser.test.util.CriteriaHelper;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.ExecutionException;
/** /**
* Tests for the navigation popup. * Tests for the navigation popup.
...@@ -231,19 +235,9 @@ public class NavigationPopupTest { ...@@ -231,19 +235,9 @@ public class NavigationPopupTest {
@Test @Test
@MediumTest @MediumTest
@Feature({"Navigation"}) @Feature({"Navigation"})
public void testFaviconFetching() { public void testFaviconFetching() throws ExecutionException {
final TestNavigationController controller = new TestNavigationController(); final TestNavigationController controller = new TestNavigationController();
final AtomicReference<NavigationPopup> popupReference = new AtomicReference<>(); final NavigationPopup popup = showPopup(controller);
ThreadUtils.runOnUiThreadBlocking(() -> {
NavigationPopup popup = new NavigationPopup(
mProfile, mActivityTestRule.getActivity(), controller, true);
popup.setWidth(300);
popup.setHeight(300);
popup.setAnchorView(mActivityTestRule.getActivity().getActivityTab().getContentView());
popup.show();
popupReference.set(popup);
});
CriteriaHelper.pollUiThread(new Criteria("All favicons did not get updated.") { CriteriaHelper.pollUiThread(new Criteria("All favicons did not get updated.") {
@Override @Override
...@@ -258,32 +252,56 @@ public class NavigationPopupTest { ...@@ -258,32 +252,56 @@ public class NavigationPopupTest {
} }
}); });
ThreadUtils.runOnUiThreadBlocking(() -> popupReference.get().dismiss()); ThreadUtils.runOnUiThreadBlocking(() -> popup.dismiss());
} }
@Test @Test
@SmallTest @SmallTest
@Feature({"Navigation"}) @Feature({"Navigation"})
public void testItemSelection() { public void testItemSelection() throws ExecutionException {
final TestNavigationController controller = new TestNavigationController(); final TestNavigationController controller = new TestNavigationController();
final AtomicReference<NavigationPopup> popupReference = new AtomicReference<>(); final NavigationPopup popup = showPopup(controller);
ThreadUtils.runOnUiThreadBlocking((Runnable) () -> popup.performItemClick(1));
Assert.assertFalse("Popup did not hide as expected.", popup.isShowing());
Assert.assertEquals(
"Popup attempted to navigate to the wrong index", 5, controller.mNavigatedIndex);
}
@Test
@SmallTest
@Feature({"Navigation"})
public void testShowAllHistory() throws ExecutionException {
final TestNavigationController controller = new TestNavigationController();
final NavigationPopup popup = showPopup(controller);
ThreadUtils.runOnUiThreadBlocking(() -> { ThreadUtils.runOnUiThreadBlocking(() -> {
ListView list = popup.getListView();
View view = list.getAdapter().getView(list.getAdapter().getCount() - 1, null, list);
TextView text = null;
if (view instanceof TextView) {
text = (TextView) view;
} else {
text = (TextView) view.findViewById(R.id.entry_title);
}
Assert.assertNotNull(text);
Assert.assertEquals(text.getResources().getString(R.string.show_full_history),
text.getText().toString());
});
}
private NavigationPopup showPopup(NavigationController controller) throws ExecutionException {
return ThreadUtils.runOnUiThreadBlocking(() -> {
NavigationPopup popup = new NavigationPopup( NavigationPopup popup = new NavigationPopup(
mProfile, mActivityTestRule.getActivity(), controller, true); mProfile, mActivityTestRule.getActivity(), controller, true, false);
popup.setWidth(300); popup.setWidth(300);
popup.setHeight(300); popup.setHeight(300);
popup.setAnchorView(mActivityTestRule.getActivity().getActivityTab().getContentView()); popup.setAnchorView(mActivityTestRule.getActivity().getActivityTab().getContentView());
popup.show(); popup.show();
popupReference.set(popup); return popup;
}); });
ThreadUtils.runOnUiThreadBlocking(
(Runnable) () -> popupReference.get().performItemClick(1));
Assert.assertFalse("Popup did not hide as expected.", popupReference.get().isShowing());
Assert.assertEquals(
"Popup attempted to navigate to the wrong index", 5, controller.mNavigatedIndex);
} }
} }
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