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; |
(...skipping 22 matching lines...) Expand all Loading... |
33 import android.view.ViewGroup; | 33 import android.view.ViewGroup; |
34 import android.view.accessibility.AccessibilityEvent; | 34 import android.view.accessibility.AccessibilityEvent; |
35 import android.view.accessibility.AccessibilityNodeInfo; | 35 import android.view.accessibility.AccessibilityNodeInfo; |
36 import android.view.accessibility.AccessibilityNodeProvider; | 36 import android.view.accessibility.AccessibilityNodeProvider; |
37 import android.view.animation.AnimationUtils; | 37 import android.view.animation.AnimationUtils; |
38 import android.view.inputmethod.EditorInfo; | 38 import android.view.inputmethod.EditorInfo; |
39 import android.view.inputmethod.InputConnection; | 39 import android.view.inputmethod.InputConnection; |
40 import android.webkit.GeolocationPermissions; | 40 import android.webkit.GeolocationPermissions; |
41 import android.webkit.JavascriptInterface; | 41 import android.webkit.JavascriptInterface; |
42 import android.webkit.ValueCallback; | 42 import android.webkit.ValueCallback; |
43 import android.widget.OverScroller; | |
44 | 43 |
45 import org.chromium.android_webview.permission.AwPermissionRequest; | 44 import org.chromium.android_webview.permission.AwPermissionRequest; |
46 import org.chromium.base.CalledByNative; | 45 import org.chromium.base.CalledByNative; |
47 import org.chromium.base.JNINamespace; | 46 import org.chromium.base.JNINamespace; |
48 import org.chromium.base.ThreadUtils; | 47 import org.chromium.base.ThreadUtils; |
49 import org.chromium.base.TraceEvent; | 48 import org.chromium.base.TraceEvent; |
50 import org.chromium.base.VisibleForTesting; | 49 import org.chromium.base.VisibleForTesting; |
51 import org.chromium.base.annotations.SuppressFBWarnings; | 50 import org.chromium.base.annotations.SuppressFBWarnings; |
52 import org.chromium.components.navigation_interception.InterceptNavigationDelega
te; | 51 import org.chromium.components.navigation_interception.InterceptNavigationDelega
te; |
53 import org.chromium.components.navigation_interception.NavigationParams; | 52 import org.chromium.components.navigation_interception.NavigationParams; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 /** | 180 /** |
182 * Class to facilitate dependency injection. Subclasses by test code to prov
ide mock versions of | 181 * Class to facilitate dependency injection. Subclasses by test code to prov
ide mock versions of |
183 * certain AwContents dependencies. | 182 * certain AwContents dependencies. |
184 */ | 183 */ |
185 public static class DependencyFactory { | 184 public static class DependencyFactory { |
186 public AwLayoutSizer createLayoutSizer() { | 185 public AwLayoutSizer createLayoutSizer() { |
187 return new AwLayoutSizer(); | 186 return new AwLayoutSizer(); |
188 } | 187 } |
189 | 188 |
190 public AwScrollOffsetManager createScrollOffsetManager( | 189 public AwScrollOffsetManager createScrollOffsetManager( |
191 AwScrollOffsetManager.Delegate delegate, OverScroller overScroll
er) { | 190 AwScrollOffsetManager.Delegate delegate) { |
192 return new AwScrollOffsetManager(delegate, overScroller); | 191 return new AwScrollOffsetManager(delegate); |
193 } | 192 } |
194 } | 193 } |
195 | 194 |
196 /** | 195 /** |
197 * Visual state callback, see {@link #insertVisualStateCallback} for details
. | 196 * Visual state callback, see {@link #insertVisualStateCallback} for details
. |
198 * | 197 * |
199 */ | 198 */ |
200 @VisibleForTesting | 199 @VisibleForTesting |
201 public abstract static class VisualStateCallback { | 200 public abstract static class VisualStateCallback { |
202 /** | 201 /** |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 public void scrollContainerViewTo(int x, int y) { | 555 public void scrollContainerViewTo(int x, int y) { |
557 mInternalAccessAdapter.super_scrollTo(x, y); | 556 mInternalAccessAdapter.super_scrollTo(x, y); |
558 } | 557 } |
559 | 558 |
560 @Override | 559 @Override |
561 public void scrollNativeTo(int x, int y) { | 560 public void scrollNativeTo(int x, int y) { |
562 if (!isDestroyed()) nativeScrollTo(mNativeAwContents, x, y); | 561 if (!isDestroyed()) nativeScrollTo(mNativeAwContents, x, y); |
563 } | 562 } |
564 | 563 |
565 @Override | 564 @Override |
| 565 public void smoothScroll( |
| 566 long currentMs, int startX, int startY, int dx, int dy, long dur
ationMs) { |
| 567 mContentViewCore.smoothScroll(startX + dx, startY + dy, durationMs); |
| 568 } |
| 569 |
| 570 @Override |
566 public int getContainerViewScrollX() { | 571 public int getContainerViewScrollX() { |
567 return mContainerView.getScrollX(); | 572 return mContainerView.getScrollX(); |
568 } | 573 } |
569 | 574 |
570 @Override | 575 @Override |
571 public int getContainerViewScrollY() { | 576 public int getContainerViewScrollY() { |
572 return mContainerView.getScrollY(); | 577 return mContainerView.getScrollY(); |
573 } | 578 } |
574 | 579 |
575 @Override | 580 @Override |
(...skipping 19 matching lines...) Expand all Loading... |
595 // WebViewClassic does. | 600 // WebViewClassic does. |
596 mLayoutSizer.freezeLayoutRequests(); | 601 mLayoutSizer.freezeLayoutRequests(); |
597 } | 602 } |
598 | 603 |
599 @Override | 604 @Override |
600 public void onPinchEnded() { | 605 public void onPinchEnded() { |
601 mLayoutSizer.unfreezeLayoutRequests(); | 606 mLayoutSizer.unfreezeLayoutRequests(); |
602 } | 607 } |
603 | 608 |
604 @Override | 609 @Override |
605 public void onFlingCancelGesture() { | |
606 mScrollOffsetManager.finishScroll(); | |
607 } | |
608 | |
609 @Override | |
610 public void onScrollUpdateGestureConsumed() { | 610 public void onScrollUpdateGestureConsumed() { |
611 mScrollAccessibilityHelper.postViewScrolledAccessibilityEventCallbac
k(); | 611 mScrollAccessibilityHelper.postViewScrolledAccessibilityEventCallbac
k(); |
612 } | 612 } |
613 } | 613 } |
614 | 614 |
615 //--------------------------------------------------------------------------
------------------ | 615 //--------------------------------------------------------------------------
------------------ |
616 private class AwComponentCallbacks implements ComponentCallbacks2 { | 616 private class AwComponentCallbacks implements ComponentCallbacks2 { |
617 @Override | 617 @Override |
618 public void onTrimMemory(final int level) { | 618 public void onTrimMemory(final int level) { |
619 if (isDestroyed()) return; | 619 if (isDestroyed()) return; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 mContentViewCore.updateDoubleTapSupport(supportsDoubleTa
pZoom); | 699 mContentViewCore.updateDoubleTapSupport(supportsDoubleTa
pZoom); |
700 mContentViewCore.updateMultiTouchZoomSupport(supportsMul
tiTouchZoom); | 700 mContentViewCore.updateMultiTouchZoomSupport(supportsMul
tiTouchZoom); |
701 } | 701 } |
702 | 702 |
703 }; | 703 }; |
704 mSettings.setZoomListener(zoomListener); | 704 mSettings.setZoomListener(zoomListener); |
705 mDefaultVideoPosterRequestHandler = new DefaultVideoPosterRequestHandler
(mContentsClient); | 705 mDefaultVideoPosterRequestHandler = new DefaultVideoPosterRequestHandler
(mContentsClient); |
706 mSettings.setDefaultVideoPosterURL( | 706 mSettings.setDefaultVideoPosterURL( |
707 mDefaultVideoPosterRequestHandler.getDefaultVideoPosterURL()); | 707 mDefaultVideoPosterRequestHandler.getDefaultVideoPosterURL()); |
708 mSettings.setDIPScale(mDIPScale); | 708 mSettings.setDIPScale(mDIPScale); |
709 mScrollOffsetManager = dependencyFactory.createScrollOffsetManager( | 709 mScrollOffsetManager = |
710 new AwScrollOffsetManagerDelegate(), new OverScroller(mContext))
; | 710 dependencyFactory.createScrollOffsetManager(new AwScrollOffsetMa
nagerDelegate()); |
711 mScrollAccessibilityHelper = new ScrollAccessibilityHelper(mContainerVie
w); | 711 mScrollAccessibilityHelper = new ScrollAccessibilityHelper(mContainerVie
w); |
712 | 712 |
713 setOverScrollMode(mContainerView.getOverScrollMode()); | 713 setOverScrollMode(mContainerView.getOverScrollMode()); |
714 setScrollBarStyle(mInternalAccessAdapter.super_getScrollBarStyle()); | 714 setScrollBarStyle(mInternalAccessAdapter.super_getScrollBarStyle()); |
715 | 715 |
716 setNewAwContents(nativeInit(mBrowserContext)); | 716 setNewAwContents(nativeInit(mBrowserContext)); |
717 | 717 |
718 onContainerViewChanged(); | 718 onContainerViewChanged(); |
719 } | 719 } |
720 | 720 |
(...skipping 1221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1942 */ | 1942 */ |
1943 public float getScale() { | 1943 public float getScale() { |
1944 return (float) (mPageScaleFactor * mDIPScale); | 1944 return (float) (mPageScaleFactor * mDIPScale); |
1945 } | 1945 } |
1946 | 1946 |
1947 /** | 1947 /** |
1948 * @see android.webkit.WebView#flingScroll(int, int) | 1948 * @see android.webkit.WebView#flingScroll(int, int) |
1949 */ | 1949 */ |
1950 public void flingScroll(int velocityX, int velocityY) { | 1950 public void flingScroll(int velocityX, int velocityY) { |
1951 if (TRACE) Log.d(TAG, "flingScroll"); | 1951 if (TRACE) Log.d(TAG, "flingScroll"); |
1952 // Cancel the current smooth scroll, if there is one. | |
1953 mScrollOffsetManager.finishScroll(); | |
1954 // TODO(hush): crbug.com/493765. A hit test at 0, 0 may not | |
1955 // target the scroll at root scrolling layer. Instead, we | |
1956 // should add a method flingRootLayer to ContentViewCore | |
1957 // and call it here to specifically target the scroll at | |
1958 // the root layer. | |
1959 mContentViewCore.flingViewport(SystemClock.uptimeMillis(), -velocityX, -
velocityY); | 1952 mContentViewCore.flingViewport(SystemClock.uptimeMillis(), -velocityX, -
velocityY); |
1960 } | 1953 } |
1961 | 1954 |
1962 /** | 1955 /** |
1963 * @see android.webkit.WebView#pageUp(boolean) | 1956 * @see android.webkit.WebView#pageUp(boolean) |
1964 */ | 1957 */ |
1965 public boolean pageUp(boolean top) { | 1958 public boolean pageUp(boolean top) { |
1966 if (TRACE) Log.d(TAG, "pageUp"); | 1959 if (TRACE) Log.d(TAG, "pageUp"); |
1967 return mScrollOffsetManager.pageUp(top); | 1960 return mScrollOffsetManager.pageUp(top); |
1968 } | 1961 } |
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2582 // This change notification comes from the renderer thread, not from the
cc/ impl thread. | 2575 // This change notification comes from the renderer thread, not from the
cc/ impl thread. |
2583 mLayoutSizer.onContentSizeChanged(widthCss, heightCss); | 2576 mLayoutSizer.onContentSizeChanged(widthCss, heightCss); |
2584 } | 2577 } |
2585 | 2578 |
2586 @CalledByNative | 2579 @CalledByNative |
2587 private void scrollContainerViewTo(int x, int y) { | 2580 private void scrollContainerViewTo(int x, int y) { |
2588 mScrollOffsetManager.scrollContainerViewTo(x, y); | 2581 mScrollOffsetManager.scrollContainerViewTo(x, y); |
2589 } | 2582 } |
2590 | 2583 |
2591 @CalledByNative | 2584 @CalledByNative |
2592 public boolean isSmoothScrollingActive() { | |
2593 return mScrollOffsetManager.isSmoothScrollingActive(); | |
2594 } | |
2595 | |
2596 @CalledByNative | |
2597 private void updateScrollState(int maxContainerViewScrollOffsetX, | 2585 private void updateScrollState(int maxContainerViewScrollOffsetX, |
2598 int maxContainerViewScrollOffsetY, int contentWidthDip, int contentH
eightDip, | 2586 int maxContainerViewScrollOffsetY, int contentWidthDip, int contentH
eightDip, |
2599 float pageScaleFactor, float minPageScaleFactor, float maxPageScaleF
actor) { | 2587 float pageScaleFactor, float minPageScaleFactor, float maxPageScaleF
actor) { |
2600 mContentWidthDip = contentWidthDip; | 2588 mContentWidthDip = contentWidthDip; |
2601 mContentHeightDip = contentHeightDip; | 2589 mContentHeightDip = contentHeightDip; |
2602 mScrollOffsetManager.setMaxScrollOffset(maxContainerViewScrollOffsetX, | 2590 mScrollOffsetManager.setMaxScrollOffset(maxContainerViewScrollOffsetX, |
2603 maxContainerViewScrollOffsetY); | 2591 maxContainerViewScrollOffsetY); |
2604 setPageScaleFactorAndLimits(pageScaleFactor, minPageScaleFactor, maxPage
ScaleFactor); | 2592 setPageScaleFactorAndLimits(pageScaleFactor, minPageScaleFactor, maxPage
ScaleFactor); |
2605 } | 2593 } |
2606 | 2594 |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3029 return mScrollOffsetManager.computeVerticalScrollOffset(); | 3017 return mScrollOffsetManager.computeVerticalScrollOffset(); |
3030 } | 3018 } |
3031 | 3019 |
3032 @Override | 3020 @Override |
3033 public int computeVerticalScrollExtent() { | 3021 public int computeVerticalScrollExtent() { |
3034 return mScrollOffsetManager.computeVerticalScrollExtent(); | 3022 return mScrollOffsetManager.computeVerticalScrollExtent(); |
3035 } | 3023 } |
3036 | 3024 |
3037 @Override | 3025 @Override |
3038 public void computeScroll() { | 3026 public void computeScroll() { |
3039 if (mScrollOffsetManager.isSmoothScrollingActive()) { | 3027 if (isDestroyed()) return; |
3040 mScrollOffsetManager.computeScrollAndAbsorbGlow(mOverScrollGlow)
; | 3028 nativeOnComputeScroll(mNativeAwContents, AnimationUtils.currentAnima
tionTimeMillis()); |
3041 } else { | |
3042 if (isDestroyed()) return; | |
3043 nativeOnComputeScroll( | |
3044 mNativeAwContents, AnimationUtils.currentAnimationTimeMi
llis()); | |
3045 } | |
3046 } | 3029 } |
3047 } | 3030 } |
3048 | 3031 |
3049 // Return true if the GeolocationPermissionAPI should be used. | 3032 // Return true if the GeolocationPermissionAPI should be used. |
3050 @CalledByNative | 3033 @CalledByNative |
3051 private boolean useLegacyGeolocationPermissionAPI() { | 3034 private boolean useLegacyGeolocationPermissionAPI() { |
3052 // Always return true since we are not ready to swap the geolocation yet
. | 3035 // Always return true since we are not ready to swap the geolocation yet
. |
3053 // TODO: If we decide not to migrate the geolocation, there are some unr
eachable | 3036 // TODO: If we decide not to migrate the geolocation, there are some unr
eachable |
3054 // code need to remove. http://crbug.com/396184. | 3037 // code need to remove. http://crbug.com/396184. |
3055 return true; | 3038 return true; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3135 private native void nativeCreatePdfExporter(long nativeAwContents, AwPdfExpo
rter awPdfExporter); | 3118 private native void nativeCreatePdfExporter(long nativeAwContents, AwPdfExpo
rter awPdfExporter); |
3136 | 3119 |
3137 private native void nativePreauthorizePermission(long nativeAwContents, Stri
ng origin, | 3120 private native void nativePreauthorizePermission(long nativeAwContents, Stri
ng origin, |
3138 long resources); | 3121 long resources); |
3139 | 3122 |
3140 private native void nativePostMessageToFrame(long nativeAwContents, String f
rameId, | 3123 private native void nativePostMessageToFrame(long nativeAwContents, String f
rameId, |
3141 String message, String targetOrigin, int[] msgPorts); | 3124 String message, String targetOrigin, int[] msgPorts); |
3142 | 3125 |
3143 private native void nativeCreateMessageChannel(long nativeAwContents, AwMess
agePort[] ports); | 3126 private native void nativeCreateMessageChannel(long nativeAwContents, AwMess
agePort[] ports); |
3144 } | 3127 } |
OLD | NEW |