Commit a3b70c17 authored by yusufo@chromium.org's avatar yusufo@chromium.org

Move the event offsetting logic from ContentView to CVC

BUG=360664

Review URL: https://codereview.chromium.org/252623002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266586 0039d316-1c4b-4281-b951-d872f2087c98
parent 372f52ee
...@@ -33,8 +33,6 @@ public class ContentView extends FrameLayout ...@@ -33,8 +33,6 @@ public class ContentView extends FrameLayout
private final ContentViewCore mContentViewCore; private final ContentViewCore mContentViewCore;
private float mCurrentTouchOffsetX;
private float mCurrentTouchOffsetY;
private final int[] mLocationInWindow = new int[2]; private final int[] mLocationInWindow = new int[2];
/** /**
...@@ -170,10 +168,7 @@ public class ContentView extends FrameLayout ...@@ -170,10 +168,7 @@ public class ContentView extends FrameLayout
@Override @Override
public boolean onTouchEvent(MotionEvent event) { public boolean onTouchEvent(MotionEvent event) {
MotionEvent offset = createOffsetMotionEvent(event); return mContentViewCore.onTouchEvent(event);
boolean consumed = mContentViewCore.onTouchEvent(offset);
offset.recycle();
return consumed;
} }
/** /**
...@@ -183,9 +178,7 @@ public class ContentView extends FrameLayout ...@@ -183,9 +178,7 @@ public class ContentView extends FrameLayout
*/ */
@Override @Override
public boolean onHoverEvent(MotionEvent event) { public boolean onHoverEvent(MotionEvent event) {
MotionEvent offset = createOffsetMotionEvent(event); boolean consumed = mContentViewCore.onHoverEvent(event);
boolean consumed = mContentViewCore.onHoverEvent(offset);
offset.recycle();
if (!mContentViewCore.isTouchExplorationEnabled()) super.onHoverEvent(event); if (!mContentViewCore.isTouchExplorationEnabled()) super.onHoverEvent(event);
return consumed; return consumed;
} }
...@@ -200,23 +193,6 @@ public class ContentView extends FrameLayout ...@@ -200,23 +193,6 @@ public class ContentView extends FrameLayout
return false; return false;
} }
/**
* Sets the current amount to offset incoming touch events by. This is used to handle content
* moving and not lining up properly with the android input system.
* @param dx The X offset in pixels to shift touch events.
* @param dy The Y offset in pixels to shift touch events.
*/
public void setCurrentMotionEventOffsets(float dx, float dy) {
mCurrentTouchOffsetX = dx;
mCurrentTouchOffsetY = dy;
}
private MotionEvent createOffsetMotionEvent(MotionEvent src) {
MotionEvent dst = MotionEvent.obtain(src);
dst.offsetLocation(mCurrentTouchOffsetX, mCurrentTouchOffsetY);
return dst;
}
@Override @Override
protected void onConfigurationChanged(Configuration newConfig) { protected void onConfigurationChanged(Configuration newConfig) {
mContentViewCore.onConfigurationChanged(newConfig); mContentViewCore.onConfigurationChanged(newConfig);
......
...@@ -439,6 +439,10 @@ public class ContentViewCore ...@@ -439,6 +439,10 @@ public class ContentViewCore
// if there is no render process. // if there is no render process.
public static final int INVALID_RENDER_PROCESS_PID = 0; public static final int INVALID_RENDER_PROCESS_PID = 0;
// Offsets for the events that passes through this ContentViewCore.
private float mCurrentTouchOffsetX;
private float mCurrentTouchOffsetY;
/** /**
* Constructs a new ContentViewCore. Embedders must call initialize() after constructing * Constructs a new ContentViewCore. Embedders must call initialize() after constructing
* a ContentViewCore and before using it. * a ContentViewCore and before using it.
...@@ -1186,6 +1190,8 @@ public class ContentViewCore ...@@ -1186,6 +1190,8 @@ public class ContentViewCore
* @see View#onTouchEvent(MotionEvent) * @see View#onTouchEvent(MotionEvent)
*/ */
public boolean onTouchEvent(MotionEvent event) { public boolean onTouchEvent(MotionEvent event) {
MotionEvent offset = createOffsetMotionEvent(event);
cancelRequestToScrollFocusedEditableNodeIntoView(); cancelRequestToScrollFocusedEditableNodeIntoView();
if (!mRequestedVSyncForInput) { if (!mRequestedVSyncForInput) {
...@@ -1193,7 +1199,7 @@ public class ContentViewCore ...@@ -1193,7 +1199,7 @@ public class ContentViewCore
addVSyncSubscriber(); addVSyncSubscriber();
} }
final int eventAction = event.getActionMasked(); final int eventAction = offset.getActionMasked();
// Only these actions have any effect on gesture detection. Other // Only these actions have any effect on gesture detection. Other
// actions have no corresponding WebTouchEvent type and may confuse the // actions have no corresponding WebTouchEvent type and may confuse the
...@@ -1208,15 +1214,17 @@ public class ContentViewCore ...@@ -1208,15 +1214,17 @@ public class ContentViewCore
} }
if (mNativeContentViewCore == 0) return false; if (mNativeContentViewCore == 0) return false;
final int pointerCount = event.getPointerCount(); final int pointerCount = offset.getPointerCount();
return nativeOnTouchEvent(mNativeContentViewCore, event, boolean consumed = nativeOnTouchEvent(mNativeContentViewCore, offset,
event.getEventTime(), eventAction, offset.getEventTime(), eventAction,
pointerCount, event.getHistorySize(), event.getActionIndex(), pointerCount, offset.getHistorySize(), offset.getActionIndex(),
event.getX(), event.getY(), offset.getX(), offset.getY(),
pointerCount > 1 ? event.getX(1) : 0, pointerCount > 1 ? offset.getX(1) : 0,
pointerCount > 1 ? event.getY(1) : 0, pointerCount > 1 ? offset.getY(1) : 0,
event.getPointerId(0), pointerCount > 1 ? event.getPointerId(1) : -1, offset.getPointerId(0), pointerCount > 1 ? offset.getPointerId(1) : -1,
event.getTouchMajor(), pointerCount > 1 ? event.getTouchMajor(1) : 0); offset.getTouchMajor(), pointerCount > 1 ? offset.getTouchMajor(1) : 0);
offset.recycle();
return consumed;
} }
public void setIgnoreRemainingTouchEvents() { public void setIgnoreRemainingTouchEvents() {
...@@ -1709,23 +1717,25 @@ public class ContentViewCore ...@@ -1709,23 +1717,25 @@ public class ContentViewCore
*/ */
public boolean onHoverEvent(MotionEvent event) { public boolean onHoverEvent(MotionEvent event) {
TraceEvent.begin("onHoverEvent"); TraceEvent.begin("onHoverEvent");
MotionEvent offset = createOffsetMotionEvent(event);
if (mBrowserAccessibilityManager != null) { if (mBrowserAccessibilityManager != null) {
return mBrowserAccessibilityManager.onHoverEvent(event); return mBrowserAccessibilityManager.onHoverEvent(offset);
} }
// Work around Android bug where the x, y coordinates of a hover exit // Work around Android bug where the x, y coordinates of a hover exit
// event are incorrect when touch exploration is on. // event are incorrect when touch exploration is on.
if (mTouchExplorationEnabled && event.getAction() == MotionEvent.ACTION_HOVER_EXIT) { if (mTouchExplorationEnabled && offset.getAction() == MotionEvent.ACTION_HOVER_EXIT) {
return true; return true;
} }
mContainerView.removeCallbacks(mFakeMouseMoveRunnable); mContainerView.removeCallbacks(mFakeMouseMoveRunnable);
if (mNativeContentViewCore != 0) { if (mNativeContentViewCore != 0) {
nativeSendMouseMoveEvent(mNativeContentViewCore, event.getEventTime(), nativeSendMouseMoveEvent(mNativeContentViewCore, offset.getEventTime(),
event.getX(), event.getY()); offset.getX(), offset.getY());
} }
TraceEvent.end("onHoverEvent"); TraceEvent.end("onHoverEvent");
offset.recycle();
return true; return true;
} }
...@@ -1757,6 +1767,23 @@ public class ContentViewCore ...@@ -1757,6 +1767,23 @@ public class ContentViewCore
return mContainerViewInternals.super_onGenericMotionEvent(event); return mContainerViewInternals.super_onGenericMotionEvent(event);
} }
/**
* Sets the current amount to offset incoming touch events by. This is used to handle content
* moving and not lining up properly with the android input system.
* @param dx The X offset in pixels to shift touch events.
* @param dy The Y offset in pixels to shift touch events.
*/
public void setCurrentMotionEventOffsets(float dx, float dy) {
mCurrentTouchOffsetX = dx;
mCurrentTouchOffsetY = dy;
}
private MotionEvent createOffsetMotionEvent(MotionEvent src) {
MotionEvent dst = MotionEvent.obtain(src);
dst.offsetLocation(mCurrentTouchOffsetX, mCurrentTouchOffsetY);
return dst;
}
/** /**
* @see View#scrollBy(int, int) * @see View#scrollBy(int, int)
* Currently the ContentView scrolling happens in the native side. In * Currently the ContentView scrolling happens in the native side. In
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment