ContentView.java revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)package org.chromium.content.browser;
6c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)
7424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)import android.app.Activity;
84e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)import android.content.Context;
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)import android.content.res.Configuration;
10424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)import android.graphics.Bitmap;
1158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)import android.graphics.Canvas;
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import android.graphics.Rect;
13f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)import android.os.Build;
14424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)import android.util.AttributeSet;
15424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)import android.view.KeyEvent;
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)import android.view.MotionEvent;
1758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)import android.view.View;
18f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)import android.view.accessibility.AccessibilityEvent;
19a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)import android.view.accessibility.AccessibilityNodeInfo;
204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)import android.view.inputmethod.EditorInfo;
2158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)import android.view.inputmethod.InputConnection;
2258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)import android.widget.FrameLayout;
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
24424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)import com.google.common.annotations.VisibleForTesting;
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)import org.chromium.content.common.TraceEvent;
272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)import org.chromium.ui.WindowAndroid;
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)/**
3058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) * The containing view for {@link ContentViewCore} that exists in the Android UI hierarchy and
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * exposes the various {@link View} functionality to it.
32c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) *
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) * TODO(joth): Remove any methods overrides from this class that were added for WebView
34424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) *             compatibility.
35424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) */
36424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)public class ContentView extends FrameLayout
37424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)        implements ContentViewCore.InternalAccessDelegate, PageInfo {
38424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    // Used when ContentView implements a standalone View.
39424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    public static final int PERSONALITY_VIEW = ContentViewCore.PERSONALITY_VIEW;
40424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    // Used for Chrome.
41424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    public static final int PERSONALITY_CHROME = ContentViewCore.PERSONALITY_CHROME;
42424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
43424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    private final ContentViewCore mContentViewCore;
44424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
45424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    private float mCurrentTouchOffsetX;
46424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    private float mCurrentTouchOffsetY;
47424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    /**
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * Creates an instance of a ContentView.
50424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)     * @param context The Context the view is running in, through which it can
51424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)     *                access the current theme, resources, etc.
52424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)     * @param nativeWebContents A pointer to the native web contents.
5358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)     * @param windowAndroid An instance of the WindowAndroid.
54f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)     * @param personality One of {@link #PERSONALITY_CHROME} or {@link #PERSONALITY_VIEW}.
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     * @return A ContentView instance.
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)     */
5758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    public static ContentView newInstance(Context context, int nativeWebContents,
5858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)            WindowAndroid windowAndroid, int personality) {
5958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)        return newInstance(context, nativeWebContents, windowAndroid, null,
6058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)                android.R.attr.webViewStyle, personality);
6158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    }
6258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
6358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    /**
6458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)     * Creates an instance of a ContentView.
6558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)     * @param context The Context the view is running in, through which it can
665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     *                access the current theme, resources, etc.
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * @param nativeWebContents A pointer to the native web contents.
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * @param windowAndroid An instance of the WindowAndroid.
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * @param attrs The attributes of the XML tag that is inflating the view.
705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * @return A ContentView instance.
718bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)     */
728bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    public static ContentView newInstance(Context context, int nativeWebContents,
738bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)            WindowAndroid windowAndroid, AttributeSet attrs) {
748bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        // TODO(klobag): use the WebViewStyle as the default style for now. It enables scrollbar.
758bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        // When ContentView is moved to framework, we can define its own style in the res.
768bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        return newInstance(context, nativeWebContents, windowAndroid, attrs,
778bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                android.R.attr.webViewStyle);
788bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    }
790f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
800f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    /**
810f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)     * Creates an instance of a ContentView.
820f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)     * @param context The Context the view is running in, through which it can
830f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)     *                access the current theme, resources, etc.
840f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)     * @param nativeWebContents A pointer to the native web contents.
850f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)     * @param windowAndroid An instance of the WindowAndroid.
860f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)     * @param attrs The attributes of the XML tag that is inflating the view.
87a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)     * @param defStyle The default style to apply to this view.
888bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)     * @return A ContentView instance.
898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)     */
908bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    public static ContentView newInstance(Context context, int nativeWebContents,
91a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)            WindowAndroid windowAndroid, AttributeSet attrs, int defStyle) {
928bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        return newInstance(context, nativeWebContents, windowAndroid, attrs, defStyle,
938bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                PERSONALITY_VIEW);
948bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    }
958bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
968bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    private static ContentView newInstance(Context context, int nativeWebContents,
978bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)            WindowAndroid windowAndroid, AttributeSet attrs, int defStyle, int personality) {
988bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
998bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)            return new ContentView(context, nativeWebContents, windowAndroid, attrs, defStyle,
1008bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                    personality);
1018bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        } else {
1028bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)            return new JellyBeanContentView(context, nativeWebContents, windowAndroid, attrs,
1038bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)                    defStyle, personality);
1048bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        }
1058bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    }
1068bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1078bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)    protected ContentView(Context context, int nativeWebContents, WindowAndroid windowAndroid,
1088bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)            AttributeSet attrs, int defStyle, int personality) {
1098bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        super(context, attrs, defStyle);
1108bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)
1118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        mContentViewCore = new ContentViewCore(context, personality);
1128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)        mContentViewCore.initialize(this, this, nativeWebContents, windowAndroid);
113424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    }
114424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
115424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    // PageInfo implementation.
116424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
117424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    @Override
118424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    public String getUrl() {
119424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)        return mContentViewCore.getUrl();
120424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    }
121424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
122424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    @Override
123424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    public String getTitle() {
124424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)        return mContentViewCore.getTitle();
125424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    }
126424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
12758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    @Override
12858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    public boolean isReadyForSnapshot() {
1292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)        return !isCrashed() && isReady();
1302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    }
1310f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
1320f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    @Override
1330f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    public Bitmap getBitmap() {
1340f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)        return getBitmap(getWidth(), getHeight());
1350f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    }
1360f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)
1370f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    @Override
1380f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)    public Bitmap getBitmap(int width, int height) {
1395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        return mContentViewCore.getBitmap(width, height);
1405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
1415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    @Override
1435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    public int getBackgroundColor() {
1445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        return mContentViewCore.getBackgroundColor();
1455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
1465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    @Override
1485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    public View getView() {
1495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        return this;
1505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
1515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    /**
1535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * @return The core component of the ContentView that handles JNI communication.  Should only be
1545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     *         used for passing to native.
1555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     */
1565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    public ContentViewCore getContentViewCore() {
1575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        return mContentViewCore;
1585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
1595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    /**
1615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * @return The cache of scales and positions used to convert coordinates from/to CSS.
1625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     */
1635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    public RenderCoordinates getRenderCoordinates() {
1645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        return mContentViewCore.getRenderCoordinates();
1655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
1665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    /**
1685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * Returns true if the given Activity has hardware acceleration enabled
1695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * in its manifest, or in its foreground window.
1705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     *
1715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * TODO(husky): Remove when ContentViewCore.initialize() is refactored (see TODO there)
1725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * TODO(dtrainor) This is still used by other classes.  Make sure to pull some version of this
1735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * out before removing it.
174424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)     */
1755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    public static boolean hasHardwareAcceleration(Activity activity) {
1765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        return ContentViewCore.hasHardwareAcceleration(activity);
1775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
178424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
1794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    /**
1804e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)     * @return Whether the configured personality of this ContentView is {@link #PERSONALITY_VIEW}.
1814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)     */
1824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    boolean isPersonalityView() {
1834e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)        return mContentViewCore.isPersonalityView();
1844e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    }
1854e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
1864e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    /**
1874e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)     * Destroy the internal state of the WebView. This method may only be called
188f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)     * after the WebView has been removed from the view system. No other methods
1894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)     * may be called on this WebView after this method has been called.
190424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)     */
191424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    public void destroy() {
192424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)        mContentViewCore.destroy();
1935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
1945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    /**
196424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)     * Returns true initially, false after destroy() has been called.
197424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)     * It is illegal to call any other public method after destroy().
19858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)     */
19958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    public boolean isAlive() {
20058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)        return mContentViewCore.isAlive();
20158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    }
20258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
20358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    /**
20458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)     * For internal use. Throws IllegalStateException if mNativeContentView is 0.
20558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)     * Use this to ensure we get a useful Java stack trace, rather than a native
20658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)     * crash dump, from use-after-destroy bugs in Java code.
20758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)     */
20858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    void checkIsAlive() throws IllegalStateException {
20958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)        mContentViewCore.checkIsAlive();
21058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    }
21158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
21258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    public void setContentViewClient(ContentViewClient client) {
21358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)        mContentViewCore.setContentViewClient(client);
21458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    }
21558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
2165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    @VisibleForTesting
2175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    public ContentViewClient getContentViewClient() {
218f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        return mContentViewCore.getContentViewClient();
21958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    }
22058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
22158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    /**
22258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)     * Load url without fixing up the url string. Consumers of ContentView are responsible for
22358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)     * ensuring the URL passed in is properly formatted (i.e. the scheme has been added if left
22458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)     * off during user input).
22558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)     *
2265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * @param params Parameters for this load.
2275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     */
2285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    public void loadUrl(LoadUrlParams params) {
22958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)        mContentViewCore.loadUrl(params);
23058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    }
23158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
23258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    /**
23358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)     * Stops loading the current web contents.
23458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)     */
2355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    public void stopLoading() {
2365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        mContentViewCore.stopLoading();
2375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
2385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
239424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    /**
240424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)     * @return Whether the current WebContents has a previous navigation entry.
241424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)     */
242424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    public boolean canGoBack() {
243a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)        return mContentViewCore.canGoBack();
244a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    }
245424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
246424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    /**
247424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)     * @return Whether the current WebContents has a navigation entry after the current one.
248424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)     */
249424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    public boolean canGoForward() {
250424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)        return mContentViewCore.canGoForward();
251424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    }
2525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
253424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    /**
254424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)     * @param offset The offset into the navigation history.
255424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)     * @return Whether we can move in history by given offset
256a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)     */
257a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    public boolean canGoToOffset(int offset) {
258424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)        return mContentViewCore.canGoToOffset(offset);
259424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    }
260424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
261424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    /**
262424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)     * Navigates to the specified offset from the "current entry". Does nothing if the offset is out
263424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)     * of bounds.
264424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)     * @param offset The offset into the navigation history.
265424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)     */
266424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    public void goToOffset(int offset) {
26758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)        mContentViewCore.goToOffset(offset);
26858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    }
26958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
27058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    /**
27158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)     * Goes to the navigation entry before the current one.
27258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)     */
27358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    public void goBack() {
27458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)        mContentViewCore.goBack();
2755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
2765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
2775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    /**
2785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * Goes to the navigation entry following the current one.
2795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     */
28058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    public void goForward() {
28158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)        mContentViewCore.goForward();
28258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    }
28358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
28458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    /**
28558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)     * Reload the current page.
28658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)     */
28758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    public void reload() {
28858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)        mContentViewCore.reload();
28958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    }
29058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
29158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    /**
29258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)     * Clears the WebView's page history in both the backwards and forwards
29358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)     * directions.
294424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)     */
295424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    public void clearHistory() {
296424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)        mContentViewCore.clearHistory();
297424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    }
298424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
299424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    String getSelectedText() {
300424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)        return mContentViewCore.getSelectedText();
301424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    }
30258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
30358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    /**
30458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)     * Start profiling the update speed. You must call {@link #stopFpsProfiling}
30558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)     * to stop profiling.
30658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)     */
30758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    @VisibleForTesting
30858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    public void startFpsProfiling() {
30958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)        // TODO(nileshagrawal): Implement this.
31058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    }
31158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)
31258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    /**
313424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)     * Stop profiling the update speed.
314424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)     */
315424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    @VisibleForTesting
316424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    public float stopFpsProfiling() {
31758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)        // TODO(nileshagrawal): Implement this.
318424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)        return 0.0f;
319424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    }
320424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
321424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    /**
322424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)     * Fling the ContentView from the current position.
323424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)     * @param x Fling touch starting position
3245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * @param y Fling touch starting position
3255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * @param velocityX Initial velocity of the fling (X) measured in pixels per second.
3265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * @param velocityY Initial velocity of the fling (Y) measured in pixels per second.
3275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     */
3285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    @VisibleForTesting
3295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    public void fling(long timeMs, int x, int y, int velocityX, int velocityY) {
3305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        mContentViewCore.getContentViewGestureHandler().fling(timeMs, x, y, velocityX, velocityY);
3315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
332424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
333424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    void endFling(long timeMs) {
334424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)        mContentViewCore.getContentViewGestureHandler().endFling(timeMs);
335424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    }
336424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
337424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    /**
338424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)     * Start pinch zoom. You must call {@link #pinchEnd} to stop.
339424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)     */
340424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    @VisibleForTesting
341424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    public void pinchBegin(long timeMs, int x, int y) {
342424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)        mContentViewCore.getContentViewGestureHandler().pinchBegin(timeMs, x, y);
343424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)    }
344424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)
34558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    /**
34658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)     * Stop pinch zoom.
34758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)     */
34858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    @VisibleForTesting
34958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles)    public void pinchEnd(long timeMs) {
3504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)        mContentViewCore.getContentViewGestureHandler().pinchEnd(timeMs);
3514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    }
3524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
3534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    void setIgnoreSingleTap(boolean value) {
3544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)        mContentViewCore.getContentViewGestureHandler().setIgnoreSingleTap(value);
3554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    }
356a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
3574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    /**
3584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)     * Modify the ContentView magnification level. The effect of calling this
3594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)     * method is exactly as after "pinch zoom".
3604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)     *
3614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)     * @param timeMs The event time in milliseconds.
3624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)     * @param delta The ratio of the new magnification level over the current
3634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)     *            magnification level.
3644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)     * @param anchorX The magnification anchor (X) in the current view
3654e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)     *            coordinate.
3664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)     * @param anchorY The magnification anchor (Y) in the current view
3674e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)     *            coordinate.
3684e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)     */
3694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    @VisibleForTesting
370f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    public void pinchBy(long timeMs, int anchorX, int anchorY, float delta) {
371f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        mContentViewCore.getContentViewGestureHandler().pinchBy(timeMs, anchorX, anchorY, delta);
372f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    }
373f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
374f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    /**
375f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)     * Injects the passed JavaScript code in the current page and evaluates it.
376f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)     *
377f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)     * @throws IllegalStateException If the ContentView has been destroyed.
378f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)     */
379f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    public void evaluateJavaScript(String script) throws IllegalStateException {
380f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)        mContentViewCore.evaluateJavaScript(script, null);
381f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    }
382f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)
383f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)    /**
3845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * This method should be called when the containing activity is paused.
3855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     **/
3865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    public void onActivityPause() {
3875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)        mContentViewCore.onActivityPause();
3885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    }
3895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
390c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    /**
391c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)     * This method should be called when the containing activity is resumed.
392c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)     **/
393    public void onActivityResume() {
394        mContentViewCore.onActivityResume();
395    }
396
397    /**
398     * To be called when the ContentView is shown.
399     **/
400    public void onShow() {
401        mContentViewCore.onShow();
402    }
403
404    /**
405     * To be called when the ContentView is hidden.
406     **/
407    public void onHide() {
408        mContentViewCore.onHide();
409    }
410
411    /**
412     * Return the ContentSettings object used to control the settings for this
413     * WebView.
414     *
415     * Note that when ContentView is used in the PERSONALITY_CHROME role,
416     * ContentSettings can only be used for retrieving settings values. For
417     * modifications, ChromeNativePreferences is to be used.
418     * @return A ContentSettings object that can be used to control this WebView's
419     *         settings.
420     */
421    public ContentSettings getContentSettings() {
422        return mContentViewCore.getContentSettings();
423    }
424
425    /**
426     * Hides the select action bar.
427     */
428    public void hideSelectActionBar() {
429        mContentViewCore.hideSelectActionBar();
430    }
431
432    // FrameLayout overrides.
433
434    // Needed by ContentViewCore.InternalAccessDelegate
435    @Override
436    public boolean drawChild(Canvas canvas, View child, long drawingTime) {
437        return super.drawChild(canvas, child, drawingTime);
438    }
439
440    // Needed by ContentViewCore.InternalAccessDelegate
441    @Override
442    public void onScrollChanged(int l, int t, int oldl, int oldt) {
443        super.onScrollChanged(l, t, oldl, oldt);
444    }
445
446    @Override
447    protected void onSizeChanged(int w, int h, int ow, int oh) {
448        TraceEvent.begin();
449        super.onSizeChanged(w, h, ow, oh);
450        mContentViewCore.onSizeChanged(w, h, ow, oh);
451        TraceEvent.end();
452    }
453
454    @Override
455    public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
456        return mContentViewCore.onCreateInputConnection(outAttrs);
457    }
458
459    @Override
460    public boolean onCheckIsTextEditor() {
461        return mContentViewCore.onCheckIsTextEditor();
462    }
463
464    @Override
465    protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
466        TraceEvent.begin();
467        super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
468        mContentViewCore.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
469        TraceEvent.end();
470    }
471
472    @Override
473    public boolean onKeyUp(int keyCode, KeyEvent event) {
474        return mContentViewCore.onKeyUp(keyCode, event);
475    }
476
477    @Override
478    public boolean dispatchKeyEventPreIme(KeyEvent event) {
479        return mContentViewCore.dispatchKeyEventPreIme(event);
480    }
481
482    @Override
483    public boolean dispatchKeyEvent(KeyEvent event) {
484        if (isFocused()) {
485            return mContentViewCore.dispatchKeyEvent(event);
486        } else {
487            return super.dispatchKeyEvent(event);
488        }
489    }
490
491    @Override
492    public boolean onTouchEvent(MotionEvent event) {
493        MotionEvent offset = createOffsetMotionEvent(event);
494        boolean consumed = mContentViewCore.onTouchEvent(offset);
495        offset.recycle();
496        return consumed;
497    }
498
499    /**
500     * Mouse move events are sent on hover enter, hover move and hover exit.
501     * They are sent on hover exit because sometimes it acts as both a hover
502     * move and hover exit.
503     */
504    @Override
505    public boolean onHoverEvent(MotionEvent event) {
506        return mContentViewCore.onHoverEvent(event);
507    }
508
509    @Override
510    public boolean onGenericMotionEvent(MotionEvent event) {
511        return mContentViewCore.onGenericMotionEvent(event);
512    }
513
514    /**
515     * Sets the current amount to offset incoming touch events by.  This is used to handle content
516     * moving and not lining up properly with the android input system.
517     * @param dx The X offset in pixels to shift touch events.
518     * @param dy The Y offset in pixels to shift touch events.
519     */
520    public void setCurrentMotionEventOffsets(float dx, float dy) {
521        mCurrentTouchOffsetX = dx;
522        mCurrentTouchOffsetY = dy;
523    }
524
525    private MotionEvent createOffsetMotionEvent(MotionEvent src) {
526        MotionEvent dst = MotionEvent.obtain(src);
527        dst.offsetLocation(mCurrentTouchOffsetX, mCurrentTouchOffsetY);
528        return dst;
529    }
530
531    @Override
532    protected void onConfigurationChanged(Configuration newConfig) {
533        mContentViewCore.onConfigurationChanged(newConfig);
534    }
535
536    /**
537     * Currently the ContentView scrolling happens in the native side. In
538     * the Java view system, it is always pinned at (0, 0). scrollBy() and scrollTo()
539     * are overridden, so that View's mScrollX and mScrollY will be unchanged at
540     * (0, 0). This is critical for drawing ContentView correctly.
541     */
542    @Override
543    public void scrollBy(int x, int y) {
544        mContentViewCore.scrollBy(x, y);
545    }
546
547    @Override
548    public void scrollTo(int x, int y) {
549        mContentViewCore.scrollTo(x, y);
550    }
551
552    @Override
553    protected int computeHorizontalScrollExtent() {
554        // TODO (dtrainor): Need to expose scroll events properly to public. Either make getScroll*
555        // work or expose computeHorizontalScrollOffset()/computeVerticalScrollOffset as public.
556        return mContentViewCore.computeHorizontalScrollExtent();
557    }
558
559    @Override
560    protected int computeHorizontalScrollOffset() {
561        return mContentViewCore.computeHorizontalScrollOffset();
562    }
563
564    @Override
565    protected int computeHorizontalScrollRange() {
566        return mContentViewCore.computeHorizontalScrollRange();
567    }
568
569    @Override
570    protected int computeVerticalScrollExtent() {
571        return mContentViewCore.computeVerticalScrollExtent();
572    }
573
574    @Override
575    protected int computeVerticalScrollOffset() {
576        return mContentViewCore.computeVerticalScrollOffset();
577    }
578
579    @Override
580    protected int computeVerticalScrollRange() {
581        return mContentViewCore.computeVerticalScrollRange();
582    }
583
584    // End FrameLayout overrides.
585
586    @Override
587    public boolean awakenScrollBars(int startDelay, boolean invalidate) {
588        return mContentViewCore.awakenScrollBars(startDelay, invalidate);
589    }
590
591    @Override
592    public boolean awakenScrollBars() {
593        return super.awakenScrollBars();
594    }
595
596    public int getSingleTapX()  {
597        return mContentViewCore.getContentViewGestureHandler().getSingleTapX();
598    }
599
600    public int getSingleTapY()  {
601        return mContentViewCore.getContentViewGestureHandler().getSingleTapY();
602    }
603
604    @Override
605    public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
606        super.onInitializeAccessibilityNodeInfo(info);
607        mContentViewCore.onInitializeAccessibilityNodeInfo(info);
608    }
609
610    /**
611     * Fills in scrolling values for AccessibilityEvents.
612     * @param event Event being fired.
613     */
614    @Override
615    public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
616        super.onInitializeAccessibilityEvent(event);
617        mContentViewCore.onInitializeAccessibilityEvent(event);
618    }
619
620    @Override
621    protected void onAttachedToWindow() {
622        super.onAttachedToWindow();
623        mContentViewCore.onAttachedToWindow();
624    }
625
626    @Override
627    protected void onDetachedFromWindow() {
628        super.onDetachedFromWindow();
629        mContentViewCore.onDetachedFromWindow();
630    }
631
632    @Override
633    protected void onVisibilityChanged(View changedView, int visibility) {
634        super.onVisibilityChanged(changedView, visibility);
635        mContentViewCore.onVisibilityChanged(changedView, visibility);
636    }
637
638    void updateMultiTouchZoomSupport() {
639        mContentViewCore.updateMultiTouchZoomSupport();
640    }
641
642    public boolean isMultiTouchZoomSupported() {
643        return mContentViewCore.isMultiTouchZoomSupported();
644    }
645
646    /**
647     * Register the delegate to be used when content can not be handled by
648     * the rendering engine, and should be downloaded instead. This will replace
649     * the current delegate.
650     * @param delegate An implementation of ContentViewDownloadDelegate.
651     */
652    public void setDownloadDelegate(ContentViewDownloadDelegate delegate) {
653        mContentViewCore.setDownloadDelegate(delegate);
654    }
655
656    // Called by DownloadController.
657    ContentViewDownloadDelegate getDownloadDelegate() {
658        return mContentViewCore.getDownloadDelegate();
659    }
660
661    public boolean getUseDesktopUserAgent() {
662        return mContentViewCore.getUseDesktopUserAgent();
663    }
664
665    /**
666     * Set whether or not we're using a desktop user agent for the currently loaded page.
667     * @param override If true, use a desktop user agent.  Use a mobile one otherwise.
668     * @param reloadOnChange Reload the page if the UA has changed.
669     */
670    public void setUseDesktopUserAgent(boolean override, boolean reloadOnChange) {
671        mContentViewCore.setUseDesktopUserAgent(override, reloadOnChange);
672    }
673
674    /**
675     * @return Whether the native ContentView has crashed.
676     */
677    public boolean isCrashed() {
678        return mContentViewCore.isCrashed();
679    }
680
681    /**
682     * @return Whether a reload happens when this ContentView is activated.
683     */
684    public boolean needsReload() {
685        return mContentViewCore.needsReload();
686    }
687
688    /**
689     * Checks whether the WebView can be zoomed in.
690     *
691     * @return True if the WebView can be zoomed in.
692     */
693    // This method uses the term 'zoom' for legacy reasons, but relates
694    // to what chrome calls the 'page scale factor'.
695    public boolean canZoomIn() {
696        return mContentViewCore.canZoomIn();
697    }
698
699    /**
700     * Checks whether the WebView can be zoomed out.
701     *
702     * @return True if the WebView can be zoomed out.
703     */
704    // This method uses the term 'zoom' for legacy reasons, but relates
705    // to what chrome calls the 'page scale factor'.
706    public boolean canZoomOut() {
707        return mContentViewCore.canZoomOut();
708    }
709
710    /**
711     * Zooms in the WebView by 25% (or less if that would result in zooming in
712     * more than possible).
713     *
714     * @return True if there was a zoom change, false otherwise.
715     */
716    // This method uses the term 'zoom' for legacy reasons, but relates
717    // to what chrome calls the 'page scale factor'.
718    public boolean zoomIn() {
719        return mContentViewCore.zoomIn();
720    }
721
722    /**
723     * Zooms out the WebView by 20% (or less if that would result in zooming out
724     * more than possible).
725     *
726     * @return True if there was a zoom change, false otherwise.
727     */
728    // This method uses the term 'zoom' for legacy reasons, but relates
729    // to what chrome calls the 'page scale factor'.
730    public boolean zoomOut() {
731        return mContentViewCore.zoomOut();
732    }
733
734    /**
735     * Resets the zoom factor of the WebView.
736     *
737     * @return True if there was a zoom change, false otherwise.
738     */
739    // This method uses the term 'zoom' for legacy reasons, but relates
740    // to what chrome calls the 'page scale factor'.
741    public boolean zoomReset() {
742        return mContentViewCore.zoomReset();
743    }
744
745    // Invokes the graphical zoom picker widget for this ContentView.
746    public void invokeZoomPicker() {
747        mContentViewCore.invokeZoomPicker();
748    }
749
750    // Unlike legacy WebView getZoomControls which returns external zoom controls,
751    // this method returns built-in zoom controls. This method is used in tests.
752    public View getZoomControlsForTest() {
753        return mContentViewCore.getZoomControlsForTest();
754    }
755
756    /**
757     * Return the current scale of the WebView
758     * @return The current scale.
759     */
760    public float getScale() {
761        return mContentViewCore.getScale();
762    }
763
764    /**
765     * If the view is ready to draw contents to the screen. In hardware mode,
766     * the initialization of the surface texture may not occur until after the
767     * view has been added to the layout. This method will return {@code true}
768     * once the texture is actually ready.
769     */
770    public boolean isReady() {
771        return mContentViewCore.isReady();
772    }
773
774    /**
775     * Returns whether or not accessibility injection is being used.
776     */
777    public boolean isInjectingAccessibilityScript() {
778        return mContentViewCore.isInjectingAccessibilityScript();
779    }
780
781    /**
782     * Enable or disable accessibility features.
783     */
784    public void setAccessibilityState(boolean state) {
785        mContentViewCore.setAccessibilityState(state);
786    }
787
788    /**
789     * Stop any TTS notifications that are currently going on.
790     */
791    public void stopCurrentAccessibilityNotifications() {
792        mContentViewCore.stopCurrentAccessibilityNotifications();
793    }
794
795    /**
796     * Inform WebKit that Fullscreen mode has been exited by the user.
797     */
798    public void exitFullscreen() {
799        mContentViewCore.exitFullscreen();
800    }
801
802    /**
803     * Return content scroll y.
804     *
805     * @return The vertical scroll position in pixels.
806     */
807    public int getContentScrollY() {
808        return mContentViewCore.computeVerticalScrollOffset();
809    }
810
811    /**
812     * Return content height.
813     *
814     * @return The height of the content in pixels.
815     */
816    public int getContentHeight() {
817        return mContentViewCore.computeVerticalScrollRange();
818    }
819
820    ///////////////////////////////////////////////////////////////////////////////////////////////
821    //              Start Implementation of ContentViewCore.InternalAccessDelegate               //
822    ///////////////////////////////////////////////////////////////////////////////////////////////
823
824    @Override
825    public boolean super_onKeyUp(int keyCode, KeyEvent event) {
826        return super.onKeyUp(keyCode, event);
827    }
828
829    @Override
830    public boolean super_dispatchKeyEventPreIme(KeyEvent event) {
831        return super.dispatchKeyEventPreIme(event);
832    }
833
834    @Override
835    public boolean super_dispatchKeyEvent(KeyEvent event) {
836        return super.dispatchKeyEvent(event);
837    }
838
839    @Override
840    public boolean super_onGenericMotionEvent(MotionEvent event) {
841        return super.onGenericMotionEvent(event);
842    }
843
844    @Override
845    public void super_onConfigurationChanged(Configuration newConfig) {
846        super.onConfigurationChanged(newConfig);
847    }
848
849    @Override
850    public boolean super_awakenScrollBars(int startDelay, boolean invalidate) {
851        return super.awakenScrollBars(startDelay, invalidate);
852    }
853
854    ///////////////////////////////////////////////////////////////////////////////////////////////
855    //                End Implementation of ContentViewCore.InternalAccessDelegate               //
856    ///////////////////////////////////////////////////////////////////////////////////////////////
857}
858