Commit 78467bc5 authored by Jinsuk Kim's avatar Jinsuk Kim Committed by Commit Bot

Android: Migrate ContentViewCore.setContainerViewInternals

This CL renames an API setrContainerViewInternals to
setAccessDelegate and migrates to ViewEventSink that handles
view-related methods for content layer, in preparation of
deleting the class ContentViewCore.

Bug: 598880
Change-Id: I3023d0ac2959d88ad82cfe91a8c6cf2fc3955320
Reviewed-on: https://chromium-review.googlesource.com/1106649Reviewed-by: default avatarBo <boliu@chromium.org>
Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568715}
parent f0596045
......@@ -174,8 +174,7 @@ public class AwContents implements SmartClipProvider {
* Interface that consumers of {@link AwContents} must implement to allow the proper
* dispatching of view methods through the containing view.
*/
public interface InternalAccessDelegate extends ContentViewCore.InternalAccessDelegate {
public interface InternalAccessDelegate extends ViewEventSink.InternalAccessDelegate {
/**
* @see View#overScrollBy(int, int, int, int, int, int, int, int, boolean);
*/
......@@ -996,7 +995,7 @@ public class AwContents implements SmartClipProvider {
private void setInternalAccessAdapter(InternalAccessDelegate internalAccessAdapter) {
mInternalAccessAdapter = internalAccessAdapter;
mContentViewCore.setContainerViewInternals(mInternalAccessAdapter);
mViewEventSink.setAccessDelegate(mInternalAccessAdapter);
}
private void setContainerView(ViewGroup newContainerView, AwGLFunctor currentFunctor) {
......
......@@ -35,7 +35,7 @@ import org.chromium.ui.base.EventForwarder;
* the various {@link View} functionality to it.
*/
public class ContentView
extends FrameLayout implements ContentViewCore.InternalAccessDelegate, SmartClipProvider {
extends FrameLayout implements ViewEventSink.InternalAccessDelegate, SmartClipProvider {
private static final String TAG = "cr.ContentView";
// Default value to signal that the ContentView's size need not be overridden.
......@@ -321,7 +321,7 @@ public class ContentView
}
///////////////////////////////////////////////////////////////////////////////////////////////
// Start Implementation of ContentViewCore.InternalAccessDelegate //
// Start Implementation of ViewEventSink.InternalAccessDelegate //
///////////////////////////////////////////////////////////////////////////////////////////////
@Override
......@@ -340,7 +340,7 @@ public class ContentView
}
///////////////////////////////////////////////////////////////////////////////////////////////
// End Implementation of ContentViewCore.InternalAccessDelegate //
// End Implementation of ViewEventSink.InternalAccessDelegate //
///////////////////////////////////////////////////////////////////////////////////////////////
private static class ContentViewApi23 extends ContentView {
......
......@@ -14,7 +14,7 @@ import org.chromium.base.annotations.JNINamespace;
import org.chromium.content.browser.input.ImeAdapterImpl;
import org.chromium.content.browser.webcontents.WebContentsImpl;
import org.chromium.content.browser.webcontents.WebContentsUserData;
import org.chromium.content_public.browser.ContentViewCore;
import org.chromium.content_public.browser.ViewEventSink.InternalAccessDelegate;
import org.chromium.content_public.browser.WebContents;
import org.chromium.content_public.browser.WebContents.UserDataFactory;
import org.chromium.device.gamepad.GamepadList;
......@@ -27,7 +27,7 @@ import org.chromium.ui.base.EventForwarder;
@JNINamespace("content")
public class ContentUiEventHandler {
private final WebContentsImpl mWebContents;
private ContentViewCore.InternalAccessDelegate mEventDelegate;
private InternalAccessDelegate mEventDelegate;
private long mNativeContentUiEventHandler;
private static final class UserDataFactoryLazyHolder {
......@@ -45,7 +45,7 @@ public class ContentUiEventHandler {
mNativeContentUiEventHandler = nativeInit(webContents);
}
public void setEventDelegate(ContentViewCore.InternalAccessDelegate delegate) {
public void setEventDelegate(InternalAccessDelegate delegate) {
mEventDelegate = delegate;
}
......
......@@ -14,7 +14,7 @@ import org.chromium.content.browser.input.TextSuggestionHost;
import org.chromium.content.browser.selection.SelectionPopupControllerImpl;
import org.chromium.content.browser.webcontents.WebContentsImpl;
import org.chromium.content_public.browser.ContentViewCore;
import org.chromium.content_public.browser.ContentViewCore.InternalAccessDelegate;
import org.chromium.content_public.browser.ViewEventSink.InternalAccessDelegate;
import org.chromium.content_public.browser.WebContents;
import org.chromium.content_public.browser.WebContents.UserDataFactory;
import org.chromium.ui.base.ViewAndroidDelegate;
......@@ -84,7 +84,7 @@ public class ContentViewCoreImpl implements ContentViewCore {
SelectPopup.create(context, mWebContents);
Gamepad.create(context, mWebContents);
setContainerViewInternals(internalDispatcher);
ViewEventSinkImpl.from(mWebContents).setAccessDelegate(internalDispatcher);
mWebContents.getRenderCoordinates().setDeviceScaleFactor(
windowAndroid.getDisplay().getDipScale());
......@@ -95,13 +95,6 @@ public class ContentViewCoreImpl implements ContentViewCore {
return mInitialized;
}
@Override
public void setContainerViewInternals(InternalAccessDelegate internalDispatcher) {
GestureListenerManagerImpl.fromWebContents(mWebContents)
.setScrollDelegate(internalDispatcher);
ContentUiEventHandler.fromWebContents(mWebContents).setEventDelegate(internalDispatcher);
}
@Override
public void destroy() {
// This is called to fix crash. See https://crbug.com/803244
......
......@@ -17,9 +17,9 @@ import org.chromium.content.browser.input.ImeAdapterImpl;
import org.chromium.content.browser.selection.SelectionPopupControllerImpl;
import org.chromium.content.browser.webcontents.WebContentsImpl;
import org.chromium.content.browser.webcontents.WebContentsUserData;
import org.chromium.content_public.browser.ContentViewCore.InternalAccessDelegate;
import org.chromium.content_public.browser.GestureListenerManager;
import org.chromium.content_public.browser.GestureStateListener;
import org.chromium.content_public.browser.ViewEventSink.InternalAccessDelegate;
import org.chromium.content_public.browser.WebContents;
import org.chromium.content_public.browser.WebContents.UserDataFactory;
import org.chromium.ui.base.GestureEventType;
......
......@@ -69,6 +69,12 @@ public final class ViewEventSinkImpl implements ViewEventSink, ActivityStateObse
return mContext;
}
@Override
public void setAccessDelegate(ViewEventSink.InternalAccessDelegate accessDelegate) {
GestureListenerManagerImpl.fromWebContents(mWebContents).setScrollDelegate(accessDelegate);
ContentUiEventHandler.fromWebContents(mWebContents).setEventDelegate(accessDelegate);
}
@Override
public void onAttachedToWindow() {
WindowEventObserverManager.from(mWebContents).onAttachedToWindow();
......
......@@ -5,11 +5,9 @@
package org.chromium.content_public.browser;
import android.content.Context;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import org.chromium.content.browser.ContentViewCoreImpl;
import org.chromium.content_public.browser.ViewEventSink.InternalAccessDelegate;
import org.chromium.ui.base.ViewAndroidDelegate;
import org.chromium.ui.base.WindowAndroid;
......@@ -43,44 +41,6 @@ public interface ContentViewCore {
return ContentViewCoreImpl.fromWebContents(webContents);
}
/**
* Interface that consumers of {@link ContentViewCore} must implement to allow the proper
* dispatching of view methods through the containing view.
*
* <p>
* All methods with the "super_" prefix should be routed to the parent of the
* implementing container view.
*/
@SuppressWarnings("javadoc")
public interface InternalAccessDelegate {
/**
* @see View#onKeyUp(keyCode, KeyEvent)
*/
boolean super_onKeyUp(int keyCode, KeyEvent event);
/**
* @see View#dispatchKeyEvent(KeyEvent)
*/
boolean super_dispatchKeyEvent(KeyEvent event);
/**
* @see View#onGenericMotionEvent(MotionEvent)
*/
boolean super_onGenericMotionEvent(MotionEvent event);
/**
* @see View#onScrollChanged(int, int, int, int)
*/
void onScrollChanged(int lPix, int tPix, int oldlPix, int oldtPix);
}
/**
* Set the Container view Internals.
* @param internalDispatcher Handles dispatching all hidden or super methods to the
* containerView.
*/
void setContainerViewInternals(InternalAccessDelegate internalDispatcher);
/**
* Destroy the internal state of the ContentView. This method may only be
* called after the ContentView has been removed from the view system. No
......
......@@ -5,6 +5,8 @@
package org.chromium.content_public.browser;
import android.content.res.Configuration;
import android.view.KeyEvent;
import android.view.MotionEvent;
import org.chromium.content.browser.ViewEventSinkImpl;
......@@ -12,6 +14,37 @@ import org.chromium.content.browser.ViewEventSinkImpl;
* Interface for updating content with view events.
*/
public interface ViewEventSink {
/**
* Interface that consumers of WebContents must implement to allow the proper
* dispatching of view methods through the containing view.
*
* <p>
* All methods with the "super_" prefix should be routed to the parent of the
* implementing container view.
*/
@SuppressWarnings("javadoc")
public interface InternalAccessDelegate {
/**
* @see View#onKeyUp(keyCode, KeyEvent)
*/
boolean super_onKeyUp(int keyCode, KeyEvent event);
/**
* @see View#dispatchKeyEvent(KeyEvent)
*/
boolean super_dispatchKeyEvent(KeyEvent event);
/**
* @see View#onGenericMotionEvent(MotionEvent)
*/
boolean super_onGenericMotionEvent(MotionEvent event);
/**
* @see View#onScrollChanged(int, int, int, int)
*/
void onScrollChanged(int lPix, int tPix, int oldlPix, int oldtPix);
}
/**
* @return {@link ViewEventSink} instance for a given {@link WebContents}.
*/
......@@ -51,6 +84,13 @@ public interface ViewEventSink {
*/
void onConfigurationChanged(Configuration newConfig);
/**
* Set the Container view Internals.
* @param internalDispatcher Handles dispatching all hidden or super methods to the
* containerView.
*/
void setAccessDelegate(InternalAccessDelegate internalDispatcher);
void onPauseForTesting();
void onResumeForTesting();
}
......@@ -23,7 +23,7 @@ import org.chromium.base.test.util.RetryOnFailure;
import org.chromium.base.test.util.UrlUtils;
import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content_public.browser.ContentViewCore.InternalAccessDelegate;
import org.chromium.content_public.browser.ViewEventSink.InternalAccessDelegate;
import org.chromium.content_shell_apk.ContentShellActivityTestRule;
import org.chromium.content_shell_apk.ContentShellActivityTestRule.RerunWithUpdatedContainerView;
......@@ -334,12 +334,11 @@ public class ContentViewScrollingTest {
public void testOnScrollChanged() throws Throwable {
final int scrollToX = mCoordinates.getScrollXPixInt() + 2500;
final int scrollToY = mCoordinates.getScrollYPixInt() + 2500;
final TestInternalAccessDelegate containerViewInternals = new TestInternalAccessDelegate();
final TestInternalAccessDelegate accessDelegate = new TestInternalAccessDelegate();
InstrumentationRegistry.getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
mActivityTestRule.getContentViewCore().setContainerViewInternals(
containerViewInternals);
mActivityTestRule.getViewEventSink().setAccessDelegate(accessDelegate);
}
});
scrollTo(scrollToX, scrollToY);
......@@ -347,7 +346,7 @@ public class ContentViewScrollingTest {
CriteriaHelper.pollInstrumentationThread(new Criteria() {
@Override
public boolean isSatisfied() {
return containerViewInternals.isScrollChanged();
return accessDelegate.isScrollChanged();
}
});
}
......
......@@ -7,7 +7,6 @@ package org.chromium.content.browser.test.util;
import android.content.Context;
import org.chromium.content_public.browser.ContentViewCore;
import org.chromium.content_public.browser.ContentViewCore.InternalAccessDelegate;
/**
* A dummy {@link ContentViewCore} implementation that can be overriden by tests
......@@ -16,9 +15,6 @@ import org.chromium.content_public.browser.ContentViewCore.InternalAccessDelegat
public class TestContentViewCore implements ContentViewCore {
public TestContentViewCore(Context context, String productVersion) {}
@Override
public void setContainerViewInternals(InternalAccessDelegate internalDispatcher) {}
@Override
public void destroy() {}
}
......@@ -33,6 +33,7 @@ import org.chromium.content.browser.webcontents.WebContentsImpl;
import org.chromium.content_public.browser.JavascriptInjector;
import org.chromium.content_public.browser.LoadUrlParams;
import org.chromium.content_public.browser.NavigationController;
import org.chromium.content_public.browser.ViewEventSink;
import org.chromium.content_public.browser.WebContents;
import org.chromium.content_shell.Shell;
import org.chromium.content_shell.ShellViewAndroidDelegate.OnCursorUpdateHelper;
......@@ -143,6 +144,19 @@ public class ContentShellActivityTestRule extends ActivityTestRule<ContentShellA
}
}
/**
* Returns the current {@link ViewEventSink} or null if there is none;
*/
public ViewEventSink getViewEventSink() {
try {
return ThreadUtils.runOnUiThreadBlocking(() -> {
return ViewEventSink.from(getActivity().getActiveShell().getWebContents());
});
} catch (ExecutionException e) {
return null;
}
}
/**
* Returns the WebContents of this Shell.
*/
......
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