Commit 0eb293df authored by Tomasz Wiszkowski's avatar Tomasz Wiszkowski Committed by Commit Bot

Adaptive suggestions count.

This change introduces Adaptive suggestions count, where the number
of offered suggestions is driven by the available screen space.

The mechanism needs to decide whether a suggestion is eligible ahead
of Layout call, and is therefore unable to reliably identify the
height of a suggestion, therefore we use minimum suggestion height
instead.

Bug: 1050813
Change-Id: I1fc440f6e86fc0ca764b79e8c835be174bf31da6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2071139
Commit-Queue: Ender <ender@google.com>
Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarPatrick Noland <pnoland@chromium.org>
Cr-Commit-Position: refs/heads/master@{#748481}
parent 12c77448
......@@ -155,6 +155,7 @@ chrome_junit_test_java_sources = [
"junit/src/org/chromium/chrome/browser/omnibox/geo/PlatformNetworksManagerTest.java",
"junit/src/org/chromium/chrome/browser/omnibox/geo/VisibleNetworksTest.java",
"junit/src/org/chromium/chrome/browser/omnibox/geo/VisibleNetworksTrackerTest.java",
"junit/src/org/chromium/chrome/browser/omnibox/suggestions/AutocompleteMediatorUnitTest.java",
"junit/src/org/chromium/chrome/browser/omnibox/suggestions/answer/AnswerSuggestionProcessorUnitTest.java",
"junit/src/org/chromium/chrome/browser/omnibox/suggestions/base/BaseSuggestionProcessorTest.java",
"junit/src/org/chromium/chrome/browser/omnibox/suggestions/base/BaseSuggestionViewBinderUnitTest.java",
......
......@@ -7,7 +7,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/suggestions_url_view"
android:minHeight="@dimen/omnibox_suggestion_edit_url_min_height"
android:minHeight="@dimen/omnibox_suggestion_comfortable_height"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground" >
......
......@@ -318,7 +318,6 @@
<dimen name="omnibox_suggestion_list_padding_bottom">8dp</dimen>
<dimen name="omnibox_suggestion_first_line_text_size">16sp</dimen>
<dimen name="omnibox_suggestion_second_line_text_size">14sp</dimen>
<dimen name="omnibox_suggestion_edit_url_min_height">60dp</dimen>
<dimen name="omnibox_suggestion_start_offset_without_icon">18dp</dimen>
<dimen name="omnibox_suggestion_start_offset_with_icon">56dp</dimen>
......
......@@ -750,7 +750,7 @@
<style name="OmniboxSuggestionIconButton">
<item name="android:background">?attr/selectableItemBackground</item>
<item name="android:layout_width">@dimen/min_touch_target_size</item>
<item name="android:layout_height">@dimen/omnibox_suggestion_edit_url_min_height</item>
<item name="android:layout_height">@dimen/omnibox_suggestion_comfortable_height</item>
<item name="tint">@color/default_icon_color</item>
</style>
......
......@@ -22,6 +22,11 @@ public interface SuggestionProcessor {
*/
int getViewTypeId();
/**
* @return The minimum possible height of the suggestion view for this suggestion.
*/
int getMinimumSuggestionViewHeight();
/**
* @see org.chromium.chrome.browser.omnibox.UrlFocusChangeListener#onUrlFocusChange(boolean)
*/
......
......@@ -33,6 +33,20 @@ public abstract class BaseSuggestionViewProcessor implements SuggestionProcessor
private final SuggestionHost mSuggestionHost;
private boolean mEnableCompactSuggestions;
private final int mDesiredFaviconWidthPx;
private int mSuggestionSizePx;
/**
* @param context Current context.
* @param host A handle to the object using the suggestions.
*/
public BaseSuggestionViewProcessor(Context context, SuggestionHost host) {
mContext = context;
mSuggestionHost = host;
mDesiredFaviconWidthPx = mContext.getResources().getDimensionPixelSize(
R.dimen.omnibox_suggestion_favicon_size);
mSuggestionSizePx = mContext.getResources().getDimensionPixelSize(
R.dimen.omnibox_suggestion_comfortable_height);
}
@Override
public void onUrlFocusChange(boolean hasFocus) {}
......@@ -47,19 +61,18 @@ public abstract class BaseSuggestionViewProcessor implements SuggestionProcessor
public void onNativeInitialized() {
mEnableCompactSuggestions =
ChromeFeatureList.isEnabled(ChromeFeatureList.OMNIBOX_COMPACT_SUGGESTIONS);
if (mEnableCompactSuggestions) {
mSuggestionSizePx = mContext.getResources().getDimensionPixelSize(
R.dimen.omnibox_suggestion_compact_height);
}
}
@Override
public void onSuggestionsReceived() {}
/**
* @param host A handle to the object using the suggestions.
*/
public BaseSuggestionViewProcessor(Context context, SuggestionHost host) {
mContext = context;
mSuggestionHost = host;
mDesiredFaviconWidthPx = mContext.getResources().getDimensionPixelSize(
R.dimen.omnibox_suggestion_favicon_size);
@Override
public int getMinimumSuggestionViewHeight() {
return mSuggestionSizePx;
}
/**
......
......@@ -102,11 +102,16 @@ public class EditUrlSuggestionProcessor implements OnClickListener, SuggestionPr
/** Supplies additional control over suggestion model. */
private final SuggestionHost mSuggestionHost;
/** Minimum height of the corresponding view. */
private final int mMinViewHeight;
/**
* @param locationBarDelegate A means of modifying the location bar.
*/
public EditUrlSuggestionProcessor(Context context, SuggestionHost suggestionHost,
LocationBarDelegate locationBarDelegate, Supplier<LargeIconBridge> iconBridgeSupplier) {
mMinViewHeight = context.getResources().getDimensionPixelSize(
R.dimen.omnibox_suggestion_comfortable_height);
mLocationBarDelegate = locationBarDelegate;
mDesiredFaviconWidthPx = context.getResources().getDimensionPixelSize(
R.dimen.omnibox_suggestion_favicon_size);
......@@ -125,6 +130,11 @@ public class EditUrlSuggestionProcessor implements OnClickListener, SuggestionPr
return (ViewGroup) inflater.inflate(R.layout.edit_url_suggestion_layout, null);
}
@Override
public int getMinimumSuggestionViewHeight() {
return mMinViewHeight;
}
@Override
public boolean doesProcessSuggestion(OmniboxSuggestion suggestion) {
Tab activeTab = mTabProvider != null ? mTabProvider.get() : null;
......
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