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.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
8 import android.app.Activity; | 8 import android.app.Activity; |
9 import android.content.ComponentCallbacks2; | 9 import android.content.ComponentCallbacks2; |
10 import android.content.Context; | 10 import android.content.Context; |
11 import android.content.res.Configuration; | 11 import android.content.res.Configuration; |
12 import android.graphics.Bitmap; | 12 import android.graphics.Bitmap; |
13 import android.graphics.Canvas; | 13 import android.graphics.Canvas; |
14 import android.graphics.Color; | 14 import android.graphics.Color; |
15 import android.graphics.Paint; | 15 import android.graphics.Paint; |
16 import android.graphics.Picture; | 16 import android.graphics.Picture; |
17 import android.graphics.Rect; | 17 import android.graphics.Rect; |
18 import android.net.Uri; | 18 import android.net.Uri; |
19 import android.net.http.SslCertificate; | 19 import android.net.http.SslCertificate; |
20 import android.os.AsyncTask; | 20 import android.os.AsyncTask; |
21 import android.os.Build; | 21 import android.os.Build; |
22 import android.os.Bundle; | 22 import android.os.Bundle; |
23 import android.os.Handler; | 23 import android.os.Handler; |
24 import android.os.Message; | 24 import android.os.Message; |
25 import android.os.SystemClock; | |
25 import android.text.TextUtils; | 26 import android.text.TextUtils; |
26 import android.util.Base64; | 27 import android.util.Base64; |
28 import android.util.FloatMath; | |
27 import android.util.Log; | 29 import android.util.Log; |
28 import android.util.Pair; | 30 import android.util.Pair; |
29 import android.view.KeyEvent; | 31 import android.view.KeyEvent; |
30 import android.view.MotionEvent; | 32 import android.view.MotionEvent; |
31 import android.view.View; | 33 import android.view.View; |
32 import android.view.ViewGroup; | 34 import android.view.ViewGroup; |
33 import android.view.accessibility.AccessibilityEvent; | 35 import android.view.accessibility.AccessibilityEvent; |
34 import android.view.accessibility.AccessibilityNodeInfo; | 36 import android.view.accessibility.AccessibilityNodeInfo; |
35 import android.view.accessibility.AccessibilityNodeProvider; | 37 import android.view.accessibility.AccessibilityNodeProvider; |
38 import android.view.animation.AnimationUtils; | |
36 import android.view.inputmethod.EditorInfo; | 39 import android.view.inputmethod.EditorInfo; |
37 import android.view.inputmethod.InputConnection; | 40 import android.view.inputmethod.InputConnection; |
38 import android.webkit.GeolocationPermissions; | 41 import android.webkit.GeolocationPermissions; |
39 import android.webkit.JavascriptInterface; | 42 import android.webkit.JavascriptInterface; |
40 import android.webkit.ValueCallback; | 43 import android.webkit.ValueCallback; |
41 import android.widget.OverScroller; | 44 import android.widget.OverScroller; |
42 | 45 |
43 import org.chromium.android_webview.permission.AwPermissionRequest; | 46 import org.chromium.android_webview.permission.AwPermissionRequest; |
44 import org.chromium.base.CalledByNative; | 47 import org.chromium.base.CalledByNative; |
45 import org.chromium.base.JNINamespace; | 48 import org.chromium.base.JNINamespace; |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
567 public void onPinchEnded() { | 570 public void onPinchEnded() { |
568 mLayoutSizer.unfreezeLayoutRequests(); | 571 mLayoutSizer.unfreezeLayoutRequests(); |
569 } | 572 } |
570 | 573 |
571 @Override | 574 @Override |
572 public void onFlingCancelGesture() { | 575 public void onFlingCancelGesture() { |
573 mScrollOffsetManager.onFlingCancelGesture(); | 576 mScrollOffsetManager.onFlingCancelGesture(); |
574 } | 577 } |
575 | 578 |
576 @Override | 579 @Override |
577 public void onUnhandledFlingStartEvent(int velocityX, int velocityY) { | |
578 mScrollOffsetManager.onUnhandledFlingStartEvent(velocityX, velocityY ); | |
579 } | |
580 | |
581 @Override | |
582 public void onScrollUpdateGestureConsumed() { | 580 public void onScrollUpdateGestureConsumed() { |
583 mScrollAccessibilityHelper.postViewScrolledAccessibilityEventCallbac k(); | 581 mScrollAccessibilityHelper.postViewScrolledAccessibilityEventCallbac k(); |
584 } | 582 } |
585 } | 583 } |
586 | 584 |
587 //-------------------------------------------------------------------------- ------------------ | 585 //-------------------------------------------------------------------------- ------------------ |
588 private class AwComponentCallbacks implements ComponentCallbacks2 { | 586 private class AwComponentCallbacks implements ComponentCallbacks2 { |
589 @Override | 587 @Override |
590 public void onTrimMemory(final int level) { | 588 public void onTrimMemory(final int level) { |
591 if (isDestroyed()) return; | 589 if (isDestroyed()) return; |
(...skipping 1280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1872 */ | 1870 */ |
1873 public float getScale() { | 1871 public float getScale() { |
1874 return (float) (mPageScaleFactor * mDIPScale); | 1872 return (float) (mPageScaleFactor * mDIPScale); |
1875 } | 1873 } |
1876 | 1874 |
1877 /** | 1875 /** |
1878 * @see android.webkit.WebView#flingScroll(int, int) | 1876 * @see android.webkit.WebView#flingScroll(int, int) |
1879 */ | 1877 */ |
1880 public void flingScroll(int velocityX, int velocityY) { | 1878 public void flingScroll(int velocityX, int velocityY) { |
1881 if (TRACE) Log.d(TAG, "flingScroll"); | 1879 if (TRACE) Log.d(TAG, "flingScroll"); |
1882 mScrollOffsetManager.flingScroll(velocityX, velocityY); | 1880 mContentViewCore.fling(SystemClock.uptimeMillis(), 0, 0, -velocityX, -ve locityY); |
1883 } | 1881 } |
1884 | 1882 |
1885 /** | 1883 /** |
1886 * @see android.webkit.WebView#pageUp(boolean) | 1884 * @see android.webkit.WebView#pageUp(boolean) |
1887 */ | 1885 */ |
1888 public boolean pageUp(boolean top) { | 1886 public boolean pageUp(boolean top) { |
1889 if (TRACE) Log.d(TAG, "pageUp"); | 1887 if (TRACE) Log.d(TAG, "pageUp"); |
1890 return mScrollOffsetManager.pageUp(top); | 1888 return mScrollOffsetManager.pageUp(top); |
1891 } | 1889 } |
1892 | 1890 |
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2483 // This change notification comes from the renderer thread, not from the cc/ impl thread. | 2481 // This change notification comes from the renderer thread, not from the cc/ impl thread. |
2484 mLayoutSizer.onContentSizeChanged(widthCss, heightCss); | 2482 mLayoutSizer.onContentSizeChanged(widthCss, heightCss); |
2485 } | 2483 } |
2486 | 2484 |
2487 @CalledByNative | 2485 @CalledByNative |
2488 private void scrollContainerViewTo(int x, int y) { | 2486 private void scrollContainerViewTo(int x, int y) { |
2489 mScrollOffsetManager.scrollContainerViewTo(x, y); | 2487 mScrollOffsetManager.scrollContainerViewTo(x, y); |
2490 } | 2488 } |
2491 | 2489 |
2492 @CalledByNative | 2490 @CalledByNative |
2493 public boolean isFlingActive() { | 2491 public boolean isSmoothScrollingActive() { |
2494 return mScrollOffsetManager.isFlingActive(); | 2492 return mScrollOffsetManager.isSmoothScrollingActive(); |
2495 } | 2493 } |
2496 | 2494 |
2497 @CalledByNative | 2495 @CalledByNative |
2498 private void updateScrollState(int maxContainerViewScrollOffsetX, | 2496 private void updateScrollState(int maxContainerViewScrollOffsetX, |
2499 int maxContainerViewScrollOffsetY, int contentWidthDip, int contentH eightDip, | 2497 int maxContainerViewScrollOffsetY, int contentWidthDip, int contentH eightDip, |
2500 float pageScaleFactor, float minPageScaleFactor, float maxPageScaleF actor) { | 2498 float pageScaleFactor, float minPageScaleFactor, float maxPageScaleF actor) { |
2501 mContentWidthDip = contentWidthDip; | 2499 mContentWidthDip = contentWidthDip; |
2502 mContentHeightDip = contentHeightDip; | 2500 mContentHeightDip = contentHeightDip; |
2503 mScrollOffsetManager.setMaxScrollOffset(maxContainerViewScrollOffsetX, | 2501 mScrollOffsetManager.setMaxScrollOffset(maxContainerViewScrollOffsetX, |
2504 maxContainerViewScrollOffsetY); | 2502 maxContainerViewScrollOffsetY); |
2505 setPageScaleFactorAndLimits(pageScaleFactor, minPageScaleFactor, maxPage ScaleFactor); | 2503 setPageScaleFactorAndLimits(pageScaleFactor, minPageScaleFactor, maxPage ScaleFactor); |
2506 } | 2504 } |
2507 | 2505 |
2508 @CalledByNative | 2506 @CalledByNative |
2509 private void setAwAutofillClient(AwAutofillClient client) { | 2507 private void setAwAutofillClient(AwAutofillClient client) { |
2510 mAwAutofillClient = client; | 2508 mAwAutofillClient = client; |
2511 client.init(mContentViewCore); | 2509 client.init(mContentViewCore); |
2512 } | 2510 } |
2513 | 2511 |
2514 @CalledByNative | 2512 @CalledByNative |
2515 private void didOverscroll(int deltaX, int deltaY) { | 2513 private void didOverscroll(int deltaX, int deltaY, float velocityX, float ve locityY, |
2516 if (mOverScrollGlow != null) { | 2514 boolean firstOverscrollX, boolean firstOverscrollY) { |
2517 mOverScrollGlow.setOverScrollDeltas(deltaX, deltaY); | 2515 if (mOverScrollGlow == null) return; |
2516 | |
2517 mOverScrollGlow.setOverScrollDeltas(deltaX, deltaY); | |
2518 | |
2519 // TODO(jdduke): Skip this for components with non-zero velocity? | |
jdduke (slow)
2015/05/12 20:46:06
It's quite possible we don't even need these check
hush (inactive)
2015/05/13 23:26:20
OverScrollGlow class has all the information it ne
| |
2520 if ((velocityX != 0 && firstOverscrollX) || (velocityY != 0 && firstOver scrollY)) { | |
aelias_OOO_until_Jul13
2015/05/09 03:32:04
Could you explain why the first overscroll needs t
hush (inactive)
2015/05/12 19:08:45
I guess the original idea to absorb the glow if it
jdduke (slow)
2015/05/12 19:34:11
I would love for this to be the case, but Chrome's
hush (inactive)
2015/05/13 23:26:20
Okay.. I will just continue using WebView's custom
| |
2521 final int oldX = mContainerView.getScrollX(); | |
2522 final int oldY = mContainerView.getScrollY(); | |
2523 final int x = oldX + deltaX; | |
2524 final int y = oldX + deltaY; | |
hush (inactive)
2015/05/13 23:26:20
It should have been oldY + deltaY.
| |
2525 final int scrollRangeX = mScrollOffsetManager.computeMaximumHorizont alScrollOffset(); | |
2526 final int scrollRangeY = mScrollOffsetManager.computeMaximumVertical ScrollOffset(); | |
2527 mOverScrollGlow.absorbGlow(x, y, oldX, oldY, scrollRangeX, scrollRan geY, | |
2528 FloatMath.hypot(velocityX, velocityY)); | |
2529 } else { | |
2530 mScrollOffsetManager.overScrollBy(deltaX, deltaY); | |
2518 } | 2531 } |
2519 | 2532 |
2520 mScrollOffsetManager.overScrollBy(deltaX, deltaY); | 2533 if (mOverScrollGlow.isAnimating()) { |
2521 | |
2522 if (mOverScrollGlow != null && mOverScrollGlow.isAnimating()) { | |
2523 postInvalidateOnAnimation(); | 2534 postInvalidateOnAnimation(); |
2524 } | 2535 } |
2525 } | 2536 } |
2526 | 2537 |
2527 // ------------------------------------------------------------------------- ------------------ | 2538 // ------------------------------------------------------------------------- ------------------ |
2528 // Helper methods | 2539 // Helper methods |
2529 // ------------------------------------------------------------------------- ------------------ | 2540 // ------------------------------------------------------------------------- ------------------ |
2530 | 2541 |
2531 private void setPageScaleFactorAndLimits( | 2542 private void setPageScaleFactorAndLimits( |
2532 float pageScaleFactor, float minPageScaleFactor, float maxPageScaleF actor) { | 2543 float pageScaleFactor, float minPageScaleFactor, float maxPageScaleF actor) { |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2916 return mScrollOffsetManager.computeVerticalScrollOffset(); | 2927 return mScrollOffsetManager.computeVerticalScrollOffset(); |
2917 } | 2928 } |
2918 | 2929 |
2919 @Override | 2930 @Override |
2920 public int computeVerticalScrollExtent() { | 2931 public int computeVerticalScrollExtent() { |
2921 return mScrollOffsetManager.computeVerticalScrollExtent(); | 2932 return mScrollOffsetManager.computeVerticalScrollExtent(); |
2922 } | 2933 } |
2923 | 2934 |
2924 @Override | 2935 @Override |
2925 public void computeScroll() { | 2936 public void computeScroll() { |
2926 mScrollOffsetManager.computeScrollAndAbsorbGlow(mOverScrollGlow); | 2937 if (mScrollOffsetManager.willComputeScroll()) { |
2938 mScrollOffsetManager.computeScrollAndAbsorbGlow(mOverScrollGlow) ; | |
2939 } else { | |
2940 if (isDestroyed()) return; | |
2941 nativeOnComputeScroll( | |
2942 mNativeAwContents, AnimationUtils.currentAnimationTimeMi llis()); | |
2943 } | |
2927 } | 2944 } |
2928 } | 2945 } |
2929 | 2946 |
2930 // Return true if the GeolocationPermissionAPI should be used. | 2947 // Return true if the GeolocationPermissionAPI should be used. |
2931 @CalledByNative | 2948 @CalledByNative |
2932 private boolean useLegacyGeolocationPermissionAPI() { | 2949 private boolean useLegacyGeolocationPermissionAPI() { |
2933 // Always return true since we are not ready to swap the geolocation yet . | 2950 // Always return true since we are not ready to swap the geolocation yet . |
2934 // TODO: If we decide not to migrate the geolocation, there are some unr eachable | 2951 // TODO: If we decide not to migrate the geolocation, there are some unr eachable |
2935 // code need to remove. http://crbug.com/396184. | 2952 // code need to remove. http://crbug.com/396184. |
2936 return true; | 2953 return true; |
(...skipping 16 matching lines...) Expand all Loading... | |
2953 AwContentsClientBridge contentsClientBridge, | 2970 AwContentsClientBridge contentsClientBridge, |
2954 AwContentsIoThreadClient ioThreadClient, | 2971 AwContentsIoThreadClient ioThreadClient, |
2955 InterceptNavigationDelegate navigationInterceptionDelegate); | 2972 InterceptNavigationDelegate navigationInterceptionDelegate); |
2956 private native WebContents nativeGetWebContents(long nativeAwContents); | 2973 private native WebContents nativeGetWebContents(long nativeAwContents); |
2957 | 2974 |
2958 private native void nativeDocumentHasImages(long nativeAwContents, Message m essage); | 2975 private native void nativeDocumentHasImages(long nativeAwContents, Message m essage); |
2959 private native void nativeGenerateMHTML( | 2976 private native void nativeGenerateMHTML( |
2960 long nativeAwContents, String path, ValueCallback<String> callback); | 2977 long nativeAwContents, String path, ValueCallback<String> callback); |
2961 | 2978 |
2962 private native void nativeAddVisitedLinks(long nativeAwContents, String[] vi sitedLinks); | 2979 private native void nativeAddVisitedLinks(long nativeAwContents, String[] vi sitedLinks); |
2980 private native void nativeOnComputeScroll( | |
2981 long nativeAwContents, long currentAnimationTimeMillis); | |
2963 private native boolean nativeOnDraw(long nativeAwContents, Canvas canvas, | 2982 private native boolean nativeOnDraw(long nativeAwContents, Canvas canvas, |
2964 boolean isHardwareAccelerated, int scrollX, int scrollY, | 2983 boolean isHardwareAccelerated, int scrollX, int scrollY, |
2965 int visibleLeft, int visibleTop, int visibleRight, int visibleBottom ); | 2984 int visibleLeft, int visibleTop, int visibleRight, int visibleBottom ); |
2966 private native void nativeFindAllAsync(long nativeAwContents, String searchS tring); | 2985 private native void nativeFindAllAsync(long nativeAwContents, String searchS tring); |
2967 private native void nativeFindNext(long nativeAwContents, boolean forward); | 2986 private native void nativeFindNext(long nativeAwContents, boolean forward); |
2968 private native void nativeClearMatches(long nativeAwContents); | 2987 private native void nativeClearMatches(long nativeAwContents); |
2969 private native void nativeClearCache(long nativeAwContents, boolean includeD iskFiles); | 2988 private native void nativeClearCache(long nativeAwContents, boolean includeD iskFiles); |
2970 private native byte[] nativeGetCertificate(long nativeAwContents); | 2989 private native byte[] nativeGetCertificate(long nativeAwContents); |
2971 | 2990 |
2972 // Coordinates in desity independent pixels. | 2991 // Coordinates in desity independent pixels. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3012 private native void nativeCreatePdfExporter(long nativeAwContents, AwPdfExpo rter awPdfExporter); | 3031 private native void nativeCreatePdfExporter(long nativeAwContents, AwPdfExpo rter awPdfExporter); |
3013 | 3032 |
3014 private native void nativePreauthorizePermission(long nativeAwContents, Stri ng origin, | 3033 private native void nativePreauthorizePermission(long nativeAwContents, Stri ng origin, |
3015 long resources); | 3034 long resources); |
3016 | 3035 |
3017 private native void nativePostMessageToFrame(long nativeAwContents, String f rameId, | 3036 private native void nativePostMessageToFrame(long nativeAwContents, String f rameId, |
3018 String message, String targetOrigin, int[] msgPorts); | 3037 String message, String targetOrigin, int[] msgPorts); |
3019 | 3038 |
3020 private native void nativeCreateMessageChannel(long nativeAwContents, AwMess agePort[] ports); | 3039 private native void nativeCreateMessageChannel(long nativeAwContents, AwMess agePort[] ports); |
3021 } | 3040 } |
OLD | NEW |