Chromium Code Reviews| Index: chrome/android/shell/java/src/org/chromium/chrome/shell/omnibox/SuggestionPopup.java |
| diff --git a/chrome/android/shell/java/src/org/chromium/chrome/shell/omnibox/SuggestionPopup.java b/chrome/android/shell/java/src/org/chromium/chrome/shell/omnibox/SuggestionPopup.java |
| index 883918adac4389ee24c20c8c79c44d17f027598c..53147c60b3a056ef8cbfd611f409b18e59321b1b 100644 |
| --- a/chrome/android/shell/java/src/org/chromium/chrome/shell/omnibox/SuggestionPopup.java |
| +++ b/chrome/android/shell/java/src/org/chromium/chrome/shell/omnibox/SuggestionPopup.java |
| @@ -5,6 +5,7 @@ |
| package org.chromium.chrome.shell.omnibox; |
| import android.content.Context; |
| +import android.graphics.Rect; |
| import android.os.Handler; |
| import android.text.Editable; |
| import android.text.TextUtils; |
| @@ -20,6 +21,7 @@ import android.widget.TextView; |
| import org.chromium.chrome.browser.omnibox.AutocompleteController; |
| import org.chromium.chrome.browser.omnibox.AutocompleteController.OnSuggestionsReceivedListener; |
| import org.chromium.chrome.browser.omnibox.OmniboxSuggestion; |
| +import org.chromium.chrome.shell.ChromeShellActivity; |
| import org.chromium.chrome.shell.ChromeShellToolbar; |
| import org.chromium.chrome.shell.R; |
| @@ -40,6 +42,7 @@ public class SuggestionPopup implements OnSuggestionsReceivedListener, TextWatch |
| private Runnable mRequestSuggestions; |
| private ListPopupWindow mSuggestionsPopup; |
| private SuggestionArrayAdapter mSuggestionArrayAdapter; |
| + private int mSuggestionsPopupItemsCount; |
| /** |
| * Initializes a suggestion popup that will track urlField value and display suggestions based |
| @@ -57,6 +60,7 @@ public class SuggestionPopup implements OnSuggestionsReceivedListener, TextWatch |
| int oldLeft, int oldTop, int oldRight, int oldBottom) { |
| if (mSuggestionsPopup == null || !mSuggestionsPopup.isShowing()) return; |
| mSuggestionsPopup.setWidth(mUrlField.getWidth()); |
| + mSuggestionsPopup.setHeight(getSuggestionPopupHeight()); |
| mSuggestionsPopup.show(); |
| } |
| }; |
| @@ -98,13 +102,31 @@ public class SuggestionPopup implements OnSuggestionsReceivedListener, TextWatch |
| if (mRequestSuggestions != null) mRequestSuggestions = null; |
| } |
| - // OnSuggestionsReceivedListener implementation |
| + private int getSuggestionPopupHeight() { |
| + Rect appRect = new Rect(); |
| + ((ChromeShellActivity)mContext).getWindow().getDecorView(). |
| + getWindowVisibleDisplayFrame(appRect); |
| + int dropDownItemHeight = mContext.getResources(). |
| + getDimensionPixelSize(R.dimen.dropdown_item_height); |
| + int popupHeight = appRect.height(); |
| + if (mSuggestionsPopup != null) { |
| + int height = dropDownItemHeight; |
|
Bernhard Bauer
2014/09/02 08:54:15
This assignment is unnecessary.
ankit
2014/09/02 09:23:04
Done.
|
| + height = mSuggestionsPopupItemsCount * dropDownItemHeight; |
| + if (height < appRect.height()) |
|
Bernhard Bauer
2014/09/02 08:54:15
You could use popupHeight instead of appRect.heigh
ankit
2014/09/02 09:23:04
Done.
|
| + popupHeight = height; |
| + } |
| + // Maintaining margin height equal to |dropDownItemHeight|. |
| + return (popupHeight - dropDownItemHeight > 0) ? |
| + (popupHeight - dropDownItemHeight) : popupHeight; |
|
Bernhard Bauer
2014/09/02 08:54:15
There's still a discontinuity here: As |popupHeigh
ankit
2014/09/02 09:23:04
As per current logic when number of suggestion ite
Bernhard Bauer
2014/09/02 09:31:01
Hm, now that I think about it, doesn't the margin
|
| + } |
| + // OnSuggestionsReceivedListener implementation |
| @Override |
| public void onSuggestionsReceived(List<OmniboxSuggestion> suggestions, |
| String inlineAutocompleteText) { |
| if (!mUrlField.isFocused() || suggestions.isEmpty()) |
| return; |
| + mSuggestionsPopupItemsCount = suggestions.size(); |
| if (mSuggestionsPopup == null) { |
| mSuggestionsPopup = new ListPopupWindow( |
| mContext, null, android.R.attr.autoCompleteTextViewStyle); |
| @@ -116,9 +138,11 @@ public class SuggestionPopup implements OnSuggestionsReceivedListener, TextWatch |
| } |
| }); |
| } |
| + mSuggestionsPopup.setInputMethodMode(ListPopupWindow.INPUT_METHOD_NEEDED); |
| mSuggestionsPopup.setWidth(mUrlField.getWidth()); |
| mSuggestionArrayAdapter = |
| new SuggestionArrayAdapter(mContext, R.layout.dropdown_item, suggestions); |
| + mSuggestionsPopup.setHeight(getSuggestionPopupHeight()); |
| mSuggestionsPopup.setAdapter(mSuggestionArrayAdapter); |
| mSuggestionsPopup.setAnchorView(mUrlField); |
| mSuggestionsPopup.setOnItemClickListener(new OnItemClickListener() { |