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

Side by Side Diff: content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java

Issue 335943002: [Android] Composited selection handle rendering (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@input_native_handles_final
Patch Set: Fix animation tests Created 6 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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.content.browser; 5 package org.chromium.content.browser;
6 6
7 import android.annotation.SuppressLint; 7 import android.annotation.SuppressLint;
8 import android.app.Activity; 8 import android.app.Activity;
9 import android.app.SearchManager; 9 import android.app.SearchManager;
10 import android.content.ClipboardManager;
10 import android.content.ContentResolver; 11 import android.content.ContentResolver;
11 import android.content.Context; 12 import android.content.Context;
12 import android.content.Intent; 13 import android.content.Intent;
13 import android.content.pm.FeatureInfo; 14 import android.content.pm.FeatureInfo;
14 import android.content.pm.PackageManager; 15 import android.content.pm.PackageManager;
15 import android.content.res.Configuration; 16 import android.content.res.Configuration;
16 import android.database.ContentObserver; 17 import android.database.ContentObserver;
17 import android.graphics.Bitmap; 18 import android.graphics.Bitmap;
18 import android.graphics.Canvas; 19 import android.graphics.Canvas;
19 import android.graphics.Rect; 20 import android.graphics.Rect;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 import org.chromium.base.JNINamespace; 56 import org.chromium.base.JNINamespace;
56 import org.chromium.base.ObserverList; 57 import org.chromium.base.ObserverList;
57 import org.chromium.base.ObserverList.RewindableIterator; 58 import org.chromium.base.ObserverList.RewindableIterator;
58 import org.chromium.base.TraceEvent; 59 import org.chromium.base.TraceEvent;
59 import org.chromium.content.R; 60 import org.chromium.content.R;
60 import org.chromium.content.browser.ScreenOrientationListener.ScreenOrientationO bserver; 61 import org.chromium.content.browser.ScreenOrientationListener.ScreenOrientationO bserver;
61 import org.chromium.content.browser.accessibility.AccessibilityInjector; 62 import org.chromium.content.browser.accessibility.AccessibilityInjector;
62 import org.chromium.content.browser.accessibility.BrowserAccessibilityManager; 63 import org.chromium.content.browser.accessibility.BrowserAccessibilityManager;
63 import org.chromium.content.browser.input.AdapterInputConnection; 64 import org.chromium.content.browser.input.AdapterInputConnection;
64 import org.chromium.content.browser.input.GamepadList; 65 import org.chromium.content.browser.input.GamepadList;
65 import org.chromium.content.browser.input.HandleView;
66 import org.chromium.content.browser.input.ImeAdapter; 66 import org.chromium.content.browser.input.ImeAdapter;
67 import org.chromium.content.browser.input.ImeAdapter.AdapterInputConnectionFacto ry; 67 import org.chromium.content.browser.input.ImeAdapter.AdapterInputConnectionFacto ry;
68 import org.chromium.content.browser.input.InputMethodManagerWrapper; 68 import org.chromium.content.browser.input.InputMethodManagerWrapper;
69 import org.chromium.content.browser.input.InsertionHandleController; 69 import org.chromium.content.browser.input.PastePopupMenu;
70 import org.chromium.content.browser.input.PastePopupMenu.PastePopupMenuDelegate;
71 import org.chromium.content.browser.input.PopupTouchHandleDrawable;
72 import org.chromium.content.browser.input.PopupTouchHandleDrawable.PopupTouchHan dleDrawableDelegate;
70 import org.chromium.content.browser.input.SelectPopup; 73 import org.chromium.content.browser.input.SelectPopup;
71 import org.chromium.content.browser.input.SelectPopupDialog; 74 import org.chromium.content.browser.input.SelectPopupDialog;
72 import org.chromium.content.browser.input.SelectPopupDropdown; 75 import org.chromium.content.browser.input.SelectPopupDropdown;
73 import org.chromium.content.browser.input.SelectPopupItem; 76 import org.chromium.content.browser.input.SelectPopupItem;
74 import org.chromium.content.browser.input.SelectionHandleController; 77 import org.chromium.content.browser.input.SelectionEventType;
75 import org.chromium.content.common.ContentSwitches; 78 import org.chromium.content.common.ContentSwitches;
76 import org.chromium.content_public.browser.GestureStateListener; 79 import org.chromium.content_public.browser.GestureStateListener;
77 import org.chromium.content_public.browser.WebContents; 80 import org.chromium.content_public.browser.WebContents;
78 import org.chromium.ui.base.DeviceFormFactor; 81 import org.chromium.ui.base.DeviceFormFactor;
79 import org.chromium.ui.base.ViewAndroid; 82 import org.chromium.ui.base.ViewAndroid;
80 import org.chromium.ui.base.ViewAndroidDelegate; 83 import org.chromium.ui.base.ViewAndroidDelegate;
81 import org.chromium.ui.base.WindowAndroid; 84 import org.chromium.ui.base.WindowAndroid;
82 import org.chromium.ui.gfx.DeviceDisplayInfo; 85 import org.chromium.ui.gfx.DeviceDisplayInfo;
83 86
84 import java.lang.annotation.Annotation; 87 import java.lang.annotation.Annotation;
(...skipping 16 matching lines...) Expand all
101 private static final String TAG = "ContentViewCore"; 104 private static final String TAG = "ContentViewCore";
102 105
103 // Used to avoid enabling zooming in / out if resulting zooming will 106 // Used to avoid enabling zooming in / out if resulting zooming will
104 // produce little visible difference. 107 // produce little visible difference.
105 private static final float ZOOM_CONTROLS_EPSILON = 0.007f; 108 private static final float ZOOM_CONTROLS_EPSILON = 0.007f;
106 109
107 // Used to represent gestures for long press and long tap. 110 // Used to represent gestures for long press and long tap.
108 private static final int IS_LONG_PRESS = 1; 111 private static final int IS_LONG_PRESS = 1;
109 private static final int IS_LONG_TAP = 2; 112 private static final int IS_LONG_TAP = 2;
110 113
111 // Length of the delay (in ms) before fading in handles after the last page movement.
112 private static final int TEXT_HANDLE_FADE_IN_DELAY = 300;
113
114 // These values are obtained from Samsung. 114 // These values are obtained from Samsung.
115 private static final int SPEN_ACTION_DOWN = 211; 115 private static final int SPEN_ACTION_DOWN = 211;
116 private static final int SPEN_ACTION_UP = 212; 116 private static final int SPEN_ACTION_UP = 212;
117 private static final int SPEN_ACTION_MOVE = 213; 117 private static final int SPEN_ACTION_MOVE = 213;
118 private static final int SPEN_ACTION_CANCEL = 214; 118 private static final int SPEN_ACTION_CANCEL = 214;
119 private static Boolean sIsSPenSupported; 119 private static Boolean sIsSPenSupported;
120 120
121 // If the embedder adds a JavaScript interface object that contains an indir ect reference to 121 // If the embedder adds a JavaScript interface object that contains an indir ect reference to
122 // the ContentViewCore, then storing a strong ref to the interface object on the native 122 // the ContentViewCore, then storing a strong ref to the interface object on the native
123 // side would prevent garbage collection of the ContentViewCore (as that str ong ref would 123 // side would prevent garbage collection of the ContentViewCore (as that str ong ref would
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 private SelectPopup mSelectPopup; 263 private SelectPopup mSelectPopup;
264 264
265 private Runnable mFakeMouseMoveRunnable = null; 265 private Runnable mFakeMouseMoveRunnable = null;
266 266
267 // Only valid when focused on a text / password field. 267 // Only valid when focused on a text / password field.
268 private ImeAdapter mImeAdapter; 268 private ImeAdapter mImeAdapter;
269 private ImeAdapter.AdapterInputConnectionFactory mAdapterInputConnectionFact ory; 269 private ImeAdapter.AdapterInputConnectionFactory mAdapterInputConnectionFact ory;
270 private AdapterInputConnection mInputConnection; 270 private AdapterInputConnection mInputConnection;
271 private InputMethodManagerWrapper mInputMethodManagerWrapper; 271 private InputMethodManagerWrapper mInputMethodManagerWrapper;
272 272
273 private SelectionHandleController mSelectionHandleController; 273 // Lazily created paste popup menu, triggered either via long press in an
274 private InsertionHandleController mInsertionHandleController; 274 // editable region or from tapping the insertion handle.
275 private PastePopupMenu mPastePopupMenu;
275 276
276 private Runnable mDeferredHandleFadeInRunnable; 277 private PopupTouchHandleDrawableDelegate mTouchHandleDelegate;
277 278
278 private PositionObserver mPositionObserver; 279 private PositionObserver mPositionObserver;
279 private PositionObserver.Listener mPositionListener;
280 280
281 // Size of the viewport in physical pixels as set from onSizeChanged. 281 // Size of the viewport in physical pixels as set from onSizeChanged.
282 private int mViewportWidthPix; 282 private int mViewportWidthPix;
283 private int mViewportHeightPix; 283 private int mViewportHeightPix;
284 private int mPhysicalBackingWidthPix; 284 private int mPhysicalBackingWidthPix;
285 private int mPhysicalBackingHeightPix; 285 private int mPhysicalBackingHeightPix;
286 private int mOverdrawBottomHeightPix; 286 private int mOverdrawBottomHeightPix;
287 private int mViewportSizeOffsetWidthPix; 287 private int mViewportSizeOffsetWidthPix;
288 private int mViewportSizeOffsetHeightPix; 288 private int mViewportSizeOffsetHeightPix;
289 289
290 // Cached copy of all positions and scales as reported by the renderer. 290 // Cached copy of all positions and scales as reported by the renderer.
291 private final RenderCoordinates mRenderCoordinates; 291 private final RenderCoordinates mRenderCoordinates;
292 292
293 private final RenderCoordinates.NormalizedPoint mStartHandlePoint;
294 private final RenderCoordinates.NormalizedPoint mEndHandlePoint;
295 private final RenderCoordinates.NormalizedPoint mInsertionHandlePoint;
296
297 // Tracks whether a selection is currently active. When applied to selected text, indicates 293 // Tracks whether a selection is currently active. When applied to selected text, indicates
298 // whether the last selected text is still highlighted. 294 // whether the last selected text is still highlighted.
299 private boolean mHasSelection; 295 private boolean mHasSelection;
296 private boolean mHasInsertion;
300 private String mLastSelectedText; 297 private String mLastSelectedText;
301 private boolean mFocusedNodeEditable; 298 private boolean mFocusedNodeEditable;
302 private ActionMode mActionMode; 299 private ActionMode mActionMode;
303 private boolean mUnselectAllOnActionModeDismiss; 300 private boolean mUnselectAllOnActionModeDismiss;
304 301
305 // Delegate that will handle GET downloads, and be notified of completion of POST downloads. 302 // Delegate that will handle GET downloads, and be notified of completion of POST downloads.
306 private ContentViewDownloadDelegate mDownloadDelegate; 303 private ContentViewDownloadDelegate mDownloadDelegate;
307 304
308 // The AccessibilityInjector that handles loading Accessibility scripts into the web page. 305 // The AccessibilityInjector that handles loading Accessibility scripts into the web page.
309 private AccessibilityInjector mAccessibilityInjector; 306 private AccessibilityInjector mAccessibilityInjector;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 mInputMethodManagerWrapper = new InputMethodManagerWrapper(mContext); 380 mInputMethodManagerWrapper = new InputMethodManagerWrapper(mContext);
384 381
385 mRenderCoordinates = new RenderCoordinates(); 382 mRenderCoordinates = new RenderCoordinates();
386 float deviceScaleFactor = getContext().getResources().getDisplayMetrics( ).density; 383 float deviceScaleFactor = getContext().getResources().getDisplayMetrics( ).density;
387 String forceScaleFactor = CommandLine.getInstance().getSwitchValue( 384 String forceScaleFactor = CommandLine.getInstance().getSwitchValue(
388 ContentSwitches.FORCE_DEVICE_SCALE_FACTOR); 385 ContentSwitches.FORCE_DEVICE_SCALE_FACTOR);
389 if (forceScaleFactor != null) { 386 if (forceScaleFactor != null) {
390 deviceScaleFactor = Float.valueOf(forceScaleFactor); 387 deviceScaleFactor = Float.valueOf(forceScaleFactor);
391 } 388 }
392 mRenderCoordinates.setDeviceScaleFactor(deviceScaleFactor); 389 mRenderCoordinates.setDeviceScaleFactor(deviceScaleFactor);
393 mStartHandlePoint = mRenderCoordinates.createNormalizedPoint();
394 mEndHandlePoint = mRenderCoordinates.createNormalizedPoint();
395 mInsertionHandlePoint = mRenderCoordinates.createNormalizedPoint();
396 mAccessibilityManager = (AccessibilityManager) 390 mAccessibilityManager = (AccessibilityManager)
397 getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); 391 getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
398 mGestureStateListeners = new ObserverList<GestureStateListener>(); 392 mGestureStateListeners = new ObserverList<GestureStateListener>();
399 mGestureStateListenersIterator = mGestureStateListeners.rewindableIterat or(); 393 mGestureStateListenersIterator = mGestureStateListeners.rewindableIterat or();
400 394
401 mEditable = Editable.Factory.getInstance().newEditable(""); 395 mEditable = Editable.Factory.getInstance().newEditable("");
402 Selection.setSelection(mEditable, 0); 396 Selection.setSelection(mEditable, 0);
403 } 397 }
404 398
405 /** 399 /**
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 return mInputConnection; 537 return mInputConnection;
544 } 538 }
545 539
546 private ImeAdapter createImeAdapter(Context context) { 540 private ImeAdapter createImeAdapter(Context context) {
547 return new ImeAdapter(mInputMethodManagerWrapper, 541 return new ImeAdapter(mInputMethodManagerWrapper,
548 new ImeAdapter.ImeAdapterDelegate() { 542 new ImeAdapter.ImeAdapterDelegate() {
549 @Override 543 @Override
550 public void onImeEvent(boolean isFinish) { 544 public void onImeEvent(boolean isFinish) {
551 getContentViewClient().onImeEvent(); 545 getContentViewClient().onImeEvent();
552 if (!isFinish) { 546 if (!isFinish) {
553 hideHandles(); 547 hideTextHandles();
554 } 548 }
555 } 549 }
556 550
557 @Override 551 @Override
558 public void onDismissInput() { 552 public void onDismissInput() {
559 getContentViewClient().onImeStateChangeRequested(false); 553 getContentViewClient().onImeStateChangeRequested(false);
560 } 554 }
561 555
562 @Override 556 @Override
563 public View getAttachedView() { 557 public View getAttachedView() {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 // is a vital component of the ContentViewCore, so embedders must exercise c aution in what 600 // is a vital component of the ContentViewCore, so embedders must exercise c aution in what
607 // they do with the ContentViewCore before calling initialize(). 601 // they do with the ContentViewCore before calling initialize().
608 // We supply the nativeWebContents pointer here rather than in the construct or to allow us 602 // We supply the nativeWebContents pointer here rather than in the construct or to allow us
609 // to set the private browsing mode at a later point for the WebView impleme ntation. 603 // to set the private browsing mode at a later point for the WebView impleme ntation.
610 // Note that the caller remains the owner of the nativeWebContents and is re sponsible for 604 // Note that the caller remains the owner of the nativeWebContents and is re sponsible for
611 // deleting it after destroying the ContentViewCore. 605 // deleting it after destroying the ContentViewCore.
612 public void initialize(ViewGroup containerView, InternalAccessDelegate inter nalDispatcher, 606 public void initialize(ViewGroup containerView, InternalAccessDelegate inter nalDispatcher,
613 long nativeWebContents, WindowAndroid windowAndroid) { 607 long nativeWebContents, WindowAndroid windowAndroid) {
614 setContainerView(containerView); 608 setContainerView(containerView);
615 609
616 mPositionListener = new PositionObserver.Listener() {
617 @Override
618 public void onPositionChanged(int x, int y) {
619 if (isSelectionHandleShowing() || isInsertionHandleShowing()) {
620 temporarilyHideTextHandles();
621 }
622 }
623 };
624
625 long windowNativePointer = windowAndroid.getNativePointer(); 610 long windowNativePointer = windowAndroid.getNativePointer();
626 assert windowNativePointer != 0; 611 assert windowNativePointer != 0;
627 mViewAndroid = new ViewAndroid(windowAndroid, getViewAndroidDelegate()); 612 mViewAndroid = new ViewAndroid(windowAndroid, getViewAndroidDelegate());
628 long viewAndroidNativePointer = mViewAndroid.getNativePointer(); 613 long viewAndroidNativePointer = mViewAndroid.getNativePointer();
629 assert viewAndroidNativePointer != 0; 614 assert viewAndroidNativePointer != 0;
630 615
631 mZoomControlsDelegate = new ZoomControlsDelegate() { 616 mZoomControlsDelegate = new ZoomControlsDelegate() {
632 @Override 617 @Override
633 public void invokeZoomPicker() {} 618 public void invokeZoomPicker() {}
634 @Override 619 @Override
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 * <li>Disconnecting the old container view from this ContentViewCore</l i> 669 * <li>Disconnecting the old container view from this ContentViewCore</l i>
685 * <li>Updating the InternalAccessDelegate</li> 670 * <li>Updating the InternalAccessDelegate</li>
686 * <li>Reconciling the state of this ContentViewCore with the new contai ner view</li> 671 * <li>Reconciling the state of this ContentViewCore with the new contai ner view</li>
687 * <li>Tearing down and recreating the native GL rendering where appropr iate</li> 672 * <li>Tearing down and recreating the native GL rendering where appropr iate</li>
688 * <li>etc.</li> 673 * <li>etc.</li>
689 * </ul> 674 * </ul>
690 */ 675 */
691 public void setContainerView(ViewGroup containerView) { 676 public void setContainerView(ViewGroup containerView) {
692 TraceEvent.begin(); 677 TraceEvent.begin();
693 if (mContainerView != null) { 678 if (mContainerView != null) {
694 mPositionObserver.removeListener(mPositionListener); 679 mPastePopupMenu = null;
695 mSelectionHandleController = null;
696 mInsertionHandleController = null;
697 mInputConnection = null; 680 mInputConnection = null;
681 hidePopups();
698 } 682 }
699 683
700 mContainerView = containerView; 684 mContainerView = containerView;
701 mPositionObserver = new ViewPositionObserver(mContainerView); 685 mPositionObserver = new ViewPositionObserver(mContainerView);
702 String contentDescription = "Web View"; 686 String contentDescription = "Web View";
703 if (R.string.accessibility_content_view == 0) { 687 if (R.string.accessibility_content_view == 0) {
704 Log.w(TAG, "Setting contentDescription to 'Web View' as no value was specified."); 688 Log.w(TAG, "Setting contentDescription to 'Web View' as no value was specified.");
705 } else { 689 } else {
706 contentDescription = mContext.getResources().getString( 690 contentDescription = mContext.getResources().getString(
707 R.string.accessibility_content_view); 691 R.string.accessibility_content_view);
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 return MotionEvent.ACTION_CANCEL; 1143 return MotionEvent.ACTION_CANCEL;
1160 default: 1144 default:
1161 return eventActionMasked; 1145 return eventActionMasked;
1162 } 1146 }
1163 } 1147 }
1164 1148
1165 /** 1149 /**
1166 * @see View#onTouchEvent(MotionEvent) 1150 * @see View#onTouchEvent(MotionEvent)
1167 */ 1151 */
1168 public boolean onTouchEvent(MotionEvent event) { 1152 public boolean onTouchEvent(MotionEvent event) {
1153 final boolean isTouchHandleEvent = false;
1154 return onTouchEventImpl(event, isTouchHandleEvent);
1155 }
1156
1157 private boolean onTouchEventImpl(MotionEvent event, boolean isTouchHandleEve nt) {
1169 TraceEvent.begin("onTouchEvent"); 1158 TraceEvent.begin("onTouchEvent");
1170 try { 1159 try {
1171 int eventAction = event.getActionMasked(); 1160 int eventAction = event.getActionMasked();
1172 1161
1173 if (eventAction == MotionEvent.ACTION_DOWN) { 1162 if (eventAction == MotionEvent.ACTION_DOWN) {
1174 cancelRequestToScrollFocusedEditableNodeIntoView(); 1163 cancelRequestToScrollFocusedEditableNodeIntoView();
1175 } 1164 }
1176 1165
1177 if (isSPenSupported(mContext)) 1166 if (isSPenSupported(mContext))
1178 eventAction = convertSPenEventAction(eventAction); 1167 eventAction = convertSPenEventAction(eventAction);
1179 1168 if (!isValidTouchEventActionForNative(eventAction)) return false;
1180 // Only these actions have any effect on gesture detection. Other
1181 // actions have no corresponding WebTouchEvent type and may confuse the
1182 // touch pipline, so we ignore them entirely.
1183 if (eventAction != MotionEvent.ACTION_DOWN
1184 && eventAction != MotionEvent.ACTION_UP
1185 && eventAction != MotionEvent.ACTION_CANCEL
1186 && eventAction != MotionEvent.ACTION_MOVE
1187 && eventAction != MotionEvent.ACTION_POINTER_DOWN
1188 && eventAction != MotionEvent.ACTION_POINTER_UP) {
1189 return false;
1190 }
1191 1169
1192 if (mNativeContentViewCore == 0) return false; 1170 if (mNativeContentViewCore == 0) return false;
1193 1171
1194 // A zero offset is quite common, in which case the unnecessary copy should be avoided. 1172 // A zero offset is quite common, in which case the unnecessary copy should be avoided.
1195 MotionEvent offset = null; 1173 MotionEvent offset = null;
1196 if (mCurrentTouchOffsetX != 0 || mCurrentTouchOffsetY != 0) { 1174 if (mCurrentTouchOffsetX != 0 || mCurrentTouchOffsetY != 0) {
1197 offset = createOffsetMotionEvent(event); 1175 offset = createOffsetMotionEvent(event);
1198 event = offset; 1176 event = offset;
1199 } 1177 }
1200 1178
1201 final int pointerCount = event.getPointerCount(); 1179 final int pointerCount = event.getPointerCount();
1202 final boolean consumed = nativeOnTouchEvent(mNativeContentViewCore, event, 1180 final boolean consumed = nativeOnTouchEvent(mNativeContentViewCore, event,
1203 event.getEventTime(), eventAction, 1181 event.getEventTime(), eventAction,
1204 pointerCount, event.getHistorySize(), event.getActionIndex() , 1182 pointerCount, event.getHistorySize(), event.getActionIndex() ,
1205 event.getX(), event.getY(), 1183 event.getX(), event.getY(),
1206 pointerCount > 1 ? event.getX(1) : 0, 1184 pointerCount > 1 ? event.getX(1) : 0,
1207 pointerCount > 1 ? event.getY(1) : 0, 1185 pointerCount > 1 ? event.getY(1) : 0,
1208 event.getPointerId(0), pointerCount > 1 ? event.getPointerId (1) : -1, 1186 event.getPointerId(0), pointerCount > 1 ? event.getPointerId (1) : -1,
1209 event.getTouchMajor(), pointerCount > 1 ? event.getTouchMajo r(1) : 0, 1187 event.getTouchMajor(), pointerCount > 1 ? event.getTouchMajo r(1) : 0,
1210 event.getRawX(), event.getRawY(), 1188 event.getRawX(), event.getRawY(),
1211 event.getToolType(0), 1189 event.getToolType(0),
1212 pointerCount > 1 ? event.getToolType(1) : MotionEvent.TOOL_T YPE_UNKNOWN, 1190 pointerCount > 1 ? event.getToolType(1) : MotionEvent.TOOL_T YPE_UNKNOWN,
1213 event.getButtonState()); 1191 event.getButtonState(),
1192 isTouchHandleEvent);
1214 1193
1215 if (offset != null) offset.recycle(); 1194 if (offset != null) offset.recycle();
1216 return consumed; 1195 return consumed;
1217 } finally { 1196 } finally {
1218 TraceEvent.end("onTouchEvent"); 1197 TraceEvent.end("onTouchEvent");
1219 } 1198 }
1220 } 1199 }
1221 1200
1201 private static boolean isValidTouchEventActionForNative(int eventAction) {
1202 // Only these actions have any effect on gesture detection. Other
1203 // actions have no corresponding WebTouchEvent type and may confuse the
1204 // touch pipline, so we ignore them entirely.
1205 return eventAction == MotionEvent.ACTION_DOWN
1206 || eventAction == MotionEvent.ACTION_UP
1207 || eventAction == MotionEvent.ACTION_CANCEL
1208 || eventAction == MotionEvent.ACTION_MOVE
1209 || eventAction == MotionEvent.ACTION_POINTER_DOWN
1210 || eventAction == MotionEvent.ACTION_POINTER_UP;
1211 }
1212
1222 public void setIgnoreRemainingTouchEvents() { 1213 public void setIgnoreRemainingTouchEvents() {
1223 resetGestureDetection(); 1214 resetGestureDetection();
1224 } 1215 }
1225 1216
1226 public boolean isScrollInProgress() { 1217 public boolean isScrollInProgress() {
1227 return mTouchScrollInProgress || mPotentiallyActiveFlingCount > 0; 1218 return mTouchScrollInProgress || mPotentiallyActiveFlingCount > 0;
1228 } 1219 }
1229 1220
1230 @SuppressWarnings("unused") 1221 @SuppressWarnings("unused")
1231 @CalledByNative 1222 @CalledByNative
1232 private void onFlingStartEventConsumed(int vx, int vy) { 1223 private void onFlingStartEventConsumed(int vx, int vy) {
1233 mTouchScrollInProgress = false; 1224 mTouchScrollInProgress = false;
1234 mPotentiallyActiveFlingCount++; 1225 mPotentiallyActiveFlingCount++;
1235 temporarilyHideTextHandles();
1236 for (mGestureStateListenersIterator.rewind(); 1226 for (mGestureStateListenersIterator.rewind();
1237 mGestureStateListenersIterator.hasNext();) { 1227 mGestureStateListenersIterator.hasNext();) {
1238 mGestureStateListenersIterator.next().onFlingStartGesture( 1228 mGestureStateListenersIterator.next().onFlingStartGesture(
1239 vx, vy, computeVerticalScrollOffset(), computeVerticalScroll Extent()); 1229 vx, vy, computeVerticalScrollOffset(), computeVerticalScroll Extent());
1240 } 1230 }
1241 } 1231 }
1242 1232
1243 @SuppressWarnings("unused") 1233 @SuppressWarnings("unused")
1244 @CalledByNative 1234 @CalledByNative
1245 private void onFlingStartEventHadNoConsumer(int vx, int vy) { 1235 private void onFlingStartEventHadNoConsumer(int vx, int vy) {
1246 mTouchScrollInProgress = false; 1236 mTouchScrollInProgress = false;
1247 for (mGestureStateListenersIterator.rewind(); 1237 for (mGestureStateListenersIterator.rewind();
1248 mGestureStateListenersIterator.hasNext();) { 1238 mGestureStateListenersIterator.hasNext();) {
1249 mGestureStateListenersIterator.next().onUnhandledFlingStartEvent(vx, vy); 1239 mGestureStateListenersIterator.next().onUnhandledFlingStartEvent(vx, vy);
1250 } 1240 }
1251 } 1241 }
1252 1242
1253 @SuppressWarnings("unused") 1243 @SuppressWarnings("unused")
1254 @CalledByNative 1244 @CalledByNative
1255 private void onFlingCancelEventAck() { 1245 private void onFlingCancelEventAck() {
1256 updateGestureStateListener(GestureEventType.FLING_CANCEL); 1246 updateGestureStateListener(GestureEventType.FLING_CANCEL);
1257 } 1247 }
1258 1248
1259 @SuppressWarnings("unused") 1249 @SuppressWarnings("unused")
1260 @CalledByNative 1250 @CalledByNative
1261 private void onScrollBeginEventAck() { 1251 private void onScrollBeginEventAck() {
1262 mTouchScrollInProgress = true; 1252 mTouchScrollInProgress = true;
1263 temporarilyHideTextHandles(); 1253 hidePastePopup();
1264 mZoomControlsDelegate.invokeZoomPicker(); 1254 mZoomControlsDelegate.invokeZoomPicker();
1265 updateGestureStateListener(GestureEventType.SCROLL_START); 1255 updateGestureStateListener(GestureEventType.SCROLL_START);
1266 } 1256 }
1267 1257
1268 @SuppressWarnings("unused") 1258 @SuppressWarnings("unused")
1269 @CalledByNative 1259 @CalledByNative
1270 private void onScrollUpdateGestureConsumed() { 1260 private void onScrollUpdateGestureConsumed() {
1271 mZoomControlsDelegate.invokeZoomPicker(); 1261 mZoomControlsDelegate.invokeZoomPicker();
1272 for (mGestureStateListenersIterator.rewind(); 1262 for (mGestureStateListenersIterator.rewind();
1273 mGestureStateListenersIterator.hasNext();) { 1263 mGestureStateListenersIterator.hasNext();) {
1274 mGestureStateListenersIterator.next().onScrollUpdateGestureConsumed( ); 1264 mGestureStateListenersIterator.next().onScrollUpdateGestureConsumed( );
1275 } 1265 }
1276 } 1266 }
1277 1267
1278 @SuppressWarnings("unused") 1268 @SuppressWarnings("unused")
1279 @CalledByNative 1269 @CalledByNative
1280 private void onScrollEndEventAck() { 1270 private void onScrollEndEventAck() {
1281 if (!mTouchScrollInProgress) return; 1271 if (!mTouchScrollInProgress) return;
1282 mTouchScrollInProgress = false; 1272 mTouchScrollInProgress = false;
1283 updateGestureStateListener(GestureEventType.SCROLL_END); 1273 updateGestureStateListener(GestureEventType.SCROLL_END);
1284 } 1274 }
1285 1275
1286 @SuppressWarnings("unused") 1276 @SuppressWarnings("unused")
1287 @CalledByNative 1277 @CalledByNative
1288 private void onPinchBeginEventAck() { 1278 private void onPinchBeginEventAck() {
1289 temporarilyHideTextHandles();
1290 updateGestureStateListener(GestureEventType.PINCH_BEGIN); 1279 updateGestureStateListener(GestureEventType.PINCH_BEGIN);
1291 } 1280 }
1292 1281
1293 @SuppressWarnings("unused") 1282 @SuppressWarnings("unused")
1294 @CalledByNative 1283 @CalledByNative
1295 private void onPinchEndEventAck() { 1284 private void onPinchEndEventAck() {
1296 updateGestureStateListener(GestureEventType.PINCH_END); 1285 updateGestureStateListener(GestureEventType.PINCH_END);
1297 } 1286 }
1298 1287
1299 @SuppressWarnings("unused") 1288 @SuppressWarnings("unused")
1300 @CalledByNative 1289 @CalledByNative
1301 private void onSingleTapEventAck(boolean consumed, int x, int y) { 1290 private void onSingleTapEventAck(boolean consumed, int x, int y) {
1302 for (mGestureStateListenersIterator.rewind(); 1291 for (mGestureStateListenersIterator.rewind();
1303 mGestureStateListenersIterator.hasNext();) { 1292 mGestureStateListenersIterator.hasNext();) {
1304 mGestureStateListenersIterator.next().onSingleTap(consumed, x, y); 1293 mGestureStateListenersIterator.next().onSingleTap(consumed, x, y);
1305 } 1294 }
1306 } 1295 }
1307 1296
1308 @SuppressWarnings("unused")
1309 @CalledByNative
1310 private void onDoubleTapEventAck() {
1311 temporarilyHideTextHandles();
1312 }
1313
1314 /** 1297 /**
1315 * Called just prior to a tap or press gesture being forwarded to the render er. 1298 * Called just prior to a tap or press gesture being forwarded to the render er.
1316 */ 1299 */
1317 @SuppressWarnings("unused") 1300 @SuppressWarnings("unused")
1318 @CalledByNative 1301 @CalledByNative
1319 private boolean filterTapOrPressEvent(int type, int x, int y) { 1302 private boolean filterTapOrPressEvent(int type, int x, int y) {
1320 if (type == GestureEventType.LONG_PRESS && offerLongPressToEmbedder()) { 1303 if (type == GestureEventType.LONG_PRESS && offerLongPressToEmbedder()) {
1321 return true; 1304 return true;
1322 } 1305 }
1323 updateForTapOrPress(type, x, y); 1306 updateForTapOrPress(type, x, y);
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1487 * Return the ContentSettings object used to retrieve the settings for this 1470 * Return the ContentSettings object used to retrieve the settings for this
1488 * ContentViewCore. For modifications, ChromeNativePreferences is to be used . 1471 * ContentViewCore. For modifications, ChromeNativePreferences is to be used .
1489 * @return A ContentSettings object that can be used to retrieve this 1472 * @return A ContentSettings object that can be used to retrieve this
1490 * ContentViewCore's settings. 1473 * ContentViewCore's settings.
1491 */ 1474 */
1492 public ContentSettings getContentSettings() { 1475 public ContentSettings getContentSettings() {
1493 return mContentSettings; 1476 return mContentSettings;
1494 } 1477 }
1495 1478
1496 private void hidePopups() { 1479 private void hidePopups() {
1480 mUnselectAllOnActionModeDismiss = true;
1481 hideSelectActionBar();
1482 hidePastePopup();
1497 hideSelectPopup(); 1483 hideSelectPopup();
1498 hideHandles(); 1484 hideTextHandles();
1499 hideSelectActionBar();
1500 } 1485 }
1501 1486
1502 public void hideSelectActionBar() { 1487 public void hideSelectActionBar() {
1503 if (mActionMode != null) { 1488 if (mActionMode != null) {
1504 mActionMode.finish(); 1489 mActionMode.finish();
1505 mActionMode = null; 1490 mActionMode = null;
1506 } 1491 }
1507 } 1492 }
1508 1493
1509 public boolean isSelectActionBarShowing() { 1494 public boolean isSelectActionBarShowing() {
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
1940 1925
1941 if (mContainerView.isFocusable() && mContainerView.isFocusableInTouchMod e() 1926 if (mContainerView.isFocusable() && mContainerView.isFocusableInTouchMod e()
1942 && !mContainerView.isFocused()) { 1927 && !mContainerView.isFocused()) {
1943 mContainerView.requestFocus(); 1928 mContainerView.requestFocus();
1944 } 1929 }
1945 1930
1946 if (!mPopupZoomer.isShowing()) mPopupZoomer.setLastTouch(xPix, yPix); 1931 if (!mPopupZoomer.isShowing()) mPopupZoomer.setLastTouch(xPix, yPix);
1947 1932
1948 mLastTapX = (int) xPix; 1933 mLastTapX = (int) xPix;
1949 mLastTapY = (int) yPix; 1934 mLastTapY = (int) yPix;
1950
1951 if (type == GestureEventType.LONG_PRESS
1952 || type == GestureEventType.LONG_TAP) {
1953 getInsertionHandleController().allowAutomaticShowing();
1954 getSelectionHandleController().allowAutomaticShowing();
1955 } else {
1956 if (mFocusedNodeEditable) getInsertionHandleController().allowAutoma ticShowing();
1957 }
1958 } 1935 }
1959 1936
1960 /** 1937 /**
1961 * @return The x coordinate for the last point that a tap or press gesture w as initiated from. 1938 * @return The x coordinate for the last point that a tap or press gesture w as initiated from.
1962 */ 1939 */
1963 public int getLastTapX() { 1940 public int getLastTapX() {
1964 return mLastTapX; 1941 return mLastTapX;
1965 } 1942 }
1966 1943
1967 /** 1944 /**
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2010 */ 1987 */
2011 public void setDownloadDelegate(ContentViewDownloadDelegate delegate) { 1988 public void setDownloadDelegate(ContentViewDownloadDelegate delegate) {
2012 mDownloadDelegate = delegate; 1989 mDownloadDelegate = delegate;
2013 } 1990 }
2014 1991
2015 // Called by DownloadController. 1992 // Called by DownloadController.
2016 ContentViewDownloadDelegate getDownloadDelegate() { 1993 ContentViewDownloadDelegate getDownloadDelegate() {
2017 return mDownloadDelegate; 1994 return mDownloadDelegate;
2018 } 1995 }
2019 1996
2020 private SelectionHandleController getSelectionHandleController() {
2021 if (mSelectionHandleController == null) {
2022 mSelectionHandleController = new SelectionHandleController(
2023 getContainerView(), mPositionObserver) {
2024 @Override
2025 public void selectBetweenCoordinates(int x1, int y1, int x2, int y2) {
2026 if (mNativeContentViewCore != 0 && !(x1 == x2 && y1 == y2)) {
2027 nativeSelectBetweenCoordinates(mNativeContentViewCore,
2028 x1, y1 - mRenderCoordinates.getContentOffsetYPix (),
2029 x2, y2 - mRenderCoordinates.getContentOffsetYPix ());
2030 }
2031 }
2032
2033 @Override
2034 public void showHandles(int startDir, int endDir) {
2035 final boolean wasShowing = isShowing();
2036 super.showHandles(startDir, endDir);
2037 if (!wasShowing || mActionMode == null) showSelectActionBar( );
2038 }
2039
2040 };
2041
2042 mSelectionHandleController.hideAndDisallowAutomaticShowing();
2043 }
2044
2045 return mSelectionHandleController;
2046 }
2047
2048 private InsertionHandleController getInsertionHandleController() {
2049 if (mInsertionHandleController == null) {
2050 mInsertionHandleController = new InsertionHandleController(
2051 getContainerView(), mPositionObserver) {
2052 private static final int AVERAGE_LINE_HEIGHT = 14;
2053
2054 @Override
2055 public void setCursorPosition(int x, int y) {
2056 if (mNativeContentViewCore != 0) {
2057 nativeMoveCaret(mNativeContentViewCore,
2058 x, y - mRenderCoordinates.getContentOffsetYPix() );
2059 }
2060 }
2061
2062 @Override
2063 public void paste() {
2064 mImeAdapter.paste();
2065 hideHandles();
2066 }
2067
2068 @Override
2069 public int getLineHeight() {
2070 return (int) Math.ceil(
2071 mRenderCoordinates.fromLocalCssToPix(AVERAGE_LINE_HE IGHT));
2072 }
2073
2074 @Override
2075 public void showHandle() {
2076 super.showHandle();
2077 }
2078 };
2079
2080 mInsertionHandleController.hideAndDisallowAutomaticShowing();
2081 }
2082
2083 return mInsertionHandleController;
2084 }
2085
2086 @VisibleForTesting
2087 public InsertionHandleController getInsertionHandleControllerForTest() {
2088 return mInsertionHandleController;
2089 }
2090
2091 @VisibleForTesting
2092 public SelectionHandleController getSelectionHandleControllerForTest() {
2093 return mSelectionHandleController;
2094 }
2095
2096 private void updateHandleScreenPositions() {
2097 if (isSelectionHandleShowing()) {
2098 mSelectionHandleController.setStartHandlePosition(
2099 mStartHandlePoint.getXPix(), mStartHandlePoint.getYPix());
2100 mSelectionHandleController.setEndHandlePosition(
2101 mEndHandlePoint.getXPix(), mEndHandlePoint.getYPix());
2102 }
2103
2104 if (isInsertionHandleShowing()) {
2105 mInsertionHandleController.setHandlePosition(
2106 mInsertionHandlePoint.getXPix(), mInsertionHandlePoint.getYP ix());
2107 }
2108 }
2109
2110 private void hideHandles() {
2111 if (mSelectionHandleController != null) {
2112 mSelectionHandleController.hideAndDisallowAutomaticShowing();
2113 }
2114 if (mInsertionHandleController != null) {
2115 mInsertionHandleController.hideAndDisallowAutomaticShowing();
2116 }
2117 mPositionObserver.removeListener(mPositionListener);
2118 }
2119
2120 private void showSelectActionBar() { 1997 private void showSelectActionBar() {
2121 if (mActionMode != null) { 1998 if (mActionMode != null) {
2122 mActionMode.invalidate(); 1999 mActionMode.invalidate();
2123 return; 2000 return;
2124 } 2001 }
2125 2002
2126 // Start a new action mode with a SelectActionModeCallback. 2003 // Start a new action mode with a SelectActionModeCallback.
2127 SelectActionModeCallback.ActionHandler actionHandler = 2004 SelectActionModeCallback.ActionHandler actionHandler =
2128 new SelectActionModeCallback.ActionHandler() { 2005 new SelectActionModeCallback.ActionHandler() {
2129 @Override 2006 @Override
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
2196 2073
2197 @Override 2074 @Override
2198 public boolean isSelectionEditable() { 2075 public boolean isSelectionEditable() {
2199 return mFocusedNodeEditable; 2076 return mFocusedNodeEditable;
2200 } 2077 }
2201 2078
2202 @Override 2079 @Override
2203 public void onDestroyActionMode() { 2080 public void onDestroyActionMode() {
2204 mActionMode = null; 2081 mActionMode = null;
2205 if (mUnselectAllOnActionModeDismiss) { 2082 if (mUnselectAllOnActionModeDismiss) {
2206 hideHandles(); 2083 hideTextHandles();
2207 if (isSelectionEditable()) { 2084 if (isSelectionEditable()) {
2208 int selectionEnd = Selection.getSelectionEnd(mEditable); 2085 int selectionEnd = Selection.getSelectionEnd(mEditable);
2209 mInputConnection.setSelection(selectionEnd, selectionEnd ); 2086 mInputConnection.setSelection(selectionEnd, selectionEnd );
2210 } else { 2087 } else {
2211 mImeAdapter.unselect(); 2088 mImeAdapter.unselect();
2212 } 2089 }
2213 } 2090 }
2214 getContentViewClient().onContextualActionBarHidden(); 2091 getContentViewClient().onContextualActionBarHidden();
2215 } 2092 }
2216 2093
(...skipping 23 matching lines...) Expand all
2240 } 2117 }
2241 mUnselectAllOnActionModeDismiss = true; 2118 mUnselectAllOnActionModeDismiss = true;
2242 if (mActionMode == null) { 2119 if (mActionMode == null) {
2243 // There is no ActionMode, so remove the selection. 2120 // There is no ActionMode, so remove the selection.
2244 mImeAdapter.unselect(); 2121 mImeAdapter.unselect();
2245 } else { 2122 } else {
2246 getContentViewClient().onContextualActionBarShown(); 2123 getContentViewClient().onContextualActionBarShown();
2247 } 2124 }
2248 } 2125 }
2249 2126
2127 private void hidePastePopup() {
2128 if (mPastePopupMenu == null) return;
2129 mPastePopupMenu.hide();
2130 }
2131
2132 @CalledByNative
2133 private void onSelectionEvent(int eventType, float posXDip, float posYDip) {
2134 switch (eventType) {
2135 case SelectionEventType.SELECTION_SHOWN:
2136 mHasSelection = true;
2137 // TODO(cjhopman): Remove this when there is a better signal tha t long press caused
2138 // a selection. See http://crbug.com/150151.
2139 mContainerView.performHapticFeedback(HapticFeedbackConstants.LON G_PRESS);
2140 showSelectActionBar();
2141 break;
2142
2143 case SelectionEventType.SELECTION_CLEARED:
2144 mHasSelection = false;
2145 mUnselectAllOnActionModeDismiss = false;
2146 hideSelectActionBar();
2147 break;
2148
2149 case SelectionEventType.INSERTION_SHOWN:
2150 mHasInsertion = true;
2151 break;
2152
2153 case SelectionEventType.INSERTION_MOVED:
2154 // TODO(jdduke): Handle case where movement triggered by focus.
2155 hidePastePopup();
2156 break;
2157
2158 case SelectionEventType.INSERTION_TAPPED:
2159 if (getPastePopup().isShowing())
2160 mPastePopupMenu.hide();
2161 else
2162 showPastePopup((int) posXDip, (int) posYDip);
2163 break;
2164
2165 case SelectionEventType.INSERTION_CLEARED:
2166 mHasInsertion = false;
2167 hidePastePopup();
2168 break;
2169
2170 default:
2171 assert false : "Invalid selection event type.";
2172 }
2173 }
2174
2250 public boolean getUseDesktopUserAgent() { 2175 public boolean getUseDesktopUserAgent() {
2251 if (mNativeContentViewCore != 0) { 2176 if (mNativeContentViewCore != 0) {
2252 return nativeGetUseDesktopUserAgent(mNativeContentViewCore); 2177 return nativeGetUseDesktopUserAgent(mNativeContentViewCore);
2253 } 2178 }
2254 return false; 2179 return false;
2255 } 2180 }
2256 2181
2257 /** 2182 /**
2258 * Set whether or not we're using a desktop user agent for the currently loa ded page. 2183 * Set whether or not we're using a desktop user agent for the currently loa ded page.
2259 * @param override If true, use a desktop user agent. Use a mobile one othe rwise. 2184 * @param override If true, use a desktop user agent. Use a mobile one othe rwise.
2260 * @param reloadOnChange Reload the page if the UA has changed. 2185 * @param reloadOnChange Reload the page if the UA has changed.
2261 */ 2186 */
2262 public void setUseDesktopUserAgent(boolean override, boolean reloadOnChange) { 2187 public void setUseDesktopUserAgent(boolean override, boolean reloadOnChange) {
2263 if (mNativeContentViewCore != 0) { 2188 if (mNativeContentViewCore != 0) {
2264 nativeSetUseDesktopUserAgent(mNativeContentViewCore, override, reloa dOnChange); 2189 nativeSetUseDesktopUserAgent(mNativeContentViewCore, override, reloa dOnChange);
2265 } 2190 }
2266 } 2191 }
2267 2192
2268 public void clearSslPreferences() { 2193 public void clearSslPreferences() {
2269 if (mNativeContentViewCore != 0) nativeClearSslPreferences(mNativeConten tViewCore); 2194 if (mNativeContentViewCore != 0) nativeClearSslPreferences(mNativeConten tViewCore);
2270 } 2195 }
2271 2196
2272 private boolean isSelectionHandleShowing() { 2197 private void hideTextHandles() {
2273 return mSelectionHandleController != null && mSelectionHandleController. isShowing(); 2198 mHasSelection = false;
2274 } 2199 mHasInsertion = false;
2275 2200 if (mNativeContentViewCore != 0) nativeHideTextHandles(mNativeContentVie wCore);
2276 private boolean isInsertionHandleShowing() {
2277 return mInsertionHandleController != null && mInsertionHandleController. isShowing();
2278 }
2279
2280 // Makes the insertion/selection handles invisible. They will fade back in s hortly after the
2281 // last call to scheduleTextHandleFadeIn (or temporarilyHideTextHandles).
2282 private void temporarilyHideTextHandles() {
2283 if (isSelectionHandleShowing() && !mSelectionHandleController.isDragging ()) {
2284 mSelectionHandleController.setHandleVisibility(HandleView.INVISIBLE) ;
2285 }
2286 if (isInsertionHandleShowing() && !mInsertionHandleController.isDragging ()) {
2287 mInsertionHandleController.setHandleVisibility(HandleView.INVISIBLE) ;
2288 }
2289 scheduleTextHandleFadeIn();
2290 }
2291
2292 private boolean allowTextHandleFadeIn() {
2293 if (mTouchScrollInProgress) return false;
2294
2295 if (mPopupZoomer.isShowing()) return false;
2296
2297 return true;
2298 }
2299
2300 // Cancels any pending fade in and schedules a new one.
2301 private void scheduleTextHandleFadeIn() {
2302 if (!isInsertionHandleShowing() && !isSelectionHandleShowing()) return;
2303
2304 if (mDeferredHandleFadeInRunnable == null) {
2305 mDeferredHandleFadeInRunnable = new Runnable() {
2306 @Override
2307 public void run() {
2308 if (!allowTextHandleFadeIn()) {
2309 // Delay fade in until it is allowed.
2310 scheduleTextHandleFadeIn();
2311 } else {
2312 if (isSelectionHandleShowing()) {
2313 mSelectionHandleController.beginHandleFadeIn();
2314 }
2315 if (isInsertionHandleShowing()) {
2316 mInsertionHandleController.beginHandleFadeIn();
2317 }
2318 }
2319 }
2320 };
2321 }
2322
2323 mContainerView.removeCallbacks(mDeferredHandleFadeInRunnable);
2324 mContainerView.postDelayed(mDeferredHandleFadeInRunnable, TEXT_HANDLE_FA DE_IN_DELAY);
2325 } 2201 }
2326 2202
2327 /** 2203 /**
2328 * Shows the IME if the focused widget could accept text input. 2204 * Shows the IME if the focused widget could accept text input.
2329 */ 2205 */
2330 public void showImeIfNeeded() { 2206 public void showImeIfNeeded() {
2331 assert mWebContents != null; 2207 assert mWebContents != null;
2332 mWebContents.showImeIfNeeded(); 2208 mWebContents.showImeIfNeeded();
2333 } 2209 }
2334 2210
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2379 pageScaleFactor != mRenderCoordinates.getPageScaleFactor(); 2255 pageScaleFactor != mRenderCoordinates.getPageScaleFactor();
2380 final boolean scrollChanged = 2256 final boolean scrollChanged =
2381 pageScaleChanged 2257 pageScaleChanged
2382 || scrollOffsetX != mRenderCoordinates.getScrollX() 2258 || scrollOffsetX != mRenderCoordinates.getScrollX()
2383 || scrollOffsetY != mRenderCoordinates.getScrollY(); 2259 || scrollOffsetY != mRenderCoordinates.getScrollY();
2384 final boolean contentOffsetChanged = 2260 final boolean contentOffsetChanged =
2385 contentOffsetYPix != mRenderCoordinates.getContentOffsetYPix(); 2261 contentOffsetYPix != mRenderCoordinates.getContentOffsetYPix();
2386 2262
2387 final boolean needHidePopupZoomer = contentSizeChanged || scrollChanged; 2263 final boolean needHidePopupZoomer = contentSizeChanged || scrollChanged;
2388 final boolean needUpdateZoomControls = scaleLimitsChanged || scrollChang ed; 2264 final boolean needUpdateZoomControls = scaleLimitsChanged || scrollChang ed;
2389 final boolean needTemporarilyHideHandles = scrollChanged;
2390 2265
2391 if (needHidePopupZoomer) mPopupZoomer.hide(true); 2266 if (needHidePopupZoomer) mPopupZoomer.hide(true);
2392 2267
2393 if (scrollChanged) { 2268 if (scrollChanged) {
2394 mContainerViewInternals.onScrollChanged( 2269 mContainerViewInternals.onScrollChanged(
2395 (int) mRenderCoordinates.fromLocalCssToPix(scrollOffsetX), 2270 (int) mRenderCoordinates.fromLocalCssToPix(scrollOffsetX),
2396 (int) mRenderCoordinates.fromLocalCssToPix(scrollOffsetY), 2271 (int) mRenderCoordinates.fromLocalCssToPix(scrollOffsetY),
2397 (int) mRenderCoordinates.getScrollXPix(), 2272 (int) mRenderCoordinates.getScrollXPix(),
2398 (int) mRenderCoordinates.getScrollYPix()); 2273 (int) mRenderCoordinates.getScrollYPix());
2399 } 2274 }
2400 2275
2401 mRenderCoordinates.updateFrameInfo( 2276 mRenderCoordinates.updateFrameInfo(
2402 scrollOffsetX, scrollOffsetY, 2277 scrollOffsetX, scrollOffsetY,
2403 contentWidth, contentHeight, 2278 contentWidth, contentHeight,
2404 viewportWidth, viewportHeight, 2279 viewportWidth, viewportHeight,
2405 pageScaleFactor, minPageScaleFactor, maxPageScaleFactor, 2280 pageScaleFactor, minPageScaleFactor, maxPageScaleFactor,
2406 contentOffsetYPix); 2281 contentOffsetYPix);
2407 2282
2408 if (scrollChanged || contentOffsetChanged) { 2283 if (scrollChanged || contentOffsetChanged) {
2409 for (mGestureStateListenersIterator.rewind(); 2284 for (mGestureStateListenersIterator.rewind();
2410 mGestureStateListenersIterator.hasNext();) { 2285 mGestureStateListenersIterator.hasNext();) {
2411 mGestureStateListenersIterator.next().onScrollOffsetOrExtentChan ged( 2286 mGestureStateListenersIterator.next().onScrollOffsetOrExtentChan ged(
2412 computeVerticalScrollOffset(), 2287 computeVerticalScrollOffset(),
2413 computeVerticalScrollExtent()); 2288 computeVerticalScrollExtent());
2414 } 2289 }
2415 } 2290 }
2416 2291
2417 if (needTemporarilyHideHandles) temporarilyHideTextHandles();
2418 if (needUpdateZoomControls) mZoomControlsDelegate.updateZoomControls(); 2292 if (needUpdateZoomControls) mZoomControlsDelegate.updateZoomControls();
2419 if (contentOffsetChanged) updateHandleScreenPositions();
2420 2293
2421 // Update offsets for fullscreen. 2294 // Update offsets for fullscreen.
2422 final float controlsOffsetPix = controlsOffsetYCss * deviceScale; 2295 final float controlsOffsetPix = controlsOffsetYCss * deviceScale;
2423 final float overdrawBottomHeightPix = overdrawBottomHeightCss * deviceSc ale; 2296 final float overdrawBottomHeightPix = overdrawBottomHeightCss * deviceSc ale;
2424 getContentViewClient().onOffsetsForFullscreenChanged( 2297 getContentViewClient().onOffsetsForFullscreenChanged(
2425 controlsOffsetPix, contentOffsetYPix, overdrawBottomHeightPix); 2298 controlsOffsetPix, contentOffsetYPix, overdrawBottomHeightPix);
2426 2299
2427 if (mBrowserAccessibilityManager != null) { 2300 if (mBrowserAccessibilityManager != null) {
2428 mBrowserAccessibilityManager.notifyFrameInfoInitialized(); 2301 mBrowserAccessibilityManager.notifyFrameInfoInitialized();
2429 } 2302 }
2430 } 2303 }
2431 2304
2432 @CalledByNative 2305 @CalledByNative
2433 private void updateImeAdapter(long nativeImeAdapterAndroid, int textInputTyp e, 2306 private void updateImeAdapter(long nativeImeAdapterAndroid, int textInputTyp e,
2434 String text, int selectionStart, int selectionEnd, 2307 String text, int selectionStart, int selectionEnd,
2435 int compositionStart, int compositionEnd, boolean showImeIfNeeded, 2308 int compositionStart, int compositionEnd, boolean showImeIfNeeded,
2436 boolean isNonImeChange) { 2309 boolean isNonImeChange) {
2437 TraceEvent.begin(); 2310 TraceEvent.begin();
2438 mFocusedNodeEditable = (textInputType != ImeAdapter.getTextInputTypeNone ()); 2311 mFocusedNodeEditable = (textInputType != ImeAdapter.getTextInputTypeNone ());
2312 if (!mFocusedNodeEditable) hidePastePopup();
2439 2313
2440 mImeAdapter.updateKeyboardVisibility( 2314 mImeAdapter.updateKeyboardVisibility(
2441 nativeImeAdapterAndroid, textInputType, showImeIfNeeded); 2315 nativeImeAdapterAndroid, textInputType, showImeIfNeeded);
2442 2316
2443 if (mInputConnection != null) { 2317 if (mInputConnection != null) {
2444 mInputConnection.updateState(text, selectionStart, selectionEnd, com positionStart, 2318 mInputConnection.updateState(text, selectionStart, selectionEnd, com positionStart,
2445 compositionEnd, isNonImeChange); 2319 compositionEnd, isNonImeChange);
2446 } 2320 }
2447 2321
2448 if (mActionMode != null) mActionMode.invalidate(); 2322 if (mActionMode != null) mActionMode.invalidate();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2498 */ 2372 */
2499 public SelectPopup getSelectPopupForTest() { 2373 public SelectPopup getSelectPopupForTest() {
2500 return mSelectPopup; 2374 return mSelectPopup;
2501 } 2375 }
2502 2376
2503 @SuppressWarnings("unused") 2377 @SuppressWarnings("unused")
2504 @CalledByNative 2378 @CalledByNative
2505 private void showDisambiguationPopup(Rect targetRect, Bitmap zoomedBitmap) { 2379 private void showDisambiguationPopup(Rect targetRect, Bitmap zoomedBitmap) {
2506 mPopupZoomer.setBitmap(zoomedBitmap); 2380 mPopupZoomer.setBitmap(zoomedBitmap);
2507 mPopupZoomer.show(targetRect); 2381 mPopupZoomer.show(targetRect);
2508 temporarilyHideTextHandles();
2509 } 2382 }
2510 2383
2511 @SuppressWarnings("unused") 2384 @SuppressWarnings("unused")
2512 @CalledByNative 2385 @CalledByNative
2513 private TouchEventSynthesizer createTouchEventSynthesizer() { 2386 private TouchEventSynthesizer createTouchEventSynthesizer() {
2514 return new TouchEventSynthesizer(this); 2387 return new TouchEventSynthesizer(this);
2515 } 2388 }
2516 2389
2517 @SuppressWarnings("unused") 2390 @SuppressWarnings("unused")
2518 @CalledByNative 2391 @CalledByNative
2392 private PopupTouchHandleDrawable createPopupTouchHandleDrawable() {
2393 if (mTouchHandleDelegate == null) {
2394 mTouchHandleDelegate = new PopupTouchHandleDrawableDelegate() {
2395 public View getParent() {
2396 return getContainerView();
2397 }
2398
2399 public PositionObserver getParentPositionObserver() {
2400 return mPositionObserver;
2401 }
2402
2403 public boolean onTouchHandleEvent(MotionEvent event) {
2404 final boolean isTouchHandleEvent = true;
2405 return onTouchEventImpl(event, isTouchHandleEvent);
2406 }
2407 };
2408 }
2409 return new PopupTouchHandleDrawable(mTouchHandleDelegate);
2410 }
2411
2412 @SuppressWarnings("unused")
2413 @CalledByNative
2519 private void onSelectionChanged(String text) { 2414 private void onSelectionChanged(String text) {
2520 mLastSelectedText = text; 2415 mLastSelectedText = text;
2521 getContentViewClient().onSelectionChanged(text); 2416 getContentViewClient().onSelectionChanged(text);
2522 } 2417 }
2523 2418
2524 @SuppressWarnings("unused") 2419 @SuppressWarnings("unused")
2525 @CalledByNative
2526 private void showSelectionHandlesAutomatically() {
2527 getSelectionHandleController().allowAutomaticShowing();
2528 }
2529
2530 @SuppressWarnings("unused")
2531 @CalledByNative
2532 private void onSelectionBoundsChanged(Rect anchorRectDip, int anchorDir, Rec t focusRectDip,
2533 int focusDir, boolean isAnchorFirst) {
2534 // All coordinates are in DIP.
2535 int x1 = anchorRectDip.left;
2536 int y1 = anchorRectDip.bottom;
2537 int x2 = focusRectDip.left;
2538 int y2 = focusRectDip.bottom;
2539
2540 if (x1 != x2 || y1 != y2 ||
2541 (mSelectionHandleController != null && mSelectionHandleControlle r.isDragging())) {
2542 if (mInsertionHandleController != null) {
2543 mInsertionHandleController.hide();
2544 }
2545 if (isAnchorFirst) {
2546 mStartHandlePoint.setLocalDip(x1, y1);
2547 mEndHandlePoint.setLocalDip(x2, y2);
2548 } else {
2549 mStartHandlePoint.setLocalDip(x2, y2);
2550 mEndHandlePoint.setLocalDip(x1, y1);
2551 }
2552
2553 boolean wereSelectionHandlesShowing = getSelectionHandleController() .isShowing();
2554
2555 getSelectionHandleController().onSelectionChanged(anchorDir, focusDi r);
2556 updateHandleScreenPositions();
2557 mHasSelection = true;
2558
2559 if (!wereSelectionHandlesShowing && getSelectionHandleController().i sShowing()) {
2560 // TODO(cjhopman): Remove this when there is a better signal tha t long press caused
2561 // a selection. See http://crbug.com/150151.
2562 mContainerView.performHapticFeedback(HapticFeedbackConstants.LON G_PRESS);
2563 }
2564
2565 } else {
2566 mUnselectAllOnActionModeDismiss = false;
2567 hideSelectActionBar();
2568 if (x1 != 0 && y1 != 0 && mFocusedNodeEditable) {
2569 // Selection is a caret, and a text field is focused.
2570 if (mSelectionHandleController != null) {
2571 mSelectionHandleController.hide();
2572 }
2573 mInsertionHandlePoint.setLocalDip(x1, y1);
2574
2575 getInsertionHandleController().onCursorPositionChanged();
2576 updateHandleScreenPositions();
2577 if (mInputMethodManagerWrapper.isWatchingCursor(mContainerView)) {
2578 final int xPix = (int) mInsertionHandlePoint.getXPix();
2579 final int yPix = (int) mInsertionHandlePoint.getYPix();
2580 mInputMethodManagerWrapper.updateCursor(
2581 mContainerView, xPix, yPix, xPix, yPix);
2582 }
2583 } else {
2584 // Deselection
2585 if (mSelectionHandleController != null) {
2586 mSelectionHandleController.hideAndDisallowAutomaticShowing() ;
2587 }
2588 if (mInsertionHandleController != null) {
2589 mInsertionHandleController.hideAndDisallowAutomaticShowing() ;
2590 }
2591 }
2592 mHasSelection = false;
2593 }
2594 if (isSelectionHandleShowing() || isInsertionHandleShowing()) {
2595 mPositionObserver.addListener(mPositionListener);
2596 }
2597 }
2598
2599 @SuppressWarnings("unused")
2600 @CalledByNative 2420 @CalledByNative
2601 private static void onEvaluateJavaScriptResult( 2421 private static void onEvaluateJavaScriptResult(
2602 String jsonResult, JavaScriptCallback callback) { 2422 String jsonResult, JavaScriptCallback callback) {
2603 callback.handleJavaScriptResult(jsonResult); 2423 callback.handleJavaScriptResult(jsonResult);
2604 } 2424 }
2605 2425
2606 @SuppressWarnings("unused") 2426 @SuppressWarnings("unused")
2607 @CalledByNative 2427 @CalledByNative
2608 private void showPastePopup(int xDip, int yDip) { 2428 private void showPastePopup(int xDip, int yDip) {
2609 mInsertionHandlePoint.setLocalDip(xDip, yDip); 2429 final float contentOffsetYPix = mRenderCoordinates.getContentOffsetYPix( );
2610 getInsertionHandleController().showHandle(); 2430 getPastePopup().showAt(
2611 updateHandleScreenPositions(); 2431 (int) mRenderCoordinates.fromDipToPix(xDip),
2612 getInsertionHandleController().showHandleWithPastePopup(); 2432 (int) (mRenderCoordinates.fromDipToPix(yDip) + contentOffsetYPix));
2433 }
2434
2435 private PastePopupMenu getPastePopup() {
2436 if (mPastePopupMenu == null) {
2437 mPastePopupMenu = new PastePopupMenu(getContainerView(),
2438 new PastePopupMenuDelegate() {
2439 public void paste() {
2440 mImeAdapter.paste();
2441 hideTextHandles();
2442 }
2443 public boolean canPaste() {
2444 if (!mFocusedNodeEditable) return false;
2445 return ((ClipboardManager) mContext.getSystemService(
2446 Context.CLIPBOARD_SERVICE)).hasPrimaryClip();
2447 }
2448 });
2449 }
2450 return mPastePopupMenu;
2613 } 2451 }
2614 2452
2615 @SuppressWarnings("unused") 2453 @SuppressWarnings("unused")
2616 @CalledByNative 2454 @CalledByNative
2617 private void onRenderProcessChange() { 2455 private void onRenderProcessChange() {
2618 attachImeAdapter(); 2456 attachImeAdapter();
2619 } 2457 }
2620 2458
2621 /** 2459 /**
2622 * Attaches the native ImeAdapter object to the java ImeAdapter to allow com munication via JNI. 2460 * Attaches the native ImeAdapter object to the java ImeAdapter to allow com munication via JNI.
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after
3287 long nativeContentViewCoreImpl, int orientation); 3125 long nativeContentViewCoreImpl, int orientation);
3288 3126
3289 // All touch events (including flings, scrolls etc) accept coordinates in ph ysical pixels. 3127 // All touch events (including flings, scrolls etc) accept coordinates in ph ysical pixels.
3290 private native boolean nativeOnTouchEvent( 3128 private native boolean nativeOnTouchEvent(
3291 long nativeContentViewCoreImpl, MotionEvent event, 3129 long nativeContentViewCoreImpl, MotionEvent event,
3292 long timeMs, int action, int pointerCount, int historySize, int acti onIndex, 3130 long timeMs, int action, int pointerCount, int historySize, int acti onIndex,
3293 float x0, float y0, float x1, float y1, 3131 float x0, float y0, float x1, float y1,
3294 int pointerId0, int pointerId1, 3132 int pointerId0, int pointerId1,
3295 float touchMajor0, float touchMajor1, 3133 float touchMajor0, float touchMajor1,
3296 float rawX, float rawY, 3134 float rawX, float rawY,
3297 int androidToolType0, int androidToolType1, int androidButtonState); 3135 int androidToolType0, int androidToolType1, int androidButtonState,
3136 boolean isTouchHandleEvent);
3298 3137
3299 private native int nativeSendMouseMoveEvent( 3138 private native int nativeSendMouseMoveEvent(
3300 long nativeContentViewCoreImpl, long timeMs, float x, float y); 3139 long nativeContentViewCoreImpl, long timeMs, float x, float y);
3301 3140
3302 private native int nativeSendMouseWheelEvent( 3141 private native int nativeSendMouseWheelEvent(
3303 long nativeContentViewCoreImpl, long timeMs, float x, float y, float verticalAxis); 3142 long nativeContentViewCoreImpl, long timeMs, float x, float y, float verticalAxis);
3304 3143
3305 private native void nativeScrollBegin( 3144 private native void nativeScrollBegin(
3306 long nativeContentViewCoreImpl, long timeMs, float x, float y, float hintX, 3145 long nativeContentViewCoreImpl, long timeMs, float x, float y, float hintX,
3307 float hintY); 3146 float hintY);
(...skipping 24 matching lines...) Expand all
3332 private native void nativePinchEnd(long nativeContentViewCoreImpl, long time Ms); 3171 private native void nativePinchEnd(long nativeContentViewCoreImpl, long time Ms);
3333 3172
3334 private native void nativePinchBy(long nativeContentViewCoreImpl, long timeM s, 3173 private native void nativePinchBy(long nativeContentViewCoreImpl, long timeM s,
3335 float anchorX, float anchorY, float deltaScale); 3174 float anchorX, float anchorY, float deltaScale);
3336 3175
3337 private native void nativeSelectBetweenCoordinates( 3176 private native void nativeSelectBetweenCoordinates(
3338 long nativeContentViewCoreImpl, float x1, float y1, float x2, float y2); 3177 long nativeContentViewCoreImpl, float x1, float y1, float x2, float y2);
3339 3178
3340 private native void nativeMoveCaret(long nativeContentViewCoreImpl, float x, float y); 3179 private native void nativeMoveCaret(long nativeContentViewCoreImpl, float x, float y);
3341 3180
3181 private native void nativeHideTextHandles(long nativeContentViewCoreImpl);
3182
3342 private native void nativeResetGestureDetection(long nativeContentViewCoreIm pl); 3183 private native void nativeResetGestureDetection(long nativeContentViewCoreIm pl);
3343 private native void nativeSetDoubleTapSupportEnabled( 3184 private native void nativeSetDoubleTapSupportEnabled(
3344 long nativeContentViewCoreImpl, boolean enabled); 3185 long nativeContentViewCoreImpl, boolean enabled);
3345 private native void nativeSetMultiTouchZoomSupportEnabled( 3186 private native void nativeSetMultiTouchZoomSupportEnabled(
3346 long nativeContentViewCoreImpl, boolean enabled); 3187 long nativeContentViewCoreImpl, boolean enabled);
3347 3188
3348 private native void nativeSelectPopupMenuItems(long nativeContentViewCoreImp l, int[] indices); 3189 private native void nativeSelectPopupMenuItems(long nativeContentViewCoreImp l, int[] indices);
3349 3190
3350 private native void nativeClearHistory(long nativeContentViewCoreImpl); 3191 private native void nativeClearHistory(long nativeContentViewCoreImpl);
3351 3192
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3387 3228
3388 private native void nativeExtractSmartClipData(long nativeContentViewCoreImp l, 3229 private native void nativeExtractSmartClipData(long nativeContentViewCoreImp l,
3389 int x, int y, int w, int h); 3230 int x, int y, int w, int h);
3390 private native void nativeSetBackgroundOpaque(long nativeContentViewCoreImpl , boolean opaque); 3231 private native void nativeSetBackgroundOpaque(long nativeContentViewCoreImpl , boolean opaque);
3391 3232
3392 private native void nativeResumeResponseDeferredAtStart( 3233 private native void nativeResumeResponseDeferredAtStart(
3393 long nativeContentViewCoreImpl); 3234 long nativeContentViewCoreImpl);
3394 private native void nativeSetHasPendingNavigationTransitionForTesting( 3235 private native void nativeSetHasPendingNavigationTransitionForTesting(
3395 long nativeContentViewCoreImpl); 3236 long nativeContentViewCoreImpl);
3396 } 3237 }
OLDNEW
« no previous file with comments | « content/content_tests.gypi ('k') | content/public/android/java/src/org/chromium/content/browser/input/CursorController.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698