Commit 0c0a2f90 authored by Ted Choc's avatar Ted Choc Committed by Commit Bot

Remove LocationBar/UrlBar references from SuggestionView.

This converts the custom view tracking logic with just static/
explicit offsets.  This view no longer is under the crazy development
that made the custom tracking somewhat reasonable.  It is now just
overly complicated and more difficult to reason about.  Phone converted
to static offsets a while ago, so this unifies it with tablets.

BUG=883143

Change-Id: I6076501bee54f052a372be97aaab97686f44497b
Reviewed-on: https://chromium-review.googlesource.com/1228985
Commit-Queue: Ted Choc <tedchoc@chromium.org>
Reviewed-by: default avatarTheresa <twellington@chromium.org>
Reviewed-by: default avatarPedro Amaral <amaralp@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592993}
parent 5fe10abf
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
<dimen name="tab_strip_and_toolbar_height">96dp</dimen> <dimen name="tab_strip_and_toolbar_height">96dp</dimen>
<dimen name="location_bar_icon_width">40dp</dimen> <dimen name="location_bar_icon_width">40dp</dimen>
<dimen name="omnibox_suggestion_start_offset">@dimen/location_bar_icon_width</dimen>
<!-- NTP dimensions --> <!-- NTP dimensions -->
<dimen name="ntp_search_box_transition_length">60dp</dimen> <dimen name="ntp_search_box_transition_length">60dp</dimen>
......
...@@ -287,13 +287,11 @@ ...@@ -287,13 +287,11 @@
<!-- omnibox_suggestion_answer_line2_vertical_spacing + 2dp --> <!-- omnibox_suggestion_answer_line2_vertical_spacing + 2dp -->
<dimen name="omnibox_suggestion_answer_image_vertical_spacing">5dp</dimen> <dimen name="omnibox_suggestion_answer_image_vertical_spacing">5dp</dimen>
<dimen name="omnibox_suggestion_answer_image_horizontal_spacing">4dp</dimen> <dimen name="omnibox_suggestion_answer_image_horizontal_spacing">4dp</dimen>
<dimen name="omnibox_suggestion_phone_url_bar_left_offset">10dp</dimen> <dimen name="omnibox_suggestion_start_offset">18dp</dimen>
<dimen name="omnibox_suggestion_phone_url_bar_left_offset_rtl">10dp</dimen>
<dimen name="omnibox_suggestion_refine_width">48dp</dimen> <dimen name="omnibox_suggestion_refine_width">48dp</dimen>
<dimen name="omnibox_suggestion_text_vertical_padding">5dp</dimen> <dimen name="omnibox_suggestion_text_vertical_padding">5dp</dimen>
<dimen name="omnibox_suggestion_multiline_text_vertical_padding">10dp</dimen> <dimen name="omnibox_suggestion_multiline_text_vertical_padding">10dp</dimen>
<dimen name="omnibox_suggestion_refine_view_modern_end_padding">4dp</dimen> <dimen name="omnibox_suggestion_refine_view_modern_end_padding">4dp</dimen>
<dimen name="omnibox_suggestion_list_modern_offset">8dp</dimen>
<!-- NTP dimensions --> <!-- NTP dimensions -->
<dimen name="tile_grid_layout_max_width">504dp</dimen> <dimen name="tile_grid_layout_max_width">504dp</dimen>
......
...@@ -165,15 +165,6 @@ public interface LocationBar extends UrlBarDelegate { ...@@ -165,15 +165,6 @@ public interface LocationBar extends UrlBarDelegate {
*/ */
void setDefaultTextEditActionModeCallback(ToolbarActionModeCallback callback); void setDefaultTextEditActionModeCallback(ToolbarActionModeCallback callback);
/**
* Returns whether the {@link UrlBar} must be queried for its location on screen when
* suggestions are being laid out by {@link SuggestionView}.
* TODO(dfalcantara): Revisit this after M58.
*
* @return Whether or not the {@link UrlBar} has to be explicitly checked for its location.
*/
boolean mustQueryUrlBarLocationForSuggestions();
/** /**
* @return Whether suggestions are being shown for the location bar. * @return Whether suggestions are being shown for the location bar.
*/ */
......
...@@ -21,6 +21,7 @@ import android.support.annotation.DrawableRes; ...@@ -21,6 +21,7 @@ import android.support.annotation.DrawableRes;
import android.support.annotation.IntDef; import android.support.annotation.IntDef;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.view.MarginLayoutParamsCompat; import android.support.v4.view.MarginLayoutParamsCompat;
import android.support.v4.view.ViewCompat;
import android.support.v7.content.res.AppCompatResources; import android.support.v7.content.res.AppCompatResources;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
...@@ -406,7 +407,7 @@ public class LocationBarLayout extends FrameLayout ...@@ -406,7 +407,7 @@ public class LocationBarLayout extends FrameLayout
mUrlCoordinator.setDelegate(this); mUrlCoordinator.setDelegate(this);
mSuggestionItems = new ArrayList<OmniboxResultItem>(); mSuggestionItems = new ArrayList<OmniboxResultItem>();
mSuggestionListAdapter = new OmniboxResultsAdapter(getContext(), this, mSuggestionItems); mSuggestionListAdapter = new OmniboxResultsAdapter(getContext(), mSuggestionItems);
mMicButton = (TintedImageButton) findViewById(R.id.mic_button); mMicButton = (TintedImageButton) findViewById(R.id.mic_button);
...@@ -471,11 +472,8 @@ public class LocationBarLayout extends FrameLayout ...@@ -471,11 +472,8 @@ public class LocationBarLayout extends FrameLayout
mUrlCoordinator.setUrlDirectionListener(new UrlBar.UrlDirectionListener() { mUrlCoordinator.setUrlDirectionListener(new UrlBar.UrlDirectionListener() {
@Override @Override
public void onUrlDirectionChanged(int layoutDirection) { public void onUrlDirectionChanged(int layoutDirection) {
ApiCompatibilityUtils.setLayoutDirection(LocationBarLayout.this, layoutDirection); ViewCompat.setLayoutDirection(LocationBarLayout.this, layoutDirection);
updateSuggestionListLayoutDirection();
if (mSuggestionList != null) {
mSuggestionList.updateSuggestionsLayoutDirection(layoutDirection);
}
} }
}); });
} }
...@@ -958,6 +956,7 @@ public class LocationBarLayout extends FrameLayout ...@@ -958,6 +956,7 @@ public class LocationBarLayout extends FrameLayout
updateButtonVisibility(); updateButtonVisibility();
mSuggestionListAdapter.setToolbarDataProvider(toolbarDataProvider);
mUrlCoordinator.setOnFocusChangedCallback(this::onUrlFocusChange); mUrlCoordinator.setOnFocusChangedCallback(this::onUrlFocusChange);
} }
...@@ -1303,6 +1302,11 @@ public class LocationBarLayout extends FrameLayout ...@@ -1303,6 +1302,11 @@ public class LocationBarLayout extends FrameLayout
public View getAnchorView() { public View getAnchorView() {
return getRootView().findViewById(R.id.toolbar); return getRootView().findViewById(R.id.toolbar);
} }
@Override
public View getAlignmentView() {
return mIsTablet ? LocationBarLayout.this : null;
}
}; };
// TODO(tedchoc): Investigate lazily building the suggestion list off of the UI thread. // TODO(tedchoc): Investigate lazily building the suggestion list off of the UI thread.
try (StrictModeContext unused = StrictModeContext.allowDiskReads()) { try (StrictModeContext unused = StrictModeContext.allowDiskReads()) {
...@@ -1424,6 +1428,7 @@ public class LocationBarLayout extends FrameLayout ...@@ -1424,6 +1428,7 @@ public class LocationBarLayout extends FrameLayout
} }
mSuggestionList.show(); mSuggestionList.show();
updateSuggestionListLayoutDirection();
} else if (!visible && isShowing) { } else if (!visible && isShowing) {
mSuggestionList.setVisibility(GONE); mSuggestionList.setVisibility(GONE);
...@@ -1433,6 +1438,13 @@ public class LocationBarLayout extends FrameLayout ...@@ -1433,6 +1438,13 @@ public class LocationBarLayout extends FrameLayout
maybeShowOmniboxResultsContainer(); maybeShowOmniboxResultsContainer();
} }
private void updateSuggestionListLayoutDirection() {
if (mSuggestionList == null) return;
int layoutDirection = ViewCompat.getLayoutDirection(this);
mSuggestionList.updateSuggestionsLayoutDirection(layoutDirection);
mSuggestionListAdapter.setLayoutDirection(layoutDirection);
}
/** /**
* Updates the URL we will navigate to from suggestion, if needed. This will update the search * Updates the URL we will navigate to from suggestion, if needed. This will update the search
* URL to be of the corpus type if query in the omnibox is displayed and update aqs= parameter * URL to be of the corpus type if query in the omnibox is displayed and update aqs= parameter
...@@ -2165,11 +2177,6 @@ public class LocationBarLayout extends FrameLayout ...@@ -2165,11 +2177,6 @@ public class LocationBarLayout extends FrameLayout
@Override @Override
public void setShowTitle(boolean showTitle) { } public void setShowTitle(boolean showTitle) { }
@Override
public boolean mustQueryUrlBarLocationForSuggestions() {
return mIsTablet;
}
@Override @Override
public AutocompleteController getAutocompleteController() { public AutocompleteController getAutocompleteController() {
return mAutocomplete; return mAutocomplete;
......
...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.omnibox; ...@@ -7,6 +7,7 @@ package org.chromium.chrome.browser.omnibox;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.view.ViewCompat;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
...@@ -14,6 +15,7 @@ import android.widget.BaseAdapter; ...@@ -14,6 +15,7 @@ import android.widget.BaseAdapter;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.browser.toolbar.ToolbarDataProvider;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
...@@ -27,17 +29,16 @@ public class OmniboxResultsAdapter extends BaseAdapter { ...@@ -27,17 +29,16 @@ public class OmniboxResultsAdapter extends BaseAdapter {
private final List<OmniboxResultItem> mSuggestionItems; private final List<OmniboxResultItem> mSuggestionItems;
private final Context mContext; private final Context mContext;
private final LocationBar mLocationBar; private ToolbarDataProvider mDataProvider;
private OmniboxSuggestionDelegate mSuggestionDelegate; private OmniboxSuggestionDelegate mSuggestionDelegate;
private boolean mUseDarkColors = true; private boolean mUseDarkColors = true;
private Set<String> mPendingAnswerRequestUrls = new HashSet<>(); private Set<String> mPendingAnswerRequestUrls = new HashSet<>();
private int mLayoutDirection;
public OmniboxResultsAdapter( public OmniboxResultsAdapter(
Context context, Context context,
LocationBar locationBar,
List<OmniboxResultItem> suggestionItems) { List<OmniboxResultItem> suggestionItems) {
mContext = context; mContext = context;
mLocationBar = locationBar;
mSuggestionItems = suggestionItems; mSuggestionItems = suggestionItems;
} }
...@@ -66,17 +67,23 @@ public class OmniboxResultsAdapter extends BaseAdapter { ...@@ -66,17 +67,23 @@ public class OmniboxResultsAdapter extends BaseAdapter {
if (convertView instanceof SuggestionView) { if (convertView instanceof SuggestionView) {
suggestionView = (SuggestionView) convertView; suggestionView = (SuggestionView) convertView;
} else { } else {
suggestionView = new SuggestionView(mContext, mLocationBar); suggestionView = new SuggestionView(mContext);
} }
OmniboxResultItem item = mSuggestionItems.get(position); OmniboxResultItem item = mSuggestionItems.get(position);
maybeFetchAnswerIcon(item); maybeFetchAnswerIcon(item);
suggestionView.init(item, mSuggestionDelegate, position, mUseDarkColors); suggestionView.init(item, mSuggestionDelegate, position, mUseDarkColors);
ViewCompat.setLayoutDirection(suggestionView, mLayoutDirection);
return suggestionView; return suggestionView;
} }
private void maybeFetchAnswerIcon(OmniboxResultItem item) { private void maybeFetchAnswerIcon(OmniboxResultItem item) {
ThreadUtils.assertOnUiThread(); ThreadUtils.assertOnUiThread();
// Attempting to fetch answer data before we have a profile to request it for.
if (mDataProvider == null) return;
// Do not refetch an answer image if it already exists. // Do not refetch an answer image if it already exists.
if (item.getAnswerImage() != null) return; if (item.getAnswerImage() != null) return;
OmniboxSuggestion suggestion = item.getSuggestion(); OmniboxSuggestion suggestion = item.getSuggestion();
...@@ -88,8 +95,8 @@ public class OmniboxResultsAdapter extends BaseAdapter { ...@@ -88,8 +95,8 @@ public class OmniboxResultsAdapter extends BaseAdapter {
if (mPendingAnswerRequestUrls.contains(url)) return; if (mPendingAnswerRequestUrls.contains(url)) return;
mPendingAnswerRequestUrls.add(url); mPendingAnswerRequestUrls.add(url);
AnswersImage.requestAnswersImage(mLocationBar.getToolbarDataProvider().getProfile(), url, AnswersImage.requestAnswersImage(
new AnswersImage.AnswersImageObserver() { mDataProvider.getProfile(), url, new AnswersImage.AnswersImageObserver() {
@Override @Override
public void onAnswersImageChanged(Bitmap bitmap) { public void onAnswersImageChanged(Bitmap bitmap) {
ThreadUtils.assertOnUiThread(); ThreadUtils.assertOnUiThread();
...@@ -120,6 +127,13 @@ public class OmniboxResultsAdapter extends BaseAdapter { ...@@ -120,6 +127,13 @@ public class OmniboxResultsAdapter extends BaseAdapter {
} }
} }
/**
* Sets the data provider for the toolbar.
*/
public void setToolbarDataProvider(ToolbarDataProvider provider) {
mDataProvider = provider;
}
/** /**
* Set the selection delegate for suggestion entries in the adapter. * Set the selection delegate for suggestion entries in the adapter.
* *
...@@ -129,6 +143,14 @@ public class OmniboxResultsAdapter extends BaseAdapter { ...@@ -129,6 +143,14 @@ public class OmniboxResultsAdapter extends BaseAdapter {
mSuggestionDelegate = delegate; mSuggestionDelegate = delegate;
} }
/**
* Sets the layout direction to be used for any new suggestion views.
* @see View#setLayoutDirection(int)
*/
public void setLayoutDirection(int layoutDirection) {
mLayoutDirection = layoutDirection;
}
/** /**
* @return The selection delegate for suggestion entries in the adapter. * @return The selection delegate for suggestion entries in the adapter.
*/ */
......
...@@ -16,7 +16,6 @@ import android.view.View; ...@@ -16,7 +16,6 @@ import android.view.View;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ListView; import android.widget.ListView;
import org.chromium.base.ApiCompatibilityUtils;
import org.chromium.base.VisibleForTesting; import org.chromium.base.VisibleForTesting;
import org.chromium.chrome.R; import org.chromium.chrome.R;
import org.chromium.chrome.browser.WindowDelegate; import org.chromium.chrome.browser.WindowDelegate;
...@@ -39,6 +38,7 @@ public class OmniboxSuggestionsList extends ListView { ...@@ -39,6 +38,7 @@ public class OmniboxSuggestionsList extends ListView {
private final int mSuggestionAnswerHeight; private final int mSuggestionAnswerHeight;
private final int mSuggestionDefinitionHeight; private final int mSuggestionDefinitionHeight;
private final View mAnchorView; private final View mAnchorView;
private final View mAlignmentView;
private final int[] mTempPosition = new int[2]; private final int[] mTempPosition = new int[2];
private final Rect mTempRect = new Rect(); private final Rect mTempRect = new Rect();
...@@ -55,6 +55,14 @@ public class OmniboxSuggestionsList extends ListView { ...@@ -55,6 +55,14 @@ public class OmniboxSuggestionsList extends ListView {
/** Return the anchor view the suggestion list should be drawn below. */ /** Return the anchor view the suggestion list should be drawn below. */
View getAnchorView(); View getAnchorView();
/**
* Return the view that the omnibox suggestions should be aligned horizontally to. The
* view must be a descendant of {@link #getAnchorView()}. If null, the suggestions will
* be aligned to the start of {@link #getAnchorView()}.
*/
@Nullable
View getAlignmentView();
/** Return the bottom sheet for the containing UI to be used in sizing. */ /** Return the bottom sheet for the containing UI to be used in sizing. */
@Nullable @Nullable
BottomSheet getBottomSheet(); BottomSheet getBottomSheet();
...@@ -100,6 +108,26 @@ public class OmniboxSuggestionsList extends ListView { ...@@ -100,6 +108,26 @@ public class OmniboxSuggestionsList extends ListView {
mTempRect.top + mTempRect.bottom + getPaddingTop() + getPaddingBottom(); mTempRect.top + mTempRect.bottom + getPaddingTop() + getPaddingBottom();
mAnchorView = mEmbedder.getAnchorView(); mAnchorView = mEmbedder.getAnchorView();
mAlignmentView = mEmbedder.getAlignmentView();
if (mAlignmentView != null) {
adjustSidePadding();
mAlignmentView.addOnLayoutChangeListener(new OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom,
int oldLeft, int oldTop, int oldRight, int oldBottom) {
adjustSidePadding();
}
});
}
}
private void adjustSidePadding() {
if (mAlignmentView == null) return;
ViewUtils.getRelativeLayoutPosition(mAnchorView, mAlignmentView, mTempPosition);
setPadding(mTempPosition[0], getPaddingTop(),
mAnchorView.getWidth() - mAlignmentView.getWidth() - mTempPosition[0],
getPaddingBottom());
} }
/** /**
...@@ -297,7 +325,7 @@ public class OmniboxSuggestionsList extends ListView { ...@@ -297,7 +325,7 @@ public class OmniboxSuggestionsList extends ListView {
for (int i = 0; i < getChildCount(); i++) { for (int i = 0; i < getChildCount(); i++) {
View childView = getChildAt(i); View childView = getChildAt(i);
if (!(childView instanceof SuggestionView)) continue; if (!(childView instanceof SuggestionView)) continue;
ApiCompatibilityUtils.setLayoutDirection(childView, layoutDirection); ViewCompat.setLayoutDirection(childView, layoutDirection);
} }
} }
......
...@@ -35,7 +35,6 @@ import org.chromium.chrome.R; ...@@ -35,7 +35,6 @@ import org.chromium.chrome.R;
import org.chromium.chrome.browser.omnibox.OmniboxResultsAdapter.OmniboxResultItem; import org.chromium.chrome.browser.omnibox.OmniboxResultsAdapter.OmniboxResultItem;
import org.chromium.chrome.browser.omnibox.OmniboxResultsAdapter.OmniboxSuggestionDelegate; import org.chromium.chrome.browser.omnibox.OmniboxResultsAdapter.OmniboxSuggestionDelegate;
import org.chromium.chrome.browser.omnibox.OmniboxSuggestion.MatchClassification; import org.chromium.chrome.browser.omnibox.OmniboxSuggestion.MatchClassification;
import org.chromium.chrome.browser.util.ViewUtils;
import org.chromium.chrome.browser.widget.TintedDrawable; import org.chromium.chrome.browser.widget.TintedDrawable;
import org.chromium.ui.base.DeviceFormFactor; import org.chromium.ui.base.DeviceFormFactor;
...@@ -61,14 +60,8 @@ class SuggestionView extends ViewGroup { ...@@ -61,14 +60,8 @@ class SuggestionView extends ViewGroup {
int VOICE = 4; int VOICE = 4;
} }
private static final long RELAYOUT_DELAY_MS = 20;
private static final float ANSWER_IMAGE_SCALING_FACTOR = 1.15f; private static final float ANSWER_IMAGE_SCALING_FACTOR = 1.15f;
private final LocationBar mLocationBar;
private UrlBar mUrlBar;
private ImageView mNavigationButton;
private final int mSuggestionHeight; private final int mSuggestionHeight;
private final int mSuggestionAnswerHeight; private final int mSuggestionAnswerHeight;
private int mNumAnswerLines = 1; private int mNumAnswerLines = 1;
...@@ -84,7 +77,6 @@ class SuggestionView extends ViewGroup { ...@@ -84,7 +77,6 @@ class SuggestionView extends ViewGroup {
private Boolean mUseDarkColors; private Boolean mUseDarkColors;
private int mPosition; private int mPosition;
private int mRefineViewOffsetPx; private int mRefineViewOffsetPx;
private int mSuggestionViewStartOffset;
private final SuggestionContentsContainer mContentsView; private final SuggestionContentsContainer mContentsView;
...@@ -92,23 +84,18 @@ class SuggestionView extends ViewGroup { ...@@ -92,23 +84,18 @@ class SuggestionView extends ViewGroup {
private final View mRefineView; private final View mRefineView;
private TintedDrawable mRefineIcon; private TintedDrawable mRefineIcon;
private final int mRefineViewModernEndPadding; private final int mRefineViewModernEndPadding;
private final int mSuggestionListModernOffset;
private final int[] mViewPositionHolder = new int[2];
// Pre-computed offsets in px. // Pre-computed offsets in px.
private final int mPhoneUrlBarLeftOffsetPx; private final int mSuggestionStartOffsetPx;
private final int mPhoneUrlBarLeftOffsetRtlPx; private final int mSuggestionIconWidthPx;
/** /**
* Constructs a new omnibox suggestion view. * Constructs a new omnibox suggestion view.
* *
* @param context The context used to construct the suggestion view. * @param context The context used to construct the suggestion view.
* @param locationBar The location bar showing these suggestions.
*/ */
public SuggestionView(Context context, LocationBar locationBar) { public SuggestionView(Context context) {
super(context); super(context);
mLocationBar = locationBar;
mSuggestionHeight = mSuggestionHeight =
context.getResources().getDimensionPixelOffset(R.dimen.omnibox_suggestion_height); context.getResources().getDimensionPixelOffset(R.dimen.omnibox_suggestion_height);
...@@ -189,15 +176,10 @@ class SuggestionView extends ViewGroup { ...@@ -189,15 +176,10 @@ class SuggestionView extends ViewGroup {
mRefineViewModernEndPadding = getResources().getDimensionPixelSize( mRefineViewModernEndPadding = getResources().getDimensionPixelSize(
R.dimen.omnibox_suggestion_refine_view_modern_end_padding); R.dimen.omnibox_suggestion_refine_view_modern_end_padding);
mSuggestionListModernOffset = mSuggestionStartOffsetPx =
getResources().getDimensionPixelSize(R.dimen.omnibox_suggestion_list_modern_offset); getResources().getDimensionPixelOffset(R.dimen.omnibox_suggestion_start_offset);
mSuggestionIconWidthPx =
mUrlBar = (UrlBar) locationBar.getContainerView().findViewById(R.id.url_bar); getResources().getDimensionPixelSize(R.dimen.location_bar_icon_width);
mPhoneUrlBarLeftOffsetPx = getResources().getDimensionPixelOffset(
R.dimen.omnibox_suggestion_phone_url_bar_left_offset);
mPhoneUrlBarLeftOffsetRtlPx = getResources().getDimensionPixelOffset(
R.dimen.omnibox_suggestion_phone_url_bar_left_offset_rtl);
} }
@Override @Override
...@@ -286,8 +268,6 @@ class SuggestionView extends ViewGroup { ...@@ -286,8 +268,6 @@ class SuggestionView extends ViewGroup {
*/ */
public void init(OmniboxResultItem suggestionItem, OmniboxSuggestionDelegate suggestionDelegate, public void init(OmniboxResultItem suggestionItem, OmniboxSuggestionDelegate suggestionDelegate,
int position, boolean useDarkColors) { int position, boolean useDarkColors) {
ViewCompat.setLayoutDirection(this, ViewCompat.getLayoutDirection(mUrlBar));
// Update the position unconditionally. // Update the position unconditionally.
mPosition = position; mPosition = position;
jumpDrawablesToCurrentState(); jumpDrawablesToCurrentState();
...@@ -318,9 +298,6 @@ class SuggestionView extends ViewGroup { ...@@ -318,9 +298,6 @@ class SuggestionView extends ViewGroup {
.getDimension(R.dimen.omnibox_suggestion_second_line_text_size)); .getDimension(R.dimen.omnibox_suggestion_second_line_text_size));
mRefineViewOffsetPx = mRefineViewModernEndPadding; mRefineViewOffsetPx = mRefineViewModernEndPadding;
mSuggestionViewStartOffset = !mLocationBar.mustQueryUrlBarLocationForSuggestions()
? mSuggestionListModernOffset
: 0;
// Suggestions with attached answers are rendered with rich results regardless of which // Suggestions with attached answers are rendered with rich results regardless of which
// suggestion type they are. // suggestion type they are.
...@@ -638,10 +615,8 @@ class SuggestionView extends ViewGroup { ...@@ -638,10 +615,8 @@ class SuggestionView extends ViewGroup {
* Container view for the contents of the suggestion (the search query, URL, and suggestion type * Container view for the contents of the suggestion (the search query, URL, and suggestion type
* icon). * icon).
*/ */
private class SuggestionContentsContainer extends ViewGroup implements OnLayoutChangeListener { private class SuggestionContentsContainer extends ViewGroup {
private int mSuggestionIconLeft = Integer.MIN_VALUE; private int mTextStart = Integer.MIN_VALUE;
private int mTextLeft = Integer.MIN_VALUE;
private int mTextRight = Integer.MIN_VALUE;
private Drawable mSuggestionIcon; private Drawable mSuggestionIcon;
@SuggestionIcon @SuggestionIcon
private int mSuggestionIconType = SuggestionIcon.UNDEFINED; private int mSuggestionIconType = SuggestionIcon.UNDEFINED;
...@@ -654,13 +629,6 @@ class SuggestionView extends ViewGroup { ...@@ -654,13 +629,6 @@ class SuggestionView extends ViewGroup {
private float mMatchContentsWidth; private float mMatchContentsWidth;
private boolean mForceIsFocused; private boolean mForceIsFocused;
private final Runnable mRelayoutRunnable = new Runnable() {
@Override
public void run() {
requestLayout();
}
};
// TODO(crbug.com/635567): Fix this properly. // TODO(crbug.com/635567): Fix this properly.
@SuppressLint("InlinedApi") @SuppressLint("InlinedApi")
SuggestionContentsContainer(Context context, Drawable backgroundDrawable) { SuggestionContentsContainer(Context context, Drawable backgroundDrawable) {
...@@ -755,15 +723,15 @@ class SuggestionView extends ViewGroup { ...@@ -755,15 +723,15 @@ class SuggestionView extends ViewGroup {
super.onDraw(canvas); super.onDraw(canvas);
if (DeviceFormFactor.isNonMultiDisplayContextOnTablet(getContext())) { if (DeviceFormFactor.isNonMultiDisplayContextOnTablet(getContext())) {
// Use the same image transform matrix as the navigation icon to ensure the same
// scaling, which requires centering vertically based on the height of the
// navigation icon view and not the image itself.
canvas.save(); canvas.save();
mSuggestionIconLeft = getSuggestionIconLeftPosition(); float suggestionIconLeft =
canvas.translate( (mSuggestionIconWidthPx - mSuggestionIcon.getIntrinsicWidth()) / 2f;
mSuggestionIconLeft, if (ApiCompatibilityUtils.isLayoutRtl(this)) {
(getMeasuredHeight() - mNavigationButton.getMeasuredHeight()) / 2f); suggestionIconLeft += getMeasuredWidth() - mSuggestionIconWidthPx;
canvas.concat(mNavigationButton.getImageMatrix()); }
float suggestionIconTop =
(getMeasuredHeight() - mSuggestionIcon.getIntrinsicHeight()) / 2f;
canvas.translate(suggestionIconLeft, suggestionIconTop);
mSuggestionIcon.draw(canvas); mSuggestionIcon.draw(canvas);
canvas.restore(); canvas.restore();
} }
...@@ -771,21 +739,10 @@ class SuggestionView extends ViewGroup { ...@@ -771,21 +739,10 @@ class SuggestionView extends ViewGroup {
@Override @Override
protected void onLayout(boolean changed, int l, int t, int r, int b) { protected void onLayout(boolean changed, int l, int t, int r, int b) {
View locationBarView = mLocationBar.getContainerView();
if (mUrlBar == null) {
mUrlBar = (UrlBar) locationBarView.findViewById(R.id.url_bar);
mUrlBar.addOnLayoutChangeListener(this);
}
if (mNavigationButton == null) {
mNavigationButton =
(ImageView) locationBarView.findViewById(R.id.navigation_button);
mNavigationButton.addOnLayoutChangeListener(this);
}
// Align the text to be pixel perfectly aligned with the text in the url bar. // Align the text to be pixel perfectly aligned with the text in the url bar.
boolean isRTL = ApiCompatibilityUtils.isLayoutRtl(this); boolean isRTL = ApiCompatibilityUtils.isLayoutRtl(this);
if (DeviceFormFactor.isNonMultiDisplayContextOnTablet(getContext())) { if (DeviceFormFactor.isNonMultiDisplayContextOnTablet(getContext())) {
int textWidth = isRTL ? mTextRight : (r - l - mTextLeft); int textWidth = isRTL ? mTextStart : (r - l - mTextStart);
final float maxRequiredWidth = mSuggestionDelegate.getMaxRequiredWidth(); final float maxRequiredWidth = mSuggestionDelegate.getMaxRequiredWidth();
final float maxMatchContentsWidth = mSuggestionDelegate.getMaxMatchContentsWidth(); final float maxMatchContentsWidth = mSuggestionDelegate.getMaxMatchContentsWidth();
float paddingStart = (textWidth > maxRequiredWidth) float paddingStart = (textWidth > maxRequiredWidth)
...@@ -848,114 +805,34 @@ class SuggestionView extends ViewGroup { ...@@ -848,114 +805,34 @@ class SuggestionView extends ViewGroup {
final int answerImageBottom = answerImageTop + mAnswerImage.getMeasuredHeight(); final int answerImageBottom = answerImageTop + mAnswerImage.getMeasuredHeight();
if (isRTL) { if (isRTL) {
mTextLine1.layout(0, line1Top, mTextRight, line1Bottom); int rightStartPos = r - l - mTextStart;
mAnswerImage.layout( mTextLine1.layout(0, line1Top, rightStartPos, line1Bottom);
mTextRight - imageWidth, answerImageTop, mTextRight, answerImageBottom); mAnswerImage.layout(rightStartPos - imageWidth, answerImageTop, rightStartPos,
answerImageBottom);
mTextLine2.layout( mTextLine2.layout(
0, line2Top, mTextRight - (imageWidth + imageSpacing), line2Bottom); 0, line2Top, rightStartPos - (imageWidth + imageSpacing), line2Bottom);
} else { } else {
mTextLine1.layout( mTextLine1.layout(mTextStart, line1Top, r - l, line1Bottom);
mTextLeft + mSuggestionViewStartOffset, line1Top, r - l, line1Bottom); mAnswerImage.layout(
mAnswerImage.layout(mTextLeft + mSuggestionViewStartOffset, answerImageTop, mTextStart, answerImageTop, mTextStart + imageWidth, answerImageBottom);
mTextLeft + imageWidth, answerImageBottom);
mTextLine2.layout( mTextLine2.layout(
mTextLeft + imageWidth + imageSpacing + mSuggestionViewStartOffset, mTextStart + imageWidth + imageSpacing, line2Top, r - l, line2Bottom);
line2Top, r - l, line2Bottom);
}
int suggestionIconPosition = getSuggestionIconLeftPosition();
if (mSuggestionIconLeft != suggestionIconPosition
&& mSuggestionIconLeft != Integer.MIN_VALUE) {
mContentsView.postInvalidateOnAnimation();
}
mSuggestionIconLeft = suggestionIconPosition;
}
private int getUrlBarLeftOffset() {
if (mLocationBar.mustQueryUrlBarLocationForSuggestions()) {
View contentView = getRootView().findViewById(android.R.id.content);
ViewUtils.getRelativeLayoutPosition(contentView, mUrlBar, mViewPositionHolder);
return mViewPositionHolder[0];
} else {
return ApiCompatibilityUtils.isLayoutRtl(this) ? mPhoneUrlBarLeftOffsetRtlPx
: mPhoneUrlBarLeftOffsetPx;
} }
} }
/**
* @return The left offset for the suggestion text.
*/
private int getSuggestionTextLeftPosition() {
if (mLocationBar == null) return 0;
int leftOffset = getUrlBarLeftOffset();
View contentView = getRootView().findViewById(android.R.id.content);
ViewUtils.getRelativeLayoutPosition(contentView, this, mViewPositionHolder);
return leftOffset + mUrlBar.getPaddingLeft() - mViewPositionHolder[0];
}
/**
* @return The right offset for the suggestion text.
*/
private int getSuggestionTextRightPosition() {
if (mLocationBar == null) return 0;
int leftOffset = getUrlBarLeftOffset();
View contentView = getRootView().findViewById(android.R.id.content);
ViewUtils.getRelativeLayoutPosition(contentView, this, mViewPositionHolder);
// When a user types into the omnibox, buttons on the url action container e.g. delete
// become visible, shrinking the url bar's width. Add the url action container's width
// to the url bar for consistency.
int buttonWidth = 0;
if (mLocationBar instanceof LocationBarPhone) {
buttonWidth = mLocationBar.getUrlContainerMarginEnd();
}
return leftOffset + mUrlBar.getWidth() + buttonWidth - mUrlBar.getPaddingRight()
- mViewPositionHolder[0];
}
/**
* @return The left offset for the suggestion type icon that aligns it with the url bar.
*/
private int getSuggestionIconLeftPosition() {
if (mNavigationButton == null) return 0;
// Ensure the suggestion icon matches the location of the navigation icon in the omnibox
// perfectly.
mNavigationButton.getLocationOnScreen(mViewPositionHolder);
int navButtonXPosition = mViewPositionHolder[0] + mNavigationButton.getPaddingLeft();
getLocationOnScreen(mViewPositionHolder);
return navButtonXPosition - mViewPositionHolder[0];
}
@Override @Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int width = MeasureSpec.getSize(widthMeasureSpec); mTextStart = mSuggestionStartOffsetPx;
int height = MeasureSpec.getSize(heightMeasureSpec);
boolean isRTL = ApiCompatibilityUtils.isLayoutRtl(this);
mTextLeft = getSuggestionTextLeftPosition();
mTextRight = getSuggestionTextRightPosition();
// TODO(tedchoc): Instead of comparing width/height, compare the last text (including // TODO(tedchoc): Instead of comparing width/height, compare the last text (including
// style spans) measured and if that remains the same along with the // style spans) measured and if that remains the same along with the
// height/width of this view, then we should be able to skip measure // height/width of this view, then we should be able to skip measure
// properly. // properly.
int maxWidth = width - (isRTL ? mTextRight : mTextLeft); int maxWidth = MeasureSpec.getSize(widthMeasureSpec) - mTextStart;
if (mTextLine1.getMeasuredWidth() != width mTextLine1.measure(MeasureSpec.makeMeasureSpec(maxWidth, MeasureSpec.AT_MOST),
|| mTextLine1.getMeasuredHeight() != height) { MeasureSpec.makeMeasureSpec(mSuggestionHeight, MeasureSpec.AT_MOST));
mTextLine1.measure(MeasureSpec.makeMeasureSpec(maxWidth, MeasureSpec.AT_MOST), mTextLine2.measure(MeasureSpec.makeMeasureSpec(maxWidth, MeasureSpec.AT_MOST),
MeasureSpec.makeMeasureSpec(mSuggestionHeight, MeasureSpec.AT_MOST)); MeasureSpec.makeMeasureSpec(mSuggestionHeight, MeasureSpec.AT_MOST));
}
if (mTextLine2.getMeasuredWidth() != width
|| mTextLine2.getMeasuredHeight() != height) {
mTextLine2.measure(MeasureSpec.makeMeasureSpec(maxWidth, MeasureSpec.AT_MOST),
MeasureSpec.makeMeasureSpec(mSuggestionHeight, MeasureSpec.AT_MOST));
}
if (mAnswerImage.getVisibility() == VISIBLE) { if (mAnswerImage.getVisibility() == VISIBLE) {
float textSize = mContentsView.mTextLine2.getTextSize(); float textSize = mContentsView.mTextLine2.getTextSize();
...@@ -982,22 +859,6 @@ class SuggestionView extends ViewGroup { ...@@ -982,22 +859,6 @@ class SuggestionView extends ViewGroup {
} }
} }
@Override
public void invalidate() {
if (getSuggestionTextLeftPosition() != mTextLeft
|| getSuggestionTextRightPosition() != mTextRight) {
// When the text position is changed, it typically is caused by the suggestions
// appearing while the URL bar on the phone is gaining focus (if you trigger an
// intent that will result in suggestions being shown before focusing the omnibox).
// Triggering a relayout will cause any animations to stutter, so we continually
// push the relayout to end of the UI queue until the animation is complete.
removeCallbacks(mRelayoutRunnable);
postDelayed(mRelayoutRunnable, RELAYOUT_DELAY_MS);
} else {
super.invalidate();
}
}
@Override @Override
public boolean isFocused() { public boolean isFocused() {
return mForceIsFocused || super.isFocused(); return mForceIsFocused || super.isFocused();
...@@ -1047,55 +908,5 @@ class SuggestionView extends ViewGroup { ...@@ -1047,55 +908,5 @@ class SuggestionView extends ViewGroup {
mSuggestionIconType = type; mSuggestionIconType = type;
invalidate(); invalidate();
} }
@Override
public void onLayoutChange(
View v, int left, int top, int right, int bottom, int oldLeft,
int oldTop, int oldRight, int oldBottom) {
boolean needsInvalidate = false;
if (v == mNavigationButton) {
if (mSuggestionIconLeft != getSuggestionIconLeftPosition()
&& mSuggestionIconLeft != Integer.MIN_VALUE) {
needsInvalidate = true;
}
} else {
if (mTextLeft != getSuggestionTextLeftPosition()
&& mTextLeft != Integer.MIN_VALUE) {
needsInvalidate = true;
}
if (mTextRight != getSuggestionTextRightPosition()
&& mTextRight != Integer.MIN_VALUE) {
needsInvalidate = true;
}
}
if (needsInvalidate) {
removeCallbacks(mRelayoutRunnable);
postDelayed(mRelayoutRunnable, RELAYOUT_DELAY_MS);
}
}
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (mNavigationButton != null) mNavigationButton.addOnLayoutChangeListener(this);
if (mUrlBar != null) mUrlBar.addOnLayoutChangeListener(this);
if (mLocationBar != null) {
mLocationBar.getContainerView().addOnLayoutChangeListener(this);
}
getRootView().addOnLayoutChangeListener(this);
}
@Override
protected void onDetachedFromWindow() {
removeCallbacks(mRelayoutRunnable);
if (mNavigationButton != null) mNavigationButton.removeOnLayoutChangeListener(this);
if (mUrlBar != null) mUrlBar.removeOnLayoutChangeListener(this);
if (mLocationBar != null) {
mLocationBar.getContainerView().removeOnLayoutChangeListener(this);
}
getRootView().removeOnLayoutChangeListener(this);
super.onDetachedFromWindow();
}
} }
} }
...@@ -63,11 +63,6 @@ public class SearchActivityLocationBarLayout extends LocationBarLayout { ...@@ -63,11 +63,6 @@ public class SearchActivityLocationBarLayout extends LocationBarLayout {
mDelegate.backKeyPressed(); mDelegate.backKeyPressed();
} }
@Override
public boolean mustQueryUrlBarLocationForSuggestions() {
return true;
}
@Override @Override
public void setUrlToPageUrl() { public void setUrlToPageUrl() {
// Explicitly do nothing. The tab is invisible, so showing its URL would be confusing. // Explicitly do nothing. The tab is invisible, so showing its URL would be confusing.
......
...@@ -816,11 +816,6 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar, ...@@ -816,11 +816,6 @@ public class CustomTabToolbar extends ToolbarLayout implements LocationBar,
} }
} }
@Override
public boolean mustQueryUrlBarLocationForSuggestions() {
return false;
}
// Temporary fix to override ToolbarLayout's highlight-related methods // Temporary fix to override ToolbarLayout's highlight-related methods
@Override @Override
public void setMenuButtonHighlight(boolean highlight) {} public void setMenuButtonHighlight(boolean highlight) {}
......
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