summaryrefslogtreecommitdiffstats
path: root/android_webview
diff options
context:
space:
mode:
authormkosiba@chromium.org <mkosiba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-12 15:19:02 +0000
committermkosiba@chromium.org <mkosiba@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-12 15:19:02 +0000
commite7c5b164531f6f447839bd958056c6845aaa232b (patch)
tree71468b0f0d78170dcb5aaa803aaad2eb8d04befc /android_webview
parente1920eaf5b053691b3db3e6ec28538faa0fe7e1d (diff)
downloadchromium_src-e7c5b164531f6f447839bd958056c6845aaa232b.zip
chromium_src-e7c5b164531f6f447839bd958056c6845aaa232b.tar.gz
chromium_src-e7c5b164531f6f447839bd958056c6845aaa232b.tar.bz2
[android] Plumb through page scale to the InProcessViewRenderer.
The InProcessViewRenderer needs to know the current pageScale so that it can correctly convert phsical <-> CSS pixels. BUG=b/9756394 TEST=AndroidWebViewTest Android-only change, trybots are happy with it. NOTRY=true Review URL: https://chromiumcodereview.appspot.com/18242011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@211401 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'android_webview')
-rw-r--r--android_webview/browser/browser_view_renderer.h1
-rw-r--r--android_webview/browser/in_process_view_renderer.cc19
-rw-r--r--android_webview/browser/in_process_view_renderer.h2
-rw-r--r--android_webview/browser/renderer_host/aw_render_view_host_ext.cc2
-rw-r--r--android_webview/browser/renderer_host/aw_render_view_host_ext.h2
-rw-r--r--android_webview/java/src/org/chromium/android_webview/AwContents.java17
-rw-r--r--android_webview/javatests/src/org/chromium/android_webview/test/AndroidScrollIntegrationTest.java102
-rw-r--r--android_webview/native/aw_contents.cc11
-rw-r--r--android_webview/native/aw_contents.h6
9 files changed, 127 insertions, 35 deletions
diff --git a/android_webview/browser/browser_view_renderer.h b/android_webview/browser/browser_view_renderer.h
index 20f3782..bcbc61a 100644
--- a/android_webview/browser/browser_view_renderer.h
+++ b/android_webview/browser/browser_view_renderer.h
@@ -111,6 +111,7 @@ class BrowserViewRenderer {
// Sets the scale for logical<->physical pixel conversions.
virtual void SetDipScale(float dip_scale) = 0;
+ virtual void SetPageScaleFactor(float page_scale_factor) = 0;
// Set the root layer scroll offset to |new_value|.
virtual void ScrollTo(gfx::Vector2d new_value) = 0;
diff --git a/android_webview/browser/in_process_view_renderer.cc b/android_webview/browser/in_process_view_renderer.cc
index dee6c69..7de534c 100644
--- a/android_webview/browser/in_process_view_renderer.cc
+++ b/android_webview/browser/in_process_view_renderer.cc
@@ -156,6 +156,7 @@ InProcessViewRenderer::InProcessViewRenderer(
compositor_(NULL),
visible_(false),
dip_scale_(0.0),
+ page_scale_factor_(1.0),
continuous_invalidate_(false),
block_invalidates_(false),
do_ensure_continuous_invalidation_task_pending_(false),
@@ -506,6 +507,11 @@ void InProcessViewRenderer::SetDipScale(float dip_scale) {
CHECK(dip_scale_ > 0);
}
+void InProcessViewRenderer::SetPageScaleFactor(float page_scale_factor) {
+ page_scale_factor_ = page_scale_factor;
+ CHECK(page_scale_factor_ > 0);
+}
+
void InProcessViewRenderer::ScrollTo(gfx::Vector2d new_value) {
DCHECK(dip_scale_ > 0);
// In general we don't guarantee that the scroll offset transforms are
@@ -515,7 +521,7 @@ void InProcessViewRenderer::ScrollTo(gfx::Vector2d new_value) {
// The reason we explicitly do rounding here is that it seems to yeld the
// most stabile transformation.
gfx::Vector2dF new_value_css = gfx::ToRoundedVector2d(
- gfx::ScaleVector2d(new_value, 1.0f / dip_scale_));
+ gfx::ScaleVector2d(new_value, 1.0f / (dip_scale_ * page_scale_factor_)));
DCHECK(scroll_offset_css_ != new_value_css);
@@ -537,9 +543,10 @@ void InProcessViewRenderer::SetTotalRootLayerScrollOffset(
scroll_offset_css_ = new_value_css;
DCHECK(dip_scale_ > 0);
+ DCHECK(page_scale_factor_ > 0);
- gfx::Vector2d scroll_offset =
- gfx::ToRoundedVector2d(gfx::ScaleVector2d(new_value_css, dip_scale_));
+ gfx::Vector2d scroll_offset = gfx::ToRoundedVector2d(
+ gfx::ScaleVector2d(new_value_css, dip_scale_ * page_scale_factor_));
client_->ScrollContainerViewTo(scroll_offset);
}
@@ -553,10 +560,12 @@ void InProcessViewRenderer::DidOverscroll(
gfx::Vector2dF current_fling_velocity) {
// TODO(mkosiba): Enable this once flinging is handled entirely Java-side.
// DCHECK(current_fling_velocity.IsZero());
+ const float physical_pixel_scale = dip_scale_ * page_scale_factor_;
gfx::Vector2d overscroll_delta = gfx::ToRoundedVector2d(gfx::ScaleVector2d(
- accumulated_overscroll - previous_accumulated_overscroll_, dip_scale_));
+ accumulated_overscroll - previous_accumulated_overscroll_,
+ physical_pixel_scale));
previous_accumulated_overscroll_ +=
- gfx::ScaleVector2d(overscroll_delta, 1.0f / dip_scale_);
+ gfx::ScaleVector2d(overscroll_delta, 1.0f / physical_pixel_scale);
client_->DidOverscroll(overscroll_delta);
}
diff --git a/android_webview/browser/in_process_view_renderer.h b/android_webview/browser/in_process_view_renderer.h
index 8630609..c6f5160 100644
--- a/android_webview/browser/in_process_view_renderer.h
+++ b/android_webview/browser/in_process_view_renderer.h
@@ -46,6 +46,7 @@ class InProcessViewRenderer : public BrowserViewRenderer,
virtual void OnVisibilityChanged(bool visible) OVERRIDE;
virtual void OnSizeChanged(int width, int height) OVERRIDE;
virtual void ScrollTo(gfx::Vector2d new_value) OVERRIDE;
+ virtual void SetPageScaleFactor(float page_scale_factor) OVERRIDE;
virtual void OnAttachedToWindow(int width, int height) OVERRIDE;
virtual void OnDetachedFromWindow() OVERRIDE;
virtual void SetDipScale(float dip_scale) OVERRIDE;
@@ -85,6 +86,7 @@ class InProcessViewRenderer : public BrowserViewRenderer,
bool visible_;
float dip_scale_;
+ float page_scale_factor_;
// When true, we should continuously invalidate and keep drawing, for example
// to drive animation.
diff --git a/android_webview/browser/renderer_host/aw_render_view_host_ext.cc b/android_webview/browser/renderer_host/aw_render_view_host_ext.cc
index 2450092..46bb312 100644
--- a/android_webview/browser/renderer_host/aw_render_view_host_ext.cc
+++ b/android_webview/browser/renderer_host/aw_render_view_host_ext.cc
@@ -140,7 +140,7 @@ void AwRenderViewHostExt::OnUpdateHitTestData(
}
void AwRenderViewHostExt::OnPageScaleFactorChanged(float page_scale_factor) {
- client_->OnPageScaleFactorChanged(page_scale_factor);
+ client_->OnWebLayoutPageScaleFactorChanged(page_scale_factor);
}
} // namespace android_webview
diff --git a/android_webview/browser/renderer_host/aw_render_view_host_ext.h b/android_webview/browser/renderer_host/aw_render_view_host_ext.h
index 85ecfea..1f764f8 100644
--- a/android_webview/browser/renderer_host/aw_render_view_host_ext.h
+++ b/android_webview/browser/renderer_host/aw_render_view_host_ext.h
@@ -23,7 +23,7 @@ namespace android_webview {
class AwRenderViewHostExtClient {
public:
// Called when the RenderView page scale changes.
- virtual void OnPageScaleFactorChanged(float page_scale_factor) = 0;
+ virtual void OnWebLayoutPageScaleFactorChanged(float page_scale_factor) = 0;
protected:
virtual ~AwRenderViewHostExtClient() {}
diff --git a/android_webview/java/src/org/chromium/android_webview/AwContents.java b/android_webview/java/src/org/chromium/android_webview/AwContents.java
index ab05434..61257ea 100644
--- a/android_webview/java/src/org/chromium/android_webview/AwContents.java
+++ b/android_webview/java/src/org/chromium/android_webview/AwContents.java
@@ -325,10 +325,15 @@ public class AwContents {
//--------------------------------------------------------------------------------------------
// NOTE: This content size change notification comes from the compositor and reflects the size
// of the content on screen (but not neccessarily in the renderer main thread).
- private class AwContentSizeChangeListener implements ContentViewCore.ContentSizeChangeListener {
+ private class AwContentUpdateFrameInfoListener
+ implements ContentViewCore.UpdateFrameInfoListener {
@Override
- public void onContentSizeChanged(int widthPix, int heightPix) {
+ public void onFrameInfoUpdated(float widthCss, float heightCss, float pageScaleFactor) {
+ int widthPix = (int) Math.floor(widthCss * mDIPScale * pageScaleFactor);
+ int heightPix = (int) Math.floor(heightCss * mDIPScale * pageScaleFactor);
mScrollOffsetManager.setContentSize(widthPix, heightPix);
+
+ nativeSetDisplayedPageScaleFactor(mNativeAwContents, pageScaleFactor);
}
}
@@ -504,7 +509,7 @@ public class AwContents {
nativeSetJavaPeers(mNativeAwContents, this, mWebContentsDelegate, mContentsClientBridge,
mIoThreadClient, mInterceptNavigationDelegate);
mContentsClient.installWebContentsObserver(mContentViewCore);
- mContentViewCore.setContentSizeChangeListener(new AwContentSizeChangeListener());
+ mContentViewCore.setUpdateFrameInfoListener(new AwContentUpdateFrameInfoListener());
mSettings.setWebContents(nativeWebContents);
nativeSetDipScale(mNativeAwContents, (float) mDIPScale);
}
@@ -1531,9 +1536,9 @@ public class AwContents {
}
@CalledByNative
- private void onPageScaleFactorChanged(float pageScaleFactor) {
+ private void onWebLayoutPageScaleFactorChanged(float webLayoutPageScaleFactor) {
// This change notification comes from the renderer thread, not from the cc/ impl thread.
- mLayoutSizer.onPageScaleChanged(pageScaleFactor);
+ mLayoutSizer.onPageScaleChanged(webLayoutPageScaleFactor);
}
@CalledByNative
@@ -1644,6 +1649,8 @@ public class AwContents {
private native void nativeOnAttachedToWindow(int nativeAwContents, int w, int h);
private native void nativeOnDetachedFromWindow(int nativeAwContents);
private native void nativeSetDipScale(int nativeAwContents, float dipScale);
+ private native void nativeSetDisplayedPageScaleFactor(int nativeAwContents,
+ float pageScaleFactor);
// Returns null if save state fails.
private native byte[] nativeGetOpaqueState(int nativeAwContents);
diff --git a/android_webview/javatests/src/org/chromium/android_webview/test/AndroidScrollIntegrationTest.java b/android_webview/javatests/src/org/chromium/android_webview/test/AndroidScrollIntegrationTest.java
index 9767f2b..2666f58 100644
--- a/android_webview/javatests/src/org/chromium/android_webview/test/AndroidScrollIntegrationTest.java
+++ b/android_webview/javatests/src/org/chromium/android_webview/test/AndroidScrollIntegrationTest.java
@@ -110,17 +110,20 @@ public class AndroidScrollIntegrationTest extends AwTestBase {
};
}
- private String makeTestPage(String onscrollObserver, String firstFrameObserver) {
- String headers =
- "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"> " +
- "<style type=\"text/css\"> " +
- " div { " +
- " width:1000px; " +
- " height:10000px; " +
- " background-color: blue; " +
- " } " +
- "</style> ";
- String content = "<div>test div</div> ";
+ private static final String TEST_PAGE_COMMON_HEADERS =
+ "<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\"> " +
+ "<style type=\"text/css\"> " +
+ " div { " +
+ " width:1000px; " +
+ " height:10000px; " +
+ " background-color: blue; " +
+ " } " +
+ "</style> ";
+ private static final String TEST_PAGE_COMMON_CONTENT = "<div>test div</div> ";
+
+ private String makeTestPage(String onscrollObserver, String firstFrameObserver,
+ String extraContent) {
+ String content = TEST_PAGE_COMMON_CONTENT + extraContent;
if (onscrollObserver != null) {
content +=
"<script> " +
@@ -144,7 +147,7 @@ public class AndroidScrollIntegrationTest extends AwTestBase {
" window.requestAnimationFrame(window.onAnimationFrame); " +
"</script>";
}
- return CommonResources.makeHtmlPageFrom(headers, content);
+ return CommonResources.makeHtmlPageFrom(TEST_PAGE_COMMON_HEADERS, content);
}
private void scrollToOnMainSync(final View view, final int xPix, final int yPix) {
@@ -218,7 +221,7 @@ public class AndroidScrollIntegrationTest extends AwTestBase {
private void loadTestPageAndWaitForFirstFrame(final ScrollTestContainerView testContainerView,
final TestAwContentsClient contentsClient,
- final String onscrollObserverName) throws Exception {
+ final String onscrollObserverName, final String extraContent) throws Exception {
final JavascriptEventObserver firstFrameObserver = new JavascriptEventObserver();
final String firstFrameObserverName = "firstFrameObserver";
enableJavaScriptOnUiThread(testContainerView.getAwContents());
@@ -232,7 +235,8 @@ public class AndroidScrollIntegrationTest extends AwTestBase {
});
loadDataSync(testContainerView.getAwContents(), contentsClient.getOnPageFinishedHelper(),
- makeTestPage(onscrollObserverName, firstFrameObserverName), "text/html", false);
+ makeTestPage(onscrollObserverName, firstFrameObserverName, extraContent),
+ "text/html", false);
// We wait for "a couple" of frames for the active tree in CC to stabilize and for pending
// tree activations to stop clobbering the root scroll layer's scroll offset. This wait
@@ -268,7 +272,7 @@ public class AndroidScrollIntegrationTest extends AwTestBase {
}
});
- loadTestPageAndWaitForFirstFrame(testContainerView, contentsClient, "onscrollObserver");
+ loadTestPageAndWaitForFirstFrame(testContainerView, contentsClient, "onscrollObserver", "");
scrollToOnMainSync(testContainerView, targetScrollXPix, targetScrollYPix);
@@ -293,7 +297,7 @@ public class AndroidScrollIntegrationTest extends AwTestBase {
final int targetScrollYPix = (int) Math.round(targetScrollYCss * deviceDIPScale);
loadDataSync(testContainerView.getAwContents(), contentsClient.getOnPageFinishedHelper(),
- makeTestPage(null, null), "text/html", false);
+ makeTestPage(null, null, ""), "text/html", false);
final CallbackHelper onScrollToCallbackHelper =
testContainerView.getOnScrollToCallbackHelper();
@@ -326,7 +330,7 @@ public class AndroidScrollIntegrationTest extends AwTestBase {
final int maxScrollYPix = (int) Math.round(maxScrollYCss * deviceDIPScale);
loadDataSync(testContainerView.getAwContents(), contentsClient.getOnPageFinishedHelper(),
- makeTestPage(null, null), "text/html", false);
+ makeTestPage(null, null, ""), "text/html", false);
setMaxScrollOnMainSync(testContainerView, maxScrollXPix, maxScrollYPix);
@@ -367,7 +371,7 @@ public class AndroidScrollIntegrationTest extends AwTestBase {
setMaxScrollOnMainSync(testContainerView, maxScrollXPix, maxScrollYPix);
- loadTestPageAndWaitForFirstFrame(testContainerView, contentsClient, null);
+ loadTestPageAndWaitForFirstFrame(testContainerView, contentsClient, null, "");
final CallbackHelper onScrollToCallbackHelper =
testContainerView.getOnScrollToCallbackHelper();
@@ -401,7 +405,7 @@ public class AndroidScrollIntegrationTest extends AwTestBase {
final int overScrollDeltaX = 30;
final int oneStep = 1;
- loadTestPageAndWaitForFirstFrame(testContainerView, contentsClient, null);
+ loadTestPageAndWaitForFirstFrame(testContainerView, contentsClient, null, "");
// Scroll separately in different dimensions because of vertical/horizontal scroll
// snap.
@@ -433,7 +437,7 @@ public class AndroidScrollIntegrationTest extends AwTestBase {
final int overScrollDeltaY = 30;
final int oneStep = 1;
- loadTestPageAndWaitForFirstFrame(testContainerView, contentsClient, null);
+ loadTestPageAndWaitForFirstFrame(testContainerView, contentsClient, null, "");
int overScrollCallCount = overScrollByCallbackHelper.getCallCount();
AwTestTouchUtils.dragCompleteView(testContainerView,
@@ -446,4 +450,62 @@ public class AndroidScrollIntegrationTest extends AwTestBase {
assertScrollOnMainSync(testContainerView, 0, 0);
}
+
+ @SmallTest
+ @Feature({"AndroidWebView"})
+ public void testScrollToBottomAtPageScaleX0dot5() throws Throwable {
+ // The idea behind this test is to check that scrolling to the bottom on ther renderer side
+ // results in the view also reporting as being scrolled to the bottom.
+ final TestAwContentsClient contentsClient = new TestAwContentsClient();
+ final ScrollTestContainerView testContainerView =
+ (ScrollTestContainerView) createAwTestContainerViewOnMainSync(contentsClient);
+ enableJavaScriptOnUiThread(testContainerView.getAwContents());
+
+ final int targetScrollXCss = 1000;
+ final int targetScrollYCss = 10000;
+
+ final String pageHeaders =
+ "<meta name=\"viewport\" content=\"width=device-width, initial-scale=0.6\"> " +
+ "<style type=\"text/css\"> " +
+ " div { " +
+ " width:1000px; " +
+ " height:10000px; " +
+ " background-color: blue; " +
+ " } " +
+ " body { " +
+ " margin: 0px; " +
+ " padding: 0px; " +
+ " } " +
+ "</style> ";
+
+ loadDataSync(testContainerView.getAwContents(), contentsClient.getOnPageFinishedHelper(),
+ CommonResources.makeHtmlPageFrom(pageHeaders, TEST_PAGE_COMMON_CONTENT),
+ "text/html", false);
+
+ final double deviceDIPScale =
+ DeviceDisplayInfo.create(testContainerView.getContext()).getDIPScale();
+
+ final CallbackHelper onScrollToCallbackHelper =
+ testContainerView.getOnScrollToCallbackHelper();
+ final int scrollToCallCount = onScrollToCallbackHelper.getCallCount();
+ executeJavaScriptAndWaitForResult(testContainerView.getAwContents(), contentsClient,
+ "window.scrollTo(" + targetScrollXCss + "," + targetScrollYCss + ")");
+ onScrollToCallbackHelper.waitForCallback(scrollToCallCount);
+
+ getInstrumentation().runOnMainSync(new Runnable() {
+ @Override
+ public void run() {
+ AwContents awContents = testContainerView.getAwContents();
+ int maxHorizontal = awContents.computeHorizontalScrollRange() -
+ testContainerView.getWidth();
+ int maxVertical = awContents.computeVerticalScrollRange() -
+ testContainerView.getHeight();
+ // Due to rounding going from CSS -> physical pixels it is possible that more than
+ // one physical pixels corespond to one CSS pixel, which is why we can't do a
+ // simple equality test here.
+ assertTrue(maxHorizontal - awContents.computeHorizontalScrollOffset() < 3);
+ assertTrue(maxVertical - awContents.computeVerticalScrollOffset() < 3);
+ }
+ });
+ }
}
diff --git a/android_webview/native/aw_contents.cc b/android_webview/native/aw_contents.cc
index 357e072..ec95670 100644
--- a/android_webview/native/aw_contents.cc
+++ b/android_webview/native/aw_contents.cc
@@ -714,16 +714,23 @@ void AwContents::SetDipScale(JNIEnv* env, jobject obj, jfloat dipScale) {
browser_view_renderer_->SetDipScale(dipScale);
}
+void AwContents::SetDisplayedPageScaleFactor(JNIEnv* env,
+ jobject obj,
+ jfloat pageScaleFactor) {
+ browser_view_renderer_->SetPageScaleFactor(pageScaleFactor);
+}
+
void AwContents::ScrollTo(JNIEnv* env, jobject obj, jint xPix, jint yPix) {
browser_view_renderer_->ScrollTo(gfx::Vector2d(xPix, yPix));
}
-void AwContents::OnPageScaleFactorChanged(float page_scale_factor) {
+void AwContents::OnWebLayoutPageScaleFactorChanged(float page_scale_factor) {
JNIEnv* env = AttachCurrentThread();
ScopedJavaLocalRef<jobject> obj = java_ref_.get(env);
if (obj.is_null())
return;
- Java_AwContents_onPageScaleFactorChanged(env, obj.obj(), page_scale_factor);
+ Java_AwContents_onWebLayoutPageScaleFactorChanged(env, obj.obj(),
+ page_scale_factor);
}
ScopedJavaLocalRef<jobject> AwContents::CapturePicture(JNIEnv* env,
diff --git a/android_webview/native/aw_contents.h b/android_webview/native/aw_contents.h
index 7a44f4f..484ea10 100644
--- a/android_webview/native/aw_contents.h
+++ b/android_webview/native/aw_contents.h
@@ -140,7 +140,8 @@ class AwContents : public FindHelper::Listener,
const bool precomposed) OVERRIDE;
// AwRenderViewHostExtClient implementation.
- virtual void OnPageScaleFactorChanged(float page_scale_factor) OVERRIDE;
+ virtual void OnWebLayoutPageScaleFactorChanged(
+ float page_scale_factor) OVERRIDE;
// BrowserViewRenderer::Client implementation.
virtual bool RequestDrawGL(jobject canvas) OVERRIDE;
@@ -156,6 +157,9 @@ class AwContents : public FindHelper::Listener,
void ScrollTo(JNIEnv* env, jobject obj, jint xPix, jint yPix);
void SetDipScale(JNIEnv* env, jobject obj, jfloat dipScale);
+ void SetDisplayedPageScaleFactor(JNIEnv* env,
+ jobject obj,
+ jfloat pageScaleFactor);
void SetSaveFormData(bool enabled);