ContentView.java revision 5d1f7b1de12d16ceb2c938c56701a3e8bfa558f7
1762bb9d0ad20320b9f97a841dce57ba5e8e48b07Richard Smith// Copyright 2012 The Chromium Authors. All rights reserved.
2d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor// Use of this source code is governed by a BSD-style license that can be
37536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor// found in the LICENSE file.
48491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
57536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorpackage org.chromium.content.browser;
67536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor
77536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorimport android.content.Context;
87536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorimport android.content.res.Configuration;
97536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorimport android.graphics.Bitmap;
107536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorimport android.graphics.Canvas;
117536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorimport android.graphics.Rect;
127536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorimport android.os.Build;
137536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorimport android.util.AttributeSet;
147536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorimport android.view.KeyEvent;
157536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorimport android.view.MotionEvent;
167536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorimport android.view.View;
177536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregorimport android.view.accessibility.AccessibilityEvent;
18d0937224f383c7cc72c947119380f9713a070c73Douglas Gregorimport android.view.accessibility.AccessibilityNodeInfo;
198491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregorimport android.view.inputmethod.EditorInfo;
208491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregorimport android.view.inputmethod.InputConnection;
218491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregorimport android.widget.FrameLayout;
228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
238491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregorimport com.google.common.annotations.VisibleForTesting;
248491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
258491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregorimport org.chromium.base.TraceEvent;
268491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregorimport org.chromium.ui.base.WindowAndroid;
278491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor
288491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor/**
298491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor * The containing view for {@link ContentViewCore} that exists in the Android UI hierarchy and
308491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor * exposes the various {@link View} functionality to it.
318491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor *
328491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor * TODO(joth): Remove any methods overrides from this class that were added for WebView
33dace95b13e2ceb0c3ec8de6babd926dc5114e1e5Douglas Gregor *             compatibility.
348491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor */
358491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregorpublic class ContentView extends FrameLayout
368491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor        implements ContentViewCore.InternalAccessDelegate, PageInfo {
37d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor
38d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    private final ContentViewCore mContentViewCore;
39cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
40cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor    private float mCurrentTouchOffsetX;
41cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor    private float mCurrentTouchOffsetY;
42d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    private final int[] mLocationInWindow = new int[2];
43cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
44d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    /**
45cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor     * Creates an instance of a ContentView.
46cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor     * @param context The Context the view is running in, through which it can
47cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor     *                access the current theme, resources, etc.
489ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor     * @param nativeWebContents A pointer to the native web contents.
49cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor     * @param windowAndroid An instance of the WindowAndroid.
50cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor     * @return A ContentView instance.
51cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor     */
52cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor    public static ContentView newInstance(Context context, long nativeWebContents,
53cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor            WindowAndroid windowAndroid) {
54cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor        return newInstance(context, nativeWebContents, windowAndroid, null,
55cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor                android.R.attr.webViewStyle);
56cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor    }
57cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
58cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor    /**
59cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor     * Creates an instance of a ContentView.
60cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor     * @param context The Context the view is running in, through which it can
61cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor     *                access the current theme, resources, etc.
62cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor     * @param nativeWebContents A pointer to the native web contents.
63cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor     * @param windowAndroid An instance of the WindowAndroid.
64cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor     * @param attrs The attributes of the XML tag that is inflating the view.
65cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor     * @return A ContentView instance.
66cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor     */
67cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor    public static ContentView newInstance(Context context, long nativeWebContents,
68cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor            WindowAndroid windowAndroid, AttributeSet attrs) {
69cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor        // TODO(klobag): use the WebViewStyle as the default style for now. It enables scrollbar.
70cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor        // When ContentView is moved to framework, we can define its own style in the res.
71cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor        return newInstance(context, nativeWebContents, windowAndroid, attrs,
72cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor                android.R.attr.webViewStyle);
73cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor    }
74cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
75cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor    /**
76cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor     * Creates an instance of a ContentView.
77cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor     * @param context The Context the view is running in, through which it can
78cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor     *                access the current theme, resources, etc.
79cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor     * @param nativeWebContents A pointer to the native web contents.
80cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor     * @param windowAndroid An instance of the WindowAndroid.
81cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor     * @param attrs The attributes of the XML tag that is inflating the view.
82cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor     * @param defStyle The default style to apply to this view.
83cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor     * @return A ContentView instance.
84cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor     */
85cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor    public static ContentView newInstance(Context context, long nativeWebContents,
86cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor            WindowAndroid windowAndroid, AttributeSet attrs, int defStyle) {
87cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
88cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor            return new ContentView(context, nativeWebContents, windowAndroid, attrs, defStyle);
89cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor        } else {
90cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor            return new JellyBeanContentView(context, nativeWebContents, windowAndroid, attrs,
91cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor                    defStyle);
92cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor        }
93cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor    }
94cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
95cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor    protected ContentView(Context context, long nativeWebContents, WindowAndroid windowAndroid,
96cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor            AttributeSet attrs, int defStyle) {
97cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor        super(context, attrs, defStyle);
98cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
99cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor        if (getScrollBarStyle() == View.SCROLLBARS_INSIDE_OVERLAY) {
100cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor            setHorizontalScrollBarEnabled(false);
101cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor            setVerticalScrollBarEnabled(false);
102cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor        }
103cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
104cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor        setFocusable(true);
105cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor        setFocusableInTouchMode(true);
106cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
107cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor        mContentViewCore = new ContentViewCore(context);
108cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor        mContentViewCore.initialize(this, this, nativeWebContents, windowAndroid);
109cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor    }
110cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
111cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor    /**
112cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor     * @return The URL of the page.
113cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor     */
114cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor    public String getUrl() {
115cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor        return mContentViewCore.getUrl();
116cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor    }
117cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
118cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor    // PageInfo implementation.
119cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
120cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor    @Override
121cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor    public String getTitle() {
122cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor        return mContentViewCore.getTitle();
123cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor    }
124cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor
125cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor    @Override
126cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor    public boolean isReadyForSnapshot() {
127cff163e3cc78277496b30fa40070b46abdc290dbDouglas Gregor        return mContentViewCore.isReady();
128d0937224f383c7cc72c947119380f9713a070c73Douglas Gregor    }
129bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor
130e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor    @Override
13110738d36b150aa65206890c1c845cdba076e4200Douglas Gregor    public Bitmap getBitmap() {
13210738d36b150aa65206890c1c845cdba076e4200Douglas Gregor        return getBitmap(getWidth(), getHeight());
13310738d36b150aa65206890c1c845cdba076e4200Douglas Gregor    }
13410738d36b150aa65206890c1c845cdba076e4200Douglas Gregor
13510738d36b150aa65206890c1c845cdba076e4200Douglas Gregor    @Override
13610738d36b150aa65206890c1c845cdba076e4200Douglas Gregor    public Bitmap getBitmap(int width, int height) {
13710738d36b150aa65206890c1c845cdba076e4200Douglas Gregor        return mContentViewCore.getBitmap(width, height);
13810738d36b150aa65206890c1c845cdba076e4200Douglas Gregor    }
13910738d36b150aa65206890c1c845cdba076e4200Douglas Gregor
14010738d36b150aa65206890c1c845cdba076e4200Douglas Gregor    @Override
14110738d36b150aa65206890c1c845cdba076e4200Douglas Gregor    public int getBackgroundColor() {
14210738d36b150aa65206890c1c845cdba076e4200Douglas Gregor        return mContentViewCore.getBackgroundColor();
14310738d36b150aa65206890c1c845cdba076e4200Douglas Gregor    }
14410738d36b150aa65206890c1c845cdba076e4200Douglas Gregor
14510738d36b150aa65206890c1c845cdba076e4200Douglas Gregor    @Override
14610738d36b150aa65206890c1c845cdba076e4200Douglas Gregor    public View getView() {
14710738d36b150aa65206890c1c845cdba076e4200Douglas Gregor        return this;
14810738d36b150aa65206890c1c845cdba076e4200Douglas Gregor    }
14910738d36b150aa65206890c1c845cdba076e4200Douglas Gregor
15010738d36b150aa65206890c1c845cdba076e4200Douglas Gregor    /**
151e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor     * @return The core component of the ContentView that handles JNI communication.  Should only be
152bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor     *         used for passing to native.
153bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor     */
1549ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor    public ContentViewCore getContentViewCore() {
155bebbe0d9b7568ce43a464286bee49429489ef483Douglas Gregor        return mContentViewCore;
1569ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor    }
15761c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor
15861c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor    /**
15961c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor     * @return The cache of scales and positions used to convert coordinates from/to CSS.
16061c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor     */
16161c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor    public RenderCoordinates getRenderCoordinates() {
162a669c534cf414339060868d70d2348fea9ce6c7dDouglas Gregor        return mContentViewCore.getRenderCoordinates();
16356c04588ef3cfa1bbc968fd68de2480a4e66971dDouglas Gregor    }
1640b64ba926752110cff1344a46b36e29396cc4d25Peter Collingbourne
165fc038e9ef8ed262724f42597ca5c844de97b1202Eli Friedman    /**
166e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor     * Destroy the internal state of the WebView. This method may only be called
16774e2fc332e07c76d4e69ccbd0e9e47a0bafd3908Douglas Gregor     * after the WebView has been removed from the view system. No other methods
1688ff7e32f9480bf00d8d8476c650907853d1cc354Eli Friedman     * may be called on this WebView after this method has been called.
16956c04588ef3cfa1bbc968fd68de2480a4e66971dDouglas Gregor     */
170e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor    public void destroy() {
171e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor        mContentViewCore.destroy();
172e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor    }
173399ad970a25efcbfa7111e17f48285a70fba2731Douglas Gregor
1740c9e4799fd78d350a037498b2c797f2b2558791cDouglas Gregor    /**
1750c9e4799fd78d350a037498b2c797f2b2558791cDouglas Gregor     * Returns true initially, false after destroy() has been called.
1760c9e4799fd78d350a037498b2c797f2b2558791cDouglas Gregor     * It is illegal to call any other public method after destroy().
1770c9e4799fd78d350a037498b2c797f2b2558791cDouglas Gregor     */
17856c04588ef3cfa1bbc968fd68de2480a4e66971dDouglas Gregor    public boolean isAlive() {
17956c04588ef3cfa1bbc968fd68de2480a4e66971dDouglas Gregor        return mContentViewCore.isAlive();
18056c04588ef3cfa1bbc968fd68de2480a4e66971dDouglas Gregor    }
18156c04588ef3cfa1bbc968fd68de2480a4e66971dDouglas Gregor
1826ccab97c17c17f38eb92c7fe02c766508875bd97Douglas Gregor    public void setContentViewClient(ContentViewClient client) {
1836ccab97c17c17f38eb92c7fe02c766508875bd97Douglas Gregor        mContentViewCore.setContentViewClient(client);
1846ccab97c17c17f38eb92c7fe02c766508875bd97Douglas Gregor    }
1856ccab97c17c17f38eb92c7fe02c766508875bd97Douglas Gregor
186a31040f16604849b3b1dc36015056c81bae68ad1Douglas Gregor    @VisibleForTesting
187a31040f16604849b3b1dc36015056c81bae68ad1Douglas Gregor    public ContentViewClient getContentViewClient() {
188a31040f16604849b3b1dc36015056c81bae68ad1Douglas Gregor        return mContentViewCore.getContentViewClient();
1895b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl    }
190a31040f16604849b3b1dc36015056c81bae68ad1Douglas Gregor
191a31040f16604849b3b1dc36015056c81bae68ad1Douglas Gregor    /**
1926f52675ec400a0ee89ec6214c4845b8ee274304aDouglas Gregor     * Load url without fixing up the url string. Consumers of ContentView are responsible for
193fef2189421b89dad5582b6dd7561badd4224d974Peter Collingbourne     * ensuring the URL passed in is properly formatted (i.e. the scheme has been added if left
194fef2189421b89dad5582b6dd7561badd4224d974Peter Collingbourne     * off during user input).
195fef2189421b89dad5582b6dd7561badd4224d974Peter Collingbourne     *
196fef2189421b89dad5582b6dd7561badd4224d974Peter Collingbourne     * @param params Parameters for this load.
197fef2189421b89dad5582b6dd7561badd4224d974Peter Collingbourne     */
198fef2189421b89dad5582b6dd7561badd4224d974Peter Collingbourne    public void loadUrl(LoadUrlParams params) {
1996f52675ec400a0ee89ec6214c4845b8ee274304aDouglas Gregor        mContentViewCore.loadUrl(params);
2006f52675ec400a0ee89ec6214c4845b8ee274304aDouglas Gregor    }
2016f52675ec400a0ee89ec6214c4845b8ee274304aDouglas Gregor
2026f52675ec400a0ee89ec6214c4845b8ee274304aDouglas Gregor    /**
2036f52675ec400a0ee89ec6214c4845b8ee274304aDouglas Gregor     * @return Whether the current WebContents has a previous navigation entry.
2046f52675ec400a0ee89ec6214c4845b8ee274304aDouglas Gregor     */
2056f52675ec400a0ee89ec6214c4845b8ee274304aDouglas Gregor    public boolean canGoBack() {
2066f52675ec400a0ee89ec6214c4845b8ee274304aDouglas Gregor        return mContentViewCore.canGoBack();
207781def075d4a486a5b367c6730fe77cb1f721ac1Douglas Gregor    }
208781def075d4a486a5b367c6730fe77cb1f721ac1Douglas Gregor
209781def075d4a486a5b367c6730fe77cb1f721ac1Douglas Gregor    /**
210a669c534cf414339060868d70d2348fea9ce6c7dDouglas Gregor     * @return Whether the current WebContents has a navigation entry after the current one.
211a669c534cf414339060868d70d2348fea9ce6c7dDouglas Gregor     */
212a669c534cf414339060868d70d2348fea9ce6c7dDouglas Gregor    public boolean canGoForward() {
213a669c534cf414339060868d70d2348fea9ce6c7dDouglas Gregor        return mContentViewCore.canGoForward();
214a669c534cf414339060868d70d2348fea9ce6c7dDouglas Gregor    }
215ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
216ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    /**
217a669c534cf414339060868d70d2348fea9ce6c7dDouglas Gregor     * Goes to the navigation entry before the current one.
218a669c534cf414339060868d70d2348fea9ce6c7dDouglas Gregor     */
219a669c534cf414339060868d70d2348fea9ce6c7dDouglas Gregor    public void goBack() {
220a669c534cf414339060868d70d2348fea9ce6c7dDouglas Gregor        mContentViewCore.goBack();
221a669c534cf414339060868d70d2348fea9ce6c7dDouglas Gregor    }
222a669c534cf414339060868d70d2348fea9ce6c7dDouglas Gregor
223a669c534cf414339060868d70d2348fea9ce6c7dDouglas Gregor    /**
224e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor     * Goes to the navigation entry following the current one.
225e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor     */
226a669c534cf414339060868d70d2348fea9ce6c7dDouglas Gregor    public void goForward() {
22710ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        mContentViewCore.goForward();
22810ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    }
22910ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor
23010ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    /**
23110ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor     * Fling the ContentView from the current position.
23210ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor     * @param x Fling touch starting position
23310ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor     * @param y Fling touch starting position
23410ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor     * @param velocityX Initial velocity of the fling (X) measured in pixels per second.
23510ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor     * @param velocityY Initial velocity of the fling (Y) measured in pixels per second.
23610ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor     */
23710ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    @VisibleForTesting
23810ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    public void fling(long timeMs, int x, int y, int velocityX, int velocityY) {
23910ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        mContentViewCore.flingForTest(timeMs, x, y, velocityX, velocityY);
24010ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    }
24110ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor
24210ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    /**
24310ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor     * Injects the passed JavaScript code in the current page and evaluates it.
24410ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor     *
24510ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor     * @throws IllegalStateException If the ContentView has been destroyed.
24610ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor     */
24710ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    public void evaluateJavaScript(String script) throws IllegalStateException {
24810ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        mContentViewCore.evaluateJavaScript(script, null);
24910ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    }
25010ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor
25110ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    /**
25210ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor     * To be called when the ContentView is shown.
25310ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor     **/
25410ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    public void onShow() {
25510ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        mContentViewCore.onShow();
25610ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    }
25710ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor
25810ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    /**
25910ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor     * To be called when the ContentView is hidden.
26010ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor     **/
26110ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    public void onHide() {
26210ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        mContentViewCore.onHide();
26310ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    }
26410ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor
26510ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    /**
26610ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor     * Hides the select action bar.
26710ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor     */
26810ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    public void hideSelectActionBar() {
26910ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        mContentViewCore.hideSelectActionBar();
27010ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    }
27110ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor
27210ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    // FrameLayout overrides.
27310ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor
27410ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    // Needed by ContentViewCore.InternalAccessDelegate
27510ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    @Override
27610ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    public boolean drawChild(Canvas canvas, View child, long drawingTime) {
27710ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        return super.drawChild(canvas, child, drawingTime);
27810ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    }
27910ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor
28010ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    // Needed by ContentViewCore.InternalAccessDelegate
28110ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    @Override
28210ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    public void onScrollChanged(int l, int t, int oldl, int oldt) {
28310ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        super.onScrollChanged(l, t, oldl, oldt);
28410ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    }
28510ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor
28610ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    @Override
28710ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    protected void onSizeChanged(int w, int h, int ow, int oh) {
28810ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        TraceEvent.begin();
28910ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        super.onSizeChanged(w, h, ow, oh);
29010ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        mContentViewCore.onSizeChanged(w, h, ow, oh);
29110ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        TraceEvent.end();
29210ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    }
29310ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor
29410ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    @Override
29510ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
29610ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        super.onLayout(changed, left, top, right, bottom);
29710ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        if (changed) {
29810ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor            getLocationInWindow(mLocationInWindow);
29910ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor            mContentViewCore.onLocationInWindowChanged(mLocationInWindow[0], mLocationInWindow[1]);
30010ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        }
30110ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    }
30210ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor
30310ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    @Override
30410ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
30510ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        return mContentViewCore.onCreateInputConnection(outAttrs);
30610ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    }
30710ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor
30810ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    @Override
30910ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    public boolean onCheckIsTextEditor() {
31010ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        return mContentViewCore.onCheckIsTextEditor();
31110ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    }
31210ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor
313651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines    @Override
31410ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
31510ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        TraceEvent.begin();
316651f13cea278ec967336033dd032faef0e9fc2ecStephen Hines        super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
31710ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        mContentViewCore.onFocusChanged(gainFocus);
31810ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        TraceEvent.end();
31910ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    }
32010ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor
32110ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    @Override
32210ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    public void onWindowFocusChanged(boolean hasWindowFocus) {
32310ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        super.onWindowFocusChanged(hasWindowFocus);
32410ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        mContentViewCore.onWindowFocusChanged(hasWindowFocus);
32510ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    }
32610ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor
32710ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    @Override
32810ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    public boolean onKeyUp(int keyCode, KeyEvent event) {
32910ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        return mContentViewCore.onKeyUp(keyCode, event);
33010ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    }
33110ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor
33210ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    @Override
33310ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    public boolean dispatchKeyEventPreIme(KeyEvent event) {
33410ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        return mContentViewCore.dispatchKeyEventPreIme(event);
33510ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    }
33610ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor
33710ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    @Override
33810ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    public boolean dispatchKeyEvent(KeyEvent event) {
33910ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        if (isFocused()) {
34010ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor            return mContentViewCore.dispatchKeyEvent(event);
34110ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        } else {
34210ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor            return super.dispatchKeyEvent(event);
34310ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        }
34410ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    }
34510ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor
34610ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    @Override
34710ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    public boolean onTouchEvent(MotionEvent event) {
34810ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        MotionEvent offset = createOffsetMotionEvent(event);
34910ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        boolean consumed = mContentViewCore.onTouchEvent(offset);
35010ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        offset.recycle();
35110ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        return consumed;
35210ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor    }
353ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith
354ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith    /**
355419563768ef4929a622d7c2b066856e82901bb91Richard Smith     * Mouse move events are sent on hover enter, hover move and hover exit.
356419563768ef4929a622d7c2b066856e82901bb91Richard Smith     * They are sent on hover exit because sometimes it acts as both a hover
357419563768ef4929a622d7c2b066856e82901bb91Richard Smith     * move and hover exit.
358419563768ef4929a622d7c2b066856e82901bb91Richard Smith     */
359419563768ef4929a622d7c2b066856e82901bb91Richard Smith    @Override
360419563768ef4929a622d7c2b066856e82901bb91Richard Smith    public boolean onHoverEvent(MotionEvent event) {
361419563768ef4929a622d7c2b066856e82901bb91Richard Smith        MotionEvent offset = createOffsetMotionEvent(event);
362419563768ef4929a622d7c2b066856e82901bb91Richard Smith        boolean consumed = mContentViewCore.onHoverEvent(offset);
363419563768ef4929a622d7c2b066856e82901bb91Richard Smith        offset.recycle();
36410ffc00e2177f042808f507c8dd50b744ed6f738Douglas Gregor        super.onHoverEvent(event);
365a669c534cf414339060868d70d2348fea9ce6c7dDouglas Gregor        return consumed;
366925910d488051cbd4e38f350c1e9d69c473f09a0Douglas Gregor    }
367925910d488051cbd4e38f350c1e9d69c473f09a0Douglas Gregor
368925910d488051cbd4e38f350c1e9d69c473f09a0Douglas Gregor    @Override
369a669c534cf414339060868d70d2348fea9ce6c7dDouglas Gregor    public boolean onGenericMotionEvent(MotionEvent event) {
370e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor        return mContentViewCore.onGenericMotionEvent(event);
371e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor    }
3729ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor
3739ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor    @Override
3749ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor    public boolean performLongClick() {
3759ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor        return false;
3769ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor    }
3779ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor
3789ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor    /**
3799ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor     * Sets the current amount to offset incoming touch events by.  This is used to handle content
3809ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor     * moving and not lining up properly with the android input system.
3819ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor     * @param dx The X offset in pixels to shift touch events.
3829ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor     * @param dy The Y offset in pixels to shift touch events.
3839ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor     */
3849ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor    public void setCurrentMotionEventOffsets(float dx, float dy) {
3859ef75899bae6dd9a4be1252ae9cadcb619c170ffDouglas Gregor        mCurrentTouchOffsetX = dx;
386e186269a8a41dbff1ebea2c251048892979d1078Douglas Gregor        mCurrentTouchOffsetY = dy;
38712c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor    }
38812c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor
38912c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor    private MotionEvent createOffsetMotionEvent(MotionEvent src) {
39012c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor        MotionEvent dst = MotionEvent.obtain(src);
39112c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor        dst.offsetLocation(mCurrentTouchOffsetX, mCurrentTouchOffsetY);
39212c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor        return dst;
39312c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor    }
39412c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor
39512c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor    @Override
39612c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor    protected void onConfigurationChanged(Configuration newConfig) {
39712c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor        mContentViewCore.onConfigurationChanged(newConfig);
39812c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor    }
39912c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor
40012c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor    /**
40112c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor     * Currently the ContentView scrolling happens in the native side. In
40212c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor     * the Java view system, it is always pinned at (0, 0). scrollBy() and scrollTo()
40312c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor     * are overridden, so that View's mScrollX and mScrollY will be unchanged at
40412c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor     * (0, 0). This is critical for drawing ContentView correctly.
40512c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor     */
40612c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor    @Override
40712c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor    public void scrollBy(int x, int y) {
40812c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor        mContentViewCore.scrollBy(x, y);
40912c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor    }
41012c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor
41112c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor    @Override
41212c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor    public void scrollTo(int x, int y) {
41312c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor        mContentViewCore.scrollTo(x, y);
41498a75581e155a7dac853a69b0151960f8e2aacbdNick Lewycky    }
41598a75581e155a7dac853a69b0151960f8e2aacbdNick Lewycky
41698a75581e155a7dac853a69b0151960f8e2aacbdNick Lewycky    @Override
41798a75581e155a7dac853a69b0151960f8e2aacbdNick Lewycky    protected int computeHorizontalScrollExtent() {
41898a75581e155a7dac853a69b0151960f8e2aacbdNick Lewycky        // TODO(dtrainor): Need to expose scroll events properly to public. Either make getScroll*
41998a75581e155a7dac853a69b0151960f8e2aacbdNick Lewycky        // work or expose computeHorizontalScrollOffset()/computeVerticalScrollOffset as public.
42098a75581e155a7dac853a69b0151960f8e2aacbdNick Lewycky        return mContentViewCore.computeHorizontalScrollExtent();
42198a75581e155a7dac853a69b0151960f8e2aacbdNick Lewycky    }
42298a75581e155a7dac853a69b0151960f8e2aacbdNick Lewycky
42398a75581e155a7dac853a69b0151960f8e2aacbdNick Lewycky    @Override
42498a75581e155a7dac853a69b0151960f8e2aacbdNick Lewycky    protected int computeHorizontalScrollOffset() {
425        return mContentViewCore.computeHorizontalScrollOffset();
426    }
427
428    @Override
429    protected int computeHorizontalScrollRange() {
430        return mContentViewCore.computeHorizontalScrollRange();
431    }
432
433    @Override
434    protected int computeVerticalScrollExtent() {
435        return mContentViewCore.computeVerticalScrollExtent();
436    }
437
438    @Override
439    protected int computeVerticalScrollOffset() {
440        return mContentViewCore.computeVerticalScrollOffset();
441    }
442
443    @Override
444    protected int computeVerticalScrollRange() {
445        return mContentViewCore.computeVerticalScrollRange();
446    }
447
448    // End FrameLayout overrides.
449
450    @Override
451    public boolean awakenScrollBars(int startDelay, boolean invalidate) {
452        return mContentViewCore.awakenScrollBars(startDelay, invalidate);
453    }
454
455    @Override
456    public boolean awakenScrollBars() {
457        return super.awakenScrollBars();
458    }
459
460    public int getSingleTapX()  {
461        return mContentViewCore.getSingleTapX();
462    }
463
464    public int getSingleTapY()  {
465        return mContentViewCore.getSingleTapY();
466    }
467
468    @Override
469    public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
470        super.onInitializeAccessibilityNodeInfo(info);
471        mContentViewCore.onInitializeAccessibilityNodeInfo(info);
472    }
473
474    /**
475     * Fills in scrolling values for AccessibilityEvents.
476     * @param event Event being fired.
477     */
478    @Override
479    public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
480        super.onInitializeAccessibilityEvent(event);
481        mContentViewCore.onInitializeAccessibilityEvent(event);
482    }
483
484    @Override
485    protected void onAttachedToWindow() {
486        super.onAttachedToWindow();
487        mContentViewCore.onAttachedToWindow();
488    }
489
490    @Override
491    protected void onDetachedFromWindow() {
492        super.onDetachedFromWindow();
493        mContentViewCore.onDetachedFromWindow();
494    }
495
496    @Override
497    protected void onVisibilityChanged(View changedView, int visibility) {
498        super.onVisibilityChanged(changedView, visibility);
499        mContentViewCore.onVisibilityChanged(changedView, visibility);
500    }
501
502    /**
503     * Return the current scale of the WebView
504     * @return The current scale.
505     */
506    public float getScale() {
507        return mContentViewCore.getScale();
508    }
509
510    /**
511     * Enable or disable accessibility features.
512     */
513    public void setAccessibilityState(boolean state) {
514        mContentViewCore.setAccessibilityState(state);
515    }
516
517    /**
518     * Inform WebKit that Fullscreen mode has been exited by the user.
519     */
520    public void exitFullscreen() {
521        mContentViewCore.exitFullscreen();
522    }
523
524    /**
525     * Return content scroll y.
526     *
527     * @return The vertical scroll position in pixels.
528     */
529    public int getContentScrollY() {
530        return mContentViewCore.computeVerticalScrollOffset();
531    }
532
533    /**
534     * Return content height.
535     *
536     * @return The height of the content in pixels.
537     */
538    public int getContentHeight() {
539        return mContentViewCore.computeVerticalScrollRange();
540    }
541
542    ///////////////////////////////////////////////////////////////////////////////////////////////
543    //              Start Implementation of ContentViewCore.InternalAccessDelegate               //
544    ///////////////////////////////////////////////////////////////////////////////////////////////
545
546    @Override
547    public boolean super_onKeyUp(int keyCode, KeyEvent event) {
548        return super.onKeyUp(keyCode, event);
549    }
550
551    @Override
552    public boolean super_dispatchKeyEventPreIme(KeyEvent event) {
553        return super.dispatchKeyEventPreIme(event);
554    }
555
556    @Override
557    public boolean super_dispatchKeyEvent(KeyEvent event) {
558        return super.dispatchKeyEvent(event);
559    }
560
561    @Override
562    public boolean super_onGenericMotionEvent(MotionEvent event) {
563        return super.onGenericMotionEvent(event);
564    }
565
566    @Override
567    public void super_onConfigurationChanged(Configuration newConfig) {
568        super.onConfigurationChanged(newConfig);
569    }
570
571    @Override
572    public boolean super_awakenScrollBars(int startDelay, boolean invalidate) {
573        return super.awakenScrollBars(startDelay, invalidate);
574    }
575
576    ///////////////////////////////////////////////////////////////////////////////////////////////
577    //                End Implementation of ContentViewCore.InternalAccessDelegate               //
578    ///////////////////////////////////////////////////////////////////////////////////////////////
579}
580