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

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: Clean up paste popup interaction 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.PackageManager; 14 import android.content.pm.PackageManager;
14 import android.content.res.Configuration; 15 import android.content.res.Configuration;
15 import android.database.ContentObserver; 16 import android.database.ContentObserver;
16 import android.graphics.Bitmap; 17 import android.graphics.Bitmap;
17 import android.graphics.Canvas; 18 import android.graphics.Canvas;
18 import android.graphics.Color; 19 import android.graphics.Color;
19 import android.graphics.Rect; 20 import android.graphics.Rect;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 import org.chromium.base.JNINamespace; 55 import org.chromium.base.JNINamespace;
55 import org.chromium.base.ObserverList; 56 import org.chromium.base.ObserverList;
56 import org.chromium.base.ObserverList.RewindableIterator; 57 import org.chromium.base.ObserverList.RewindableIterator;
57 import org.chromium.base.TraceEvent; 58 import org.chromium.base.TraceEvent;
58 import org.chromium.content.R; 59 import org.chromium.content.R;
59 import org.chromium.content.browser.ScreenOrientationListener.ScreenOrientationO bserver; 60 import org.chromium.content.browser.ScreenOrientationListener.ScreenOrientationO bserver;
60 import org.chromium.content.browser.accessibility.AccessibilityInjector; 61 import org.chromium.content.browser.accessibility.AccessibilityInjector;
61 import org.chromium.content.browser.accessibility.BrowserAccessibilityManager; 62 import org.chromium.content.browser.accessibility.BrowserAccessibilityManager;
62 import org.chromium.content.browser.input.AdapterInputConnection; 63 import org.chromium.content.browser.input.AdapterInputConnection;
63 import org.chromium.content.browser.input.GamepadList; 64 import org.chromium.content.browser.input.GamepadList;
64 import org.chromium.content.browser.input.HandleView;
65 import org.chromium.content.browser.input.ImeAdapter; 65 import org.chromium.content.browser.input.ImeAdapter;
66 import org.chromium.content.browser.input.ImeAdapter.AdapterInputConnectionFacto ry; 66 import org.chromium.content.browser.input.ImeAdapter.AdapterInputConnectionFacto ry;
67 import org.chromium.content.browser.input.InputMethodManagerWrapper; 67 import org.chromium.content.browser.input.InputMethodManagerWrapper;
68 import org.chromium.content.browser.input.InsertionHandleController; 68 import org.chromium.content.browser.input.PastePopupMenu;
69 import org.chromium.content.browser.input.PastePopupMenu.PastePopupMenuDelegate;
70 import org.chromium.content.browser.input.PopupTouchHandleDrawable;
71 import org.chromium.content.browser.input.PopupTouchHandleDrawable.PopupTouchHan dleDrawableDelegate;
69 import org.chromium.content.browser.input.SelectPopup; 72 import org.chromium.content.browser.input.SelectPopup;
70 import org.chromium.content.browser.input.SelectPopupDialog; 73 import org.chromium.content.browser.input.SelectPopupDialog;
71 import org.chromium.content.browser.input.SelectPopupDropdown; 74 import org.chromium.content.browser.input.SelectPopupDropdown;
72 import org.chromium.content.browser.input.SelectPopupItem; 75 import org.chromium.content.browser.input.SelectPopupItem;
73 import org.chromium.content.browser.input.SelectionHandleController; 76 import org.chromium.content.browser.input.SelectionEventType;
74 import org.chromium.content.common.ContentSwitches; 77 import org.chromium.content.common.ContentSwitches;
75 import org.chromium.content_public.browser.GestureStateListener; 78 import org.chromium.content_public.browser.GestureStateListener;
76 import org.chromium.content_public.browser.WebContents; 79 import org.chromium.content_public.browser.WebContents;
77 import org.chromium.ui.base.DeviceFormFactor; 80 import org.chromium.ui.base.DeviceFormFactor;
78 import org.chromium.ui.base.ViewAndroid; 81 import org.chromium.ui.base.ViewAndroid;
79 import org.chromium.ui.base.ViewAndroidDelegate; 82 import org.chromium.ui.base.ViewAndroidDelegate;
80 import org.chromium.ui.base.WindowAndroid; 83 import org.chromium.ui.base.WindowAndroid;
81 import org.chromium.ui.gfx.DeviceDisplayInfo; 84 import org.chromium.ui.gfx.DeviceDisplayInfo;
82 85
83 import java.lang.annotation.Annotation; 86 import java.lang.annotation.Annotation;
(...skipping 16 matching lines...) Expand all
100 private static final String TAG = "ContentViewCore"; 103 private static final String TAG = "ContentViewCore";
101 104
102 // Used to avoid enabling zooming in / out if resulting zooming will 105 // Used to avoid enabling zooming in / out if resulting zooming will
103 // produce little visible difference. 106 // produce little visible difference.
104 private static final float ZOOM_CONTROLS_EPSILON = 0.007f; 107 private static final float ZOOM_CONTROLS_EPSILON = 0.007f;
105 108
106 // Used to represent gestures for long press and long tap. 109 // Used to represent gestures for long press and long tap.
107 private static final int IS_LONG_PRESS = 1; 110 private static final int IS_LONG_PRESS = 1;
108 private static final int IS_LONG_TAP = 2; 111 private static final int IS_LONG_TAP = 2;
109 112
110 // Length of the delay (in ms) before fading in handles after the last page movement.
111 private static final int TEXT_HANDLE_FADE_IN_DELAY = 300;
112
113 // If the embedder adds a JavaScript interface object that contains an indir ect reference to 113 // If the embedder adds a JavaScript interface object that contains an indir ect reference to
114 // the ContentViewCore, then storing a strong ref to the interface object on the native 114 // the ContentViewCore, then storing a strong ref to the interface object on the native
115 // side would prevent garbage collection of the ContentViewCore (as that str ong ref would 115 // side would prevent garbage collection of the ContentViewCore (as that str ong ref would
116 // create a new GC root). 116 // create a new GC root).
117 // For that reason, we store only a weak reference to the interface object o n the 117 // For that reason, we store only a weak reference to the interface object o n the
118 // native side. However we still need a strong reference on the Java side to 118 // native side. However we still need a strong reference on the Java side to
119 // prevent garbage collection if the embedder doesn't maintain their own ref to the 119 // prevent garbage collection if the embedder doesn't maintain their own ref to the
120 // interface object - the Java side ref won't create a new GC root. 120 // interface object - the Java side ref won't create a new GC root.
121 // This map stores those refernces. We put into the map on addJavaScriptInte rface() 121 // This map stores those refernces. We put into the map on addJavaScriptInte rface()
122 // and remove from it in removeJavaScriptInterface(). 122 // and remove from it in removeJavaScriptInterface().
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 private SelectPopup mSelectPopup; 252 private SelectPopup mSelectPopup;
253 253
254 private Runnable mFakeMouseMoveRunnable = null; 254 private Runnable mFakeMouseMoveRunnable = null;
255 255
256 // Only valid when focused on a text / password field. 256 // Only valid when focused on a text / password field.
257 private ImeAdapter mImeAdapter; 257 private ImeAdapter mImeAdapter;
258 private ImeAdapter.AdapterInputConnectionFactory mAdapterInputConnectionFact ory; 258 private ImeAdapter.AdapterInputConnectionFactory mAdapterInputConnectionFact ory;
259 private AdapterInputConnection mInputConnection; 259 private AdapterInputConnection mInputConnection;
260 private InputMethodManagerWrapper mInputMethodManagerWrapper; 260 private InputMethodManagerWrapper mInputMethodManagerWrapper;
261 261
262 private SelectionHandleController mSelectionHandleController; 262 // Lazily created paste popup menu, triggered either via long press in an
263 private InsertionHandleController mInsertionHandleController; 263 // editable region or from tapping the insertion handle.
264 private PastePopupMenu mPastePopupMenu;
265 private boolean mAllowAutomaticPastePopupShowing;
264 266
265 private Runnable mDeferredHandleFadeInRunnable; 267 private PopupTouchHandleDrawableDelegate mTouchHandleDelegate;
266 268
267 private PositionObserver mPositionObserver; 269 private PositionObserver mPositionObserver;
268 private PositionObserver.Listener mPositionListener;
269 270
270 // Size of the viewport in physical pixels as set from onSizeChanged. 271 // Size of the viewport in physical pixels as set from onSizeChanged.
271 private int mViewportWidthPix; 272 private int mViewportWidthPix;
272 private int mViewportHeightPix; 273 private int mViewportHeightPix;
273 private int mPhysicalBackingWidthPix; 274 private int mPhysicalBackingWidthPix;
274 private int mPhysicalBackingHeightPix; 275 private int mPhysicalBackingHeightPix;
275 private int mOverdrawBottomHeightPix; 276 private int mOverdrawBottomHeightPix;
276 private int mViewportSizeOffsetWidthPix; 277 private int mViewportSizeOffsetWidthPix;
277 private int mViewportSizeOffsetHeightPix; 278 private int mViewportSizeOffsetHeightPix;
278 279
279 // Cached copy of all positions and scales as reported by the renderer. 280 // Cached copy of all positions and scales as reported by the renderer.
280 private final RenderCoordinates mRenderCoordinates; 281 private final RenderCoordinates mRenderCoordinates;
281 282
282 private final RenderCoordinates.NormalizedPoint mStartHandlePoint;
283 private final RenderCoordinates.NormalizedPoint mEndHandlePoint;
284 private final RenderCoordinates.NormalizedPoint mInsertionHandlePoint;
285
286 // Tracks whether a selection is currently active. When applied to selected text, indicates 283 // Tracks whether a selection is currently active. When applied to selected text, indicates
287 // whether the last selected text is still highlighted. 284 // whether the last selected text is still highlighted.
288 private boolean mHasSelection; 285 private boolean mHasSelection;
286 private boolean mHasInsertion;
289 private String mLastSelectedText; 287 private String mLastSelectedText;
290 private boolean mSelectionEditable; 288 private boolean mSelectionEditable;
291 private ActionMode mActionMode; 289 private ActionMode mActionMode;
292 private boolean mUnselectAllOnActionModeDismiss; 290 private boolean mUnselectAllOnActionModeDismiss;
293 291
294 // Delegate that will handle GET downloads, and be notified of completion of POST downloads. 292 // Delegate that will handle GET downloads, and be notified of completion of POST downloads.
295 private ContentViewDownloadDelegate mDownloadDelegate; 293 private ContentViewDownloadDelegate mDownloadDelegate;
296 294
297 // The AccessibilityInjector that handles loading Accessibility scripts into the web page. 295 // The AccessibilityInjector that handles loading Accessibility scripts into the web page.
298 private AccessibilityInjector mAccessibilityInjector; 296 private AccessibilityInjector mAccessibilityInjector;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 mInputMethodManagerWrapper = new InputMethodManagerWrapper(mContext); 370 mInputMethodManagerWrapper = new InputMethodManagerWrapper(mContext);
373 371
374 mRenderCoordinates = new RenderCoordinates(); 372 mRenderCoordinates = new RenderCoordinates();
375 float deviceScaleFactor = getContext().getResources().getDisplayMetrics( ).density; 373 float deviceScaleFactor = getContext().getResources().getDisplayMetrics( ).density;
376 String forceScaleFactor = CommandLine.getInstance().getSwitchValue( 374 String forceScaleFactor = CommandLine.getInstance().getSwitchValue(
377 ContentSwitches.FORCE_DEVICE_SCALE_FACTOR); 375 ContentSwitches.FORCE_DEVICE_SCALE_FACTOR);
378 if (forceScaleFactor != null) { 376 if (forceScaleFactor != null) {
379 deviceScaleFactor = Float.valueOf(forceScaleFactor); 377 deviceScaleFactor = Float.valueOf(forceScaleFactor);
380 } 378 }
381 mRenderCoordinates.setDeviceScaleFactor(deviceScaleFactor); 379 mRenderCoordinates.setDeviceScaleFactor(deviceScaleFactor);
382 mStartHandlePoint = mRenderCoordinates.createNormalizedPoint();
383 mEndHandlePoint = mRenderCoordinates.createNormalizedPoint();
384 mInsertionHandlePoint = mRenderCoordinates.createNormalizedPoint();
385 mAccessibilityManager = (AccessibilityManager) 380 mAccessibilityManager = (AccessibilityManager)
386 getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); 381 getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
387 mGestureStateListeners = new ObserverList<GestureStateListener>(); 382 mGestureStateListeners = new ObserverList<GestureStateListener>();
388 mGestureStateListenersIterator = mGestureStateListeners.rewindableIterat or(); 383 mGestureStateListenersIterator = mGestureStateListeners.rewindableIterat or();
389 384
390 mEditable = Editable.Factory.getInstance().newEditable(""); 385 mEditable = Editable.Factory.getInstance().newEditable("");
391 Selection.setSelection(mEditable, 0); 386 Selection.setSelection(mEditable, 0);
392 } 387 }
393 388
394 /** 389 /**
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 return mInputConnection; 527 return mInputConnection;
533 } 528 }
534 529
535 private ImeAdapter createImeAdapter(Context context) { 530 private ImeAdapter createImeAdapter(Context context) {
536 return new ImeAdapter(mInputMethodManagerWrapper, 531 return new ImeAdapter(mInputMethodManagerWrapper,
537 new ImeAdapter.ImeAdapterDelegate() { 532 new ImeAdapter.ImeAdapterDelegate() {
538 @Override 533 @Override
539 public void onImeEvent(boolean isFinish) { 534 public void onImeEvent(boolean isFinish) {
540 getContentViewClient().onImeEvent(); 535 getContentViewClient().onImeEvent();
541 if (!isFinish) { 536 if (!isFinish) {
542 hideHandles(); 537 hideTextHandles();
543 } 538 }
544 } 539 }
545 540
546 @Override 541 @Override
547 public void onDismissInput() { 542 public void onDismissInput() {
548 getContentViewClient().onImeStateChangeRequested(false); 543 getContentViewClient().onImeStateChangeRequested(false);
549 } 544 }
550 545
551 @Override 546 @Override
552 public View getAttachedView() { 547 public View getAttachedView() {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 // is a vital component of the ContentViewCore, so embedders must exercise c aution in what 590 // is a vital component of the ContentViewCore, so embedders must exercise c aution in what
596 // they do with the ContentViewCore before calling initialize(). 591 // they do with the ContentViewCore before calling initialize().
597 // We supply the nativeWebContents pointer here rather than in the construct or to allow us 592 // We supply the nativeWebContents pointer here rather than in the construct or to allow us
598 // to set the private browsing mode at a later point for the WebView impleme ntation. 593 // to set the private browsing mode at a later point for the WebView impleme ntation.
599 // Note that the caller remains the owner of the nativeWebContents and is re sponsible for 594 // Note that the caller remains the owner of the nativeWebContents and is re sponsible for
600 // deleting it after destroying the ContentViewCore. 595 // deleting it after destroying the ContentViewCore.
601 public void initialize(ViewGroup containerView, InternalAccessDelegate inter nalDispatcher, 596 public void initialize(ViewGroup containerView, InternalAccessDelegate inter nalDispatcher,
602 long nativeWebContents, WindowAndroid windowAndroid) { 597 long nativeWebContents, WindowAndroid windowAndroid) {
603 setContainerView(containerView); 598 setContainerView(containerView);
604 599
605 mPositionListener = new PositionObserver.Listener() {
606 @Override
607 public void onPositionChanged(int x, int y) {
608 if (isSelectionHandleShowing() || isInsertionHandleShowing()) {
609 temporarilyHideTextHandles();
610 }
611 }
612 };
613
614 long windowNativePointer = windowAndroid != null ? windowAndroid.getNati vePointer() : 0; 600 long windowNativePointer = windowAndroid != null ? windowAndroid.getNati vePointer() : 0;
615 601
616 long viewAndroidNativePointer = 0; 602 long viewAndroidNativePointer = 0;
617 if (windowNativePointer != 0) { 603 if (windowNativePointer != 0) {
618 mViewAndroid = new ViewAndroid(windowAndroid, getViewAndroidDelegate ()); 604 mViewAndroid = new ViewAndroid(windowAndroid, getViewAndroidDelegate ());
619 viewAndroidNativePointer = mViewAndroid.getNativePointer(); 605 viewAndroidNativePointer = mViewAndroid.getNativePointer();
620 } 606 }
621 607
622 mZoomControlsDelegate = new ZoomControlsDelegate() { 608 mZoomControlsDelegate = new ZoomControlsDelegate() {
623 @Override 609 @Override
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 * <li>Disconnecting the old container view from this ContentViewCore</l i> 661 * <li>Disconnecting the old container view from this ContentViewCore</l i>
676 * <li>Updating the InternalAccessDelegate</li> 662 * <li>Updating the InternalAccessDelegate</li>
677 * <li>Reconciling the state of this ContentViewCore with the new contai ner view</li> 663 * <li>Reconciling the state of this ContentViewCore with the new contai ner view</li>
678 * <li>Tearing down and recreating the native GL rendering where appropr iate</li> 664 * <li>Tearing down and recreating the native GL rendering where appropr iate</li>
679 * <li>etc.</li> 665 * <li>etc.</li>
680 * </ul> 666 * </ul>
681 */ 667 */
682 public void setContainerView(ViewGroup containerView) { 668 public void setContainerView(ViewGroup containerView) {
683 TraceEvent.begin(); 669 TraceEvent.begin();
684 if (mContainerView != null) { 670 if (mContainerView != null) {
685 mPositionObserver.removeListener(mPositionListener); 671 mPastePopupMenu = null;
686 mSelectionHandleController = null;
687 mInsertionHandleController = null;
688 mInputConnection = null; 672 mInputConnection = null;
689 } 673 }
690 674
691 mContainerView = containerView; 675 mContainerView = containerView;
692 mPositionObserver = new ViewPositionObserver(mContainerView); 676 mPositionObserver = new ViewPositionObserver(mContainerView);
693 String contentDescription = "Web View"; 677 String contentDescription = "Web View";
694 if (R.string.accessibility_content_view == 0) { 678 if (R.string.accessibility_content_view == 0) {
695 Log.w(TAG, "Setting contentDescription to 'Web View' as no value was specified."); 679 Log.w(TAG, "Setting contentDescription to 'Web View' as no value was specified.");
696 } else { 680 } else {
697 contentDescription = mContext.getResources().getString( 681 contentDescription = mContext.getResources().getString(
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
1118 1102
1119 /** 1103 /**
1120 * @see View#onTouchEvent(MotionEvent) 1104 * @see View#onTouchEvent(MotionEvent)
1121 */ 1105 */
1122 public boolean onTouchEvent(MotionEvent event) { 1106 public boolean onTouchEvent(MotionEvent event) {
1123 TraceEvent.begin("onTouchEvent"); 1107 TraceEvent.begin("onTouchEvent");
1124 try { 1108 try {
1125 cancelRequestToScrollFocusedEditableNodeIntoView(); 1109 cancelRequestToScrollFocusedEditableNodeIntoView();
1126 1110
1127 final int eventAction = event.getActionMasked(); 1111 final int eventAction = event.getActionMasked();
1128 1112 if (!isValidTouchEventActionForNative(eventAction)) return false;
1129 // Only these actions have any effect on gesture detection. Other
1130 // actions have no corresponding WebTouchEvent type and may confuse the
1131 // touch pipline, so we ignore them entirely.
1132 if (eventAction != MotionEvent.ACTION_DOWN
1133 && eventAction != MotionEvent.ACTION_UP
1134 && eventAction != MotionEvent.ACTION_CANCEL
1135 && eventAction != MotionEvent.ACTION_MOVE
1136 && eventAction != MotionEvent.ACTION_POINTER_DOWN
1137 && eventAction != MotionEvent.ACTION_POINTER_UP) {
1138 return false;
1139 }
1140 1113
1141 if (mNativeContentViewCore == 0) return false; 1114 if (mNativeContentViewCore == 0) return false;
1142 1115
1143 // A zero offset is quite common, in which case the unnecessary copy should be avoided. 1116 // A zero offset is quite common, in which case the unnecessary copy should be avoided.
1144 MotionEvent offset = null; 1117 MotionEvent offset = null;
1145 if (mCurrentTouchOffsetX != 0 || mCurrentTouchOffsetY != 0) { 1118 if (mCurrentTouchOffsetX != 0 || mCurrentTouchOffsetY != 0) {
1146 offset = createOffsetMotionEvent(event); 1119 offset = createOffsetMotionEvent(event);
1147 event = offset; 1120 event = offset;
1148 } 1121 }
1149 1122
(...skipping 11 matching lines...) Expand all
1161 pointerCount > 1 ? event.getToolType(1) : MotionEvent.TOOL_T YPE_UNKNOWN, 1134 pointerCount > 1 ? event.getToolType(1) : MotionEvent.TOOL_T YPE_UNKNOWN,
1162 event.getButtonState()); 1135 event.getButtonState());
1163 1136
1164 if (offset != null) offset.recycle(); 1137 if (offset != null) offset.recycle();
1165 return consumed; 1138 return consumed;
1166 } finally { 1139 } finally {
1167 TraceEvent.end("onTouchEvent"); 1140 TraceEvent.end("onTouchEvent");
1168 } 1141 }
1169 } 1142 }
1170 1143
1144 private static boolean isValidTouchEventActionForNative(int eventAction) {
1145 // Only these actions have any effect on gesture detection. Other
1146 // actions have no corresponding WebTouchEvent type and may confuse the
1147 // touch pipline, so we ignore them entirely.
1148 return eventAction == MotionEvent.ACTION_DOWN
1149 || eventAction == MotionEvent.ACTION_UP
1150 || eventAction == MotionEvent.ACTION_CANCEL
1151 || eventAction == MotionEvent.ACTION_MOVE
1152 || eventAction == MotionEvent.ACTION_POINTER_DOWN
1153 || eventAction == MotionEvent.ACTION_POINTER_UP;
1154 }
1155
1171 public void setIgnoreRemainingTouchEvents() { 1156 public void setIgnoreRemainingTouchEvents() {
1172 resetGestureDetection(); 1157 resetGestureDetection();
1173 } 1158 }
1174 1159
1175 public boolean isScrollInProgress() { 1160 public boolean isScrollInProgress() {
1176 return mTouchScrollInProgress || mPotentiallyActiveFlingCount > 0; 1161 return mTouchScrollInProgress || mPotentiallyActiveFlingCount > 0;
1177 } 1162 }
1178 1163
1179 @SuppressWarnings("unused") 1164 @SuppressWarnings("unused")
1180 @CalledByNative 1165 @CalledByNative
1181 private void onFlingStartEventConsumed(int vx, int vy) { 1166 private void onFlingStartEventConsumed(int vx, int vy) {
1182 mTouchScrollInProgress = false; 1167 mTouchScrollInProgress = false;
1183 mPotentiallyActiveFlingCount++; 1168 mPotentiallyActiveFlingCount++;
1184 temporarilyHideTextHandles();
1185 for (mGestureStateListenersIterator.rewind(); 1169 for (mGestureStateListenersIterator.rewind();
1186 mGestureStateListenersIterator.hasNext();) { 1170 mGestureStateListenersIterator.hasNext();) {
1187 mGestureStateListenersIterator.next().onFlingStartGesture( 1171 mGestureStateListenersIterator.next().onFlingStartGesture(
1188 vx, vy, computeVerticalScrollOffset(), computeVerticalScroll Extent()); 1172 vx, vy, computeVerticalScrollOffset(), computeVerticalScroll Extent());
1189 } 1173 }
1190 } 1174 }
1191 1175
1192 @SuppressWarnings("unused") 1176 @SuppressWarnings("unused")
1193 @CalledByNative 1177 @CalledByNative
1194 private void onFlingStartEventHadNoConsumer(int vx, int vy) { 1178 private void onFlingStartEventHadNoConsumer(int vx, int vy) {
1195 mTouchScrollInProgress = false; 1179 mTouchScrollInProgress = false;
1196 for (mGestureStateListenersIterator.rewind(); 1180 for (mGestureStateListenersIterator.rewind();
1197 mGestureStateListenersIterator.hasNext();) { 1181 mGestureStateListenersIterator.hasNext();) {
1198 mGestureStateListenersIterator.next().onUnhandledFlingStartEvent(vx, vy); 1182 mGestureStateListenersIterator.next().onUnhandledFlingStartEvent(vx, vy);
1199 } 1183 }
1200 } 1184 }
1201 1185
1202 @SuppressWarnings("unused") 1186 @SuppressWarnings("unused")
1203 @CalledByNative 1187 @CalledByNative
1204 private void onFlingCancelEventAck() { 1188 private void onFlingCancelEventAck() {
1205 updateGestureStateListener(GestureEventType.FLING_CANCEL); 1189 updateGestureStateListener(GestureEventType.FLING_CANCEL);
1206 } 1190 }
1207 1191
1208 @SuppressWarnings("unused") 1192 @SuppressWarnings("unused")
1209 @CalledByNative 1193 @CalledByNative
1210 private void onScrollBeginEventAck() { 1194 private void onScrollBeginEventAck() {
1195 hidePastePopup();
1211 mTouchScrollInProgress = true; 1196 mTouchScrollInProgress = true;
1212 temporarilyHideTextHandles();
1213 mZoomControlsDelegate.invokeZoomPicker(); 1197 mZoomControlsDelegate.invokeZoomPicker();
1214 updateGestureStateListener(GestureEventType.SCROLL_START); 1198 updateGestureStateListener(GestureEventType.SCROLL_START);
1215 } 1199 }
1216 1200
1217 @SuppressWarnings("unused") 1201 @SuppressWarnings("unused")
1218 @CalledByNative 1202 @CalledByNative
1219 private void onScrollUpdateGestureConsumed() { 1203 private void onScrollUpdateGestureConsumed() {
1220 mZoomControlsDelegate.invokeZoomPicker(); 1204 mZoomControlsDelegate.invokeZoomPicker();
1221 for (mGestureStateListenersIterator.rewind(); 1205 for (mGestureStateListenersIterator.rewind();
1222 mGestureStateListenersIterator.hasNext();) { 1206 mGestureStateListenersIterator.hasNext();) {
1223 mGestureStateListenersIterator.next().onScrollUpdateGestureConsumed( ); 1207 mGestureStateListenersIterator.next().onScrollUpdateGestureConsumed( );
1224 } 1208 }
1225 } 1209 }
1226 1210
1227 @SuppressWarnings("unused") 1211 @SuppressWarnings("unused")
1228 @CalledByNative 1212 @CalledByNative
1229 private void onScrollEndEventAck() { 1213 private void onScrollEndEventAck() {
1230 if (!mTouchScrollInProgress) return; 1214 if (!mTouchScrollInProgress) return;
1231 mTouchScrollInProgress = false; 1215 mTouchScrollInProgress = false;
1232 updateGestureStateListener(GestureEventType.SCROLL_END); 1216 updateGestureStateListener(GestureEventType.SCROLL_END);
1233 } 1217 }
1234 1218
1235 @SuppressWarnings("unused") 1219 @SuppressWarnings("unused")
1236 @CalledByNative 1220 @CalledByNative
1237 private void onPinchBeginEventAck() { 1221 private void onPinchBeginEventAck() {
1238 temporarilyHideTextHandles();
1239 updateGestureStateListener(GestureEventType.PINCH_BEGIN); 1222 updateGestureStateListener(GestureEventType.PINCH_BEGIN);
1240 } 1223 }
1241 1224
1242 @SuppressWarnings("unused") 1225 @SuppressWarnings("unused")
1243 @CalledByNative 1226 @CalledByNative
1244 private void onPinchEndEventAck() { 1227 private void onPinchEndEventAck() {
1245 updateGestureStateListener(GestureEventType.PINCH_END); 1228 updateGestureStateListener(GestureEventType.PINCH_END);
1246 } 1229 }
1247 1230
1248 @SuppressWarnings("unused") 1231 @SuppressWarnings("unused")
1249 @CalledByNative 1232 @CalledByNative
1250 private void onSingleTapEventAck(boolean consumed, int x, int y) { 1233 private void onSingleTapEventAck(boolean consumed, int x, int y) {
1251 for (mGestureStateListenersIterator.rewind(); 1234 for (mGestureStateListenersIterator.rewind();
1252 mGestureStateListenersIterator.hasNext();) { 1235 mGestureStateListenersIterator.hasNext();) {
1253 mGestureStateListenersIterator.next().onSingleTap(consumed, x, y); 1236 mGestureStateListenersIterator.next().onSingleTap(consumed, x, y);
1254 } 1237 }
1255 } 1238 }
1256 1239
1257 @SuppressWarnings("unused")
1258 @CalledByNative
1259 private void onDoubleTapEventAck() {
1260 temporarilyHideTextHandles();
1261 }
1262
1263 /** 1240 /**
1264 * Called just prior to a tap or press gesture being forwarded to the render er. 1241 * Called just prior to a tap or press gesture being forwarded to the render er.
1265 */ 1242 */
1266 @SuppressWarnings("unused") 1243 @SuppressWarnings("unused")
1267 @CalledByNative 1244 @CalledByNative
1268 private boolean filterTapOrPressEvent(int type, int x, int y) { 1245 private boolean filterTapOrPressEvent(int type, int x, int y) {
1269 if (type == GestureEventType.LONG_PRESS && offerLongPressToEmbedder()) { 1246 if (type == GestureEventType.LONG_PRESS && offerLongPressToEmbedder()) {
1270 return true; 1247 return true;
1271 } 1248 }
1272 updateForTapOrPress(type, x, y); 1249 updateForTapOrPress(type, x, y);
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
1418 * Return the ContentSettings object used to retrieve the settings for this 1395 * Return the ContentSettings object used to retrieve the settings for this
1419 * ContentViewCore. For modifications, ChromeNativePreferences is to be used . 1396 * ContentViewCore. For modifications, ChromeNativePreferences is to be used .
1420 * @return A ContentSettings object that can be used to retrieve this 1397 * @return A ContentSettings object that can be used to retrieve this
1421 * ContentViewCore's settings. 1398 * ContentViewCore's settings.
1422 */ 1399 */
1423 public ContentSettings getContentSettings() { 1400 public ContentSettings getContentSettings() {
1424 return mContentSettings; 1401 return mContentSettings;
1425 } 1402 }
1426 1403
1427 private void hidePopups() { 1404 private void hidePopups() {
1405 mUnselectAllOnActionModeDismiss = true;
1406 hideSelectActionBar();
1407 hidePastePopup();
1428 hideSelectPopup(); 1408 hideSelectPopup();
1429 hideHandles(); 1409 hideTextHandles();
1430 hideSelectActionBar();
1431 } 1410 }
1432 1411
1433 public void hideSelectActionBar() { 1412 public void hideSelectActionBar() {
1434 if (mActionMode != null) { 1413 if (mActionMode != null) {
1435 mActionMode.finish(); 1414 mActionMode.finish();
1436 mActionMode = null; 1415 mActionMode = null;
1437 } 1416 }
1438 } 1417 }
1439 1418
1440 public boolean isSelectActionBarShowing() { 1419 public boolean isSelectActionBarShowing() {
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
1875 if (mContainerView.isFocusable() && mContainerView.isFocusableInTouchMod e() 1854 if (mContainerView.isFocusable() && mContainerView.isFocusableInTouchMod e()
1876 && !mContainerView.isFocused()) { 1855 && !mContainerView.isFocused()) {
1877 mContainerView.requestFocus(); 1856 mContainerView.requestFocus();
1878 } 1857 }
1879 1858
1880 if (!mPopupZoomer.isShowing()) mPopupZoomer.setLastTouch(xPix, yPix); 1859 if (!mPopupZoomer.isShowing()) mPopupZoomer.setLastTouch(xPix, yPix);
1881 1860
1882 mLastTapX = (int) xPix; 1861 mLastTapX = (int) xPix;
1883 mLastTapY = (int) yPix; 1862 mLastTapY = (int) yPix;
1884 1863
1885 if (type == GestureEventType.LONG_PRESS 1864 if (type == GestureEventType.LONG_PRESS) mAllowAutomaticPastePopupShowin g = true;
1886 || type == GestureEventType.LONG_TAP) {
1887 getInsertionHandleController().allowAutomaticShowing();
1888 getSelectionHandleController().allowAutomaticShowing();
1889 } else {
1890 if (mSelectionEditable) getInsertionHandleController().allowAutomati cShowing();
1891 }
1892 } 1865 }
1893 1866
1894 /** 1867 /**
1895 * @return The x coordinate for the last point that a tap or press gesture w as initiated from. 1868 * @return The x coordinate for the last point that a tap or press gesture w as initiated from.
1896 */ 1869 */
1897 public int getLastTapX() { 1870 public int getLastTapX() {
1898 return mLastTapX; 1871 return mLastTapX;
1899 } 1872 }
1900 1873
1901 /** 1874 /**
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1944 */ 1917 */
1945 public void setDownloadDelegate(ContentViewDownloadDelegate delegate) { 1918 public void setDownloadDelegate(ContentViewDownloadDelegate delegate) {
1946 mDownloadDelegate = delegate; 1919 mDownloadDelegate = delegate;
1947 } 1920 }
1948 1921
1949 // Called by DownloadController. 1922 // Called by DownloadController.
1950 ContentViewDownloadDelegate getDownloadDelegate() { 1923 ContentViewDownloadDelegate getDownloadDelegate() {
1951 return mDownloadDelegate; 1924 return mDownloadDelegate;
1952 } 1925 }
1953 1926
1954 private SelectionHandleController getSelectionHandleController() {
1955 if (mSelectionHandleController == null) {
1956 mSelectionHandleController = new SelectionHandleController(
1957 getContainerView(), mPositionObserver) {
1958 @Override
1959 public void selectBetweenCoordinates(int x1, int y1, int x2, int y2) {
1960 if (mNativeContentViewCore != 0 && !(x1 == x2 && y1 == y2)) {
1961 nativeSelectBetweenCoordinates(mNativeContentViewCore,
1962 x1, y1 - mRenderCoordinates.getContentOffsetYPix (),
1963 x2, y2 - mRenderCoordinates.getContentOffsetYPix ());
1964 }
1965 }
1966
1967 @Override
1968 public void showHandles(int startDir, int endDir) {
1969 final boolean wasShowing = isShowing();
1970 super.showHandles(startDir, endDir);
1971 if (!wasShowing || mActionMode == null) showSelectActionBar( );
1972 }
1973
1974 };
1975
1976 mSelectionHandleController.hideAndDisallowAutomaticShowing();
1977 }
1978
1979 return mSelectionHandleController;
1980 }
1981
1982 private InsertionHandleController getInsertionHandleController() {
1983 if (mInsertionHandleController == null) {
1984 mInsertionHandleController = new InsertionHandleController(
1985 getContainerView(), mPositionObserver) {
1986 private static final int AVERAGE_LINE_HEIGHT = 14;
1987
1988 @Override
1989 public void setCursorPosition(int x, int y) {
1990 if (mNativeContentViewCore != 0) {
1991 nativeMoveCaret(mNativeContentViewCore,
1992 x, y - mRenderCoordinates.getContentOffsetYPix() );
1993 }
1994 }
1995
1996 @Override
1997 public void paste() {
1998 mImeAdapter.paste();
1999 hideHandles();
2000 }
2001
2002 @Override
2003 public int getLineHeight() {
2004 return (int) Math.ceil(
2005 mRenderCoordinates.fromLocalCssToPix(AVERAGE_LINE_HE IGHT));
2006 }
2007 };
2008
2009 mInsertionHandleController.hideAndDisallowAutomaticShowing();
2010 }
2011
2012 return mInsertionHandleController;
2013 }
2014
2015 @VisibleForTesting
2016 public InsertionHandleController getInsertionHandleControllerForTest() {
2017 return mInsertionHandleController;
2018 }
2019
2020 @VisibleForTesting
2021 public SelectionHandleController getSelectionHandleControllerForTest() {
2022 return mSelectionHandleController;
2023 }
2024
2025 private void updateHandleScreenPositions() {
2026 if (isSelectionHandleShowing()) {
2027 mSelectionHandleController.setStartHandlePosition(
2028 mStartHandlePoint.getXPix(), mStartHandlePoint.getYPix());
2029 mSelectionHandleController.setEndHandlePosition(
2030 mEndHandlePoint.getXPix(), mEndHandlePoint.getYPix());
2031 }
2032
2033 if (isInsertionHandleShowing()) {
2034 mInsertionHandleController.setHandlePosition(
2035 mInsertionHandlePoint.getXPix(), mInsertionHandlePoint.getYP ix());
2036 }
2037 }
2038
2039 private void hideHandles() {
2040 if (mSelectionHandleController != null) {
2041 mSelectionHandleController.hideAndDisallowAutomaticShowing();
2042 }
2043 if (mInsertionHandleController != null) {
2044 mInsertionHandleController.hideAndDisallowAutomaticShowing();
2045 }
2046 mPositionObserver.removeListener(mPositionListener);
2047 }
2048
2049 private void showSelectActionBar() { 1927 private void showSelectActionBar() {
2050 if (mActionMode != null) { 1928 if (mActionMode != null) {
2051 mActionMode.invalidate(); 1929 mActionMode.invalidate();
2052 return; 1930 return;
2053 } 1931 }
2054 1932
2055 // Start a new action mode with a SelectActionModeCallback. 1933 // Start a new action mode with a SelectActionModeCallback.
2056 SelectActionModeCallback.ActionHandler actionHandler = 1934 SelectActionModeCallback.ActionHandler actionHandler =
2057 new SelectActionModeCallback.ActionHandler() { 1935 new SelectActionModeCallback.ActionHandler() {
2058 @Override 1936 @Override
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
2168 } 2046 }
2169 mUnselectAllOnActionModeDismiss = true; 2047 mUnselectAllOnActionModeDismiss = true;
2170 if (mActionMode == null) { 2048 if (mActionMode == null) {
2171 // There is no ActionMode, so remove the selection. 2049 // There is no ActionMode, so remove the selection.
2172 mImeAdapter.unselect(); 2050 mImeAdapter.unselect();
2173 } else { 2051 } else {
2174 getContentViewClient().onContextualActionBarShown(); 2052 getContentViewClient().onContextualActionBarShown();
2175 } 2053 }
2176 } 2054 }
2177 2055
2056 private void hidePastePopup() {
2057 mAllowAutomaticPastePopupShowing = false;
2058 if (mPastePopupMenu == null) return;
2059 mPastePopupMenu.hide();
2060 }
2061
2062 @CalledByNative
2063 private void onSelectionEvent(int eventType, float posXDip, float posYDip) {
2064 boolean shouldShowPastePopup = false;
2065 switch (eventType) {
2066 case SelectionEventType.SELECTION_SHOWN:
2067 mHasSelection = true;
2068 // TODO(cjhopman): Remove this when there is a better signal tha t long press caused
2069 // a selection. See http://crbug.com/150151.
2070 mContainerView.performHapticFeedback(HapticFeedbackConstants.LON G_PRESS);
2071 showSelectActionBar();
2072 break;
2073
2074 case SelectionEventType.SELECTION_CLEARED:
2075 mHasSelection = false;
2076 mUnselectAllOnActionModeDismiss = false;
2077 hideSelectActionBar();
2078 break;
2079
2080 case SelectionEventType.INSERTION_SHOWN:
2081 mHasInsertion = true;
2082 shouldShowPastePopup = mAllowAutomaticPastePopupShowing;
2083 break;
2084
2085 case SelectionEventType.INSERTION_MOVED:
2086 // TODO(jdduke): Handle case where movement triggered by focus.
2087 hidePastePopup();
2088 break;
2089
2090 case SelectionEventType.INSERTION_TAPPED:
2091 if (getPastePopup().isShowing())
2092 mPastePopupMenu.hide();
2093 else
2094 shouldShowPastePopup = true;
2095 break;
2096
2097 case SelectionEventType.INSERTION_CLEARED:
2098 mHasInsertion = false;
2099 hidePastePopup();
2100 break;
2101
2102 default:
2103 assert false : "Invalid selection event type.";
2104 }
2105 if (shouldShowPastePopup) {
2106 final float contentOffsetYPix = mRenderCoordinates.getContentOffsetY Pix();
2107 getPastePopup().showAt(
2108 (int) mRenderCoordinates.fromDipToPix(posXDip),
2109 (int) (mRenderCoordinates.fromDipToPix(posYDip) + contentOffsetY Pix));
2110 }
2111 }
2112
2178 public boolean getUseDesktopUserAgent() { 2113 public boolean getUseDesktopUserAgent() {
2179 if (mNativeContentViewCore != 0) { 2114 if (mNativeContentViewCore != 0) {
2180 return nativeGetUseDesktopUserAgent(mNativeContentViewCore); 2115 return nativeGetUseDesktopUserAgent(mNativeContentViewCore);
2181 } 2116 }
2182 return false; 2117 return false;
2183 } 2118 }
2184 2119
2185 /** 2120 /**
2186 * Set whether or not we're using a desktop user agent for the currently loa ded page. 2121 * Set whether or not we're using a desktop user agent for the currently loa ded page.
2187 * @param override If true, use a desktop user agent. Use a mobile one othe rwise. 2122 * @param override If true, use a desktop user agent. Use a mobile one othe rwise.
2188 * @param reloadOnChange Reload the page if the UA has changed. 2123 * @param reloadOnChange Reload the page if the UA has changed.
2189 */ 2124 */
2190 public void setUseDesktopUserAgent(boolean override, boolean reloadOnChange) { 2125 public void setUseDesktopUserAgent(boolean override, boolean reloadOnChange) {
2191 if (mNativeContentViewCore != 0) { 2126 if (mNativeContentViewCore != 0) {
2192 nativeSetUseDesktopUserAgent(mNativeContentViewCore, override, reloa dOnChange); 2127 nativeSetUseDesktopUserAgent(mNativeContentViewCore, override, reloa dOnChange);
2193 } 2128 }
2194 } 2129 }
2195 2130
2196 public void clearSslPreferences() { 2131 public void clearSslPreferences() {
2197 if (mNativeContentViewCore != 0) nativeClearSslPreferences(mNativeConten tViewCore); 2132 if (mNativeContentViewCore != 0) nativeClearSslPreferences(mNativeConten tViewCore);
2198 } 2133 }
2199 2134
2200 private boolean isSelectionHandleShowing() { 2135 private void hideTextHandles() {
2201 return mSelectionHandleController != null && mSelectionHandleController. isShowing(); 2136 mHasSelection = false;
2202 } 2137 mHasInsertion = false;
2203 2138 if (mNativeContentViewCore != 0) nativeHideTextHandles(mNativeContentVie wCore);
2204 private boolean isInsertionHandleShowing() {
2205 return mInsertionHandleController != null && mInsertionHandleController. isShowing();
2206 }
2207
2208 // Makes the insertion/selection handles invisible. They will fade back in s hortly after the
2209 // last call to scheduleTextHandleFadeIn (or temporarilyHideTextHandles).
2210 private void temporarilyHideTextHandles() {
2211 if (isSelectionHandleShowing() && !mSelectionHandleController.isDragging ()) {
2212 mSelectionHandleController.setHandleVisibility(HandleView.INVISIBLE) ;
2213 }
2214 if (isInsertionHandleShowing() && !mInsertionHandleController.isDragging ()) {
2215 mInsertionHandleController.setHandleVisibility(HandleView.INVISIBLE) ;
2216 }
2217 scheduleTextHandleFadeIn();
2218 }
2219
2220 private boolean allowTextHandleFadeIn() {
2221 if (mTouchScrollInProgress) return false;
2222
2223 if (mPopupZoomer.isShowing()) return false;
2224
2225 return true;
2226 }
2227
2228 // Cancels any pending fade in and schedules a new one.
2229 private void scheduleTextHandleFadeIn() {
2230 if (!isInsertionHandleShowing() && !isSelectionHandleShowing()) return;
2231
2232 if (mDeferredHandleFadeInRunnable == null) {
2233 mDeferredHandleFadeInRunnable = new Runnable() {
2234 @Override
2235 public void run() {
2236 if (!allowTextHandleFadeIn()) {
2237 // Delay fade in until it is allowed.
2238 scheduleTextHandleFadeIn();
2239 } else {
2240 if (isSelectionHandleShowing()) {
2241 mSelectionHandleController.beginHandleFadeIn();
2242 }
2243 if (isInsertionHandleShowing()) {
2244 mInsertionHandleController.beginHandleFadeIn();
2245 }
2246 }
2247 }
2248 };
2249 }
2250
2251 mContainerView.removeCallbacks(mDeferredHandleFadeInRunnable);
2252 mContainerView.postDelayed(mDeferredHandleFadeInRunnable, TEXT_HANDLE_FA DE_IN_DELAY);
2253 } 2139 }
2254 2140
2255 /** 2141 /**
2256 * Shows the IME if the focused widget could accept text input. 2142 * Shows the IME if the focused widget could accept text input.
2257 */ 2143 */
2258 public void showImeIfNeeded() { 2144 public void showImeIfNeeded() {
2259 if (mNativeContentViewCore != 0) nativeShowImeIfNeeded(mNativeContentVie wCore); 2145 if (mNativeContentViewCore != 0) nativeShowImeIfNeeded(mNativeContentVie wCore);
2260 } 2146 }
2261 2147
2262 /** 2148 /**
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2306 pageScaleFactor != mRenderCoordinates.getPageScaleFactor(); 2192 pageScaleFactor != mRenderCoordinates.getPageScaleFactor();
2307 final boolean scrollChanged = 2193 final boolean scrollChanged =
2308 pageScaleChanged 2194 pageScaleChanged
2309 || scrollOffsetX != mRenderCoordinates.getScrollX() 2195 || scrollOffsetX != mRenderCoordinates.getScrollX()
2310 || scrollOffsetY != mRenderCoordinates.getScrollY(); 2196 || scrollOffsetY != mRenderCoordinates.getScrollY();
2311 final boolean contentOffsetChanged = 2197 final boolean contentOffsetChanged =
2312 contentOffsetYPix != mRenderCoordinates.getContentOffsetYPix(); 2198 contentOffsetYPix != mRenderCoordinates.getContentOffsetYPix();
2313 2199
2314 final boolean needHidePopupZoomer = contentSizeChanged || scrollChanged; 2200 final boolean needHidePopupZoomer = contentSizeChanged || scrollChanged;
2315 final boolean needUpdateZoomControls = scaleLimitsChanged || scrollChang ed; 2201 final boolean needUpdateZoomControls = scaleLimitsChanged || scrollChang ed;
2316 final boolean needTemporarilyHideHandles = scrollChanged;
2317 2202
2318 if (needHidePopupZoomer) mPopupZoomer.hide(true); 2203 if (needHidePopupZoomer) mPopupZoomer.hide(true);
2319 2204
2320 if (scrollChanged) { 2205 if (scrollChanged) {
2321 mContainerViewInternals.onScrollChanged( 2206 mContainerViewInternals.onScrollChanged(
2322 (int) mRenderCoordinates.fromLocalCssToPix(scrollOffsetX), 2207 (int) mRenderCoordinates.fromLocalCssToPix(scrollOffsetX),
2323 (int) mRenderCoordinates.fromLocalCssToPix(scrollOffsetY), 2208 (int) mRenderCoordinates.fromLocalCssToPix(scrollOffsetY),
2324 (int) mRenderCoordinates.getScrollXPix(), 2209 (int) mRenderCoordinates.getScrollXPix(),
2325 (int) mRenderCoordinates.getScrollYPix()); 2210 (int) mRenderCoordinates.getScrollYPix());
2326 } 2211 }
2327 2212
2328 mRenderCoordinates.updateFrameInfo( 2213 mRenderCoordinates.updateFrameInfo(
2329 scrollOffsetX, scrollOffsetY, 2214 scrollOffsetX, scrollOffsetY,
2330 contentWidth, contentHeight, 2215 contentWidth, contentHeight,
2331 viewportWidth, viewportHeight, 2216 viewportWidth, viewportHeight,
2332 pageScaleFactor, minPageScaleFactor, maxPageScaleFactor, 2217 pageScaleFactor, minPageScaleFactor, maxPageScaleFactor,
2333 contentOffsetYPix); 2218 contentOffsetYPix);
2334 2219
2335 if (scrollChanged || contentOffsetChanged) { 2220 if (scrollChanged || contentOffsetChanged) {
2336 for (mGestureStateListenersIterator.rewind(); 2221 for (mGestureStateListenersIterator.rewind();
2337 mGestureStateListenersIterator.hasNext();) { 2222 mGestureStateListenersIterator.hasNext();) {
2338 mGestureStateListenersIterator.next().onScrollOffsetOrExtentChan ged( 2223 mGestureStateListenersIterator.next().onScrollOffsetOrExtentChan ged(
2339 computeVerticalScrollOffset(), 2224 computeVerticalScrollOffset(),
2340 computeVerticalScrollExtent()); 2225 computeVerticalScrollExtent());
2341 } 2226 }
2342 } 2227 }
2343 2228
2344 if (needTemporarilyHideHandles) temporarilyHideTextHandles();
2345 if (needUpdateZoomControls) mZoomControlsDelegate.updateZoomControls(); 2229 if (needUpdateZoomControls) mZoomControlsDelegate.updateZoomControls();
2346 if (contentOffsetChanged) updateHandleScreenPositions();
2347 2230
2348 // Update offsets for fullscreen. 2231 // Update offsets for fullscreen.
2349 final float controlsOffsetPix = controlsOffsetYCss * deviceScale; 2232 final float controlsOffsetPix = controlsOffsetYCss * deviceScale;
2350 final float overdrawBottomHeightPix = overdrawBottomHeightCss * deviceSc ale; 2233 final float overdrawBottomHeightPix = overdrawBottomHeightCss * deviceSc ale;
2351 getContentViewClient().onOffsetsForFullscreenChanged( 2234 getContentViewClient().onOffsetsForFullscreenChanged(
2352 controlsOffsetPix, contentOffsetYPix, overdrawBottomHeightPix); 2235 controlsOffsetPix, contentOffsetYPix, overdrawBottomHeightPix);
2353 2236
2354 if (mBrowserAccessibilityManager != null) { 2237 if (mBrowserAccessibilityManager != null) {
2355 mBrowserAccessibilityManager.notifyFrameInfoInitialized(); 2238 mBrowserAccessibilityManager.notifyFrameInfoInitialized();
2356 } 2239 }
2357 } 2240 }
2358 2241
2359 @CalledByNative 2242 @CalledByNative
2360 private void updateImeAdapter(long nativeImeAdapterAndroid, int textInputTyp e, 2243 private void updateImeAdapter(long nativeImeAdapterAndroid, int textInputTyp e,
2361 String text, int selectionStart, int selectionEnd, 2244 String text, int selectionStart, int selectionEnd,
2362 int compositionStart, int compositionEnd, boolean showImeIfNeeded, 2245 int compositionStart, int compositionEnd, boolean showImeIfNeeded,
2363 boolean isNonImeChange) { 2246 boolean isNonImeChange) {
2364 TraceEvent.begin(); 2247 TraceEvent.begin();
2365 mSelectionEditable = (textInputType != ImeAdapter.getTextInputTypeNone() ); 2248 mSelectionEditable = (textInputType != ImeAdapter.getTextInputTypeNone() );
2249 if (!mSelectionEditable) hidePastePopup();
2366 2250
2367 mImeAdapter.updateKeyboardVisibility( 2251 mImeAdapter.updateKeyboardVisibility(
2368 nativeImeAdapterAndroid, textInputType, showImeIfNeeded); 2252 nativeImeAdapterAndroid, textInputType, showImeIfNeeded);
2369 2253
2370 if (mInputConnection != null) { 2254 if (mInputConnection != null) {
2371 mInputConnection.updateState(text, selectionStart, selectionEnd, com positionStart, 2255 mInputConnection.updateState(text, selectionStart, selectionEnd, com positionStart,
2372 compositionEnd, isNonImeChange); 2256 compositionEnd, isNonImeChange);
2373 } 2257 }
2374 2258
2375 if (mActionMode != null) mActionMode.invalidate(); 2259 if (mActionMode != null) mActionMode.invalidate();
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2425 */ 2309 */
2426 public SelectPopup getSelectPopupForTest() { 2310 public SelectPopup getSelectPopupForTest() {
2427 return mSelectPopup; 2311 return mSelectPopup;
2428 } 2312 }
2429 2313
2430 @SuppressWarnings("unused") 2314 @SuppressWarnings("unused")
2431 @CalledByNative 2315 @CalledByNative
2432 private void showDisambiguationPopup(Rect targetRect, Bitmap zoomedBitmap) { 2316 private void showDisambiguationPopup(Rect targetRect, Bitmap zoomedBitmap) {
2433 mPopupZoomer.setBitmap(zoomedBitmap); 2317 mPopupZoomer.setBitmap(zoomedBitmap);
2434 mPopupZoomer.show(targetRect); 2318 mPopupZoomer.show(targetRect);
2435 temporarilyHideTextHandles();
2436 } 2319 }
2437 2320
2438 @SuppressWarnings("unused") 2321 @SuppressWarnings("unused")
2439 @CalledByNative 2322 @CalledByNative
2440 private TouchEventSynthesizer createTouchEventSynthesizer() { 2323 private TouchEventSynthesizer createTouchEventSynthesizer() {
2441 return new TouchEventSynthesizer(this); 2324 return new TouchEventSynthesizer(this);
2442 } 2325 }
2443 2326
2444 @SuppressWarnings("unused") 2327 @SuppressWarnings("unused")
2445 @CalledByNative 2328 @CalledByNative
2329 private PopupTouchHandleDrawable createPopupTouchHandleDrawable() {
2330 if (mTouchHandleDelegate == null) {
2331 mTouchHandleDelegate = new PopupTouchHandleDrawableDelegate() {
2332 public boolean onTouchHandleEvent(MotionEvent event) {
2333 if (mNativeContentViewCore == 0) return false;
2334 if (!isValidTouchEventActionForNative(event.getActionMasked( ))) return false;
2335 return nativeOnTouchHandleEvent(mNativeContentViewCore, even t);
2336 }
2337 };
2338 }
2339 return new PopupTouchHandleDrawable(
2340 mTouchHandleDelegate, getContainerView(), mPositionObserver);
2341 }
2342
2343 @SuppressWarnings("unused")
2344 @CalledByNative
2446 private void onSelectionChanged(String text) { 2345 private void onSelectionChanged(String text) {
2447 mLastSelectedText = text; 2346 mLastSelectedText = text;
2448 getContentViewClient().onSelectionChanged(text); 2347 getContentViewClient().onSelectionChanged(text);
2449 } 2348 }
2450 2349
2451 @SuppressWarnings("unused") 2350 @SuppressWarnings("unused")
2452 @CalledByNative
2453 private void showSelectionHandlesAutomatically() {
2454 getSelectionHandleController().allowAutomaticShowing();
2455 }
2456
2457 @SuppressWarnings("unused")
2458 @CalledByNative
2459 private void onSelectionBoundsChanged(
2460 float anchorXDip, float anchorYDip, float focusXDip, float focusYDip ,
2461 int anchorDir, int focusDir,
2462 boolean isAnchorVisible, boolean isFocusVisible) {
2463 // TODO(jdduke): Use |is{Anchor,Focus}Visible|, as well as the action
2464 // bar height, to set handle visibility, see crbug.com/164819.
2465 if (focusXDip != anchorXDip || focusYDip != anchorYDip ||
2466 (mSelectionHandleController != null && mSelectionHandleControlle r.isDragging())) {
2467 if (mInsertionHandleController != null) {
2468 mInsertionHandleController.hide();
2469 }
2470 mStartHandlePoint.setLocalDip(anchorXDip, anchorYDip);
2471 mEndHandlePoint.setLocalDip(focusXDip, focusYDip);
2472
2473 boolean wereSelectionHandlesShowing = getSelectionHandleController() .isShowing();
2474
2475 getSelectionHandleController().onSelectionChanged(anchorDir, focusDi r);
2476 updateHandleScreenPositions();
2477 mHasSelection = true;
2478
2479 if (!wereSelectionHandlesShowing && getSelectionHandleController().i sShowing()) {
2480 // TODO(cjhopman): Remove this when there is a better signal tha t long press caused
2481 // a selection. See http://crbug.com/150151.
2482 mContainerView.performHapticFeedback(HapticFeedbackConstants.LON G_PRESS);
2483 }
2484
2485 } else {
2486 mUnselectAllOnActionModeDismiss = false;
2487 hideSelectActionBar();
2488 if (anchorXDip != 0 && anchorYDip != 0 && mSelectionEditable) {
2489 // Selection is a caret, and a text field is focused.
2490 if (mSelectionHandleController != null) {
2491 mSelectionHandleController.hide();
2492 }
2493 mInsertionHandlePoint.setLocalDip(anchorXDip, anchorYDip);
2494
2495 getInsertionHandleController().onCursorPositionChanged();
2496 updateHandleScreenPositions();
2497 if (mInputMethodManagerWrapper.isWatchingCursor(mContainerView)) {
2498 final int xPix = (int) mInsertionHandlePoint.getXPix();
2499 final int yPix = (int) mInsertionHandlePoint.getYPix();
2500 mInputMethodManagerWrapper.updateCursor(
2501 mContainerView, xPix, yPix, xPix, yPix);
2502 }
2503 } else {
2504 // Deselection
2505 hideHandles();
2506 }
2507 mHasSelection = false;
2508 }
2509 if (isSelectionHandleShowing() || isInsertionHandleShowing()) {
2510 mPositionObserver.addListener(mPositionListener);
2511 }
2512 }
2513
2514 @SuppressWarnings("unused")
2515 @CalledByNative 2351 @CalledByNative
2516 private static void onEvaluateJavaScriptResult( 2352 private static void onEvaluateJavaScriptResult(
2517 String jsonResult, JavaScriptCallback callback) { 2353 String jsonResult, JavaScriptCallback callback) {
2518 callback.handleJavaScriptResult(jsonResult); 2354 callback.handleJavaScriptResult(jsonResult);
2519 } 2355 }
2520 2356
2521 @SuppressWarnings("unused") 2357 @SuppressWarnings("unused")
2522 @CalledByNative 2358 @CalledByNative
2523 private void showPastePopup(int xDip, int yDip) { 2359 private void showPastePopup(int xDip, int yDip) {
cjhopman 2014/07/09 22:29:12 Is this called by native? Should it show the paste
jdduke (slow) 2014/07/10 02:08:39 Yeah, I was debating what to do here. I'd like to
2524 mInsertionHandlePoint.setLocalDip(xDip, yDip); 2360 /*
2525 getInsertionHandleController().showHandle(); 2361 if (mPastePopupMenu == null) {
2526 updateHandleScreenPositions(); 2362 mPastePopupMenu = new PastePopupMenu(getContainerView(),
2527 getInsertionHandleController().showHandleWithPastePopup(); 2363 new PastePopupMenuDelegate() {
2364 public void paste() {
2365 mImeAdapter.paste();
2366 }
2367 });
2368 }
2369 final float contentOffsetYPix = mRenderCoordinates.getContentOffsetYPix( );
2370 mPastePopupMenu.showAt((int) mRenderCoordinates.fromDipToPix(xDip),
2371 (int) (mRenderCoordinates.fromDipToPix(yDip) + co ntentOffsetYPix));
2372 */
2373 }
2374
2375 private PastePopupMenu getPastePopup() {
2376 if (mPastePopupMenu == null) {
2377 mPastePopupMenu = new PastePopupMenu(getContainerView(),
2378 new PastePopupMenuDelegate() {
2379 public void paste() {
2380 mImeAdapter.paste();
2381 }
2382 public boolean canPaste() {
2383 if (!mSelectionEditable) return false;
2384 return ((ClipboardManager) mContext.getSystemService(
2385 Context.CLIPBOARD_SERVICE)).hasPrimaryClip();
2386 }
2387 });
2388 }
2389 return mPastePopupMenu;
2528 } 2390 }
2529 2391
2530 @SuppressWarnings("unused") 2392 @SuppressWarnings("unused")
2531 @CalledByNative 2393 @CalledByNative
2532 private void onRenderProcessChange() { 2394 private void onRenderProcessChange() {
2533 attachImeAdapter(); 2395 attachImeAdapter();
2534 } 2396 }
2535 2397
2536 /** 2398 /**
2537 * Attaches the native ImeAdapter object to the java ImeAdapter to allow com munication via JNI. 2399 * Attaches the native ImeAdapter object to the java ImeAdapter to allow com munication via JNI.
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
3198 // All touch events (including flings, scrolls etc) accept coordinates in ph ysical pixels. 3060 // All touch events (including flings, scrolls etc) accept coordinates in ph ysical pixels.
3199 private native boolean nativeOnTouchEvent( 3061 private native boolean nativeOnTouchEvent(
3200 long nativeContentViewCoreImpl, MotionEvent event, 3062 long nativeContentViewCoreImpl, MotionEvent event,
3201 long timeMs, int action, int pointerCount, int historySize, int acti onIndex, 3063 long timeMs, int action, int pointerCount, int historySize, int acti onIndex,
3202 float x0, float y0, float x1, float y1, 3064 float x0, float y0, float x1, float y1,
3203 int pointerId0, int pointerId1, 3065 int pointerId0, int pointerId1,
3204 float touchMajor0, float touchMajor1, 3066 float touchMajor0, float touchMajor1,
3205 float rawX, float rawY, 3067 float rawX, float rawY,
3206 int androidToolType0, int androidToolType1, int androidButtonState); 3068 int androidToolType0, int androidToolType1, int androidButtonState);
3207 3069
3070 private native boolean nativeOnTouchHandleEvent(
3071 long nativeContentViewCoreImpl, MotionEvent event);
3072
3208 private native int nativeSendMouseMoveEvent( 3073 private native int nativeSendMouseMoveEvent(
3209 long nativeContentViewCoreImpl, long timeMs, float x, float y); 3074 long nativeContentViewCoreImpl, long timeMs, float x, float y);
3210 3075
3211 private native int nativeSendMouseWheelEvent( 3076 private native int nativeSendMouseWheelEvent(
3212 long nativeContentViewCoreImpl, long timeMs, float x, float y, float verticalAxis); 3077 long nativeContentViewCoreImpl, long timeMs, float x, float y, float verticalAxis);
3213 3078
3214 private native void nativeScrollBegin( 3079 private native void nativeScrollBegin(
3215 long nativeContentViewCoreImpl, long timeMs, float x, float y, float hintX, 3080 long nativeContentViewCoreImpl, long timeMs, float x, float y, float hintX,
3216 float hintY); 3081 float hintY);
3217 3082
(...skipping 23 matching lines...) Expand all
3241 private native void nativePinchEnd(long nativeContentViewCoreImpl, long time Ms); 3106 private native void nativePinchEnd(long nativeContentViewCoreImpl, long time Ms);
3242 3107
3243 private native void nativePinchBy(long nativeContentViewCoreImpl, long timeM s, 3108 private native void nativePinchBy(long nativeContentViewCoreImpl, long timeM s,
3244 float anchorX, float anchorY, float deltaScale); 3109 float anchorX, float anchorY, float deltaScale);
3245 3110
3246 private native void nativeSelectBetweenCoordinates( 3111 private native void nativeSelectBetweenCoordinates(
3247 long nativeContentViewCoreImpl, float x1, float y1, float x2, float y2); 3112 long nativeContentViewCoreImpl, float x1, float y1, float x2, float y2);
3248 3113
3249 private native void nativeMoveCaret(long nativeContentViewCoreImpl, float x, float y); 3114 private native void nativeMoveCaret(long nativeContentViewCoreImpl, float x, float y);
3250 3115
3116 private native void nativeHideTextHandles(long nativeContentViewCoreImpl);
3117
3251 private native void nativeResetGestureDetection(long nativeContentViewCoreIm pl); 3118 private native void nativeResetGestureDetection(long nativeContentViewCoreIm pl);
3252 private native void nativeSetDoubleTapSupportEnabled( 3119 private native void nativeSetDoubleTapSupportEnabled(
3253 long nativeContentViewCoreImpl, boolean enabled); 3120 long nativeContentViewCoreImpl, boolean enabled);
3254 private native void nativeSetMultiTouchZoomSupportEnabled( 3121 private native void nativeSetMultiTouchZoomSupportEnabled(
3255 long nativeContentViewCoreImpl, boolean enabled); 3122 long nativeContentViewCoreImpl, boolean enabled);
3256 3123
3257 private native void nativeLoadIfNecessary(long nativeContentViewCoreImpl); 3124 private native void nativeLoadIfNecessary(long nativeContentViewCoreImpl);
3258 private native void nativeRequestRestoreLoad(long nativeContentViewCoreImpl) ; 3125 private native void nativeRequestRestoreLoad(long nativeContentViewCoreImpl) ;
3259 3126
3260 private native void nativeReload(long nativeContentViewCoreImpl, boolean che ckForRepost); 3127 private native void nativeReload(long nativeContentViewCoreImpl, boolean che ckForRepost);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
3324 3191
3325 private native void nativeExtractSmartClipData(long nativeContentViewCoreImp l, 3192 private native void nativeExtractSmartClipData(long nativeContentViewCoreImp l,
3326 int x, int y, int w, int h); 3193 int x, int y, int w, int h);
3327 private native void nativeSetBackgroundOpaque(long nativeContentViewCoreImpl , boolean opaque); 3194 private native void nativeSetBackgroundOpaque(long nativeContentViewCoreImpl , boolean opaque);
3328 3195
3329 private native void nativeResumeResponseDeferredAtStart( 3196 private native void nativeResumeResponseDeferredAtStart(
3330 long nativeContentViewCoreImpl); 3197 long nativeContentViewCoreImpl);
3331 private native void nativeSetHasPendingNavigationTransitionForTesting( 3198 private native void nativeSetHasPendingNavigationTransitionForTesting(
3332 long nativeContentViewCoreImpl); 3199 long nativeContentViewCoreImpl);
3333 } 3200 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698