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 0d565dd629af4e9ab233e95e6389566ac1199181..460fe41aa06d3fd2b5e017c987934f35dba36003 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 |
@@ -55,6 +55,7 @@ public class ContextualSearchSelectionController { |
private boolean mWasLastTapValid; |
private boolean mIsWaitingForInvalidTapDetection; |
private boolean mShouldHandleSelectionModification; |
+ private boolean mDidExpandSelection; |
private float mX; |
private float mY; |
@@ -149,6 +150,11 @@ public class ContextualSearchSelectionController { |
* @param selection The selection portion of the context. |
*/ |
void handleSelectionChanged(String selection) { |
+ if (mDidExpandSelection) { |
+ mDidExpandSelection = false; |
+ return; |
+ } |
+ |
if (selection == null || selection.isEmpty()) { |
scheduleInvalidTapNotification(); |
// When the user taps on the page it will place the caret in that position, which |
@@ -281,6 +287,26 @@ public class ContextualSearchSelectionController { |
} |
/** |
+ * Expands the current selection by the specified amounts. |
+ * @param selectionStartAdjust The start offset adjustment of the selection to use to highlight |
+ * the search term. |
+ * @param selectionEndAdjust The end offset adjustment of the selection to use to highlight |
+ * the search term. |
+ */ |
+ void adjustSelection(int selectionStartAdjust, int selectionEndAdjust) { |
+ // TODO(donnd): add code to verify that the selection is still valid before changing it. |
+ // crbug.com/508354 |
+ |
+ if (selectionStartAdjust == 0 && selectionEndAdjust == 0) return; |
+ ContentViewCore basePageContentView = getBaseContentView(); |
+ if (basePageContentView != null && basePageContentView.getWebContents() != null) { |
+ mDidExpandSelection = true; |
+ basePageContentView.getWebContents().adjustSelectionByCharacterOffset( |
+ selectionStartAdjust, selectionEndAdjust); |
+ } |
+ } |
+ |
+ /** |
* @return whether a tap at the given coordinates should be handled or not. |
*/ |
private boolean shouldHandleTap(int x, int y) { |