summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
authoryusufo@chromium.org <yusufo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-09 22:31:45 +0000
committeryusufo@chromium.org <yusufo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-09 22:31:45 +0000
commit1521b2a1346ad796deea70fee4b4ffa029f236d8 (patch)
tree945cbfc681621583a7eb96cb8449a5b770054335 /content
parentd58499a6e4207df8a2727c62e92411b850c9895e (diff)
downloadchromium_src-1521b2a1346ad796deea70fee4b4ffa029f236d8.zip
chromium_src-1521b2a1346ad796deea70fee4b4ffa029f236d8.tar.gz
chromium_src-1521b2a1346ad796deea70fee4b4ffa029f236d8.tar.bz2
Upstream more ContentView methods
Upstream ContentView methods that has COntentViewCore counterparts upstream. These are just waiting for the ContentView version to link them to the Android View hierarchy BUG=137571 Review URL: https://chromiumcodereview.appspot.com/11038052 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@160954 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r--content/browser/android/content_view_core_impl.cc15
-rw-r--r--content/browser/android/content_view_core_impl.h2
-rw-r--r--content/public/android/java/src/org/chromium/content/browser/ContentView.java106
-rw-r--r--content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java85
4 files changed, 191 insertions, 17 deletions
diff --git a/content/browser/android/content_view_core_impl.cc b/content/browser/android/content_view_core_impl.cc
index 1908427..d1cf353 100644
--- a/content/browser/android/content_view_core_impl.cc
+++ b/content/browser/android/content_view_core_impl.cc
@@ -758,6 +758,21 @@ void ContentViewCoreImpl::RemoveJavascriptInterface(JNIEnv* env,
ConvertJavaStringToUTF16(env, name));
}
+void ContentViewCoreImpl::UpdateVSyncParameters(JNIEnv* env, jobject /* obj */,
+ jlong timebase_micros,
+ jlong interval_micros) {
+ RenderWidgetHostViewAndroid* view = GetRenderWidgetHostViewAndroid();
+ if (!view)
+ return;
+
+ RenderWidgetHostImpl* host = RenderWidgetHostImpl::From(
+ view->GetRenderWidgetHost());
+
+ host->UpdateVSyncParameters(
+ base::TimeTicks::FromInternalValue(timebase_micros),
+ base::TimeDelta::FromMicroseconds(interval_micros));
+}
+
void ContentViewCoreImpl::ScrollFocusedEditableNodeIntoView(JNIEnv* env,
jobject obj) {
RenderViewHost* host = web_contents_->GetRenderViewHost();
diff --git a/content/browser/android/content_view_core_impl.h b/content/browser/android/content_view_core_impl.h
index 02fbab4..4a60213 100644
--- a/content/browser/android/content_view_core_impl.h
+++ b/content/browser/android/content_view_core_impl.h
@@ -166,6 +166,8 @@ class ContentViewCoreImpl : public ContentViewCore,
jboolean require_annotation);
void RemoveJavascriptInterface(JNIEnv* env, jobject obj, jstring name);
int GetNavigationHistory(JNIEnv* env, jobject obj, jobject context);
+ void UpdateVSyncParameters(JNIEnv* env, jobject obj, jlong timebase_micros,
+ jlong interval_micros);
// --------------------------------------------------------------------------
// Public methods that call to Java via JNI
diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentView.java b/content/public/android/java/src/org/chromium/content/browser/ContentView.java
index c97c5b2..6d3ece5 100644
--- a/content/public/android/java/src/org/chromium/content/browser/ContentView.java
+++ b/content/public/android/java/src/org/chromium/content/browser/ContentView.java
@@ -9,6 +9,7 @@ import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Canvas;
+import android.graphics.Rect;
import android.os.Build;
import android.util.AttributeSet;
import android.view.KeyEvent;
@@ -24,6 +25,7 @@ import android.widget.FrameLayout;
import java.util.ArrayList;
import org.chromium.content.browser.ContentViewCore;
+import org.chromium.content.common.TraceEvent;
import org.chromium.ui.gfx.NativeWindow;
/**
@@ -417,7 +419,11 @@ public class ContentView extends FrameLayout implements ContentViewCore.Internal
* @VisibleForTesting
*/
public void fling(long timeMs, int x, int y, int velocityX, int velocityY) {
- // TODO(nileshagrawal): Implement this.
+ mContentViewCore.getContentViewGestureHandler().fling(timeMs, x, y, velocityX, velocityY);
+ }
+
+ void endFling(long timeMs) {
+ mContentViewCore.getContentViewGestureHandler().endFling(timeMs);
}
/**
@@ -549,15 +555,101 @@ public class ContentView extends FrameLayout implements ContentViewCore.Internal
}
@Override
+ protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
+ TraceEvent.begin();
+ super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
+ mContentViewCore.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
+ TraceEvent.end();
+ }
+
+ @Override
+ public boolean onKeyUp(int keyCode, KeyEvent event) {
+ return mContentViewCore.onKeyUp(keyCode, event);
+ }
+
+ @Override
+ public boolean dispatchKeyEventPreIme(KeyEvent event) {
+ return mContentViewCore.dispatchKeyEventPreIme(event);
+ }
+
+ @Override
+ public boolean dispatchKeyEvent(KeyEvent event) {
+ return mContentViewCore.dispatchKeyEvent(event);
+ }
+
+ @Override
public boolean onTouchEvent(MotionEvent event) {
return mContentViewCore.onTouchEvent(event);
}
+ /**
+ * Mouse move events are sent on hover enter, hover move and hover exit.
+ * They are sent on hover exit because sometimes it acts as both a hover
+ * move and hover exit.
+ */
+ @Override
+ public boolean onHoverEvent(MotionEvent event) {
+ return mContentViewCore.onHoverEvent(event);
+ }
+
+ @Override
+ public boolean onGenericMotionEvent(MotionEvent event) {
+ return mContentViewCore.onGenericMotionEvent(event);
+ }
+
@Override
protected void onConfigurationChanged(Configuration newConfig) {
mContentViewCore.onConfigurationChanged(newConfig);
}
+ /**
+ * Currently the ContentView scrolling happens in the native side. In
+ * the Java view system, it is always pinned at (0, 0). scrollBy() and scrollTo()
+ * are overridden, so that View's mScrollX and mScrollY will be unchanged at
+ * (0, 0). This is critical for drawing ContentView correctly.
+ */
+ @Override
+ public void scrollBy(int x, int y) {
+ mContentViewCore.scrollBy(x, y);
+ }
+
+ @Override
+ public void scrollTo(int x, int y) {
+ mContentViewCore.scrollTo(x, y);
+ }
+
+ @Override
+ protected int computeHorizontalScrollExtent() {
+ // TODO (dtrainor): Need to expose scroll events properly to public. Either make getScroll*
+ // work or expose computeHorizontalScrollOffset()/computeVerticalScrollOffset as public.
+ return mContentViewCore.computeHorizontalScrollExtent();
+ }
+
+ @Override
+ protected int computeHorizontalScrollOffset() {
+ return mContentViewCore.computeHorizontalScrollOffset();
+ }
+
+ @Override
+ protected int computeHorizontalScrollRange() {
+ return mContentViewCore.computeHorizontalScrollRange();
+ }
+
+ @Override
+ protected int computeVerticalScrollExtent() {
+ return mContentViewCore.computeVerticalScrollExtent();
+ }
+
+ @Override
+ protected int computeVerticalScrollOffset() {
+ return mContentViewCore.computeVerticalScrollOffset();
+ }
+
+ @Override
+ protected int computeVerticalScrollRange() {
+ return mContentViewCore.computeVerticalScrollRange();
+ }
+
// End FrameLayout overrides.
@Override
@@ -584,6 +676,10 @@ public class ContentView extends FrameLayout implements ContentViewCore.Internal
mContentViewCore.onInitializeAccessibilityNodeInfo(info);
}
+ /**
+ * Fills in scrolling values for AccessibilityEvents.
+ * @param event Event being fired.
+ */
@Override
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
super.onInitializeAccessibilityEvent(event);
@@ -755,6 +851,14 @@ public class ContentView extends FrameLayout implements ContentViewCore.Internal
}
/**
+ * Return the current scale of the WebView
+ * @return The current scale.
+ */
+ public float getScale() {
+ return mContentViewCore.getScale();
+ }
+
+ /**
* If the view is ready to draw contents to the screen. In hardware mode,
* the initialization of the surface texture may not occur until after the
* view has been added to the layout. This method will return {@code true}
diff --git a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
index 9219bbb..f6b9d8d 100644
--- a/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
+++ b/content/public/android/java/src/org/chromium/content/browser/ContentViewCore.java
@@ -18,6 +18,7 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.ResultReceiver;
+import android.os.SystemClock;
import android.util.Log;
import android.view.ActionMode;
import android.view.InputDevice;
@@ -157,6 +158,15 @@ public class ContentViewCore implements MotionEventDelegate {
// Native pointer to C++ ContentViewCoreImpl object which will be set by nativeInit().
private int mNativeContentViewCore = 0;
+ // The vsync monitor is used to lock the compositor to the display refresh rate.
+ private VSyncMonitor mVSyncMonitor;
+
+ // The VSyncMonitor gives the timebase for the actual vsync, but we don't want render until
+ // we have had a chance for input events to propagate to the compositor thread. This takes
+ // 3 ms typically, so we adjust the vsync timestamps forward by a bit to give input events a
+ // chance to arrive.
+ private static final long INPUT_EVENT_LAG_FROM_VSYNC_MICROSECONDS = 3200;
+
private ContentViewGestureHandler mContentViewGestureHandler;
private ZoomManager mZoomManager;
@@ -205,6 +215,23 @@ public class ContentViewCore implements MotionEventDelegate {
// Whether a physical keyboard is connected.
private boolean mKeyboardConnected;
+ private final VSyncMonitor.Listener mVSyncListener = new VSyncMonitor.Listener() {
+ @Override
+ public void onVSync(VSyncMonitor monitor, long vsyncTimeMicros) {
+ TraceEvent.instant("VSync");
+ if (mNativeContentViewCore == 0 || mVSyncMonitor == null) {
+ return;
+ }
+ // Compensate for input event lag. Input events are delivered immediately on pre-JB
+ // releases, so this adjustment is only done for later versions.
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ vsyncTimeMicros += INPUT_EVENT_LAG_FROM_VSYNC_MICROSECONDS;
+ }
+ nativeUpdateVSyncParameters(mNativeContentViewCore, vsyncTimeMicros,
+ mVSyncMonitor.getVSyncPeriodInMicroseconds());
+ }
+ };
+
// The AccessibilityInjector that handles loading Accessibility scripts into the web page.
private AccessibilityInjector mAccessibilityInjector;
@@ -288,15 +315,16 @@ public class ContentViewCore implements MotionEventDelegate {
return mContainerView;
}
- private ImeAdapter createImeAdapter(Context context) {
+ private ImeAdapter createImeAdapter(Context context) {
return new ImeAdapter(context, getSelectionHandleController(),
getInsertionHandleController(),
new ImeAdapter.ViewEmbedder() {
@Override
public void onImeEvent(boolean isFinish) {
getContentViewClient().onImeEvent();
- // TODO(olilan): Add undoScrollFocusedEditableNodeIntoViewIfNeeded
- // call when available.
+ if (!isFinish) {
+ undoScrollFocusedEditableNodeIntoViewIfNeeded(false);
+ }
}
@Override
@@ -482,6 +510,7 @@ public class ContentViewCore implements MotionEventDelegate {
mImeAdapter = createImeAdapter(mContext);
mKeyboardConnected = mContainerView.getResources().getConfiguration().keyboard
!= Configuration.KEYBOARD_NOKEYS;
+ mVSyncMonitor = new VSyncMonitor(mContext, mContainerView, mVSyncListener);
TraceEvent.end();
}
@@ -539,6 +568,7 @@ public class ContentViewCore implements MotionEventDelegate {
// Do not propagate the destroy() to settings, as the client may still hold a reference to
// that and could still be using it.
mContentSettings = null;
+ mVSyncMonitor.stop();
}
/**
@@ -895,14 +925,17 @@ public class ContentViewCore implements MotionEventDelegate {
public void onActivityPause() {
TraceEvent.begin();
hidePopupDialog();
+ nativeOnHide(mNativeContentViewCore);
setAccessibilityState(false);
TraceEvent.end();
+ mVSyncMonitor.stop();
}
/**
* This method should be called when the containing activity is resumed.
*/
public void onActivityResume() {
+ nativeOnShow(mNativeContentViewCore);
setAccessibilityState(true);
}
@@ -910,6 +943,7 @@ public class ContentViewCore implements MotionEventDelegate {
* To be called when the ContentView is shown.
*/
public void onShow() {
+ nativeOnShow(mNativeContentViewCore);
setAccessibilityState(true);
}
@@ -919,6 +953,8 @@ public class ContentViewCore implements MotionEventDelegate {
public void onHide() {
hidePopupDialog();
setAccessibilityState(false);
+ nativeOnHide(mNativeContentViewCore);
+ mVSyncMonitor.stop();
}
/**
@@ -1184,12 +1220,12 @@ public class ContentViewCore implements MotionEventDelegate {
return mContainerViewInternals.super_onGenericMotionEvent(event);
}
- // Note: Currently the ContentView scrolling happens in the native side. In
- // the Java view system, it is always pinned at (0, 0). Override scrollBy()
- // and scrollTo(), so that View's mScrollX and mScrollY will be unchanged at
- // (0, 0). This is critical for drawing ContentView correctly.
/**
* @see View#scrollBy(int, int)
+ * Currently the ContentView scrolling happens in the native side. In
+ * the Java view system, it is always pinned at (0, 0). scrollBy() and scrollTo()
+ * are overridden, so that View's mScrollX and mScrollY will be unchanged at
+ * (0, 0). This is critical for drawing ContentView correctly.
*/
public void scrollBy(int x, int y) {
if (mNativeContentViewCore != 0) {
@@ -1584,11 +1620,6 @@ public class ContentViewCore implements MotionEventDelegate {
getContentViewClient().onEvaluateJavaScriptResult(id, jsonResult);
}
- @CalledByNative
- private void startContentIntent(String contentUrl) {
- getContentViewClient().onStartContentIntent(getContext(), contentUrl);
- }
-
/**
* @return Whether a reload happens when this ContentView is activated.
*/
@@ -1756,7 +1787,7 @@ public class ContentViewCore implements MotionEventDelegate {
}
/**
- * Return the current scale of the WebView
+ * Return the current scale of the ContentView.
* @return The current scale.
*/
public float getScale() {
@@ -1782,6 +1813,11 @@ public class ContentViewCore implements MotionEventDelegate {
return false;
}
+ @CalledByNative
+ private void startContentIntent(String contentUrl) {
+ getContentViewClient().onStartContentIntent(getContext(), contentUrl);
+ }
+
/**
* Determines whether or not this ContentViewCore can handle this accessibility action.
* @param action The action to perform.
@@ -1814,9 +1850,6 @@ public class ContentViewCore implements MotionEventDelegate {
*/
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
mAccessibilityInjector.onInitializeAccessibilityNodeInfo(info);
-
- // TODO(dtrainor): Upstream accessibility scrolling event information once that data is
- // available in ContentViewCore. Currently internal scrolling variables aren't upstreamed.
}
/**
@@ -1824,6 +1857,23 @@ public class ContentViewCore implements MotionEventDelegate {
*/
public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
event.setClassName(this.getClass().getName());
+
+ // Identify where the top-left of the screen currently points to.
+ event.setScrollX(mNativeScrollX);
+ event.setScrollY(mNativeScrollY);
+
+ // The maximum scroll values are determined by taking the content dimensions and
+ // subtracting off the actual dimensions of the ChromeView.
+ int maxScrollX = Math.max(0, mContentWidth - getWidth());
+ int maxScrollY = Math.max(0, mContentHeight - getHeight());
+ event.setScrollable(maxScrollX > 0 || maxScrollY > 0);
+
+ // Setting the maximum scroll values requires API level 15 or higher.
+ final int SDK_VERSION_REQUIRED_TO_SET_SCROLL = 15;
+ if (Build.VERSION.SDK_INT >= SDK_VERSION_REQUIRED_TO_SET_SCROLL) {
+ event.setMaxScrollX(maxScrollX);
+ event.setMaxScrollY(maxScrollY);
+ }
}
/**
@@ -2022,4 +2072,7 @@ public class ContentViewCore implements MotionEventDelegate {
private native void nativeRemoveJavascriptInterface(int nativeContentViewCoreImpl, String name);
private native int nativeGetNavigationHistory(int nativeContentViewCoreImpl, Object context);
+
+ private native void nativeUpdateVSyncParameters(int nativeContentViewCoreImpl,
+ long timebaseMicros, long intervalMicros);
}