Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchSelectionController.java

Issue 2703473002: [TTS] Extract tapped text before showing UI. (Closed)
Patch Set: Minor update. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchSelectionController.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchSelectionController.java b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchSelectionController.java
index aa90dddbbe452f8368c4c158442a024a061e8018..49b587974341a008d32dfa2d3d67e65a834b46ae 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchSelectionController.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchSelectionController.java
@@ -41,9 +41,6 @@ public class ContextualSearchSelectionController {
// TODO(donnd): Fix in Blink, crbug.com/435778.
private static final int INVALID_IF_NO_SELECTION_CHANGE_AFTER_TAP_MS = 50;
- // The default navigation-detection-delay in milliseconds.
- private static final int TAP_NAVIGATION_DETECTION_DELAY = 16;
-
private static final String CONTAINS_WORD_PATTERN = "(\\w|\\p{L}|\\p{N})+";
// A URL is:
// 1: scheme://
@@ -69,7 +66,6 @@ public class ContextualSearchSelectionController {
private boolean mWasTapGestureDetected;
// Reflects whether the last tap was valid and whether we still have a tap-based selection.
private ContextualSearchTapState mLastTapState;
- private TapSuppressionHeuristics mTapHeuristics;
private boolean mIsWaitingForInvalidTapDetection;
private boolean mShouldHandleSelectionModification;
private boolean mDidExpandSelection;
@@ -81,6 +77,9 @@ public class ContextualSearchSelectionController {
// The time of the most last scroll activity, or 0 if none.
private long mLastScrollTimeNs;
+ // When the last tap gesture happened.
+ private long mTapTimeNanoseconds;
+
// Tracks whether a Context Menu has just been shown and the UX has been dismissed.
// The selection may be unreliable until the next reset. See crbug.com/628436.
private boolean mIsContextMenuShown;
@@ -239,6 +238,7 @@ public class ContextualSearchSelectionController {
* @param selection The selection portion of the context.
*/
void handleSelectionChanged(String selection) {
+ System.out.println("ctxs CSSC handleSelectionChanged " + selection.length());
if (mDidExpandSelection) {
mSelectedText = selection;
mDidExpandSelection = false;
@@ -262,7 +262,7 @@ public class ContextualSearchSelectionController {
mSelectedText = selection;
if (mWasTapGestureDetected) {
- mSelectionType = SelectionType.TAP;
+ assert mSelectionType == SelectionType.TAP;
handleSelection(selection, mSelectionType);
mWasTapGestureDetected = false;
} else {
@@ -281,6 +281,7 @@ public class ContextualSearchSelectionController {
boolean shouldHandleSelection = false;
switch (eventType) {
case SelectionEventType.SELECTION_HANDLES_SHOWN:
+ System.out.println("ctxs SELECTION_HANDLES_SHOWN");
if (!mIsContextMenuShown) {
mWasTapGestureDetected = false;
mSelectionType = SelectionType.LONG_PRESS;
@@ -323,17 +324,19 @@ public class ContextualSearchSelectionController {
private void handleSelection(String selection, SelectionType type) {
mShouldHandleSelectionModification = true;
boolean isValidSelection = validateSelectionSuppression(selection);
- mHandler.handleSelection(selection, isValidSelection, type, mX, mY);
+ mHandler.handleSelection(selection, isValidSelection, type, mX, mY, mTapTimeNanoseconds);
}
/**
* Resets all internal state of this class, including the tap state.
*/
private void resetAllStates() {
+ System.out.println("ctxs resetAllStates");
resetSelectionStates();
mLastTapState = null;
mLastScrollTimeNs = 0;
mIsContextMenuShown = false;
+ mTapTimeNanoseconds = 0;
}
/**
@@ -364,39 +367,11 @@ public class ContextualSearchSelectionController {
// TODO(donnd): refactor to avoid needing a new handler API method as suggested by Pedro.
if (mSelectionType != SelectionType.LONG_PRESS) {
mWasTapGestureDetected = true;
- long tapTimeNanoseconds = System.nanoTime();
- // TODO(donnd): add a policy method to get adjusted tap count.
- ChromePreferenceManager prefs = ChromePreferenceManager.getInstance();
- int adjustedTapsSinceOpen = prefs.getContextualSearchTapCount()
- - prefs.getContextualSearchTapQuickAnswerCount();
- // Explicitly destroy the old heuristics so native code can dispose data.
- if (mTapHeuristics != null) mTapHeuristics.destroy();
- mTapHeuristics =
- new TapSuppressionHeuristics(this, mLastTapState, x, y, adjustedTapsSinceOpen);
- // TODO(donnd): Move to be called when the panel closes to work with states that change.
- mTapHeuristics.logConditionState();
- // Tell the manager what it needs in order to log metrics on whether the tap would have
- // been suppressed if each of the heuristics were satisfied.
- mHandler.handleMetricsForWouldSuppressTap(mTapHeuristics);
+ mSelectionType = SelectionType.TAP;
+ mTapTimeNanoseconds = System.nanoTime();
mX = x;
mY = y;
- boolean shouldSuppressTap = mTapHeuristics.shouldSuppressTap();
- if (shouldSuppressTap) {
- mHandler.handleSuppressedTap();
- } else {
- // TODO(donnd): Find a better way to determine that a navigation will be triggered
- // by the tap, or merge with other time-consuming actions like gathering surrounding
- // text or detecting page mutations.
- new Handler().postDelayed(new Runnable() {
- @Override
- public void run() {
- mHandler.handleValidTap();
- }
- }, TAP_NAVIGATION_DETECTION_DELAY);
- }
- // Remember the tap state for subsequent tap evaluation.
- mLastTapState =
- new ContextualSearchTapState(x, y, tapTimeNanoseconds, shouldSuppressTap);
+ mHandler.handleValidTap();
} else {
// Long press; reset last tap state.
mLastTapState = null;
@@ -405,6 +380,45 @@ public class ContextualSearchSelectionController {
}
/**
+ * DLD
+ * Handles Tap suppression by making a callback to either the handler's handleSuppressedTap or
+ * handleNonSuppressedTap after a possible delay.
+ * This should be called when the context is fully build (by gathering surrounding text
+ * if needed, etc) but before showing any UX.
+ */
+ void handleShouldSuppressTap() {
+ int x = (int) mX;
+ int y = (int) mY;
+
+ // TODO(donnd): add a policy method to get adjusted tap count.
+ ChromePreferenceManager prefs = ChromePreferenceManager.getInstance();
+ int adjustedTapsSinceOpen = prefs.getContextualSearchTapCount()
+ - prefs.getContextualSearchTapQuickAnswerCount();
+ TapSuppressionHeuristics tapHeuristics =
+ new TapSuppressionHeuristics(this, mLastTapState, x, y, adjustedTapsSinceOpen);
+ // TODO(donnd): Move to be called when the panel closes to work with states that change.
+ tapHeuristics.logConditionState();
+ // Tell the manager what it needs in order to log metrics on whether the tap would have
+ // been suppressed if each of the heuristics were satisfied.
+ mHandler.handleMetricsForWouldSuppressTap(tapHeuristics);
+
+ boolean shouldSuppressTap = tapHeuristics.shouldSuppressTap();
+ if (mTapTimeNanoseconds != 0) {
+ // Remember the tap state for subsequent tap evaluation.
+ mLastTapState =
+ new ContextualSearchTapState(x, y, mTapTimeNanoseconds, shouldSuppressTap);
+ } else {
+ mLastTapState = null;
+ }
+
+ if (shouldSuppressTap) {
+ mHandler.handleSuppressedTap();
+ } else {
+ mHandler.handleNonSuppressedTap();
+ }
+ }
+
+ /**
* Gets the base page ContentViewCore.
* Deprecated, use getBaseWebContents instead.
* @return The Base Page's {@link ContentViewCore}, or {@code null} if there is no current tab.
@@ -470,6 +484,7 @@ public class ContextualSearchSelectionController {
* Un-schedules all pending notifications to check if a tap was invalid.
*/
private void unscheduleInvalidTapNotification() {
+ System.out.println("ctxs unscheduleInvalidTapNotification."); // DLD?
mRunnableHandler.removeCallbacks(mHandleInvalidTapRunnable);
mIsWaitingForInvalidTapDetection = true;
}
@@ -478,7 +493,8 @@ public class ContextualSearchSelectionController {
* Notify's the system that tap gesture has been completed.
*/
private void onInvalidTapDetectionTimeout() {
- mHandler.handleInvalidTap();
+ System.out.println("ctxs onInvalidTapDetectionTimeout -- invalid tap!"); // DLD?
+ // mHandler.handleInvalidTap();
mIsWaitingForInvalidTapDetection = false;
}

Powered by Google App Engine
This is Rietveld 408576698