| OLD | NEW |
| 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.android_webview; | 5 package org.chromium.android_webview; |
| 6 | 6 |
| 7 import android.content.pm.PackageManager; | 7 import android.content.pm.PackageManager; |
| 8 import android.content.res.Configuration; | 8 import android.content.res.Configuration; |
| 9 import android.graphics.Bitmap; | 9 import android.graphics.Bitmap; |
| 10 import android.graphics.Canvas; | 10 import android.graphics.Canvas; |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 // Bound method for suppling Picture instances to the AwContentsClient. Will
be null if the | 178 // Bound method for suppling Picture instances to the AwContentsClient. Will
be null if the |
| 179 // picture listener API has not yet been enabled, or if it is using invalida
tion-only mode. | 179 // picture listener API has not yet been enabled, or if it is using invalida
tion-only mode. |
| 180 private Callable<Picture> mPictureListenerContentProvider; | 180 private Callable<Picture> mPictureListenerContentProvider; |
| 181 | 181 |
| 182 private boolean mContainerViewFocused; | 182 private boolean mContainerViewFocused; |
| 183 private boolean mWindowFocused; | 183 private boolean mWindowFocused; |
| 184 | 184 |
| 185 private boolean mClearViewActive; | 185 private boolean mClearViewActive; |
| 186 private boolean mPictureListenerEnabled; | 186 private boolean mPictureListenerEnabled; |
| 187 | 187 |
| 188 // These come from the compositor and are updated immediately (in contrast t
o the values in |
| 189 // ContentViewCore, which are updated at end of every frame). |
| 190 private float mPageScaleFactor = 1.0f; |
| 191 private float mContentWidthDip; |
| 192 private float mContentHeightDip; |
| 193 |
| 188 private AwAutofillManagerDelegate mAwAutofillManagerDelegate; | 194 private AwAutofillManagerDelegate mAwAutofillManagerDelegate; |
| 189 | 195 |
| 190 private static final class DestroyRunnable implements Runnable { | 196 private static final class DestroyRunnable implements Runnable { |
| 191 private int mNativeAwContents; | 197 private int mNativeAwContents; |
| 192 private DestroyRunnable(int nativeAwContents) { | 198 private DestroyRunnable(int nativeAwContents) { |
| 193 mNativeAwContents = nativeAwContents; | 199 mNativeAwContents = nativeAwContents; |
| 194 } | 200 } |
| 195 @Override | 201 @Override |
| 196 public void run() { | 202 public void run() { |
| 197 // This is a no-op if not currently attached. | 203 // This is a no-op if not currently attached. |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 mInternalAccessAdapter.setMeasuredDimension(measuredWidth, measuredH
eight); | 354 mInternalAccessAdapter.setMeasuredDimension(measuredWidth, measuredH
eight); |
| 349 } | 355 } |
| 350 | 356 |
| 351 @Override | 357 @Override |
| 352 public void setFixedLayoutSize(int widthDip, int heightDip) { | 358 public void setFixedLayoutSize(int widthDip, int heightDip) { |
| 353 nativeSetFixedLayoutSize(mNativeAwContents, widthDip, heightDip); | 359 nativeSetFixedLayoutSize(mNativeAwContents, widthDip, heightDip); |
| 354 } | 360 } |
| 355 } | 361 } |
| 356 | 362 |
| 357 //--------------------------------------------------------------------------
------------------ | 363 //--------------------------------------------------------------------------
------------------ |
| 358 // NOTE: This content size change notification comes from the compositor and
reflects the size | |
| 359 // of the content on screen (but not neccessarily in the renderer main threa
d). | |
| 360 private class AwContentUpdateFrameInfoListener | |
| 361 implements ContentViewCore.UpdateFrameInfoListener { | |
| 362 @Override | |
| 363 public void onFrameInfoUpdated(float widthCss, float heightCss, float pa
geScaleFactor) { | |
| 364 if (mNativeAwContents == 0) return; | |
| 365 int widthPix = (int) Math.floor(widthCss * mDIPScale * pageScaleFact
or); | |
| 366 int heightPix = (int) Math.floor(heightCss * mDIPScale * pageScaleFa
ctor); | |
| 367 mScrollOffsetManager.setContentSize(widthPix, heightPix); | |
| 368 | |
| 369 nativeSetDisplayedPageScaleFactor(mNativeAwContents, pageScaleFactor
); | |
| 370 } | |
| 371 } | |
| 372 | |
| 373 //--------------------------------------------------------------------------
------------------ | |
| 374 private class AwScrollOffsetManagerDelegate implements AwScrollOffsetManager
.Delegate { | 364 private class AwScrollOffsetManagerDelegate implements AwScrollOffsetManager
.Delegate { |
| 375 @Override | 365 @Override |
| 376 public void overScrollContainerViewBy(int deltaX, int deltaY, int scroll
X, int scrollY, | 366 public void overScrollContainerViewBy(int deltaX, int deltaY, int scroll
X, int scrollY, |
| 377 int scrollRangeX, int scrollRangeY, boolean isTouchEvent) { | 367 int scrollRangeX, int scrollRangeY, boolean isTouchEvent) { |
| 378 mInternalAccessAdapter.overScrollBy(deltaX, deltaY, scrollX, scrollY
, | 368 mInternalAccessAdapter.overScrollBy(deltaX, deltaY, scrollX, scrollY
, |
| 379 scrollRangeX, scrollRangeY, 0, 0, isTouchEvent); | 369 scrollRangeX, scrollRangeY, 0, 0, isTouchEvent); |
| 380 } | 370 } |
| 381 | 371 |
| 382 @Override | 372 @Override |
| 383 public void scrollContainerViewTo(int x, int y) { | 373 public void scrollContainerViewTo(int x, int y) { |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 mCleanupReference = new CleanupReference(this, new DestroyRunnable(mNati
veAwContents)); | 550 mCleanupReference = new CleanupReference(this, new DestroyRunnable(mNati
veAwContents)); |
| 561 | 551 |
| 562 int nativeWebContents = nativeGetWebContents(mNativeAwContents); | 552 int nativeWebContents = nativeGetWebContents(mNativeAwContents); |
| 563 mContentViewCore = createAndInitializeContentViewCore( | 553 mContentViewCore = createAndInitializeContentViewCore( |
| 564 mContainerView, mInternalAccessAdapter, nativeWebContents, | 554 mContainerView, mInternalAccessAdapter, nativeWebContents, |
| 565 new AwGestureStateListener(), mContentsClient.getContentViewClie
nt(), | 555 new AwGestureStateListener(), mContentsClient.getContentViewClie
nt(), |
| 566 mZoomControls); | 556 mZoomControls); |
| 567 nativeSetJavaPeers(mNativeAwContents, this, mWebContentsDelegate, mConte
ntsClientBridge, | 557 nativeSetJavaPeers(mNativeAwContents, this, mWebContentsDelegate, mConte
ntsClientBridge, |
| 568 mIoThreadClient, mInterceptNavigationDelegate); | 558 mIoThreadClient, mInterceptNavigationDelegate); |
| 569 mContentsClient.installWebContentsObserver(mContentViewCore); | 559 mContentsClient.installWebContentsObserver(mContentViewCore); |
| 570 mContentViewCore.setUpdateFrameInfoListener(new AwContentUpdateFrameInfo
Listener()); | |
| 571 mSettings.setWebContents(nativeWebContents); | 560 mSettings.setWebContents(nativeWebContents); |
| 572 nativeSetDipScale(mNativeAwContents, (float) mDIPScale); | 561 nativeSetDipScale(mNativeAwContents, (float) mDIPScale); |
| 573 updateGlobalVisibleRect(); | 562 updateGlobalVisibleRect(); |
| 574 | 563 |
| 575 // The only call to onShow. onHide should never be called. | 564 // The only call to onShow. onHide should never be called. |
| 576 mContentViewCore.onShow(); | 565 mContentViewCore.onShow(); |
| 577 } | 566 } |
| 578 | 567 |
| 579 /** | 568 /** |
| 580 * Called on the "source" AwContents that is opening the popup window to | 569 * Called on the "source" AwContents that is opening the popup window to |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 mScrollOffsetManager.computeMaximumVerticalScrollOffset()))
{ | 738 mScrollOffsetManager.computeMaximumVerticalScrollOffset()))
{ |
| 750 mContainerView.invalidate(); | 739 mContainerView.invalidate(); |
| 751 } | 740 } |
| 752 } | 741 } |
| 753 | 742 |
| 754 public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { | 743 public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 755 mLayoutSizer.onMeasure(widthMeasureSpec, heightMeasureSpec); | 744 mLayoutSizer.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 756 } | 745 } |
| 757 | 746 |
| 758 public int getContentHeightCss() { | 747 public int getContentHeightCss() { |
| 759 return (int) Math.ceil(mContentViewCore.getContentHeightCss()); | 748 return (int) Math.ceil(mContentHeightDip); |
| 760 } | 749 } |
| 761 | 750 |
| 762 public int getContentWidthCss() { | 751 public int getContentWidthCss() { |
| 763 return (int) Math.ceil(mContentViewCore.getContentWidthCss()); | 752 return (int) Math.ceil(mContentWidthDip); |
| 764 } | 753 } |
| 765 | 754 |
| 766 public Picture capturePicture() { | 755 public Picture capturePicture() { |
| 767 if (mNativeAwContents == 0) return null; | 756 if (mNativeAwContents == 0) return null; |
| 768 return new AwPicture(nativeCapturePicture(mNativeAwContents, | 757 return new AwPicture(nativeCapturePicture(mNativeAwContents, |
| 769 mScrollOffsetManager.computeHorizontalScrollRange(), | 758 mScrollOffsetManager.computeHorizontalScrollRange(), |
| 770 mScrollOffsetManager.computeVerticalScrollRange())); | 759 mScrollOffsetManager.computeVerticalScrollRange())); |
| 771 } | 760 } |
| 772 | 761 |
| 773 public void clearView() { | 762 public void clearView() { |
| (...skipping 564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1338 msg.sendToTarget(); | 1327 msg.sendToTarget(); |
| 1339 } | 1328 } |
| 1340 | 1329 |
| 1341 /** | 1330 /** |
| 1342 * @see android.webkit.WebView#getScale() | 1331 * @see android.webkit.WebView#getScale() |
| 1343 * | 1332 * |
| 1344 * Please note that the scale returned is the page scale multiplied by | 1333 * Please note that the scale returned is the page scale multiplied by |
| 1345 * the screen density factor. See CTS WebViewTest.testSetInitialScale. | 1334 * the screen density factor. See CTS WebViewTest.testSetInitialScale. |
| 1346 */ | 1335 */ |
| 1347 public float getScale() { | 1336 public float getScale() { |
| 1348 return (float)(mContentViewCore.getScale() * mDIPScale); | 1337 return (float)(mPageScaleFactor * mDIPScale); |
| 1349 } | 1338 } |
| 1350 | 1339 |
| 1351 /** | 1340 /** |
| 1352 * @see android.webkit.WebView#flingScroll(int, int) | 1341 * @see android.webkit.WebView#flingScroll(int, int) |
| 1353 */ | 1342 */ |
| 1354 public void flingScroll(int velocityX, int velocityY) { | 1343 public void flingScroll(int velocityX, int velocityY) { |
| 1355 mScrollOffsetManager.flingScroll(velocityX, velocityY); | 1344 mScrollOffsetManager.flingScroll(velocityX, velocityY); |
| 1356 } | 1345 } |
| 1357 | 1346 |
| 1358 /** | 1347 /** |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1816 mLayoutSizer.onPageScaleChanged(webLayoutPageScaleFactor); | 1805 mLayoutSizer.onPageScaleChanged(webLayoutPageScaleFactor); |
| 1817 } | 1806 } |
| 1818 | 1807 |
| 1819 @CalledByNative | 1808 @CalledByNative |
| 1820 private void onWebLayoutContentsSizeChanged(int widthCss, int heightCss) { | 1809 private void onWebLayoutContentsSizeChanged(int widthCss, int heightCss) { |
| 1821 // This change notification comes from the renderer thread, not from the
cc/ impl thread. | 1810 // This change notification comes from the renderer thread, not from the
cc/ impl thread. |
| 1822 mLayoutSizer.onContentSizeChanged(widthCss, heightCss); | 1811 mLayoutSizer.onContentSizeChanged(widthCss, heightCss); |
| 1823 } | 1812 } |
| 1824 | 1813 |
| 1825 @CalledByNative | 1814 @CalledByNative |
| 1815 private void setMaxContainerViewScrollOffset(int maxX, int maxY) { |
| 1816 mScrollOffsetManager.setMaxScrollOffset(maxX, maxY); |
| 1817 } |
| 1818 |
| 1819 @CalledByNative |
| 1826 private void scrollContainerViewTo(int x, int y) { | 1820 private void scrollContainerViewTo(int x, int y) { |
| 1827 mScrollOffsetManager.scrollContainerViewTo(x, y); | 1821 mScrollOffsetManager.scrollContainerViewTo(x, y); |
| 1828 } | 1822 } |
| 1829 | 1823 |
| 1830 @CalledByNative | 1824 @CalledByNative |
| 1825 private void setContentsSize(int widthDip, int heightDip) { |
| 1826 mContentWidthDip = widthDip; |
| 1827 mContentHeightDip = heightDip; |
| 1828 } |
| 1829 |
| 1830 @CalledByNative |
| 1831 private void setPageScaleFactor(float pageScaleFactor) { |
| 1832 mPageScaleFactor = pageScaleFactor; |
| 1833 } |
| 1834 |
| 1835 @CalledByNative |
| 1831 private void setAwAutofillManagerDelegate(AwAutofillManagerDelegate delegate
) { | 1836 private void setAwAutofillManagerDelegate(AwAutofillManagerDelegate delegate
) { |
| 1832 mAwAutofillManagerDelegate = delegate; | 1837 mAwAutofillManagerDelegate = delegate; |
| 1833 delegate.init(mContentViewCore); | 1838 delegate.init(mContentViewCore); |
| 1834 } | 1839 } |
| 1835 | 1840 |
| 1836 @CalledByNative | 1841 @CalledByNative |
| 1837 private void didOverscroll(int deltaX, int deltaY) { | 1842 private void didOverscroll(int deltaX, int deltaY) { |
| 1838 if (mOverScrollGlow != null) { | 1843 if (mOverScrollGlow != null) { |
| 1839 mOverScrollGlow.setOverScrollDeltas(deltaX, deltaY); | 1844 mOverScrollGlow.setOverScrollDeltas(deltaX, deltaY); |
| 1840 } | 1845 } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1935 private native void nativeUpdateLastHitTestData(int nativeAwContents); | 1940 private native void nativeUpdateLastHitTestData(int nativeAwContents); |
| 1936 | 1941 |
| 1937 private native void nativeOnSizeChanged(int nativeAwContents, int w, int h,
int ow, int oh); | 1942 private native void nativeOnSizeChanged(int nativeAwContents, int w, int h,
int ow, int oh); |
| 1938 private native void nativeScrollTo(int nativeAwContents, int x, int y); | 1943 private native void nativeScrollTo(int nativeAwContents, int x, int y); |
| 1939 private native void nativeSetViewVisibility(int nativeAwContents, boolean vi
sible); | 1944 private native void nativeSetViewVisibility(int nativeAwContents, boolean vi
sible); |
| 1940 private native void nativeSetWindowVisibility(int nativeAwContents, boolean
visible); | 1945 private native void nativeSetWindowVisibility(int nativeAwContents, boolean
visible); |
| 1941 private native void nativeSetIsPaused(int nativeAwContents, boolean paused); | 1946 private native void nativeSetIsPaused(int nativeAwContents, boolean paused); |
| 1942 private native void nativeOnAttachedToWindow(int nativeAwContents, int w, in
t h); | 1947 private native void nativeOnAttachedToWindow(int nativeAwContents, int w, in
t h); |
| 1943 private static native void nativeOnDetachedFromWindow(int nativeAwContents); | 1948 private static native void nativeOnDetachedFromWindow(int nativeAwContents); |
| 1944 private native void nativeSetDipScale(int nativeAwContents, float dipScale); | 1949 private native void nativeSetDipScale(int nativeAwContents, float dipScale); |
| 1945 private native void nativeSetDisplayedPageScaleFactor(int nativeAwContents, | |
| 1946 float pageScaleFactor); | |
| 1947 private native void nativeSetFixedLayoutSize(int nativeAwContents, int width
Dip, int heightDip); | 1950 private native void nativeSetFixedLayoutSize(int nativeAwContents, int width
Dip, int heightDip); |
| 1948 | 1951 |
| 1949 // Returns null if save state fails. | 1952 // Returns null if save state fails. |
| 1950 private native byte[] nativeGetOpaqueState(int nativeAwContents); | 1953 private native byte[] nativeGetOpaqueState(int nativeAwContents); |
| 1951 | 1954 |
| 1952 // Returns false if restore state fails. | 1955 // Returns false if restore state fails. |
| 1953 private native boolean nativeRestoreFromOpaqueState(int nativeAwContents, by
te[] state); | 1956 private native boolean nativeRestoreFromOpaqueState(int nativeAwContents, by
te[] state); |
| 1954 | 1957 |
| 1955 private native int nativeReleasePopupAwContents(int nativeAwContents); | 1958 private native int nativeReleasePopupAwContents(int nativeAwContents); |
| 1956 private native void nativeFocusFirstNode(int nativeAwContents); | 1959 private native void nativeFocusFirstNode(int nativeAwContents); |
| 1957 private native void nativeSetBackgroundColor(int nativeAwContents, int color
); | 1960 private native void nativeSetBackgroundColor(int nativeAwContents, int color
); |
| 1958 | 1961 |
| 1959 private native int nativeGetAwDrawGLViewContext(int nativeAwContents); | 1962 private native int nativeGetAwDrawGLViewContext(int nativeAwContents); |
| 1960 private native int nativeCapturePicture(int nativeAwContents, int width, int
height); | 1963 private native int nativeCapturePicture(int nativeAwContents, int width, int
height); |
| 1961 private native void nativeEnableOnNewPicture(int nativeAwContents, boolean e
nabled); | 1964 private native void nativeEnableOnNewPicture(int nativeAwContents, boolean e
nabled); |
| 1962 | 1965 |
| 1963 private native void nativeInvokeGeolocationCallback( | 1966 private native void nativeInvokeGeolocationCallback( |
| 1964 int nativeAwContents, boolean value, String requestingFrame); | 1967 int nativeAwContents, boolean value, String requestingFrame); |
| 1965 | 1968 |
| 1966 private native void nativeSetJsOnlineProperty(int nativeAwContents, boolean
networkUp); | 1969 private native void nativeSetJsOnlineProperty(int nativeAwContents, boolean
networkUp); |
| 1967 } | 1970 } |
| OLD | NEW |