Commit 2ea93168 authored by Tomasz Wiszkowski's avatar Tomasz Wiszkowski Committed by Commit Bot

Move the Suggestion Gesture events reporting to Suggestions List.

This change extracts the gesture events from SuggestionViewDelegate
and moves the Gesture event reporting over to the
OmniboxSuggestionDropdown.

Currently, gestures are only reported by the suggestions inheriting
from BaseSuggestion MVC component. As an effect, custom suggestion
types do not correctly respond to user initiating interaction with
the Suggestions list (ie. the list may be updated as the user
attempts to scroll the list or collapses the header) and may be
reporting inaccurate times (this specifically affects the QueryTiles
at this point).

The update moves this reporting to a centralized place, ensuring
that all the events will be correctly reported, including custom
suggestion types.

The only case not covered (that was also not covered previously) is
the keyboard interaction.

Bug: 1106109
Change-Id: I54811d316cf420fc0ea7bbb10b807ef7b3ac196a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2440975Reviewed-by: default avatarTed Choc <tedchoc@chromium.org>
Reviewed-by: default avatarFilip Gorski <fgorski@chromium.org>
Commit-Queue: Tomasz Wiszkowski <ender@google.com>
Cr-Commit-Position: refs/heads/master@{#812951}
parent 1f1c745d
...@@ -495,16 +495,6 @@ class AutocompleteMediator implements OnSuggestionsReceivedListener, StartStopWi ...@@ -495,16 +495,6 @@ class AutocompleteMediator implements OnSuggestionsReceivedListener, StartStopWi
public void onLongPress() { public void onLongPress() {
AutocompleteMediator.this.onLongPress(suggestion, position); AutocompleteMediator.this.onLongPress(suggestion, position);
} }
@Override
public void onGestureUp(long timestamp) {
mLastActionUpTimestamp = timestamp;
}
@Override
public void onGestureDown() {
stopAutocomplete(false);
}
}; };
} }
...@@ -604,6 +594,14 @@ class AutocompleteMediator implements OnSuggestionsReceivedListener, StartStopWi ...@@ -604,6 +594,14 @@ class AutocompleteMediator implements OnSuggestionsReceivedListener, StartStopWi
recordMetrics(position, WindowOpenDisposition.SWITCH_TO_TAB, suggestion); recordMetrics(position, WindowOpenDisposition.SWITCH_TO_TAB, suggestion);
} }
@Override
public void onGesture(boolean isGestureUp, long timestamp) {
stopAutocomplete(false);
if (isGestureUp) {
mLastActionUpTimestamp = timestamp;
}
}
/** /**
* Triggered when the user long presses the omnibox suggestion. * Triggered when the user long presses the omnibox suggestion.
* @param suggestion The suggestion selected. * @param suggestion The suggestion selected.
......
...@@ -53,6 +53,15 @@ public interface OmniboxSuggestionsDropdown { ...@@ -53,6 +53,15 @@ public interface OmniboxSuggestionsDropdown {
* Invoked whenever the User scrolls the list to the top. * Invoked whenever the User scrolls the list to the top.
*/ */
void onSuggestionDropdownOverscrolledToTop(); void onSuggestionDropdownOverscrolledToTop();
/**
* Notify that the user is interacting with an item on the Suggestions list.
*
* @param isGestureUp Whether user pressed (false) or depressed (true) the element on the
* list.
* @param timestamp The timestamp associated with the event.
*/
void onGesture(boolean isGestureUp, long timestamp);
} }
/** Get the Android View implementing suggestion list. */ /** Get the Android View implementing suggestion list. */
......
...@@ -13,6 +13,8 @@ import android.view.ViewGroup; ...@@ -13,6 +13,8 @@ import android.view.ViewGroup;
import android.widget.AbsListView; import android.widget.AbsListView;
import android.widget.ListView; import android.widget.ListView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.core.view.ViewCompat; import androidx.core.view.ViewCompat;
...@@ -29,8 +31,8 @@ import java.util.ArrayList; ...@@ -29,8 +31,8 @@ import java.util.ArrayList;
@VisibleForTesting @VisibleForTesting
public class OmniboxSuggestionsList public class OmniboxSuggestionsList
extends ListView implements OmniboxSuggestionsDropdown, AbsListView.OnScrollListener { extends ListView implements OmniboxSuggestionsDropdown, AbsListView.OnScrollListener {
private final OmniboxSuggestionsDropdownDelegate mDropdownDelegate; private final @NonNull OmniboxSuggestionsDropdownDelegate mDropdownDelegate;
private OmniboxSuggestionsDropdown.Observer mObserver; private @Nullable OmniboxSuggestionsDropdown.Observer mObserver;
private final int[] mTempMeasureSpecs = new int[2]; private final int[] mTempMeasureSpecs = new int[2];
...@@ -186,4 +188,14 @@ public class OmniboxSuggestionsList ...@@ -186,4 +188,14 @@ public class OmniboxSuggestionsList
mObserver.onSuggestionDropdownScroll(); mObserver.onSuggestionDropdownScroll();
} }
} }
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
final int eventType = ev.getActionMasked();
if ((eventType == MotionEvent.ACTION_UP || eventType == MotionEvent.ACTION_DOWN)
&& mObserver != null) {
mObserver.onGesture(eventType == MotionEvent.ACTION_UP, ev.getEventTime());
}
return super.dispatchTouchEvent(ev);
}
} }
...@@ -11,6 +11,8 @@ import android.view.MotionEvent; ...@@ -11,6 +11,8 @@ import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.core.view.ViewCompat; import androidx.core.view.ViewCompat;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
...@@ -26,9 +28,10 @@ import org.chromium.chrome.browser.util.KeyNavigationUtil; ...@@ -26,9 +28,10 @@ import org.chromium.chrome.browser.util.KeyNavigationUtil;
@VisibleForTesting @VisibleForTesting
public class OmniboxSuggestionsRecyclerView public class OmniboxSuggestionsRecyclerView
extends RecyclerView implements OmniboxSuggestionsDropdown { extends RecyclerView implements OmniboxSuggestionsDropdown {
private final OmniboxSuggestionsDropdownDelegate mDropdownDelegate; private final @NonNull OmniboxSuggestionsDropdownDelegate mDropdownDelegate;
private final SuggestionScrollListener mScrollListener; private final @NonNull SuggestionScrollListener mScrollListener;
private OmniboxSuggestionsRecyclerViewAdapter mAdapter; private @Nullable OmniboxSuggestionsDropdown.Observer mObserver;
private @Nullable OmniboxSuggestionsRecyclerViewAdapter mAdapter;
private final int[] mTempMeasureSpecs = new int[2]; private final int[] mTempMeasureSpecs = new int[2];
...@@ -124,6 +127,7 @@ public class OmniboxSuggestionsRecyclerView ...@@ -124,6 +127,7 @@ public class OmniboxSuggestionsRecyclerView
@Override @Override
public void setObserver(OmniboxSuggestionsDropdown.Observer observer) { public void setObserver(OmniboxSuggestionsDropdown.Observer observer) {
mObserver = observer;
mScrollListener.setObserver(observer); mScrollListener.setObserver(observer);
mDropdownDelegate.setObserver(observer); mDropdownDelegate.setObserver(observer);
} }
...@@ -217,4 +221,14 @@ public class OmniboxSuggestionsRecyclerView ...@@ -217,4 +221,14 @@ public class OmniboxSuggestionsRecyclerView
return mDropdownDelegate.shouldIgnoreGenericMotionEvent(event) return mDropdownDelegate.shouldIgnoreGenericMotionEvent(event)
|| super.onGenericMotionEvent(event); || super.onGenericMotionEvent(event);
} }
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
final int eventType = ev.getActionMasked();
if ((eventType == MotionEvent.ACTION_UP || eventType == MotionEvent.ACTION_DOWN)
&& mObserver != null) {
mObserver.onGesture(eventType == MotionEvent.ACTION_UP, ev.getEventTime());
}
return super.dispatchTouchEvent(ev);
}
} }
...@@ -16,13 +16,4 @@ public interface SuggestionViewDelegate { ...@@ -16,13 +16,4 @@ public interface SuggestionViewDelegate {
/** Triggered when the user navigates to one of the suggestions without clicking on it. */ /** Triggered when the user navigates to one of the suggestions without clicking on it. */
void onSetUrlToSuggestion(); void onSetUrlToSuggestion();
/** Triggered when the user touches the suggestion view. */
void onGestureDown();
/**
* Triggered when the user touch on the suggestion view finishes.
* @param timestamp the timestamp for the ACTION_UP event.
*/
void onGestureUp(long timestamp);
} }
...@@ -7,7 +7,6 @@ package org.chromium.chrome.browser.omnibox.suggestions.base; ...@@ -7,7 +7,6 @@ package org.chromium.chrome.browser.omnibox.suggestions.base;
import android.content.Context; import android.content.Context;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
...@@ -121,18 +120,6 @@ public class BaseSuggestionView<T extends View> extends SimpleHorizontalLayoutVi ...@@ -121,18 +120,6 @@ public class BaseSuggestionView<T extends View> extends SimpleHorizontalLayoutVi
this((T) LayoutInflater.from(context).inflate(layoutId, null)); this((T) LayoutInflater.from(context).inflate(layoutId, null));
} }
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
// Whenever the suggestion dropdown is touched, we dispatch onGestureDown which is
// used to let autocomplete controller know that it should stop updating suggestions.
if (ev.getActionMasked() == MotionEvent.ACTION_DOWN) {
mDelegate.onGestureDown();
} else if (ev.getActionMasked() == MotionEvent.ACTION_UP) {
mDelegate.onGestureUp(ev.getEventTime());
}
return super.dispatchTouchEvent(ev);
}
@Override @Override
public boolean onKeyDown(int keyCode, KeyEvent event) { public boolean onKeyDown(int keyCode, KeyEvent event) {
boolean isRtl = getLayoutDirection() == LAYOUT_DIRECTION_RTL; boolean isRtl = getLayoutDirection() == LAYOUT_DIRECTION_RTL;
......
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