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

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

Issue 1239583003: Update touch selection notification names, add ESTABLISHED. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changed boolean member to track SELECTION_ESTABLISHED instead of DISSOLVED. 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 private final Handler mRunnableHandler; 47 private final Handler mRunnableHandler;
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 mIsSelectionEstablished;
57 private boolean mShouldHandleSelectionModification; 58 private boolean mShouldHandleSelectionModification;
58 private boolean mDidExpandSelection; 59 private boolean mDidExpandSelection;
59 60
60 private float mX; 61 private float mX;
61 private float mY; 62 private float mY;
62 63
63 private class ContextualSearchGestureStateListener extends GestureStateListe ner { 64 private class ContextualSearchGestureStateListener extends GestureStateListe ner {
64 @Override 65 @Override
65 public void onScrollStarted(int scrollOffsetY, int scrollExtentY) { 66 public void onScrollStarted(int scrollOffsetY, int scrollExtentY) {
66 mHandler.handleScroll(); 67 mHandler.handleScroll();
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 182
182 /** 183 /**
183 * Handles a notification that a selection event took place. 184 * Handles a notification that a selection event took place.
184 * @param eventType The type of event that took place. 185 * @param eventType The type of event that took place.
185 * @param posXPix The x coordinate of the selection start handle. 186 * @param posXPix The x coordinate of the selection start handle.
186 * @param posYPix The y coordinate of the selection start handle. 187 * @param posYPix The y coordinate of the selection start handle.
187 */ 188 */
188 void handleSelectionEvent(int eventType, float posXPix, float posYPix) { 189 void handleSelectionEvent(int eventType, float posXPix, float posYPix) {
189 boolean shouldHandleSelection = false; 190 boolean shouldHandleSelection = false;
190 switch (eventType) { 191 switch (eventType) {
191 case SelectionEventType.SELECTION_SHOWN: 192 case SelectionEventType.SELECTION_HANDLES_SHOWN:
192 mWasTapGestureDetected = false; 193 mWasTapGestureDetected = false;
193 mSelectionType = SelectionType.LONG_PRESS; 194 mSelectionType = SelectionType.LONG_PRESS;
194 shouldHandleSelection = true; 195 shouldHandleSelection = true;
195 break; 196 break;
196 case SelectionEventType.SELECTION_CLEARED: 197 case SelectionEventType.SELECTION_HANDLES_CLEARED:
197 mHandler.handleSelectionDismissal(); 198 mHandler.handleSelectionDismissal();
198 resetAllStates(); 199 resetAllStates();
199 break; 200 break;
200 case SelectionEventType.SELECTION_DRAG_STARTED: 201 case SelectionEventType.SELECTION_HANDLE_DRAG_STARTED:
201 mIsSelectionBeingModified = true; 202 mIsSelectionBeingModified = true;
202 break; 203 break;
203 case SelectionEventType.SELECTION_DRAG_STOPPED: 204 case SelectionEventType.SELECTION_HANDLE_DRAG_STOPPED:
204 mIsSelectionBeingModified = false; 205 mIsSelectionBeingModified = false;
205 shouldHandleSelection = mShouldHandleSelectionModification; 206 shouldHandleSelection = mShouldHandleSelectionModification;
206 break; 207 break;
208 case SelectionEventType.SELECTION_ESTABLISHED:
209 mIsSelectionEstablished = true;
210 break;
211 case SelectionEventType.SELECTION_DISSOLVED:
212 mIsSelectionEstablished = false;
213 break;
207 default: 214 default:
208 } 215 }
209 216
210 if (shouldHandleSelection) { 217 if (shouldHandleSelection) {
211 ContentViewCore baseContentView = getBaseContentView(); 218 ContentViewCore baseContentView = getBaseContentView();
212 if (baseContentView != null) { 219 if (baseContentView != null) {
213 String selection = baseContentView.getSelectedText(); 220 String selection = baseContentView.getSelectedText();
214 if (selection != null) { 221 if (selection != null) {
215 mX = posXPix; 222 mX = posXPix;
216 mY = posYPix; 223 mY = posYPix;
217 mSelectedText = selection; 224 mSelectedText = selection;
218 handleSelection(selection, SelectionType.LONG_PRESS); 225 handleSelection(selection, SelectionType.LONG_PRESS);
219 } 226 }
220 } 227 }
221 } 228 }
222 } 229 }
223 230
224 /** 231 /**
225 * Re-enables selection modification handling and invokes 232 * Re-enables selection modification handling and invokes
226 * ContextualSearchSelectionHandler.handleSelection(). 233 * ContextualSearchSelectionHandler.handleSelection().
227 * @param selection The text that was selected. 234 * @param selection The text that was selected.
228 * @param type The type of selection made by the user. 235 * @param type The type of selection made by the user.
229 */ 236 */
230 private void handleSelection(String selection, SelectionType type) { 237 private void handleSelection(String selection, SelectionType type) {
231 mShouldHandleSelectionModification = true; 238 mShouldHandleSelectionModification = true;
232 mHandler.handleSelection(selection, isValidSelection(selection), type, m X, mY); 239 mHandler.handleSelection(selection, isValidSelection(selection), type, m X, mY);
233 } 240 }
234 241
235
236 /** 242 /**
237 * Resets all internal state of this class, including the tap state. 243 * Resets all internal state of this class, including the tap state.
238 */ 244 */
239 private void resetAllStates() { 245 private void resetAllStates() {
240 resetSelectionStates(); 246 resetSelectionStates();
241 mWasLastTapValid = false; 247 mWasLastTapValid = false;
242 } 248 }
243 249
244 /** 250 /**
245 * Resets all of the internal state of this class that handles the selection . 251 * Resets all of the internal state of this class that handles the selection .
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 } 362 }
357 363
358 /** 364 /**
359 * @return whether a tap gesture has been detected, for testing. 365 * @return whether a tap gesture has been detected, for testing.
360 */ 366 */
361 @VisibleForTesting 367 @VisibleForTesting
362 boolean wasAnyTapGestureDetected() { 368 boolean wasAnyTapGestureDetected() {
363 return mIsWaitingForInvalidTapDetection; 369 return mIsWaitingForInvalidTapDetection;
364 } 370 }
365 371
372 /**
373 * @return whether the selection has been dissolved, for testing.
374 */
375 @VisibleForTesting
376 boolean isSelectionDissolved() {
jdduke (slow) 2015/07/16 23:15:50 Super nit: Let's keep the getter name similar to
Donn Denman 2015/07/16 23:24:51 Done.
377 return !mIsSelectionEstablished;
378 }
379
366 /** Determines if the given selection is valid or not. 380 /** Determines if the given selection is valid or not.
367 * @param selection The selection portion of the context. 381 * @param selection The selection portion of the context.
368 * @return whether the given selection is considered a valid target for a se arch. 382 * @return whether the given selection is considered a valid target for a se arch.
369 */ 383 */
370 private boolean isValidSelection(String selection) { 384 private boolean isValidSelection(String selection) {
371 return isValidSelection(selection, getBaseContentView()); 385 return isValidSelection(selection, getBaseContentView());
372 } 386 }
373 387
374 @VisibleForTesting 388 @VisibleForTesting
375 boolean isValidSelection(String selection, ContentViewCore baseContentView) { 389 boolean isValidSelection(String selection, ContentViewCore baseContentView) {
376 if (selection.length() > MAX_SELECTION_LENGTH || !doesContainAWord(selec tion)) { 390 if (selection.length() > MAX_SELECTION_LENGTH || !doesContainAWord(selec tion)) {
377 return false; 391 return false;
378 } 392 }
379 return baseContentView != null && !baseContentView.isFocusedNodeEditable (); 393 return baseContentView != null && !baseContentView.isFocusedNodeEditable ();
380 } 394 }
381 395
382 /** 396 /**
383 * Determines if the given selection contains a word or not. 397 * Determines if the given selection contains a word or not.
384 * @param selection The the selection to check for a word. 398 * @param selection The the selection to check for a word.
385 * @return Whether the selection contains a word anywhere within it or not. 399 * @return Whether the selection contains a word anywhere within it or not.
386 */ 400 */
387 @VisibleForTesting 401 @VisibleForTesting
388 public boolean doesContainAWord(String selection) { 402 public boolean doesContainAWord(String selection) {
389 return mContainsWordPattern.matcher(selection).find(); 403 return mContainsWordPattern.matcher(selection).find();
390 } 404 }
391 } 405 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698