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

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

Issue 1205033005: Adds selection expansion support for Contextual Search. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed java tests Created 5 years, 5 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 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) {

Powered by Google App Engine
This is Rietveld 408576698