Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(49)

Side by Side Diff: android_webview/java/src/org/chromium/android_webview/AwContents.java

Issue 1063853005: Unify Android Webview and Chrome's fling (Closed) Base URL: https://chromium.googlesource.com/a/chromium/src.git@master
Patch Set: Jared's comments Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 1282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1874 */ 1872 */
1875 public float getScale() { 1873 public float getScale() {
1876 return (float) (mPageScaleFactor * mDIPScale); 1874 return (float) (mPageScaleFactor * mDIPScale);
1877 } 1875 }
1878 1876
1879 /** 1877 /**
1880 * @see android.webkit.WebView#flingScroll(int, int) 1878 * @see android.webkit.WebView#flingScroll(int, int)
1881 */ 1879 */
1882 public void flingScroll(int velocityX, int velocityY) { 1880 public void flingScroll(int velocityX, int velocityY) {
1883 if (TRACE) Log.d(TAG, "flingScroll"); 1881 if (TRACE) Log.d(TAG, "flingScroll");
1884 mScrollOffsetManager.flingScroll(velocityX, velocityY); 1882 mContentViewCore.fling(SystemClock.uptimeMillis(), 0, 0, -velocityX, -ve locityY);
hush (inactive) 2015/05/27 23:11:38 Regarding the possibility of scrolling a scrollabl
jdduke (slow) 2015/05/28 15:18:08 That's a thought, though it might just be that it
hush (inactive) 2015/05/28 23:49:51 Yeah... using -100, -100 was too brittle and too m
bokan 2015/05/29 19:32:49 Sorry for late reply, "targetViewport" sgtm. "targ
1885 } 1883 }
1886 1884
1887 /** 1885 /**
1888 * @see android.webkit.WebView#pageUp(boolean) 1886 * @see android.webkit.WebView#pageUp(boolean)
1889 */ 1887 */
1890 public boolean pageUp(boolean top) { 1888 public boolean pageUp(boolean top) {
1891 if (TRACE) Log.d(TAG, "pageUp"); 1889 if (TRACE) Log.d(TAG, "pageUp");
1892 return mScrollOffsetManager.pageUp(top); 1890 return mScrollOffsetManager.pageUp(top);
1893 } 1891 }
1894 1892
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
2485 // This change notification comes from the renderer thread, not from the cc/ impl thread. 2483 // This change notification comes from the renderer thread, not from the cc/ impl thread.
2486 mLayoutSizer.onContentSizeChanged(widthCss, heightCss); 2484 mLayoutSizer.onContentSizeChanged(widthCss, heightCss);
2487 } 2485 }
2488 2486
2489 @CalledByNative 2487 @CalledByNative
2490 private void scrollContainerViewTo(int x, int y) { 2488 private void scrollContainerViewTo(int x, int y) {
2491 mScrollOffsetManager.scrollContainerViewTo(x, y); 2489 mScrollOffsetManager.scrollContainerViewTo(x, y);
2492 } 2490 }
2493 2491
2494 @CalledByNative 2492 @CalledByNative
2495 public boolean isFlingActive() { 2493 public boolean isSmoothScrollingActive() {
2496 return mScrollOffsetManager.isFlingActive(); 2494 return mScrollOffsetManager.isSmoothScrollingActive();
2497 } 2495 }
2498 2496
2499 @CalledByNative 2497 @CalledByNative
2500 private void updateScrollState(int maxContainerViewScrollOffsetX, 2498 private void updateScrollState(int maxContainerViewScrollOffsetX,
2501 int maxContainerViewScrollOffsetY, int contentWidthDip, int contentH eightDip, 2499 int maxContainerViewScrollOffsetY, int contentWidthDip, int contentH eightDip,
2502 float pageScaleFactor, float minPageScaleFactor, float maxPageScaleF actor) { 2500 float pageScaleFactor, float minPageScaleFactor, float maxPageScaleF actor) {
2503 mContentWidthDip = contentWidthDip; 2501 mContentWidthDip = contentWidthDip;
2504 mContentHeightDip = contentHeightDip; 2502 mContentHeightDip = contentHeightDip;
2505 mScrollOffsetManager.setMaxScrollOffset(maxContainerViewScrollOffsetX, 2503 mScrollOffsetManager.setMaxScrollOffset(maxContainerViewScrollOffsetX,
2506 maxContainerViewScrollOffsetY); 2504 maxContainerViewScrollOffsetY);
2507 setPageScaleFactorAndLimits(pageScaleFactor, minPageScaleFactor, maxPage ScaleFactor); 2505 setPageScaleFactorAndLimits(pageScaleFactor, minPageScaleFactor, maxPage ScaleFactor);
2508 } 2506 }
2509 2507
2510 @CalledByNative 2508 @CalledByNative
2511 private void setAwAutofillClient(AwAutofillClient client) { 2509 private void setAwAutofillClient(AwAutofillClient client) {
2512 mAwAutofillClient = client; 2510 mAwAutofillClient = client;
2513 client.init(mContentViewCore); 2511 client.init(mContentViewCore);
2514 } 2512 }
2515 2513
2514 @SuppressLint("NewApi")
2516 @CalledByNative 2515 @CalledByNative
2517 private void didOverscroll(int deltaX, int deltaY) { 2516 private void didOverscroll(int deltaX, int deltaY, float velocityX, float ve locityY) {
2518 if (mOverScrollGlow != null) {
2519 mOverScrollGlow.setOverScrollDeltas(deltaX, deltaY);
2520 }
2521
2522 mScrollOffsetManager.overScrollBy(deltaX, deltaY); 2517 mScrollOffsetManager.overScrollBy(deltaX, deltaY);
2523 2518
2524 if (mOverScrollGlow != null && mOverScrollGlow.isAnimating()) { 2519 if (mOverScrollGlow == null) return;
2520
2521 mOverScrollGlow.setOverScrollDeltas(deltaX, deltaY);
2522 final int oldX = mContainerView.getScrollX();
2523 final int oldY = mContainerView.getScrollY();
2524 final int x = oldX + deltaX;
2525 final int y = oldY + deltaY;
2526 final int scrollRangeX = mScrollOffsetManager.computeMaximumHorizontalSc rollOffset();
2527 final int scrollRangeY = mScrollOffsetManager.computeMaximumVerticalScro llOffset();
2528 mOverScrollGlow.absorbGlow(x, y, oldX, oldY, scrollRangeX, scrollRangeY,
2529 FloatMath.hypot(velocityX, velocityY));
2530
2531 if (mOverScrollGlow.isAnimating()) {
2525 postInvalidateOnAnimation(); 2532 postInvalidateOnAnimation();
2526 } 2533 }
2527 } 2534 }
2528 2535
2529 // ------------------------------------------------------------------------- ------------------ 2536 // ------------------------------------------------------------------------- ------------------
2530 // Helper methods 2537 // Helper methods
2531 // ------------------------------------------------------------------------- ------------------ 2538 // ------------------------------------------------------------------------- ------------------
2532 2539
2533 private void setPageScaleFactorAndLimits( 2540 private void setPageScaleFactorAndLimits(
2534 float pageScaleFactor, float minPageScaleFactor, float maxPageScaleF actor) { 2541 float pageScaleFactor, float minPageScaleFactor, float maxPageScaleF actor) {
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
2918 return mScrollOffsetManager.computeVerticalScrollOffset(); 2925 return mScrollOffsetManager.computeVerticalScrollOffset();
2919 } 2926 }
2920 2927
2921 @Override 2928 @Override
2922 public int computeVerticalScrollExtent() { 2929 public int computeVerticalScrollExtent() {
2923 return mScrollOffsetManager.computeVerticalScrollExtent(); 2930 return mScrollOffsetManager.computeVerticalScrollExtent();
2924 } 2931 }
2925 2932
2926 @Override 2933 @Override
2927 public void computeScroll() { 2934 public void computeScroll() {
2928 mScrollOffsetManager.computeScrollAndAbsorbGlow(mOverScrollGlow); 2935 if (mScrollOffsetManager.willComputeScroll()) {
2936 mScrollOffsetManager.computeScrollAndAbsorbGlow(mOverScrollGlow) ;
2937 } else {
2938 if (isDestroyed()) return;
2939 nativeOnComputeScroll(
2940 mNativeAwContents, AnimationUtils.currentAnimationTimeMi llis());
2941 }
2929 } 2942 }
2930 } 2943 }
2931 2944
2932 // Return true if the GeolocationPermissionAPI should be used. 2945 // Return true if the GeolocationPermissionAPI should be used.
2933 @CalledByNative 2946 @CalledByNative
2934 private boolean useLegacyGeolocationPermissionAPI() { 2947 private boolean useLegacyGeolocationPermissionAPI() {
2935 // Always return true since we are not ready to swap the geolocation yet . 2948 // Always return true since we are not ready to swap the geolocation yet .
2936 // TODO: If we decide not to migrate the geolocation, there are some unr eachable 2949 // TODO: If we decide not to migrate the geolocation, there are some unr eachable
2937 // code need to remove. http://crbug.com/396184. 2950 // code need to remove. http://crbug.com/396184.
2938 return true; 2951 return true;
(...skipping 16 matching lines...) Expand all
2955 AwContentsClientBridge contentsClientBridge, 2968 AwContentsClientBridge contentsClientBridge,
2956 AwContentsIoThreadClient ioThreadClient, 2969 AwContentsIoThreadClient ioThreadClient,
2957 InterceptNavigationDelegate navigationInterceptionDelegate); 2970 InterceptNavigationDelegate navigationInterceptionDelegate);
2958 private native WebContents nativeGetWebContents(long nativeAwContents); 2971 private native WebContents nativeGetWebContents(long nativeAwContents);
2959 2972
2960 private native void nativeDocumentHasImages(long nativeAwContents, Message m essage); 2973 private native void nativeDocumentHasImages(long nativeAwContents, Message m essage);
2961 private native void nativeGenerateMHTML( 2974 private native void nativeGenerateMHTML(
2962 long nativeAwContents, String path, ValueCallback<String> callback); 2975 long nativeAwContents, String path, ValueCallback<String> callback);
2963 2976
2964 private native void nativeAddVisitedLinks(long nativeAwContents, String[] vi sitedLinks); 2977 private native void nativeAddVisitedLinks(long nativeAwContents, String[] vi sitedLinks);
2978 private native void nativeOnComputeScroll(
2979 long nativeAwContents, long currentAnimationTimeMillis);
2965 private native boolean nativeOnDraw(long nativeAwContents, Canvas canvas, 2980 private native boolean nativeOnDraw(long nativeAwContents, Canvas canvas,
2966 boolean isHardwareAccelerated, int scrollX, int scrollY, 2981 boolean isHardwareAccelerated, int scrollX, int scrollY,
2967 int visibleLeft, int visibleTop, int visibleRight, int visibleBottom ); 2982 int visibleLeft, int visibleTop, int visibleRight, int visibleBottom );
2968 private native void nativeFindAllAsync(long nativeAwContents, String searchS tring); 2983 private native void nativeFindAllAsync(long nativeAwContents, String searchS tring);
2969 private native void nativeFindNext(long nativeAwContents, boolean forward); 2984 private native void nativeFindNext(long nativeAwContents, boolean forward);
2970 private native void nativeClearMatches(long nativeAwContents); 2985 private native void nativeClearMatches(long nativeAwContents);
2971 private native void nativeClearCache(long nativeAwContents, boolean includeD iskFiles); 2986 private native void nativeClearCache(long nativeAwContents, boolean includeD iskFiles);
2972 private native byte[] nativeGetCertificate(long nativeAwContents); 2987 private native byte[] nativeGetCertificate(long nativeAwContents);
2973 2988
2974 // Coordinates in desity independent pixels. 2989 // Coordinates in desity independent pixels.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
3014 private native void nativeCreatePdfExporter(long nativeAwContents, AwPdfExpo rter awPdfExporter); 3029 private native void nativeCreatePdfExporter(long nativeAwContents, AwPdfExpo rter awPdfExporter);
3015 3030
3016 private native void nativePreauthorizePermission(long nativeAwContents, Stri ng origin, 3031 private native void nativePreauthorizePermission(long nativeAwContents, Stri ng origin,
3017 long resources); 3032 long resources);
3018 3033
3019 private native void nativePostMessageToFrame(long nativeAwContents, String f rameId, 3034 private native void nativePostMessageToFrame(long nativeAwContents, String f rameId,
3020 String message, String targetOrigin, int[] msgPorts); 3035 String message, String targetOrigin, int[] msgPorts);
3021 3036
3022 private native void nativeCreateMessageChannel(long nativeAwContents, AwMess agePort[] ports); 3037 private native void nativeCreateMessageChannel(long nativeAwContents, AwMess agePort[] ports);
3023 } 3038 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698