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.os.Handler; | 7 import android.os.Handler; |
8 import android.text.TextUtils; | 8 import android.text.TextUtils; |
9 import android.view.View; | 9 import android.view.View; |
10 import android.view.ViewGroup; | 10 import android.view.ViewGroup; |
(...skipping 1192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1203 if (!isOverlayVideoMode()) { | 1203 if (!isOverlayVideoMode()) { |
1204 mSelectionController.handleShowUnhandledTapUIIfNeeded(x, y); | 1204 mSelectionController.handleShowUnhandledTapUIIfNeeded(x, y); |
1205 } | 1205 } |
1206 } | 1206 } |
1207 | 1207 |
1208 @Override | 1208 @Override |
1209 public boolean sendsSelectionPopupUpdates() { | 1209 public boolean sendsSelectionPopupUpdates() { |
1210 return false; | 1210 return false; |
1211 } | 1211 } |
1212 | 1212 |
1213 // TODO(donnd): add handling of an ACK to selectWordAroundCaret (crbug.com/4
35778 has details). | 1213 @Override |
| 1214 public void selectWordAroundCaretAck(boolean didSelect, int startAdjust, int
endAdjust) { |
| 1215 if (!mInternalStateController.isStillWorkingOn(InternalState.START_SHOWI
NG_TAP_UI)) { |
| 1216 return; |
| 1217 } |
| 1218 |
| 1219 if (didSelect) { |
| 1220 assert mContext != null; |
| 1221 mContext.onSelectionAdjusted(startAdjust, endAdjust); |
| 1222 showSelectionAsSearchInBar(mSelectionController.getSelectedText()); |
| 1223 } |
| 1224 mInternalStateController.notifyFinishedWorkOn(InternalState.START_SHOWIN
G_TAP_UI); |
| 1225 } |
1214 | 1226 |
1215 /** | 1227 /** |
1216 * @return Whether the display is in a full-screen video overlay mode. | 1228 * @return Whether the display is in a full-screen video overlay mode. |
1217 */ | 1229 */ |
1218 private boolean isOverlayVideoMode() { | 1230 private boolean isOverlayVideoMode() { |
1219 return mActivity.getFullscreenManager() != null | 1231 return mActivity.getFullscreenManager() != null |
1220 && mActivity.getFullscreenManager().isOverlayVideoMode(); | 1232 && mActivity.getFullscreenManager().isOverlayVideoMode(); |
1221 } | 1233 } |
1222 | 1234 |
1223 // =========================================================================
=================== | 1235 // =========================================================================
=================== |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1288 * to expand the selection to a whole word. | 1300 * to expand the selection to a whole word. |
1289 */ | 1301 */ |
1290 @Override | 1302 @Override |
1291 public void handleSelection(String selection, boolean selectionValid, Select
ionType type, | 1303 public void handleSelection(String selection, boolean selectionValid, Select
ionType type, |
1292 float x, float y) { | 1304 float x, float y) { |
1293 if (mIsAccessibilityModeEnabled) return; | 1305 if (mIsAccessibilityModeEnabled) return; |
1294 | 1306 |
1295 if (!selection.isEmpty()) { | 1307 if (!selection.isEmpty()) { |
1296 ContextualSearchUma.logSelectionIsValid(selectionValid); | 1308 ContextualSearchUma.logSelectionIsValid(selectionValid); |
1297 | 1309 |
1298 // Update the context so it knows the selection has changed. | |
1299 if (mContext != null) mContext.updateContextFromSelection(selection)
; | |
1300 | |
1301 if (selectionValid && mSearchPanel != null) { | 1310 if (selectionValid && mSearchPanel != null) { |
1302 mSearchPanel.updateBasePageSelectionYPx(y); | 1311 mSearchPanel.updateBasePageSelectionYPx(y); |
1303 if (!mSearchPanel.isShowing()) { | 1312 if (!mSearchPanel.isShowing()) { |
1304 mSearchPanel.getPanelMetrics().onSelectionEstablished(select
ion); | 1313 mSearchPanel.getPanelMetrics().onSelectionEstablished(select
ion); |
1305 } | 1314 } |
1306 showSelectionAsSearchInBar(selection); | 1315 showSelectionAsSearchInBar(selection); |
1307 | 1316 |
1308 // TODO(donnd): remove this complication when we get an ACK mess
age from | 1317 if (type == SelectionType.LONG_PRESS) { |
1309 // selectWordAroundCaret (see crbug.com/435778). | |
1310 if (type == SelectionType.TAP) { | |
1311 mInternalStateController.notifyFinishedWorkOn( | |
1312 InternalState.START_SHOWING_TAP_UI); | |
1313 } else { | |
1314 mInternalStateController.enter(InternalState.LONG_PRESS_RECO
GNIZED); | 1318 mInternalStateController.enter(InternalState.LONG_PRESS_RECO
GNIZED); |
1315 } | 1319 } |
1316 } else { | 1320 } else { |
1317 hideContextualSearch(StateChangeReason.INVALID_SELECTION); | 1321 hideContextualSearch(StateChangeReason.INVALID_SELECTION); |
1318 } | 1322 } |
1319 } | 1323 } |
1320 } | 1324 } |
1321 | 1325 |
1322 @Override | 1326 @Override |
1323 public void handleSelectionDismissal() { | 1327 public void handleSelectionDismissal() { |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1566 private native void nativeStartSearchTermResolutionRequest(long nativeContex
tualSearchManager, | 1570 private native void nativeStartSearchTermResolutionRequest(long nativeContex
tualSearchManager, |
1567 ContextualSearchContext contextualSearchContext, WebContents baseWeb
Contents); | 1571 ContextualSearchContext contextualSearchContext, WebContents baseWeb
Contents); |
1568 protected native void nativeGatherSurroundingText(long nativeContextualSearc
hManager, | 1572 protected native void nativeGatherSurroundingText(long nativeContextualSearc
hManager, |
1569 ContextualSearchContext contextualSearchContext, WebContents baseWeb
Contents); | 1573 ContextualSearchContext contextualSearchContext, WebContents baseWeb
Contents); |
1570 private native void nativeEnableContextualSearchJsApiForOverlay( | 1574 private native void nativeEnableContextualSearchJsApiForOverlay( |
1571 long nativeContextualSearchManager, WebContents overlayWebContents); | 1575 long nativeContextualSearchManager, WebContents overlayWebContents); |
1572 // Don't call these directly, instead call the private methods that cache th
e results. | 1576 // Don't call these directly, instead call the private methods that cache th
e results. |
1573 private native String nativeGetTargetLanguage(long nativeContextualSearchMan
ager); | 1577 private native String nativeGetTargetLanguage(long nativeContextualSearchMan
ager); |
1574 private native String nativeGetAcceptLanguages(long nativeContextualSearchMa
nager); | 1578 private native String nativeGetAcceptLanguages(long nativeContextualSearchMa
nager); |
1575 } | 1579 } |
OLD | NEW |