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

Side by Side 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: Add bug number 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 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.os.Handler; 7 import android.os.Handler;
8 8
9 import org.chromium.base.VisibleForTesting; 9 import org.chromium.base.VisibleForTesting;
10 import org.chromium.chrome.browser.ChromeActivity; 10 import org.chromium.chrome.browser.ChromeActivity;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 private final float mPxToDp; 48 private final float mPxToDp;
49 private final Pattern mContainsWordPattern; 49 private final Pattern mContainsWordPattern;
50 50
51 private String mSelectedText; 51 private String mSelectedText;
52 private SelectionType mSelectionType; 52 private SelectionType mSelectionType;
53 private boolean mWasTapGestureDetected; 53 private boolean mWasTapGestureDetected;
54 private boolean mIsSelectionBeingModified; 54 private boolean mIsSelectionBeingModified;
55 private boolean mWasLastTapValid; 55 private boolean mWasLastTapValid;
56 private boolean mIsWaitingForInvalidTapDetection; 56 private boolean mIsWaitingForInvalidTapDetection;
57 private boolean mShouldHandleSelectionModification; 57 private boolean mShouldHandleSelectionModification;
58 private boolean mDidExpandSelection;
58 59
59 private float mX; 60 private float mX;
60 private float mY; 61 private float mY;
61 62
62 private class ContextualSearchGestureStateListener extends GestureStateListe ner { 63 private class ContextualSearchGestureStateListener extends GestureStateListe ner {
63 @Override 64 @Override
64 public void onScrollStarted(int scrollOffsetY, int scrollExtentY) { 65 public void onScrollStarted(int scrollOffsetY, int scrollExtentY) {
65 mHandler.handleScroll(); 66 mHandler.handleScroll();
66 } 67 }
67 68
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 baseContentView.clearSelection(); 143 baseContentView.clearSelection();
143 } 144 }
144 resetAllStates(); 145 resetAllStates();
145 } 146 }
146 147
147 /** 148 /**
148 * Handles a change in the current Selection. 149 * Handles a change in the current Selection.
149 * @param selection The selection portion of the context. 150 * @param selection The selection portion of the context.
150 */ 151 */
151 void handleSelectionChanged(String selection) { 152 void handleSelectionChanged(String selection) {
153 if (mDidExpandSelection) {
154 mDidExpandSelection = false;
155 return;
156 }
157
152 if (selection == null || selection.isEmpty()) { 158 if (selection == null || selection.isEmpty()) {
153 scheduleInvalidTapNotification(); 159 scheduleInvalidTapNotification();
154 // When the user taps on the page it will place the caret in that po sition, which 160 // When the user taps on the page it will place the caret in that po sition, which
155 // will trigger a onSelectionChanged event with an empty string. 161 // will trigger a onSelectionChanged event with an empty string.
156 if (mSelectionType == SelectionType.TAP) { 162 if (mSelectionType == SelectionType.TAP) {
157 // Since we mostly ignore a selection that's empty, we only need to partially reset. 163 // Since we mostly ignore a selection that's empty, we only need to partially reset.
158 resetSelectionStates(); 164 resetSelectionStates();
159 return; 165 return;
160 } 166 }
161 } 167 }
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 280
275 /** 281 /**
276 * @return The Base Page's {@link ContentViewCore}, or {@code null} if there is no current tab. 282 * @return The Base Page's {@link ContentViewCore}, or {@code null} if there is no current tab.
277 */ 283 */
278 ContentViewCore getBaseContentView() { 284 ContentViewCore getBaseContentView() {
279 Tab currentTab = mActivity.getActivityTab(); 285 Tab currentTab = mActivity.getActivityTab();
280 return currentTab != null ? currentTab.getContentViewCore() : null; 286 return currentTab != null ? currentTab.getContentViewCore() : null;
281 } 287 }
282 288
283 /** 289 /**
290 * Expands the current selection by the specified amounts.
291 * @param selectionStartAdjust The start offset adjustment of the selection to use to highlight
292 * the search term.
293 * @param selectionEndAdjust The end offset adjustment of the selection to u se to highlight
294 * the search term.
295 */
296 void adjustSelection(int selectionStartAdjust, int selectionEndAdjust) {
297 // TODO(donnd): add code to verify that the selection is still valid bef ore changing it.
298 // crbug.com/508354
299
300 if (selectionStartAdjust == 0 && selectionEndAdjust == 0) return;
301 ContentViewCore basePageContentView = getBaseContentView();
302 if (basePageContentView != null && basePageContentView.getWebContents() != null) {
303 mDidExpandSelection = true;
304 basePageContentView.getWebContents().adjustSelectionByCharacterOffse t(
305 selectionStartAdjust, selectionEndAdjust);
306 }
307 }
308
309 /**
284 * @return whether a tap at the given coordinates should be handled or not. 310 * @return whether a tap at the given coordinates should be handled or not.
285 */ 311 */
286 private boolean shouldHandleTap(int x, int y) { 312 private boolean shouldHandleTap(int x, int y) {
287 return !mWasLastTapValid || wasTapCloseToPreviousTap(x, y); 313 return !mWasLastTapValid || wasTapCloseToPreviousTap(x, y);
288 } 314 }
289 315
290 /** 316 /**
291 * Determines whether a tap at the given coordinates is considered "close" t o the previous 317 * Determines whether a tap at the given coordinates is considered "close" t o the previous
292 * tap. 318 * tap.
293 */ 319 */
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 /** 380 /**
355 * Determines if the given selection contains a word or not. 381 * Determines if the given selection contains a word or not.
356 * @param selection The the selection to check for a word. 382 * @param selection The the selection to check for a word.
357 * @return Whether the selection contains a word anywhere within it or not. 383 * @return Whether the selection contains a word anywhere within it or not.
358 */ 384 */
359 @VisibleForTesting 385 @VisibleForTesting
360 public boolean doesContainAWord(String selection) { 386 public boolean doesContainAWord(String selection) {
361 return mContainsWordPattern.matcher(selection).find(); 387 return mContainsWordPattern.matcher(selection).find();
362 } 388 }
363 } 389 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698