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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchManager.java

Issue 2703643004: [TTS] Add an ACK message to SelectWordAroundCaret. (Closed)
Patch Set: Update the other test in ContextualSearchTapEventTest.java to know about the ACK. Created 3 years, 7 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.chrome.browser.contextualsearch; 5 package org.chromium.chrome.browser.contextualsearch;
6 6
7 import android.annotation.SuppressLint; 7 import android.annotation.SuppressLint;
8 import android.os.Handler; 8 import android.os.Handler;
9 import android.text.TextUtils; 9 import android.text.TextUtils;
10 import android.view.View; 10 import android.view.View;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 private ContextualSearchRequest mSearchRequest; 160 private ContextualSearchRequest mSearchRequest;
161 private ContextualSearchRequest mLastSearchRequestLoaded; 161 private ContextualSearchRequest mLastSearchRequestLoaded;
162 162
163 /** Whether the Accessibility Mode is enabled. */ 163 /** Whether the Accessibility Mode is enabled. */
164 private boolean mIsAccessibilityModeEnabled; 164 private boolean mIsAccessibilityModeEnabled;
165 165
166 /** Tap Experiments and other variable behavior. */ 166 /** Tap Experiments and other variable behavior. */
167 private ContextualSearchHeuristics mHeuristics; 167 private ContextualSearchHeuristics mHeuristics;
168 private QuickAnswersHeuristic mQuickAnswersHeuristic; 168 private QuickAnswersHeuristic mQuickAnswersHeuristic;
169 169
170 // Counter for how many times we've called SelectWordAroundCaret without an ACK returned.
171 // TODO(donnd): replace with a more systematic approach using the InternalSt ateController.
172 private int mSelectWordAroundCaretCounter;
173
170 /** 174 /**
171 * The delegate that is responsible for promoting a {@link ContentViewCore} to a {@link Tab} 175 * The delegate that is responsible for promoting a {@link ContentViewCore} to a {@link Tab}
172 * when necessary. 176 * when necessary.
173 */ 177 */
174 public interface ContextualSearchTabPromotionDelegate { 178 public interface ContextualSearchTabPromotionDelegate {
175 /** 179 /**
176 * Called when {@code searchContentViewCore} should be promoted to a {@l ink Tab}. 180 * Called when {@code searchContentViewCore} should be promoted to a {@l ink Tab}.
177 * @param searchUrl The Search URL to be promoted. 181 * @param searchUrl The Search URL to be promoted.
178 */ 182 */
179 void createContextualSearchTab(String searchUrl); 183 void createContextualSearchTab(String searchUrl);
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 580
577 /** 581 /**
578 * Called by native code when the surrounding text and selection range are a vailable. 582 * Called by native code when the surrounding text and selection range are a vailable.
579 * This is done for both Tap and Long-press gestures. 583 * This is done for both Tap and Long-press gestures.
580 * @param encoding The original encoding used on the base page. 584 * @param encoding The original encoding used on the base page.
581 * @param surroundingText The Text surrounding the selection. 585 * @param surroundingText The Text surrounding the selection.
582 * @param startOffset The start offset of the selection. 586 * @param startOffset The start offset of the selection.
583 * @param endOffset The end offset of the selection. 587 * @param endOffset The end offset of the selection.
584 */ 588 */
585 @CalledByNative 589 @CalledByNative
586 private void onTextSurroundingSelectionAvailable( 590 @VisibleForTesting
591 void onTextSurroundingSelectionAvailable(
587 final String encoding, final String surroundingText, int startOffset , int endOffset) { 592 final String encoding, final String surroundingText, int startOffset , int endOffset) {
588 if (mInternalStateController.isStillWorkingOn(InternalState.GATHERING_SU RROUNDINGS)) { 593 if (mInternalStateController.isStillWorkingOn(InternalState.GATHERING_SU RROUNDINGS)) {
589 assert mContext != null; 594 assert mContext != null;
590 // Sometimes Blink returns empty surroundings and 0 offsets so reset in that case. 595 // Sometimes Blink returns empty surroundings and 0 offsets so reset in that case.
591 // See crbug.com/393100. 596 // See crbug.com/393100.
592 if (surroundingText.length() == 0) { 597 if (surroundingText.length() == 0) {
593 mInternalStateController.reset(StateChangeReason.UNKNOWN); 598 mInternalStateController.reset(StateChangeReason.UNKNOWN);
594 } else { 599 } else {
595 mContext.setSurroundingText(encoding, surroundingText, startOffs et, endOffset); 600 mContext.setSurroundingText(encoding, surroundingText, startOffs et, endOffset);
596 mInternalStateController.notifyFinishedWorkOn(InternalState.GATH ERING_SURROUNDINGS); 601 mInternalStateController.notifyFinishedWorkOn(InternalState.GATH ERING_SURROUNDINGS);
(...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 } 1210 }
1206 1211
1207 @Override 1212 @Override
1208 public boolean requestSelectionPopupUpdates(boolean shouldSuggest) { 1213 public boolean requestSelectionPopupUpdates(boolean shouldSuggest) {
1209 return false; 1214 return false;
1210 } 1215 }
1211 1216
1212 @Override 1217 @Override
1213 public void cancelAllRequests() {} 1218 public void cancelAllRequests() {}
1214 1219
1215 // TODO(donnd): add handling of an ACK to selectWordAroundCaret (crbug.com/4 35778 has details). 1220 @Override
1221 public void selectWordAroundCaretAck(boolean didSelect, int startAdjust, int endAdjust) {
1222 if (mSelectWordAroundCaretCounter > 0) mSelectWordAroundCaretCounter--;
1223 if (mSelectWordAroundCaretCounter > 0
1224 || !mInternalStateController.isStillWorkingOn(InternalState.STAR T_SHOWING_TAP_UI)) {
1225 return;
1226 }
1227
1228 if (didSelect) {
1229 assert mContext != null;
1230 mContext.onSelectionAdjusted(startAdjust, endAdjust);
1231 showSelectionAsSearchInBar(mSelectionController.getSelectedText());
1232 mInternalStateController.notifyFinishedWorkOn(InternalState.START_SH OWING_TAP_UI);
1233 } else {
1234 hideContextualSearch(StateChangeReason.UNKNOWN);
1235 }
1236 }
1216 1237
1217 /** 1238 /**
1218 * @return Whether the display is in a full-screen video overlay mode. 1239 * @return Whether the display is in a full-screen video overlay mode.
1219 */ 1240 */
1220 private boolean isOverlayVideoMode() { 1241 private boolean isOverlayVideoMode() {
1221 return mActivity.getFullscreenManager() != null 1242 return mActivity.getFullscreenManager() != null
1222 && mActivity.getFullscreenManager().isOverlayVideoMode(); 1243 && mActivity.getFullscreenManager().isOverlayVideoMode();
1223 } 1244 }
1224 1245
1225 // ========================================================================= =================== 1246 // ========================================================================= ===================
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 * to expand the selection to a whole word. 1311 * to expand the selection to a whole word.
1291 */ 1312 */
1292 @Override 1313 @Override
1293 public void handleSelection(String selection, boolean selectionValid, Select ionType type, 1314 public void handleSelection(String selection, boolean selectionValid, Select ionType type,
1294 float x, float y) { 1315 float x, float y) {
1295 if (mIsAccessibilityModeEnabled) return; 1316 if (mIsAccessibilityModeEnabled) return;
1296 1317
1297 if (!selection.isEmpty()) { 1318 if (!selection.isEmpty()) {
1298 ContextualSearchUma.logSelectionIsValid(selectionValid); 1319 ContextualSearchUma.logSelectionIsValid(selectionValid);
1299 1320
1300 // Update the context so it knows the selection has changed.
1301 if (mContext != null) mContext.updateContextFromSelection(selection) ;
1302
1303 if (selectionValid && mSearchPanel != null) { 1321 if (selectionValid && mSearchPanel != null) {
1304 mSearchPanel.updateBasePageSelectionYPx(y); 1322 mSearchPanel.updateBasePageSelectionYPx(y);
1305 if (!mSearchPanel.isShowing()) { 1323 if (!mSearchPanel.isShowing()) {
1306 mSearchPanel.getPanelMetrics().onSelectionEstablished(select ion); 1324 mSearchPanel.getPanelMetrics().onSelectionEstablished(select ion);
1307 } 1325 }
1308 showSelectionAsSearchInBar(selection); 1326 showSelectionAsSearchInBar(selection);
1309 1327
1310 // TODO(donnd): remove this complication when we get an ACK mess age from 1328 if (type == SelectionType.LONG_PRESS) {
1311 // selectWordAroundCaret (see crbug.com/435778).
1312 if (type == SelectionType.TAP) {
1313 mInternalStateController.notifyFinishedWorkOn(
1314 InternalState.START_SHOWING_TAP_UI);
1315 } else {
1316 mInternalStateController.enter(InternalState.LONG_PRESS_RECO GNIZED); 1329 mInternalStateController.enter(InternalState.LONG_PRESS_RECO GNIZED);
1317 } 1330 }
1318 } else { 1331 } else {
1319 hideContextualSearch(StateChangeReason.INVALID_SELECTION); 1332 hideContextualSearch(StateChangeReason.INVALID_SELECTION);
1320 } 1333 }
1321 } 1334 }
1322 } 1335 }
1323 1336
1324 @Override 1337 @Override
1325 public void handleSelectionDismissal() { 1338 public void handleSelectionDismissal() {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 @Override 1436 @Override
1424 public void startShowingTapUi() { 1437 public void startShowingTapUi() {
1425 WebContents baseWebContents = getBaseWebContents(); 1438 WebContents baseWebContents = getBaseWebContents();
1426 // TODO(donnd): Call isTapSupported earlier so we don't waste ti me gathering 1439 // TODO(donnd): Call isTapSupported earlier so we don't waste ti me gathering
1427 // surrounding text and deciding suppression when unsupported, o r remove the whole 1440 // surrounding text and deciding suppression when unsupported, o r remove the whole
1428 // idea of unsupported taps in favor of deciding suppression bet ter. 1441 // idea of unsupported taps in favor of deciding suppression bet ter.
1429 // Details in crbug.com/715297. 1442 // Details in crbug.com/715297.
1430 if (baseWebContents != null && mPolicy.isTapSupported()) { 1443 if (baseWebContents != null && mPolicy.isTapSupported()) {
1431 mInternalStateController.notifyStartingWorkOn( 1444 mInternalStateController.notifyStartingWorkOn(
1432 InternalState.START_SHOWING_TAP_UI); 1445 InternalState.START_SHOWING_TAP_UI);
1446 mSelectWordAroundCaretCounter++;
1433 baseWebContents.selectWordAroundCaret(); 1447 baseWebContents.selectWordAroundCaret();
1434 // Let the policy know that a valid tap gesture has been rec eived. 1448 // Let the policy know that a valid tap gesture has been rec eived.
1435 mPolicy.registerTap(); 1449 mPolicy.registerTap();
1436 } else { 1450 } else {
1437 mInternalStateController.reset(StateChangeReason.UNKNOWN); 1451 mInternalStateController.reset(StateChangeReason.UNKNOWN);
1438 } 1452 }
1439 } 1453 }
1440 1454
1441 /** 1455 /**
1442 * Waits for possible Tap gesture that's near enough to the previous tap to be 1456 * Waits for possible Tap gesture that's near enough to the previous tap to be
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
1569 private native void nativeStartSearchTermResolutionRequest(long nativeContex tualSearchManager, 1583 private native void nativeStartSearchTermResolutionRequest(long nativeContex tualSearchManager,
1570 ContextualSearchContext contextualSearchContext, WebContents baseWeb Contents); 1584 ContextualSearchContext contextualSearchContext, WebContents baseWeb Contents);
1571 protected native void nativeGatherSurroundingText(long nativeContextualSearc hManager, 1585 protected native void nativeGatherSurroundingText(long nativeContextualSearc hManager,
1572 ContextualSearchContext contextualSearchContext, WebContents baseWeb Contents); 1586 ContextualSearchContext contextualSearchContext, WebContents baseWeb Contents);
1573 private native void nativeEnableContextualSearchJsApiForOverlay( 1587 private native void nativeEnableContextualSearchJsApiForOverlay(
1574 long nativeContextualSearchManager, WebContents overlayWebContents); 1588 long nativeContextualSearchManager, WebContents overlayWebContents);
1575 // Don't call these directly, instead call the private methods that cache th e results. 1589 // Don't call these directly, instead call the private methods that cache th e results.
1576 private native String nativeGetTargetLanguage(long nativeContextualSearchMan ager); 1590 private native String nativeGetTargetLanguage(long nativeContextualSearchMan ager);
1577 private native String nativeGetAcceptLanguages(long nativeContextualSearchMa nager); 1591 private native String nativeGetAcceptLanguages(long nativeContextualSearchMa nager);
1578 } 1592 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698