OLD | NEW |
---|---|
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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 private ContextualSearchRequest mSearchRequest; | 161 private ContextualSearchRequest mSearchRequest; |
162 private ContextualSearchRequest mLastSearchRequestLoaded; | 162 private ContextualSearchRequest mLastSearchRequestLoaded; |
163 | 163 |
164 /** Whether the Accessibility Mode is enabled. */ | 164 /** Whether the Accessibility Mode is enabled. */ |
165 private boolean mIsAccessibilityModeEnabled; | 165 private boolean mIsAccessibilityModeEnabled; |
166 | 166 |
167 /** Tap Experiments and other variable behavior. */ | 167 /** Tap Experiments and other variable behavior. */ |
168 private ContextualSearchHeuristics mHeuristics; | 168 private ContextualSearchHeuristics mHeuristics; |
169 private QuickAnswersHeuristic mQuickAnswersHeuristic; | 169 private QuickAnswersHeuristic mQuickAnswersHeuristic; |
170 | 170 |
171 // Counter for how many times we've called SelectWordAroundCaret without an ACK returned. | |
172 // TODO(donnd): replace with a more systematic approach using the InternalSt ateController. | |
173 private int mSelectWordAroundCaretCounter; | |
174 | |
171 /** | 175 /** |
172 * The delegate that is responsible for promoting a {@link ContentViewCore} to a {@link Tab} | 176 * The delegate that is responsible for promoting a {@link ContentViewCore} to a {@link Tab} |
173 * when necessary. | 177 * when necessary. |
174 */ | 178 */ |
175 public interface ContextualSearchTabPromotionDelegate { | 179 public interface ContextualSearchTabPromotionDelegate { |
176 /** | 180 /** |
177 * Called when {@code searchContentViewCore} should be promoted to a {@l ink Tab}. | 181 * Called when {@code searchContentViewCore} should be promoted to a {@l ink Tab}. |
178 * @param searchUrl The Search URL to be promoted. | 182 * @param searchUrl The Search URL to be promoted. |
179 */ | 183 */ |
180 void createContextualSearchTab(String searchUrl); | 184 void createContextualSearchTab(String searchUrl); |
(...skipping 1025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1206 if (!isOverlayVideoMode()) { | 1210 if (!isOverlayVideoMode()) { |
1207 mSelectionController.handleShowUnhandledTapUIIfNeeded(x, y); | 1211 mSelectionController.handleShowUnhandledTapUIIfNeeded(x, y); |
1208 } | 1212 } |
1209 } | 1213 } |
1210 | 1214 |
1211 @Override | 1215 @Override |
1212 public boolean sendsSelectionPopupUpdates() { | 1216 public boolean sendsSelectionPopupUpdates() { |
1213 return false; | 1217 return false; |
1214 } | 1218 } |
1215 | 1219 |
1216 // 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)) { | |
aelias_OOO_until_Jul13
2017/05/05 21:13:22
Can this line be deleted now? It seems the scenar
Donn Denman
2017/05/05 21:32:40
No, I don't think so. The scenario is a first tap
aelias_OOO_until_Jul13
2017/05/05 21:47:01
I don't get it, you increment the counter right ne
Donn Denman
2017/05/05 22:00:36
We simply might be in some other state at the time
| |
1225 return; | |
1226 } | |
1227 | |
1228 if (didSelect) { | |
1229 assert mContext != null; | |
1230 mContext.onSelectionAdjusted(startAdjust, endAdjust); | |
1231 showSelectionAsSearchInBar(mSelectionController.getSelectedText()); | |
1232 } | |
1233 mInternalStateController.notifyFinishedWorkOn(InternalState.START_SHOWIN G_TAP_UI); | |
1234 } | |
1217 | 1235 |
1218 /** | 1236 /** |
1219 * @return Whether the display is in a full-screen video overlay mode. | 1237 * @return Whether the display is in a full-screen video overlay mode. |
1220 */ | 1238 */ |
1221 private boolean isOverlayVideoMode() { | 1239 private boolean isOverlayVideoMode() { |
1222 return mActivity.getFullscreenManager() != null | 1240 return mActivity.getFullscreenManager() != null |
1223 && mActivity.getFullscreenManager().isOverlayVideoMode(); | 1241 && mActivity.getFullscreenManager().isOverlayVideoMode(); |
1224 } | 1242 } |
1225 | 1243 |
1226 // ========================================================================= =================== | 1244 // ========================================================================= =================== |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1291 * to expand the selection to a whole word. | 1309 * to expand the selection to a whole word. |
1292 */ | 1310 */ |
1293 @Override | 1311 @Override |
1294 public void handleSelection(String selection, boolean selectionValid, Select ionType type, | 1312 public void handleSelection(String selection, boolean selectionValid, Select ionType type, |
1295 float x, float y) { | 1313 float x, float y) { |
1296 if (mIsAccessibilityModeEnabled) return; | 1314 if (mIsAccessibilityModeEnabled) return; |
1297 | 1315 |
1298 if (!selection.isEmpty()) { | 1316 if (!selection.isEmpty()) { |
1299 ContextualSearchUma.logSelectionIsValid(selectionValid); | 1317 ContextualSearchUma.logSelectionIsValid(selectionValid); |
1300 | 1318 |
1301 // Update the context so it knows the selection has changed. | |
1302 if (mContext != null) mContext.updateContextFromSelection(selection) ; | |
1303 | |
1304 if (selectionValid && mSearchPanel != null) { | 1319 if (selectionValid && mSearchPanel != null) { |
1305 mSearchPanel.updateBasePageSelectionYPx(y); | 1320 mSearchPanel.updateBasePageSelectionYPx(y); |
1306 if (!mSearchPanel.isShowing()) { | 1321 if (!mSearchPanel.isShowing()) { |
1307 mSearchPanel.getPanelMetrics().onSelectionEstablished(select ion); | 1322 mSearchPanel.getPanelMetrics().onSelectionEstablished(select ion); |
1308 } | 1323 } |
1309 showSelectionAsSearchInBar(selection); | 1324 showSelectionAsSearchInBar(selection); |
1310 | 1325 |
1311 // TODO(donnd): remove this complication when we get an ACK mess age from | 1326 if (type == SelectionType.LONG_PRESS) { |
1312 // selectWordAroundCaret (see crbug.com/435778). | |
1313 if (type == SelectionType.TAP) { | |
1314 // Make sure we have a context -- we'll need one to show the UI. | |
1315 if (mContext == null) { | |
1316 // Some unknown failure happened, hide the UI. | |
1317 hideContextualSearch(StateChangeReason.UNKNOWN); | |
1318 return; | |
1319 } | |
1320 | |
1321 mInternalStateController.notifyFinishedWorkOn( | |
1322 InternalState.START_SHOWING_TAP_UI); | |
1323 } else { | |
1324 mInternalStateController.enter(InternalState.LONG_PRESS_RECO GNIZED); | 1327 mInternalStateController.enter(InternalState.LONG_PRESS_RECO GNIZED); |
1325 } | 1328 } |
1326 } else { | 1329 } else { |
1327 hideContextualSearch(StateChangeReason.INVALID_SELECTION); | 1330 hideContextualSearch(StateChangeReason.INVALID_SELECTION); |
1328 } | 1331 } |
1329 } | 1332 } |
1330 } | 1333 } |
1331 | 1334 |
1332 @Override | 1335 @Override |
1333 public void handleSelectionDismissal() { | 1336 public void handleSelectionDismissal() { |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1433 @Override | 1436 @Override |
1434 public void startShowingTapUi() { | 1437 public void startShowingTapUi() { |
1435 WebContents baseWebContents = getBaseWebContents(); | 1438 WebContents baseWebContents = getBaseWebContents(); |
1436 // 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 |
1437 // 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 |
1438 // idea of unsupported taps in favor of deciding suppression bet ter. | 1441 // idea of unsupported taps in favor of deciding suppression bet ter. |
1439 // Details in crbug.com/715297. | 1442 // Details in crbug.com/715297. |
1440 if (baseWebContents != null && mPolicy.isTapSupported()) { | 1443 if (baseWebContents != null && mPolicy.isTapSupported()) { |
1441 mInternalStateController.notifyStartingWorkOn( | 1444 mInternalStateController.notifyStartingWorkOn( |
1442 InternalState.START_SHOWING_TAP_UI); | 1445 InternalState.START_SHOWING_TAP_UI); |
1446 mSelectWordAroundCaretCounter++; | |
1443 baseWebContents.selectWordAroundCaret(); | 1447 baseWebContents.selectWordAroundCaret(); |
1444 // 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. |
1445 mPolicy.registerTap(); | 1449 mPolicy.registerTap(); |
1446 } else { | 1450 } else { |
1447 mInternalStateController.reset(StateChangeReason.UNKNOWN); | 1451 mInternalStateController.reset(StateChangeReason.UNKNOWN); |
1448 } | 1452 } |
1449 } | 1453 } |
1450 | 1454 |
1451 /** | 1455 /** |
1452 * 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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1576 private native void nativeStartSearchTermResolutionRequest(long nativeContex tualSearchManager, | 1580 private native void nativeStartSearchTermResolutionRequest(long nativeContex tualSearchManager, |
1577 ContextualSearchContext contextualSearchContext, WebContents baseWeb Contents); | 1581 ContextualSearchContext contextualSearchContext, WebContents baseWeb Contents); |
1578 protected native void nativeGatherSurroundingText(long nativeContextualSearc hManager, | 1582 protected native void nativeGatherSurroundingText(long nativeContextualSearc hManager, |
1579 ContextualSearchContext contextualSearchContext, WebContents baseWeb Contents); | 1583 ContextualSearchContext contextualSearchContext, WebContents baseWeb Contents); |
1580 private native void nativeEnableContextualSearchJsApiForOverlay( | 1584 private native void nativeEnableContextualSearchJsApiForOverlay( |
1581 long nativeContextualSearchManager, WebContents overlayWebContents); | 1585 long nativeContextualSearchManager, WebContents overlayWebContents); |
1582 // Don't call these directly, instead call the private methods that cache th e results. | 1586 // Don't call these directly, instead call the private methods that cache th e results. |
1583 private native String nativeGetTargetLanguage(long nativeContextualSearchMan ager); | 1587 private native String nativeGetTargetLanguage(long nativeContextualSearchMan ager); |
1584 private native String nativeGetAcceptLanguages(long nativeContextualSearchMa nager); | 1588 private native String nativeGetAcceptLanguages(long nativeContextualSearchMa nager); |
1585 } | 1589 } |
OLD | NEW |